bibliothek.extension.gui.dock.preference.preferences.choice
Class DefaultChoice<V>

java.lang.Object
  extended by bibliothek.extension.gui.dock.preference.preferences.choice.DefaultChoice<V>
Type Parameters:
V - the kind of values this choice manages
All Implemented Interfaces:
Choice
Direct Known Subclasses:
BubbleColorSchemeChoice, ButtonContentChoice, ButtonContentConditionChoice, EclipseTabChoice, TabContentFilterChoice, TabPlacementChoice, ThemeChoice

public class DefaultChoice<V>
extends java.lang.Object
implements Choice

A default implementation of Choice, provides text, id and objects for every possible choice.

Author:
Benjamin Sigg

Nested Class Summary
static interface DefaultChoice.Entry<V>
           
 
Constructor Summary
DefaultChoice(DockController controller)
          Creates a new choice, adding additional entries if there are any extensions.
 
Method Summary
 DefaultChoice.Entry<V> add(java.lang.String id, java.lang.String text, boolean textIsKey, V value)
          Adds an entry to this Choice.
 DefaultChoice.Entry<V> add(java.lang.String id, java.lang.String text, V value)
          Like add(String, String, boolean, Object) with codeIsKey set to false
 void addChoiceListener(ChoiceListener listener)
          Adds a listener to this choice.
 DefaultChoice.Entry<V> addLinked(java.lang.String id, java.lang.String text, V value)
          Like add(String, String, boolean, Object) with codeIsKey set to true
protected  boolean equals(V a, V b)
          Checks the equality of a and b.
protected  void fireInserted(int start, int end)
          Calls ChoiceListener.inserted(Choice, int, int) on all listeners that are currently known.
protected  void fireRemoved(int start, int end)
          Calls ChoiceListener.removed(Choice, int, int) on all listeners that are currently known.
protected  void fireUpdated(int start, int end)
          Calls ChoiceListener.updated(Choice, int, int) on all listeners that are currently known.
 java.lang.String getDefaultChoice()
          Gets the standard choice.
 DefaultChoice.Entry<V> getEntry(int index)
          Gets all the data that is stored at index.
 java.lang.String getId(int index)
          Gets a unique identifier for the index'th choice.
 java.lang.String getText(int index)
          Gets a name for the index'th choice.
 V getValue(int index)
          Gets the value associated with the index'th entry.
 V identifierToValue(java.lang.String id)
          Search the value for the entry width identifier id.
 int indexOfIdentifier(java.lang.String id)
          Searches the entry with the identifier id.
 int indexOfValue(V value)
          Searches the index of the entry that contains value.
 boolean isNullEntryAllowed()
          Tells whether the user choose nothing.
 void remove(int index)
          Removes the index'th entry of this choice.
 void removeChoiceListener(ChoiceListener listener)
          Removes the listener listener from this choice.
 void setController(DockController controller)
          Informs this Choice that it is now used for displaying items for controller.
 void setDefaultChoice(java.lang.String defaultChoice)
          Sets the default choice for this choice.
 void setNullEntryAllowed(boolean nullEntryAllowed)
          Sets whether the null-entry is allowed, the null-entry describes the non existing selection.
 int size()
          Gets the number of available choices.
 java.lang.String valueToIdentifier(V value)
          Searches the identifier for an entry which contains value, this method uses equals(Object, Object) to decide whether two values are equal.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultChoice

public DefaultChoice(DockController controller)
Creates a new choice, adding additional entries if there are any extensions.

Parameters:
controller - the realm in which this choice is used, can be null
Method Detail

addChoiceListener

public void addChoiceListener(ChoiceListener listener)
Description copied from interface: Choice
Adds a listener to this choice. The listener is informed about changes of the entries of this choice.

Specified by:
addChoiceListener in interface Choice
Parameters:
listener - the new listener, not null

removeChoiceListener

public void removeChoiceListener(ChoiceListener listener)
Description copied from interface: Choice
Removes the listener listener from this choice.

Specified by:
removeChoiceListener in interface Choice
Parameters:
listener - the listener to remove

fireInserted

protected void fireInserted(int start,
                            int end)
Calls ChoiceListener.inserted(Choice, int, int) on all listeners that are currently known.

Parameters:
start - the index of the first entry
end - the index of the last entry

fireRemoved

protected void fireRemoved(int start,
                           int end)
Calls ChoiceListener.removed(Choice, int, int) on all listeners that are currently known.

Parameters:
start - the index of the first entry
end - the index of the last entry

fireUpdated

protected void fireUpdated(int start,
                           int end)
Calls ChoiceListener.updated(Choice, int, int) on all listeners that are currently known.

Parameters:
start - the index of the first entry
end - the index of the last entry

setController

public void setController(DockController controller)
Description copied from interface: Choice
Informs this Choice that it is now used for displaying items for controller.

Specified by:
setController in interface Choice
Parameters:
controller - the controller in whose realm this Choice is currently used, can be null

remove

public void remove(int index)
Removes the index'th entry of this choice.

Parameters:
index - the index of the entry to remove

add

public DefaultChoice.Entry<V> add(java.lang.String id,
                                  java.lang.String text,
                                  V value)
Like add(String, String, boolean, Object) with codeIsKey set to false

Parameters:
id - the id of the new entry
text - the text of the new entry
value - the optional value
Returns:
a direct link to the data that was added

addLinked

public DefaultChoice.Entry<V> addLinked(java.lang.String id,
                                        java.lang.String text,
                                        V value)
Like add(String, String, boolean, Object) with codeIsKey set to true

Parameters:
id - the id of the new entry
text - the text of the new entry
value - the optional value
Returns:
a direct link to the data that was added

add

public DefaultChoice.Entry<V> add(java.lang.String id,
                                  java.lang.String text,
                                  boolean textIsKey,
                                  V value)
Adds an entry to this Choice.

Parameters:
id - the id of the new entry
text - the text of the new entry
textIsKey - if true, then text is interpreted as a key for a TextManager, otherwise it is just text
value - the optional value
Returns:
a direct link to the data that was added

getId

public java.lang.String getId(int index)
Description copied from interface: Choice
Gets a unique identifier for the index'th choice.

Specified by:
getId in interface Choice
Parameters:
index - the index of the choice
Returns:
the unique identifier

getText

public java.lang.String getText(int index)
Description copied from interface: Choice
Gets a name for the index'th choice.

Specified by:
getText in interface Choice
Parameters:
index - the index of the choice
Returns:
the name of that choice, should be human readable

getValue

public V getValue(int index)
Gets the value associated with the index'th entry.

Parameters:
index - the index of the entry
Returns:
the value

getEntry

public DefaultChoice.Entry<V> getEntry(int index)
Gets all the data that is stored at index.

Parameters:
index - the index of some entry
Returns:
the entry at that location

indexOfIdentifier

public int indexOfIdentifier(java.lang.String id)
Searches the entry with the identifier id.

Parameters:
id - some id, might be null
Returns:
the index or -1

indexOfValue

public int indexOfValue(V value)
Searches the index of the entry that contains value. This method uses equals(Object, Object) to compare two objects.

Parameters:
value - the value to search
Returns:
the index or -1 if value can't be found or is null

equals

protected boolean equals(V a,
                         V b)
Checks the equality of a and b.

Parameters:
a - some value, might be null
b - some value, might be null
Returns:
true if a and b are equal

valueToIdentifier

public java.lang.String valueToIdentifier(V value)
Searches the identifier for an entry which contains value, this method uses equals(Object, Object) to decide whether two values are equal.

Parameters:
value - the value to search
Returns:
its identifier, null if value is null

identifierToValue

public V identifierToValue(java.lang.String id)
Search the value for the entry width identifier id.

Parameters:
id - the id to search
Returns:
the value associated with id

size

public int size()
Description copied from interface: Choice
Gets the number of available choices.

Specified by:
size in interface Choice
Returns:
the number of choices

setNullEntryAllowed

public void setNullEntryAllowed(boolean nullEntryAllowed)
Sets whether the null-entry is allowed, the null-entry describes the non existing selection.

Parameters:
nullEntryAllowed - true if no selection is allowed

isNullEntryAllowed

public boolean isNullEntryAllowed()
Description copied from interface: Choice
Tells whether the user choose nothing.

Specified by:
isNullEntryAllowed in interface Choice
Returns:
whether the user can choose the null identifier

setDefaultChoice

public void setDefaultChoice(java.lang.String defaultChoice)
Sets the default choice for this choice.

Parameters:
defaultChoice - the default value

getDefaultChoice

public java.lang.String getDefaultChoice()
Description copied from interface: Choice
Gets the standard choice.

Specified by:
getDefaultChoice in interface Choice
Returns:
the identifier of the standard choice, null is only allowed if Choice.isNullEntryAllowed() returns true