bibliothek.extension.gui.dock.preference
Class PreferenceTreeModel

java.lang.Object
  extended by bibliothek.extension.gui.dock.preference.AbstractPreferenceModel
      extended by bibliothek.extension.gui.dock.preference.PreferenceTreeModel
All Implemented Interfaces:
PreferenceModel, TreeModel
Direct Known Subclasses:
CPreferenceModel, DockingFramesPreference

public class PreferenceTreeModel
extends AbstractPreferenceModel
implements TreeModel

A PreferenceModel that is also a TreeModel. It contains other PreferenceModels and organizes them in a tree. The nodes of this TreeModel are of the type PreferenceTreeModel.Node. The root of this model never has a name nor a model.

Author:
Benjamin Sigg

Nested Class Summary
static interface PreferenceTreeModel.Node
          A single node of a PreferenceTreeModel.
 
Constructor Summary
PreferenceTreeModel(DockController controller)
          Creates a new empty model.
PreferenceTreeModel(PathCombiner combiner, DockController controller)
          Creates a new empty model.
 
Method Summary
 void addPreferenceModelListener(PreferenceModelListener listener)
          Adds a listener to this model.
 void addTreeModelListener(TreeModelListener l)
           
 void delete(Path path)
          Deletes the node at path and all its children from the tree.
 void doOperation(int index, PreferenceOperation operation)
          Executes the enabled operation operation.
 PreferenceTreeModel.Node getChild(Object parent, int index)
           
 int getChildCount(Object parent)
           
 String getDescription(int index)
          Gets a description of the index'th object.
 int getIndexOfChild(Object parent, Object child)
           
 String getLabel(int index)
          Gets a short label that can be presented to the user for the index'th object.
 PreferenceModel getModel(Path path)
          Gets the model which was stored using path as key.
 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.
 PreferenceTreeModel.Node getRoot()
           
 int getSize()
          Gets the number of preferences stored in this model.
protected  TreeModelListener[] getTreeModelListeners()
          Gets all the listeners currently known to 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.
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 isLeaf(Object node)
           
 boolean isNatural(int index)
          Tells whether the index'th preference is natural or artificial.
 void put(Path path, String name, PreferenceModel model)
          Sets name and model of a given node.
 void putLinked(Path path, String nameId)
          Sets the name of the node at path.
 void putLinked(Path path, String nameId, PreferenceModel model)
          Sets name and model of a given node.
 void putModel(Path path, PreferenceModel model)
          Sets the model of the node at path.
 void putNode(Path path, String name)
          Sets the name of the node at path.
 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 removeTreeModelListener(TreeModelListener l)
           
 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 valueForPathChanged(TreePath path, Object newValue)
           
 void write()
          Writes the current preferences to the location where they are used.
 
Methods inherited from class bibliothek.extension.gui.dock.preference.AbstractPreferenceModel
firePreferenceAdded, firePreferenceChanged, firePreferenceRemoved, getController, listeners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PreferenceTreeModel

public PreferenceTreeModel(DockController controller)
Creates a new empty model.

Parameters:
controller - the controller in whose realm this model is used

PreferenceTreeModel

public PreferenceTreeModel(PathCombiner combiner,
                           DockController controller)
Creates a new empty model.

Parameters:
combiner - tells how to combine the Path of a model with the preferences of a model. Used in getPath(int). Not null.
controller - the controller in whose realm this model is used
See Also:
MergedPreferenceModel.MergedPreferenceModel(PathCombiner, DockController)
Method Detail

hasListeners

protected boolean hasListeners()
Description copied from class: AbstractPreferenceModel
Tells whether this model has listeners attached or not.

Overrides:
hasListeners in class AbstractPreferenceModel
Returns:
true if there are listeners

addTreeModelListener

public void addTreeModelListener(TreeModelListener l)
Specified by:
addTreeModelListener in interface TreeModel

addPreferenceModelListener

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

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

removeTreeModelListener

public void removeTreeModelListener(TreeModelListener l)
Specified by:
removeTreeModelListener in interface TreeModel

removePreferenceModelListener

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

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

getTreeModelListeners

protected TreeModelListener[] getTreeModelListeners()
Gets all the listeners currently known to this model.

Returns:
the list of listeners

getChild

public PreferenceTreeModel.Node getChild(Object parent,
                                         int index)
Specified by:
getChild in interface TreeModel

getChildCount

public int getChildCount(Object parent)
Specified by:
getChildCount in interface TreeModel

getIndexOfChild

public int getIndexOfChild(Object parent,
                           Object child)
Specified by:
getIndexOfChild in interface TreeModel

getRoot

public PreferenceTreeModel.Node getRoot()
Specified by:
getRoot in interface TreeModel

isLeaf

public boolean isLeaf(Object node)
Specified by:
isLeaf in interface TreeModel

valueForPathChanged

public void valueForPathChanged(TreePath path,
                                Object newValue)
Specified by:
valueForPathChanged in interface TreeModel

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

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

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

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

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.

Specified by:
getLabel in interface PreferenceModel
Parameters:
index - the number the preference
Returns:
a short human readable description

getPath

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

Specified by:
getPath in interface PreferenceModel
Parameters:
index - the index of the preference
Returns:
the unique path, compared to the other paths of this model

getSize

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

Specified by:
getSize in interface PreferenceModel
Returns:
the number of preferences

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.

Specified by:
getTypePath in interface PreferenceModel
Parameters:
index - the number of the value
Returns:
a unique path for the type of this value

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

Specified by:
getValueInfo in interface PreferenceModel
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.

Specified by:
getValue in interface PreferenceModel
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.

Specified by:
setValue in interface PreferenceModel
Parameters:
index - the number of the preference
value - the new value, may be null

putNode

public void putNode(Path path,
                    String name)
Sets the name of the node at path. If there is no such node, then the node and all its parents are created. Otherwise just the name gets exchanged.

Parameters:
path - the path to the node
name - the new name of the node

putLinked

public void putLinked(Path path,
                      String nameId)
Sets the name of the node at path. If there is no such node, then the node and all its parents are created. Otherwise just the name gets exchanged.

Parameters:
path - the path to the node
nameId - the new name, an identifier used for the TextManager

putModel

public void putModel(Path path,
                     PreferenceModel model)
Sets the model of the node at path. If there is no such node, then the node and all its parents are created. Otherwise just the model gets exchanged.

Parameters:
path - the path to change
model - the new model

put

public void put(Path path,
                String name,
                PreferenceModel model)
Sets name and model of a given node.

Parameters:
path - the path to the node
name - the new name
model - the new model, can be null
See Also:
putLinked(Path, String, PreferenceModel), putNode(Path, String), putModel(Path, PreferenceModel)

putLinked

public void putLinked(Path path,
                      String nameId,
                      PreferenceModel model)
Sets name and model of a given node.

Parameters:
path - the path to the node
nameId - the new name, an identifier used for a TextManager.
model - the new model, can be null

getModel

public PreferenceModel getModel(Path path)
Gets the model which was stored using path as key.

Parameters:
path - the key of some model
Returns:
the model or null

delete

public void delete(Path path)
Deletes the node at path and all its children from the tree. This also removes any PreferenceModel of the subtree. If there is no node at path, then nothing happens

Parameters:
path - the path to remove