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, EclipseTabChoice, TabContentFilterChoice, TabPlacementChoice, ThemeChoice

public class DefaultChoice<V>
extends Object
implements Choice

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

Author:
Benjamin Sigg

Constructor Summary
DefaultChoice(DockController controller)
          Creates a new choice, adding additional entries if there are any extensions.
 
Method Summary
 void add(String id, String text, V value)
          Adds an entry to this Choice.
protected  boolean equals(V a, V b)
          Checks the equality of a and b.
 String getDefaultChoice()
          Gets the standard choice.
 String getId(int index)
          Gets a unique identifier for the index'th choice.
 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(String id)
          Search the value for the entry width identifier id.
 int indexOfIdentifier(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 setDefaultChoice(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.
 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

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 void add(String id,
                String text,
                V value)
Adds an entry to this Choice.

Parameters:
id - the id of the new entry
text - the text of the new entry
value - the optional value

getId

public 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 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

indexOfIdentifier

public int indexOfIdentifier(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 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(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(String defaultChoice)
Sets the default choice for this choice.

Parameters:
defaultChoice - the default value

getDefaultChoice

public 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