|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Manages user preferences stored as key-value pairs.
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 |
public static final String PREF_APP_WIDTH
public static final String PREF_APP_HEIGHT
public static final String PREF_APP_POS_X
public static final String PREF_APP_POS_Y
Method Detail |
public void saveFrameSize(JFrame frame)
frame
- JFramepublic void setFrameSize(JFrame frame)
frame
- JFramepublic void saveFrameLocation(JFrame frame)
frame
- JFramepublic void setFrameLocation(JFrame frame)
frame
- JFramepublic List getPreferenceKeys()
public void savePreferences(File prefFile, String header) throws FileNotFoundException, IOException
prefFile
- Fileheader
- String
FileNotFoundException
IOException
public void savePreferences(File prefFile) throws FileNotFoundException, IOException
prefFile
- File
FileNotFoundException
IOException
public String getDefaultPreferencesHeader()
This method may return null if the default header has not been set.
public void setDefaultPreferencesHeader(String header)
public void loadPreferences(File prefFile) throws FileNotFoundException, IOException
prefFile
- File
FileNotFoundException
IOException
public String getPreference(String key)
If the key does not exist, the returned value is null.
key
- String
public String getPreference(String key, String defaultValue)
If the key does not exist, the returned value is the defaultValue.
key
- StringdefaultValue
- String
public int getIntValue(String key)
If the key does not exist, 0 is returned.
key
- String
public void setIntValue(String key, int value)
key
- Stringvalue
- intpublic float getFloatValue(String key)
If the key does not exist, 0 is returned.
key
- String
public void setFloatValue(String key, float value)
key
- Stringvalue
- floatpublic double getDoubleValue(String key)
If the key does not exist, 0 is returned.
key
- String
public void setDoubleValue(String key, double value)
key
- Stringvalue
- doublepublic boolean getBooleanValue(String key)
If the key does not exist, false is returned.
key
- String
public void setBooleanValue(String key, boolean value)
key
- Stringvalue
- booleanpublic Color getColorValue(String key)
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.
key
- String
public void setColorValue(String key, Color colorValue)
key
- StringcolorValue
- Colorpublic void setPreference(String key, Object value)
The value cannot be null.
key
- Stringvalue
- Objectpublic File getPreferenceFile(String folder, String filename) throws IOException
If the folder does not exist, it will be created.
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.
IOException
public File getPreferenceFile() throws IOException
If the folder does not exist, it will be created.
This method will use the default folder and default filename.
IOException
public String getDefaultPrefsFolder()
public String getDefaultPrefsFilename()
public boolean isPreferenceAvailable(String key)
public void addPreferencesChangeListener(PreferencesListener listener)
listener
- PreferencesListenerpublic void removePreferencesChangeListener(PreferencesListener listener)
listener
- PreferencesListener
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |