Class PreferenceManager
java.lang.Object
org.apache.batik.util.PreferenceManager
- Direct Known Subclasses:
XMLPreferenceManager
This class allows to manage users preferences.
Here is a short usage example:
// at application intialization
HashMap defaults = new HashMap();
defaults.put("windowSize", new Dimension(640, 480));
defaults.put("antialias", Boolean.TRUE);
PreferenceManager prefs = new PreferenceManager("application.ini", defaults);
try {
prefs.load();
} catch (IOException e) {
//
}
myApplication.setSize(prefs.getDimension("windowSize"));
myApplication.setAntialiasingOn(prefs.getBoolean("antialias"));
// later a dialog box may customize preferences
myApplication.setAntialiasingOn(antialiasCheckBox.getState());
prefs.setBoolean("antialias", antialiasCheckBox.getState());
// when leaving the application we need to save the preferences
prefs.setDimension("windowSize", myApplication.getSize());
prefs.setFiles("history", lastVisitedFileArray);
try {
prefs.save()
} catch (IOException e) {
//
}
- Version:
- $Id$
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPreferenceManager(String prefFileName) Creates a preference manager.PreferenceManager(String prefFileName, Map defaults) Creates a preference manager with a default values initialization map. -
Method Summary
Modifier and TypeMethodDescriptionbooleangetBoolean(String key) Gets a boolean preference.Retruns a Color preference.private ObjectgetDefault(String key) getDimension(String key) Returns a Dimension preference.Returns a File preference.File[]Returns an array of Files preference.floatGets a float preference.Returns a font preference.intgetInteger(String key) Gets an int preference.Returns a point preference.static StringReturns aStringrepresenting the directory wherePreferenceManagerinstances should look for preferences.getRectangle(String key) Returns a Rectangle preference.Returns a String preference.String[]getStrings(String mkey) Returns an array of String preference.protected static StringgetSystemProperty(String prop) Gets a System property if accessible.Returns an URL preference.URL[]Returns an array of URLs preference.voidload()Loads the preference file.voidsave()Saves the preference file.voidsetBoolean(String key, boolean value) Sets a boolean property.voidSets a Color preference.voidsetDimension(String key, Dimension value) Sets a Dimension preference.voidSets a File property.voidSets an array of Files property.voidSets a float property.voidSets a Font preference.voidsetInteger(String key, int value) Sets an int property.voidSets a Point preference.static voidSets aStringrepresenting the directory wherePreferenceManagerinstances should look for preferences files.voidsetRectangle(String key, Rectangle value) Sets a Rectangle preference.voidSets a String preference.voidsetStrings(String mkey, String[] values) Sets a String array preference.voidSets an URL property.voidSets an array of URLs property.
-
Field Details
-
internal
-
defaults
-
prefFileName
-
fullName
-
USER_HOME
-
USER_DIR
-
FILE_SEP
-
PREF_DIR
-
-
Constructor Details
-
PreferenceManager
Creates a preference manager.- Parameters:
prefFileName- the name of the preference file.
-
PreferenceManager
-
-
Method Details
-
getSystemProperty
-
setPreferenceDirectory
Sets aStringrepresenting the directory wherePreferenceManagerinstances should look for preferences files. The default value isnullwhich means the automatic mechanism for looking for preferences is used.- See Also:
-
getPreferenceDirectory
Returns aStringrepresenting the directory wherePreferenceManagerinstances should look for preferences.- See Also:
-
load
Loads the preference file. If the file has already been previously sucessfuly loaded or saved, it will first try to reaload it from this location. Otherwise, it will try to find the file in the following order: in the directory set bysetPreferenceDirectory(String)if it exists, in the user home directory and then in the current user directory.- Throws:
IOException- if an error occured when reading the file.- See Also:
-
save
Saves the preference file. If it has previously sucessfuly been loaded or save it will save it at the same location. In other cases it will save it in the directory set bysetPreferenceDirectory(String)if has been set and exists, otherwise in the user home directory.- Throws:
IOException- if an error occured when writing the file or if is impossible to write the file at all available locations.- See Also:
-
getDefault
-
getRectangle
-
getDimension
-
getPoint
-
getColor
-
getFont
-
getString
-
getStrings
-
getURL
-
getURLs
-
getFile
-
getFiles
-
getInteger
Gets an int preference. -
getFloat
Gets a float preference. -
getBoolean
Gets a boolean preference. If not found and no default returns false. -
setRectangle
-
setDimension
-
setPoint
-
setColor
-
setFont
-
setString
-
setStrings
-
setURL
-
setURLs
-
setFile
-
setFiles
-
setInteger
Sets an int property. -
setFloat
Sets a float property. -
setBoolean
Sets a boolean property.
-