bibliothek.extension.gui.dock.preference
Class DefaultPreferenceModel

java.lang.Object
  extended by bibliothek.extension.gui.dock.preference.AbstractPreferenceModel
      extended by bibliothek.extension.gui.dock.preference.DefaultPreferenceModel
All Implemented Interfaces:
PreferenceModel
Direct Known Subclasses:
BubbleThemePreferenceModel, CKeyStrokePreferenceModel, CLayoutPreferenceModel, EclipseThemePreferenceModel, KeyStrokePreferenceModel, LayoutPreferenceModel

public class DefaultPreferenceModel
extends AbstractPreferenceModel

An implementation of PreferenceModel using Preferences to describe its entries.

Author:
Benjamin Sigg

Constructor Summary
DefaultPreferenceModel()
           
 
Method Summary
 void add(Preference<?> preference)
          Adds preference at the end of this model.
 void doOperation(int index, PreferenceOperation operation)
          Executes the enabled operation operation.
 String getDescription(int index)
          Gets a description of the index'th object.
 String getLabel(int index)
          Gets a short label that can be presented to the user for the index'th object.
 PreferenceOperation[] getOperations(int index)
          Gets all operations for which this model has a definition for the preference at location index.
 Path getPath(int index)
          Gets the unique identifier of the index'th preference of this model.
 Preference<?> getPreference(int index)
          Gets the preference of location index.
 int getSize()
          Gets the number of preferences stored in this model.
 Path getTypePath(int index)
          Tells what kind of type the index'th value is.
 Object getValue(int index)
          Gets the index'th preference.
 Object getValueInfo(int index)
          Gets information about how the index'th value can be modified.
 int indexOf(Preference<?> preference)
          Gets the location of preference.
 void insert(int index, Preference<?> preference)
          Adds a new preference to this model.
 boolean isEnabled(int index, PreferenceOperation operation)
          Tells whether the operation operation is enabled for the preference at location index.
 boolean isNatural(int index)
          Tells whether the index'th preference is natural or artificial.
 void read()
          Uses an unknown source to update this model and load all the preferences that are currently available.
 void remove(int index)
          Removes the index'th preference of this model.
 void remove(Preference<?> preference)
          Removes preference from this model.
 void removeAll()
          Removes all preferences of this model.
 void setValue(int index, Object value)
          Sets the value of the index'th preference.
 void setValueNatural(int index)
          Like PreferenceModel.setValue(int, Object) this method changes the value of the index'th preference.
 void write()
          Writes the current preferences to the location where they are used.
 
Methods inherited from class bibliothek.extension.gui.dock.preference.AbstractPreferenceModel
addPreferenceModelListener, firePreferenceAdded, firePreferenceChanged, firePreferenceRemoved, hasListeners, listeners, removePreferenceModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultPreferenceModel

public DefaultPreferenceModel()
Method Detail

getSize

public int getSize()
Description copied from interface: PreferenceModel
Gets the number of preferences stored in this model.

Returns:
the number of preferences

getLabel

public String getLabel(int index)
Description copied from interface: PreferenceModel
Gets a short label that can be presented to the user for the index'th object.

Parameters:
index - the number the preference
Returns:
a short human readable description

getDescription

public String getDescription(int index)
Description copied from interface: PreferenceModel
Gets a description of the index'th object. The description is a longer text that will be presented to the user.

Specified by:
getDescription in interface PreferenceModel
Overrides:
getDescription in class AbstractPreferenceModel
Parameters:
index - the number of the preference
Returns:
the description, might be null, might be formated in HTML

getValueInfo

public Object getValueInfo(int index)
Description copied from interface: PreferenceModel
Gets information about how the index'th value can be modified. For an integer that might be its upper and lower boundaries. The type of this objects depends on PreferenceModel.getTypePath(int).

Parameters:
index - the index of the info
Returns:
the information or null if no information is available

getValue

public Object getValue(int index)
Description copied from interface: PreferenceModel
Gets the index'th preference. The type path determines how the value is to be presented on the screen.

Parameters:
index - the number of the preference
Returns:
the value or maybe null, has to be immutable

setValue

public void setValue(int index,
                     Object value)
Description copied from interface: PreferenceModel
Sets the value of the index'th preference.

Parameters:
index - the number of the preference
value - the new value, may be null

getTypePath

public Path getTypePath(int index)
Description copied from interface: PreferenceModel
Tells what kind of type the index'th value is. The type is represented as a path. Most times the path would equal the name of some class. Note: there is a set of standard paths defined in Path.

Parameters:
index - the number of the value
Returns:
a unique path for the type of this value

getPath

public Path getPath(int index)
Description copied from interface: PreferenceModel
Gets the unique identifier of the index'th preference of this model.

Parameters:
index - the index of the preference
Returns:
the unique path, compared to the other paths of this model

isNatural

public boolean isNatural(int index)
Description copied from interface: PreferenceModel
Tells whether the index'th preference is natural or artificial.

Specified by:
isNatural in interface PreferenceModel
Overrides:
isNatural in class AbstractPreferenceModel
Parameters:
index - the index of the preference
Returns:
true if the preference is natural, false if it is artificial

setValueNatural

public void setValueNatural(int index)
Description copied from interface: PreferenceModel
Like PreferenceModel.setValue(int, Object) this method changes the value of the index'th preference. But this time the natural preference has to extract the value from its underlying property.

Specified by:
setValueNatural in interface PreferenceModel
Overrides:
setValueNatural in class AbstractPreferenceModel
Parameters:
index - the index of the preference to update

getPreference

public Preference<?> getPreference(int index)
Gets the preference of location index.

Parameters:
index - the location of the preference
Returns:
the preference

add

public void add(Preference<?> preference)
Adds preference at the end of this model.

Parameters:
preference - the preference to add

insert

public void insert(int index,
                   Preference<?> preference)
Adds a new preference to this model.

Parameters:
index - the location of the new preference
preference - the new preference

remove

public void remove(int index)
Removes the index'th preference of this model.

Parameters:
index - the preference to remove

remove

public void remove(Preference<?> preference)
Removes preference from this model.

Parameters:
preference - the preference to remove

removeAll

public void removeAll()
Removes all preferences of this model.


indexOf

public int indexOf(Preference<?> preference)
Gets the location of preference.

Parameters:
preference - the preference to access
Returns:
the index of preference or -1

read

public void read()
Description copied from interface: PreferenceModel
Uses an unknown source to update this model and load all the preferences that are currently available. If the underlying resource cannot be read, or returns invalid data, then this model should not change its content.

Specified by:
read in interface PreferenceModel
Overrides:
read in class AbstractPreferenceModel

write

public void write()
Description copied from interface: PreferenceModel
Writes the current preferences to the location where they are used.

Specified by:
write in interface PreferenceModel
Overrides:
write in class AbstractPreferenceModel

getOperations

public PreferenceOperation[] getOperations(int index)
Description copied from interface: PreferenceModel
Gets all operations for which this model has a definition for the preference at location index. Note: a PreferenceEditor has operations as well, if the editor and the model share an operation, then the operation is considered to belong to the editor.

Specified by:
getOperations in interface PreferenceModel
Overrides:
getOperations in class AbstractPreferenceModel
Parameters:
index - the location of a preference
Returns:
the list of available operations (enabled and disabled operations), can be null

isEnabled

public boolean isEnabled(int index,
                         PreferenceOperation operation)
Description copied from interface: PreferenceModel
Tells whether the operation operation is enabled for the preference at location index.

Specified by:
isEnabled in interface PreferenceModel
Overrides:
isEnabled in class AbstractPreferenceModel
Parameters:
index - some location
operation - an operation from PreferenceModel.getOperations(int)
Returns:
true if the operation is enabled, false if not

doOperation

public void doOperation(int index,
                        PreferenceOperation operation)
Description copied from interface: PreferenceModel
Executes the enabled operation operation.

Specified by:
doOperation in interface PreferenceModel
Overrides:
doOperation in class AbstractPreferenceModel
Parameters:
index - the location of the affected preference
operation - the operation to execute