bibliothek.extension.gui.dock.preference
Class MergedPreferenceModel

java.lang.Object
  extended by bibliothek.extension.gui.dock.preference.AbstractPreferenceModel
      extended by bibliothek.extension.gui.dock.preference.MergedPreferenceModel
All Implemented Interfaces:
PreferenceModel

public class MergedPreferenceModel
extends AbstractPreferenceModel

A preference model that envelops other models and uses their preferences. This model makes use of a PathCombiner to create unique identifiers for all preferences of its sub-models.

Author:
Benjamin Sigg

Nested Class Summary
protected static class MergedPreferenceModel.Index
          Describes an index in one of the childen of a MergedPreferenceModel.
 
Constructor Summary
MergedPreferenceModel(DockController controller)
          Creates a new model
MergedPreferenceModel(PathCombiner combiner, DockController controller)
          Creates a new path.
 
Method Summary
 void add(PreferenceModel model, Path path)
          Adds model at the end of this model.
 void addPreferenceModelListener(PreferenceModelListener listener)
          Adds a listener to this model.
 void clear()
          Removes all children from this model.
 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.
 PreferenceModel getModel(int index)
          Gets the index'th model of this merged model.
 PreferenceModel getModel(Path path)
          Gets the model which was stored using the key path.
 Path getPath(int index)
          Gets the unique identifier of the index'th preference of this model.
 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.
protected  MergedPreferenceModel.Index indexAt(int globalIndex)
          Gets the model and the index that globalIndex describe in this model.
protected  int indexAt(PreferenceModel model, int index)
          Finds the global index if index is part of model.
 int indexOf(Path path)
          Gets the index of path.
 int indexOf(PreferenceModel model)
          Gets the index of model.
 void insert(int index, PreferenceModel model, Path path)
          Inserts a new submodel into this model.
 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 model of this merged model.
 void remove(MergedPreferenceModel model)
          Removes model from this merged model.
 void remove(Path path)
          Removes the model with the path path.
 void removePreferenceModelListener(PreferenceModelListener listener)
          Removes a listener from 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
doOperation, firePreferenceAdded, firePreferenceChanged, firePreferenceRemoved, getController, getOperations, hasListeners, isEnabled, listeners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MergedPreferenceModel

public MergedPreferenceModel(DockController controller)
Creates a new model

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

MergedPreferenceModel

public MergedPreferenceModel(PathCombiner combiner,
                             DockController controller)
Creates a new path.

Parameters:
combiner - tells how to combine the path of a model and of its preferences in getPath(int). Not null.
controller - the controller in whose realm this model is used
Method Detail

add

public void add(PreferenceModel model,
                Path path)
Adds model at the end of this model.

Parameters:
model - the additional model
path - the location of the new model
See Also:
insert(int, PreferenceModel, Path)

insert

public void insert(int index,
                   PreferenceModel model,
                   Path path)
Inserts a new submodel into this model.

Parameters:
index - the location of the new model
model - the new model
path - the path of the new model, the path must be unique compared to the paths of any other model.

remove

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

Parameters:
index - the location of a child

remove

public void remove(MergedPreferenceModel model)
Removes model from this merged model.

Parameters:
model - the model to remove

remove

public void remove(Path path)
Removes the model with the path path.

Parameters:
path - some path

clear

public void clear()
Removes all children from this model.


indexOf

public int indexOf(PreferenceModel model)
Gets the index of model.

Parameters:
model - some model to search
Returns:
the index or -1 if not found

indexOf

public int indexOf(Path path)
Gets the index of path.

Parameters:
path - the path of some model
Returns:
the index or -1 if not found

getModel

public PreferenceModel getModel(int index)
Gets the index'th model of this merged model.

Parameters:
index - some index
Returns:
a child of this model

getModel

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

Parameters:
path - the path of the model
Returns:
the model or null if not found

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

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

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.

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

indexAt

protected MergedPreferenceModel.Index indexAt(int globalIndex)
Gets the model and the index that globalIndex describe in this model.

Parameters:
globalIndex - some global index
Returns:
the local index

indexAt

protected int indexAt(PreferenceModel model,
                      int index)
Finds the global index if index is part of model.

Parameters:
model - a child of this model
index - an index in model
Returns:
the global index