All pastes #919905 Raw Edit

mrcheeks

public text v1 · immutable
#919905 ·published 2008-02-27 02:05 UTC
rendered paste body
// Swing code for user settings

// the configuration panel interface
public interface IConfigurationPanel{
   public String getCategoryNode(); // "Settings/General" for example
   public void saveSettings(); // save settings
   public void loadSettings(); // load settings
   public JComponent getConfigurationPanel(); // it would be better to lazy load(if panel == null panel=newpanel;return panel)
   public String getCategoryNodeTitle(); // example Nick
   public String getPanelTitle(); // example "Nick configuration"
}

// the configuration tree node model
public ConfigurationTreeNode extends DefaultMutableTreeNode{
    private IConfigurationPanel panel;
    public ConfigurationTreeNode(IConfigurationPanel panel){
        this.panel = panel;
    }
}

// IDEAS about loading saving user settings
- We can use properties file and have a PropertiesConfigurationLoader class
PropertiesConfigurationLoader
- public static Properties loadProperties(File propertiesFile);
- public static void saveProperties(File propertiesFile, Properties properties);

- We can use java serialization

- We can use XStream and JGoodies bindings to make the job easier : Jgoodies can bind a model class to a GUI object(ie a panel)
XStream can serialize the model class to xml, read it and save it.