Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.jgoodies.binding.adapter
Class PreferencesAdapter

    java.lang.Object
      com.jgoodies.common.bean.AbstractBean
          com.jgoodies.binding.beans.Model
              com.jgoodies.binding.value.AbstractValueModel
                  com.jgoodies.binding.adapter.PreferencesAdapter

All Implemented Interfaces:
  ValueModel, com.jgoodies.common.bean.ObservableBean, com.jgoodies.common.bean.ObservableBean2, Serializable

    public final class PreferencesAdapter

extends AbstractValueModel

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));

Version:
  $Revision: 1.11 $
Author:
  Karsten Lentzsch
See Also:
  `Preferences`, Serialized Form

Field Summary

Fields inherited from class com.jgoodies.binding.value.AbstractValueModel
`PROPERTYNAME_VALUE`

Fields inherited from class com.jgoodies.common.bean.AbstractBean
`changeSupport`

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.AbstractBean
`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

### PreferencesAdapter

    public 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`.

  Parameters:
    `prefs` - the `Preferences` used to store and retrieve
    `key` - the key used to get and set values in the Preferences
    `defaultValue` - the default value
  Throws:
    `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

### getValue

    public Object getValue()

  Looks up and returns the value from the preferences. The value is look up under this adapter's key. It will be converted before it is returned.

  Returns:
    the retrieved and converted value
  Throws:
    `ClassCastException` - if the type of the default value cannot be read from the preferences

### setValue

    public void setValue(Object newValue)

  Converts the given value to a string and puts it into the preferences.

  Parameters:
    `newValue` - the object to be stored
  Throws:
    `IllegalArgumentException` - if the new value cannot be stored in the preferences due to an illegal type

### getBoolean

    public boolean getBoolean()

  Looks up, converts and returns the stored value from the preferences. Returns the default value if no value has been stored before.

  Returns:
    the stored value or the default

### getDouble

    public double getDouble()

  Looks up, converts and returns the stored value from the preferences. Returns the default value if no value has been stored before.

  Returns:
    the stored value or the default

### getFloat

    public float getFloat()

  Looks up, converts and returns the stored value from the preferences. Returns the default value if no value has been stored before.

  Returns:
    the stored value or the default

### getInt

    public int getInt()

  Looks up, converts and returns the stored value from the preferences. Returns the default value if no value has been stored before.

  Returns:
    the stored value or the default

### getLong

    public long getLong()

  Looks up, converts and returns the stored value from the preferences. Returns the default value if no value has been stored before.

  Returns:
    the stored value or the default

### getString

    public String getString()

  Looks up, converts and returns the stored value from the preferences. Returns the default value if no value has been stored before.

  Overrides:
    `getString` in class `AbstractValueModel`
  Returns:
    the stored value or the default

### setBoolean

    public 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.

  Parameters:
    `newValue` - the value to put into the Preferences
  Throws:
    `ClassCastException` - if the default value is not a Boolean

### setDouble

    public 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.

  Parameters:
    `newValue` - the value to put into the Preferences
  Throws:
    `ClassCastException` - if the default value is not a Double

### setFloat

    public 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.

  Parameters:
    `newValue` - the value to put into the Preferences
  Throws:
    `ClassCastException` - if the default value is not a Float

### setInt

    public 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.

  Parameters:
    `newValue` - the value to put into the Preferences
  Throws:
    `ClassCastException` - if the default value is not an Integer

### setLong

    public 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.

  Parameters:
    `newValue` - the value to put into the Preferences
  Throws:
    `ClassCastException` - if the default value is not a Long

### setString

    public 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.

  Parameters:
    `newValue` - the value to put into the Preferences
  Throws:
    `ClassCastException` - if the default value is not a String

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2011 JGoodies Karsten Lentzsch. All Rights Reserved.