org.yasl.arch.prefs
Interface PreferencesManager

All Known Implementing Classes:
PreferencesManagerImpl

public interface PreferencesManager

Manages user preferences stored as key-value pairs.

Version:
1.0
Author:
Jeff Chapman

Field Summary
static String PREF_APP_HEIGHT
          Preference key for application height.
static String PREF_APP_POS_X
          Preference key for application x position.
static String PREF_APP_POS_Y
          Preference key for application y position.
static String PREF_APP_WIDTH
          Preference key for application width.
 
Method Summary
 void addPreferencesChangeListener(PreferencesListener listener)
          Adds a preferences listener to the manager.
 boolean getBooleanValue(String key)
          Convenience method for transforming a value to a boolean.
 Color getColorValue(String key)
          Convenience method for transforming a value to a Color.
 String getDefaultPreferencesHeader()
          Returns the value to be placed at the top of the preferences file as a comment.
 String getDefaultPrefsFilename()
          Returns the default name of the file to hold user preferences.
 String getDefaultPrefsFolder()
          Returns the default name of the folder that will hold app config files in the user's home directory.
 double getDoubleValue(String key)
          Convenience method for transforming a value to a double.
 float getFloatValue(String key)
          Convenience method for transforming a value to a float.
 int getIntValue(String key)
          Convenience method for transforming a value to an int.
 String getPreference(String key)
          Returns the value associated with the key.
 String getPreference(String key, String defaultValue)
          Returns the value associated with the key.
 File getPreferenceFile()
          Utility method for creating a file object using the user's home folder.
 File getPreferenceFile(String folder, String filename)
          Utility method for creating a file object using the user's home folder.
 List getPreferenceKeys()
          Returns list of the preference keys.
 boolean isPreferenceAvailable(String key)
          Returns true if the key is mapped in the preferences.
 void loadPreferences(File prefFile)
          Populate the preferences from the specified properties file.
 void removePreferencesChangeListener(PreferencesListener listener)
          Removes a preferences listener from the manager.
 void saveFrameLocation(JFrame frame)
          Saves the frame location in the preferences.
 void saveFrameSize(JFrame frame)
          Saves the frame size in the preferences.
 void savePreferences(File prefFile)
          Saves the preferences to the properties file specified.
 void savePreferences(File prefFile, String header)
          Saves the preferences to the properties file specified.
 void setBooleanValue(String key, boolean value)
          Convenience method for setting a boolean preference.
 void setColorValue(String key, Color colorValue)
          Convenience method for setting a Color preference.
 void setDefaultPreferencesHeader(String header)
          Sets the value to be placed at the top of the preferences file as a comment.
 void setDoubleValue(String key, double value)
          Convenience method for setting double preferences.
 void setFloatValue(String key, float value)
          Convenience method for setting float values.
 void setFrameLocation(JFrame frame)
          Sets the size of the location of the frame based on the values set in the preferences.
 void setFrameSize(JFrame frame)
          Sets the size of the frame based on the values set in the preferences.
 void setIntValue(String key, int value)
          Convenience method for setting an int value.
 void setPreference(String key, Object value)
          Sets the value to be associated with the passed key.
 

Field Detail

PREF_APP_WIDTH

public static final String PREF_APP_WIDTH
Preference key for application width.

See Also:
Constant Field Values

PREF_APP_HEIGHT

public static final String PREF_APP_HEIGHT
Preference key for application height.

See Also:
Constant Field Values

PREF_APP_POS_X

public static final String PREF_APP_POS_X
Preference key for application x position.

See Also:
Constant Field Values

PREF_APP_POS_Y

public static final String PREF_APP_POS_Y
Preference key for application y position.

See Also:
Constant Field Values
Method Detail

saveFrameSize

public void saveFrameSize(JFrame frame)
Saves the frame size in the preferences.

Parameters:
frame - JFrame

setFrameSize

public void setFrameSize(JFrame frame)
Sets the size of the frame based on the values set in the preferences.

Parameters:
frame - JFrame

saveFrameLocation

public void saveFrameLocation(JFrame frame)
Saves the frame location in the preferences.

Parameters:
frame - JFrame

setFrameLocation

public void setFrameLocation(JFrame frame)
Sets the size of the location of the frame based on the values set in the preferences.

Parameters:
frame - JFrame

getPreferenceKeys

public List getPreferenceKeys()
Returns list of the preference keys.

Returns:
List

savePreferences

public void savePreferences(File prefFile,
                            String header)
                     throws FileNotFoundException,
                            IOException
Saves the preferences to the properties file specified. The header value will be placed at the top of the file as a comment.

Parameters:
prefFile - File
header - String
Throws:
FileNotFoundException
IOException

savePreferences

public void savePreferences(File prefFile)
                     throws FileNotFoundException,
                            IOException
Saves the preferences to the properties file specified.

Parameters:
prefFile - File
Throws:
FileNotFoundException
IOException

getDefaultPreferencesHeader

public String getDefaultPreferencesHeader()
Returns the value to be placed at the top of the preferences file as a comment.

This method may return null if the default header has not been set.

Returns:
String

setDefaultPreferencesHeader

public void setDefaultPreferencesHeader(String header)
Sets the value to be placed at the top of the preferences file as a comment.

Returns:
String

loadPreferences

public void loadPreferences(File prefFile)
                     throws FileNotFoundException,
                            IOException
Populate the preferences from the specified properties file.

Parameters:
prefFile - File
Throws:
FileNotFoundException
IOException

getPreference

public String getPreference(String key)
Returns the value associated with the key.

If the key does not exist, the returned value is null.

Parameters:
key - String
Returns:
String

getPreference

public String getPreference(String key,
                            String defaultValue)
Returns the value associated with the key.

If the key does not exist, the returned value is the defaultValue.

Parameters:
key - String
defaultValue - String
Returns:
String

getIntValue

public int getIntValue(String key)
Convenience method for transforming a value to an int.

If the key does not exist, 0 is returned.

Parameters:
key - String
Returns:
int

setIntValue

public void setIntValue(String key,
                        int value)
Convenience method for setting an int value.

Parameters:
key - String
value - int

getFloatValue

public float getFloatValue(String key)
Convenience method for transforming a value to a float.

If the key does not exist, 0 is returned.

Parameters:
key - String
Returns:
float

setFloatValue

public void setFloatValue(String key,
                          float value)
Convenience method for setting float values.

Parameters:
key - String
value - float

getDoubleValue

public double getDoubleValue(String key)
Convenience method for transforming a value to a double.

If the key does not exist, 0 is returned.

Parameters:
key - String
Returns:
double

setDoubleValue

public void setDoubleValue(String key,
                           double value)
Convenience method for setting double preferences.

Parameters:
key - String
value - double

getBooleanValue

public boolean getBooleanValue(String key)
Convenience method for transforming a value to a boolean.

If the key does not exist, false is returned.

Parameters:
key - String
Returns:
boolean

setBooleanValue

public void setBooleanValue(String key,
                            boolean value)
Convenience method for setting a boolean preference.

Parameters:
key - String
value - boolean

getColorValue

public Color getColorValue(String key)
Convenience method for transforming a value to a Color.

The color should be encoded in the following format: R,G,B. For example: 23,44,8

If the key does not exist, null is returned.

Parameters:
key - String
Returns:
Color

setColorValue

public void setColorValue(String key,
                          Color colorValue)
Convenience method for setting a Color preference.

Parameters:
key - String
colorValue - Color

setPreference

public void setPreference(String key,
                          Object value)
Sets the value to be associated with the passed key.

The value cannot be null.

Parameters:
key - String
value - Object

getPreferenceFile

public File getPreferenceFile(String folder,
                              String filename)
                       throws IOException
Utility method for creating a file object using the user's home folder.

If the folder does not exist, it will be created.

Parameters:
folder - String -- The name of the folder that will hold app config files in the user's home directory.
filename - String -- The name of the file to hold user preferences.
Returns:
File
Throws:
IOException

getPreferenceFile

public File getPreferenceFile()
                       throws IOException
Utility method for creating a file object using the user's home folder.

If the folder does not exist, it will be created.

This method will use the default folder and default filename.

Returns:
File
Throws:
IOException

getDefaultPrefsFolder

public String getDefaultPrefsFolder()
Returns the default name of the folder that will hold app config files in the user's home directory.

Returns:
String

getDefaultPrefsFilename

public String getDefaultPrefsFilename()
Returns the default name of the file to hold user preferences.

Returns:
String

isPreferenceAvailable

public boolean isPreferenceAvailable(String key)
Returns true if the key is mapped in the preferences.

Returns:
boolean

addPreferencesChangeListener

public void addPreferencesChangeListener(PreferencesListener listener)
Adds a preferences listener to the manager. The listener will be notified when a preference changes.

Parameters:
listener - PreferencesListener

removePreferencesChangeListener

public void removePreferencesChangeListener(PreferencesListener listener)
Removes a preferences listener from the manager.

Parameters:
listener - PreferencesListener