ix.iface.ui
Class JPropertiesManager

java.lang.Object
  extended by ix.iface.ui.JPropertiesManager
Direct Known Subclasses:
IDEPropertiesManager

public abstract class JPropertiesManager
extends java.lang.Object

An abstarct class for managing the properties and preferences of an application. Provides lots of generically useful things for property management, including running an editor to change properties. Abstract methods are: setDefaultProperties(Properties props) makePreferencesDialog() This used to be part of the application whose properties are to be managed; it was moved to de-clutter the application and to make mechanisms available to other applications. JPropertyManagers manage Properties for PropertyApplications. If the Properties are user editable, they work together with PropertyEditors like the JPreferenceDialogs. Here is how these classes split the work: Properties hold all values under the keys. Provided by Java. PropertyManagers look after Properties, their default values, loading/saving properties, and initiating updates to the application to make the properties take effect, and updates from the application to make sure current settings are saved. The PropertyMangers also provide links between all property-related classes. PropertyEditors, e.g. JPreferencesDialogue, build the editor window, let the user change property values (providing help where available), let the user load, save, use defaults, apply, etc. PropertyApplications get changed by the values of the properties. {\bf How to make this work:} Make your application implement the PropertiesApplication interface and write the setProperty and getProperty methods; the former sets a given property in the application which should update the application, the latter determines the current setting of the property from the application. The application name is used to work out what the default property file should be (./.prefs) Write a specific properties manager for the application that subclasses JPropertiesManager. Make this specific manager create a suitable preferences editor (see below), set default values, and the name and location of property files (overwrite the getPropertiesFile or even the getDefaultPropertiesFile method if the default ./.prefs is not suitable). Write a specific preferences editor, subclassing JPreferencesDialog and specifying how each of the properties should be edited. Remember to mark properties that cannot be edited in the properties manager using the noteNoEditable method, otherwise such preperties will be emptied when other properties are edited. {\bf Making changes} When adding a property, do the following: Edit your application's properties manager to set the default value for the property; also note in the manager if the property cannot be edited. Edit your application's getProperty and setProperty methods to include the new property. If the property is editable, add to your specific properties editor to include components for editing the new property.


Field Summary
protected  PropertiesApplication application
           
 java.util.HashSet noEditComponents
           
protected  JPreferencesDialog preferencesDialog
           
protected  java.util.Properties properties
           
 
Constructor Summary
JPropertiesManager(PropertiesApplication application)
           
 
Method Summary
 void editPreferences()
           
 JPreferencesDialog ensurePreferencesDialog()
           
 java.io.File getDefaultPropertiesFile()
          Uses the application name to build a preferences file name in the current directory.
 java.util.Properties getProperties()
           
 java.io.File getPropertiesFile()
          Specify the name of the properties file to use; set to getDefaultPropertiesFile() if you don't care.
 java.lang.String getProperty(java.lang.String key)
           
 void initProperties()
          Sets up default properties, then loads the properties from file and passes them to the application.
static boolean isBooleanProperty(java.lang.String key, java.lang.String value)
           
 boolean isEditable(java.lang.String key)
           
 java.util.Properties loadProperties()
           
 java.util.Properties loadProperties(java.util.Properties props)
           
abstract  JPreferencesDialog makePreferencesDialog()
           
 void noteNoEditable(java.lang.String property)
          If there are properties that cannot be edited here, mark them as such.
 void saveApplicationProperties()
           
 void saveProperties()
           
 void saveProperties(java.util.Properties properties)
           
abstract  void setDefaultProperties(java.util.Properties props)
          Sets the default properties for the application into the given properties object; application specific.
 void setProperty(java.lang.String key, java.lang.String value)
           
 void updateApplicationFromProperties()
           
 void updateApplicationFromProperties(PropertiesApplication app)
           
 void updatePropertiesFromApplication()
           
 void updatePropertiesFromApplication(PropertiesApplication app)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

application

protected PropertiesApplication application

properties

protected java.util.Properties properties

preferencesDialog

protected JPreferencesDialog preferencesDialog

noEditComponents

public java.util.HashSet noEditComponents
Constructor Detail

JPropertiesManager

public JPropertiesManager(PropertiesApplication application)
Method Detail

setDefaultProperties

public abstract void setDefaultProperties(java.util.Properties props)
Sets the default properties for the application into the given properties object; application specific.


makePreferencesDialog

public abstract JPreferencesDialog makePreferencesDialog()

noteNoEditable

public void noteNoEditable(java.lang.String property)
If there are properties that cannot be edited here, mark them as such. Otherwise they will be emptied! (must allow user to set props to "").


isEditable

public boolean isEditable(java.lang.String key)

getPropertiesFile

public java.io.File getPropertiesFile()
Specify the name of the properties file to use; set to getDefaultPropertiesFile() if you don't care.


getProperties

public java.util.Properties getProperties()

getProperty

public java.lang.String getProperty(java.lang.String key)

setProperty

public void setProperty(java.lang.String key,
                        java.lang.String value)

editPreferences

public void editPreferences()

ensurePreferencesDialog

public JPreferencesDialog ensurePreferencesDialog()

getDefaultPropertiesFile

public java.io.File getDefaultPropertiesFile()
Uses the application name to build a preferences file name in the current directory.


initProperties

public void initProperties()
Sets up default properties, then loads the properties from file and passes them to the application.


saveProperties

public void saveProperties()

saveProperties

public void saveProperties(java.util.Properties properties)

loadProperties

public java.util.Properties loadProperties()

loadProperties

public java.util.Properties loadProperties(java.util.Properties props)

saveApplicationProperties

public void saveApplicationProperties()

updateApplicationFromProperties

public void updateApplicationFromProperties()

updateApplicationFromProperties

public void updateApplicationFromProperties(PropertiesApplication app)

updatePropertiesFromApplication

public void updatePropertiesFromApplication()

updatePropertiesFromApplication

public void updatePropertiesFromApplication(PropertiesApplication app)

isBooleanProperty

public static boolean isBooleanProperty(java.lang.String key,
                                        java.lang.String value)