V
- the kind of values this choice managespublic class DefaultChoice<V> extends Object implements Choice
Choice
, provides text, id and objects
for every possible choice.Modifier and Type | Class and Description |
---|---|
static interface |
DefaultChoice.Entry<V> |
Constructor and Description |
---|
DefaultChoice(DockController controller)
Creates a new choice, adding additional entries if there are any
extensions.
|
Modifier and Type | Method and Description |
---|---|
DefaultChoice.Entry<V> |
add(String id,
String text,
boolean textIsKey,
V value)
Adds an entry to this
Choice . |
DefaultChoice.Entry<V> |
add(String id,
String text,
V value)
|
void |
addChoiceListener(ChoiceListener listener)
Adds a listener to this choice.
|
DefaultChoice.Entry<V> |
addLinked(String id,
String text,
V value)
|
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. |
String |
getDefaultChoice()
Gets the standard choice.
|
DefaultChoice.Entry<V> |
getEntry(int index)
Gets all the data that is stored at
index . |
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 |
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(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. |
public DefaultChoice(DockController controller)
controller
- the realm in which this choice is used, can be null
public void addChoiceListener(ChoiceListener listener)
Choice
addChoiceListener
in interface Choice
listener
- the new listener, not null
public void removeChoiceListener(ChoiceListener listener)
Choice
listener
from this choice.removeChoiceListener
in interface Choice
listener
- the listener to removeprotected void fireInserted(int start, int end)
ChoiceListener.inserted(Choice, int, int)
on all listeners
that are currently known.start
- the index of the first entryend
- the index of the last entryprotected void fireRemoved(int start, int end)
ChoiceListener.removed(Choice, int, int)
on all listeners
that are currently known.start
- the index of the first entryend
- the index of the last entryprotected void fireUpdated(int start, int end)
ChoiceListener.updated(Choice, int, int)
on all listeners
that are currently known.start
- the index of the first entryend
- the index of the last entrypublic void setController(DockController controller)
Choice
Choice
that it is now used for displaying items for
controller
.setController
in interface Choice
controller
- the controller in whose realm this Choice
is currently
used, can be null
public void remove(int index)
index
- the index of the entry to removepublic DefaultChoice.Entry<V> add(String id, String text, V value)
id
- the id of the new entrytext
- the text of the new entryvalue
- the optional valuepublic DefaultChoice.Entry<V> addLinked(String id, String text, V value)
id
- the id of the new entrytext
- the text of the new entryvalue
- the optional valuepublic DefaultChoice.Entry<V> add(String id, String text, boolean textIsKey, V value)
Choice
.id
- the id of the new entrytext
- the text of the new entrytextIsKey
- if true
, then text
is interpreted as a key for a TextManager
,
otherwise it is just textvalue
- the optional valuepublic String getId(int index)
Choice
index
'th choice.public String getText(int index)
Choice
index'
th choice.public V getValue(int index)
index
'th entry.index
- the index of the entrypublic DefaultChoice.Entry<V> getEntry(int index)
index
.index
- the index of some entrypublic int indexOfIdentifier(String id)
id
.id
- some id, might be null
public int indexOfValue(V value)
value
. This
method uses equals(Object, Object)
to compare two objects.value
- the value to searchvalue
can't be found or
is null
protected boolean equals(V a, V b)
a
and b
.a
- some value, might be null
b
- some value, might be null
true
if a
and b
are equalpublic String valueToIdentifier(V value)
value
,
this method uses equals(Object, Object)
to decide whether two
values are equal.value
- the value to searchnull
if value
is null
public V identifierToValue(String id)
id
.id
- the id to searchid
public int size()
Choice
public void setNullEntryAllowed(boolean nullEntryAllowed)
null
-entry is allowed, the null
-entry
describes the non existing selection.nullEntryAllowed
- true
if no selection is allowedpublic boolean isNullEntryAllowed()
Choice
isNullEntryAllowed
in interface Choice
null
identifierpublic void setDefaultChoice(String defaultChoice)
defaultChoice
- the default valuepublic String getDefaultChoice()
Choice
getDefaultChoice
in interface Choice
null
is only
allowed if Choice.isNullEntryAllowed()
returns true