|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jgoodies.common.bean.Bean
com.jgoodies.binding.beans.Model
com.jgoodies.binding.value.AbstractValueModel
com.jgoodies.binding.adapter.PreferencesAdapter
public final class PreferencesAdapter
A ValueModel implementation that reads and writes values from/to a key
of a given 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
,
Serialized FormField Summary |
---|
Fields inherited from class com.jgoodies.common.bean.Bean |
---|
changeSupport |
Fields inherited from interface com.jgoodies.binding.value.ValueModel |
---|
PROPERTY_VALUE |
Constructor Summary | |
---|---|
PreferencesAdapter(Preferences prefs,
String key,
Object defaultValue)
Constructs a PreferencesAdapter on the given Preferences
using the specified key and default value, all which must be
non-null . |
Method Summary | |
---|---|
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. |
String |
getString()
Looks up, converts and returns the stored value from the preferences. |
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(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(Object newValue)
Converts the given value to a string and puts it into the preferences. |
Methods inherited from class com.jgoodies.binding.value.AbstractValueModel |
---|
addValueChangeListener, booleanValue, doubleValue, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, floatValue, intValue, longValue, paramString, removeValueChangeListener, setValue, setValue, setValue, setValue, setValue, toString, valueString |
Methods inherited from class com.jgoodies.binding.beans.Model |
---|
createPropertyChangeSupport, firePropertyChange |
Methods inherited from class com.jgoodies.common.bean.Bean |
---|
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, fireMultiplePropertiesChanged, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public PreferencesAdapter(Preferences prefs, String key, 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 value
NullPointerException
- if the Preferences, key, or default value
is null
IllegalArgumentException
- if the default value is of a type other
than Boolean, Double, Float, Integer, Long, or String.Method Detail |
---|
public Object getValue()
ClassCastException
- if the type of the default value
cannot be read from the preferencespublic void setValue(Object newValue)
newValue
- the object to be stored
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 String getString()
getString
in class AbstractValueModel
public void setBoolean(boolean newValue)
newValue
- the value to put into the Preferences
ClassCastException
- if the default value is not a Booleanpublic void setDouble(double newValue)
newValue
- the value to put into the Preferences
ClassCastException
- if the default value is not a Doublepublic void setFloat(float newValue)
newValue
- the value to put into the Preferences
ClassCastException
- if the default value is not a Floatpublic void setInt(int newValue)
newValue
- the value to put into the Preferences
ClassCastException
- if the default value is not an Integerpublic void setLong(long newValue)
newValue
- the value to put into the Preferences
ClassCastException
- if the default value is not a Longpublic void setString(String newValue)
newValue
- the value to put into the Preferences
ClassCastException
- if the default value is not a String
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |