public final class PreferencesAdapter extends AbstractValueModel
Preferences
node under a specified key.
Write changes fire value changes.Example:
String prefsKey = "isShowing"; Boolean defaultValue = Boolean.TRUE; Preferences prefs = Workbench.userPreferences(); ValueModel model = new PreferencesAdapter(prefs, prefsKey, defaultValue); JCheckBox showingBox = new JCheckBox("Show tips"); showingBox.setModel(new ToggleButtonAdapter(model));
Preferences
PROPERTYNAME_VALUE
Constructor and Description |
---|
PreferencesAdapter(java.util.prefs.Preferences prefs,
java.lang.String key,
java.lang.Object defaultValue)
Constructs a PreferencesAdapter on the given
Preferences
using the specified key and default value, all which must be
non-null . |
Modifier and Type | Method and Description |
---|---|
boolean |
getBoolean()
Looks up, converts and returns the stored value from the preferences.
|
double |
getDouble()
Looks up, converts and returns the stored value from the preferences.
|
float |
getFloat()
Looks up, converts and returns the stored value from the preferences.
|
int |
getInt()
Looks up, converts and returns the stored value from the preferences.
|
long |
getLong()
Looks up, converts and returns the stored value from the preferences.
|
java.lang.String |
getString()
Looks up, converts and returns the stored value from the preferences.
|
java.lang.Object |
getValue()
Looks up and returns the value from the preferences.
|
void |
setBoolean(boolean newValue)
Converts the given value to an Object and stores it in this
adapter's Preferences under this adapter's preferences key.
|
void |
setDouble(double newValue)
Converts the given value to an Object and stores it in this
adapter's Preferences under this adapter's preferences key.
|
void |
setFloat(float newValue)
Converts the given value to an Object and stores it in this
adapter's Preferences under this adapter's preferences key.
|
void |
setInt(int newValue)
Converts the given value to an Object and stores it in this
adapter's Preferences under this adapter's preferences key.
|
void |
setLong(long newValue)
Converts the given value to an Object and stores it in this
adapter's Preferences under this adapter's preferences key.
|
void |
setString(java.lang.String newValue)
Converts the given value to an Object and stores it in this
adapter's Preferences under this adapter's preferences key.
|
void |
setValue(java.lang.Object newValue)
Converts the given value to a string and puts it into the preferences.
|
addValueChangeListener, booleanValue, doubleValue, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, floatValue, intValue, longValue, paramString, removeValueChangeListener, setValue, setValue, setValue, setValue, setValue, toString, valueString
createPropertyChangeSupport, firePropertyChange
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addPropertyChangeListener, removePropertyChangeListener
public PreferencesAdapter(java.util.prefs.Preferences prefs, java.lang.String key, java.lang.Object defaultValue)
Preferences
using the specified key and default value, all which must be
non-null
.prefs
- the Preferences
used to store and retrievekey
- the key used to get and set values in the PreferencesdefaultValue
- the default valuejava.lang.NullPointerException
- if the Preferences, key, or default value
is null
java.lang.IllegalArgumentException
- if the default value is of a type other
than Boolean, Double, Float, Integer, Long, or String.public java.lang.Object getValue()
java.lang.ClassCastException
- if the type of the default value
cannot be read from the preferencespublic void setValue(java.lang.Object newValue)
newValue
- the object to be storedjava.lang.IllegalArgumentException
- if the new value cannot be stored
in the preferences due to an illegal typepublic boolean getBoolean()
public double getDouble()
public float getFloat()
public int getInt()
public long getLong()
public java.lang.String getString()
getString
in class AbstractValueModel
public void setBoolean(boolean newValue)
newValue
- the value to put into the Preferencesjava.lang.ClassCastException
- if the default value is not a Booleanpublic void setDouble(double newValue)
newValue
- the value to put into the Preferencesjava.lang.ClassCastException
- if the default value is not a Doublepublic void setFloat(float newValue)
newValue
- the value to put into the Preferencesjava.lang.ClassCastException
- if the default value is not a Floatpublic void setInt(int newValue)
newValue
- the value to put into the Preferencesjava.lang.ClassCastException
- if the default value is not an Integerpublic void setLong(long newValue)
newValue
- the value to put into the Preferencesjava.lang.ClassCastException
- if the default value is not a Longpublic void setString(java.lang.String newValue)
newValue
- the value to put into the Preferencesjava.lang.ClassCastException
- if the default value is not a StringCopyright © 2002-2010 JGoodies Karsten Lentzsch. All Rights Reserved.