Package org.apache.batik.util
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) {
//
}
-
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.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
-
-
Constructor Details
-
PreferenceManager
Creates a preference manager.- Parameters:
prefFileName- the name of the preference file.
-
PreferenceManager
Creates a preference manager with a default values initialization map.- Parameters:
prefFileName- the name of the preference file.defaults- where to get defaults value if the value is not specified in the file.
-
-
Method Details
-
getSystemProperty
Gets a System property if accessible. Returns an empty string otherwise -
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. -
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(java.lang.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(java.lang.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:
-
getRectangle
Returns a Rectangle preference. -
getDimension
Returns a Dimension preference. -
getPoint
Returns a point preference. -
getColor
Retruns a Color preference. -
getFont
Returns a font preference. -
getString
Returns a String preference. -
getStrings
Returns an array of String preference. -
getURL
Returns an URL preference. -
getURLs
Returns an array of URLs preference. -
getFile
Returns a File preference. -
getFiles
Returns an array of Files preference. -
getInteger
Gets an int preference. -
getFloat
Gets a float preference. -
getBoolean
Gets a boolean preference. If not found and no default returns false. -
setRectangle
Sets a Rectangle preference. If null removes it. -
setDimension
Sets a Dimension preference. If null removes it. -
setPoint
Sets a Point preference. If null removes it. -
setColor
Sets a Color preference. If null removes it. -
setFont
Sets a Font preference. If null removes it. -
setString
Sets a String preference. If null removes it. -
setStrings
Sets a String array preference. If null or size null removes previous preference. -
setURL
Sets an URL property. If null removes it. -
setURLs
Sets an array of URLs property. If null or size null removes previous preference. -
setFile
Sets a File property. If null removes it. -
setFiles
Sets an array of Files property. If null or size null removes previous preference. -
setInteger
Sets an int property. -
setFloat
Sets a float property. -
setBoolean
Sets a boolean property.
-