bibliothek.extension.gui.dock.preference
Class AbstractPreferenceModel

java.lang.Object
  extended by bibliothek.extension.gui.dock.preference.AbstractPreferenceModel
All Implemented Interfaces:
PreferenceModel
Direct Known Subclasses:
ButtonContentPreferenceModel, DefaultPreferenceModel, MergedPreferenceModel, PreferenceTreeModel

public abstract class AbstractPreferenceModel
extends java.lang.Object
implements PreferenceModel

An abstract implementation of PreferenceModel handling events and returning null in most methods.

Author:
Benjamin Sigg

Constructor Summary
AbstractPreferenceModel(DockController controller)
           
 
Method Summary
 void addPreferenceModelListener(PreferenceModelListener listener)
          Adds a listener to this model.
 void doOperation(int index, PreferenceOperation operation)
          Executes the enabled operation operation.
protected  void firePreferenceAdded(int beginIndex, int endIndex)
          Informs all listeners that some preferences were added.
protected  void firePreferenceChanged(int beginIndex, int endIndex)
          Informs all listeners that some preferences were changed.
protected  void firePreferenceRemoved(int beginIndex, int endIndex)
          Informs all listeners that some preferences were removed.
 DockController getController()
          Gets the DockController in whose realm this model is used.
 java.lang.String getDescription(int index)
          Gets a description of the index'th object.
 PreferenceOperation[] getOperations(int index)
          Gets all operations for which this model has a definition for the preference at location index.
protected  boolean hasListeners()
          Tells whether this model has listeners attached or not.
 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.
protected  PreferenceModelListener[] listeners()
          Gets a list of all listeners registered at this model.
 void read()
          Uses an unknown source to update this model and load all the preferences that are currently available.
 void removePreferenceModelListener(PreferenceModelListener listener)
          Removes a listener from this model.
 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface bibliothek.extension.gui.dock.preference.PreferenceModel
getLabel, getPath, getSize, getTypePath, getValue, getValueInfo, setValue
 

Constructor Detail

AbstractPreferenceModel

public AbstractPreferenceModel(DockController controller)
Method Detail

getController

public DockController getController()
Description copied from interface: PreferenceModel
Gets the DockController in whose realm this model is used. The controller is mainly necessary to load icons and text.

Specified by:
getController in interface PreferenceModel
Returns:
the controller in whose realm this model is used

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

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

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
Parameters:
index - some location
operation - an operation from PreferenceModel.getOperations(int)
Returns:
true if the operation is enabled, false if not

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
Parameters:
index - the location of a preference
Returns:
the list of available operations (enabled and disabled operations), can be null

doOperation

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

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

addPreferenceModelListener

public void addPreferenceModelListener(PreferenceModelListener listener)
Description copied from interface: PreferenceModel
Adds a listener to this model.

Specified by:
addPreferenceModelListener in interface PreferenceModel
Parameters:
listener - the new listener

removePreferenceModelListener

public void removePreferenceModelListener(PreferenceModelListener listener)
Description copied from interface: PreferenceModel
Removes a listener from this model.

Specified by:
removePreferenceModelListener in interface PreferenceModel
Parameters:
listener - the listener to remove.

listeners

protected PreferenceModelListener[] listeners()
Gets a list of all listeners registered at this model.

Returns:
the list of listeners

hasListeners

protected boolean hasListeners()
Tells whether this model has listeners attached or not.

Returns:
true if there are listeners

firePreferenceAdded

protected void firePreferenceAdded(int beginIndex,
                                   int endIndex)
Informs all listeners that some preferences were added.

Parameters:
beginIndex - the index of the first new preference
endIndex - the index of the last new preference

firePreferenceRemoved

protected void firePreferenceRemoved(int beginIndex,
                                     int endIndex)
Informs all listeners that some preferences were removed.

Parameters:
beginIndex - the index of the first removed preference
endIndex - the index of the last removed preference

firePreferenceChanged

protected void firePreferenceChanged(int beginIndex,
                                     int endIndex)
Informs all listeners that some preferences were changed.

Parameters:
beginIndex - the index of the first changed preference
endIndex - the index of the last changed preference

getDescription

public java.lang.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
Parameters:
index - the number of the preference
Returns:
the description, might be null, might be formated in HTML

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
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
Parameters:
index - the index of the preference to update