org.jfree.ui
Class KeyedComboBoxModel
java.lang.Object
org.jfree.ui.KeyedComboBoxModel
- ComboBoxModel
extends java.lang.Object
implements ComboBoxModel
The KeyedComboBox model allows to define an internal key (the data element) for every
entry in the model.
This class is usefull in all cases, where the public text differs from the internal
view on the data. A separation between presentation data and processing data is a
prequesite for localizing combobox entries. This model does not allow selected
elements, which are not in the list of valid elements.
void | add(Object key, Object cbitem) - Adds a new entry to the model.
|
void | addListDataListener(ListDataListener l) - Adds a listener to the list that's notified each time a change to the data model
occurs.
|
void | clear() - Removes all entries from the model.
|
int | findElementIndex(Object key) - Tries to find the index of element with the given key.
|
protected void | fireListDataEvent(ListDataEvent evt) - Notifies all registered list data listener of the given event.
|
Object | getElementAt(int index) - Returns the value at the specified index.
|
Object | getKeyAt(int index) - Returns the key from the given index.
|
Object | getSelectedItem() - Returns the selected item.
|
Object | getSelectedKey() - Returns the selected data element or null if none is set.
|
int | getSize() - Returns the length of the list.
|
void | removeDataElement(Object key) - Removes an entry from the model.
|
void | removeListDataListener(ListDataListener l) - Removes a listener from the list that's notified each time a change to the data model
occurs.
|
void | setData(Object[] keys, Object[] values) - Replaces the data in this combobox model.
|
void | setSelectedItem(Object anItem) - Set the selected item.
|
void | setSelectedKey(Object anItem) - Defines the selected key.
|
KeyedComboBoxModel
public KeyedComboBoxModel(Object[] keys,
Object[] values)
Creates a new keyed combobox model for the given keys and values.
Keys and values must have the same number of items.
keys
- the keysvalues
- the values
add
public void add(Object key,
Object cbitem)
Adds a new entry to the model.
key
- the keycbitem
- the display value.
addListDataListener
public void addListDataListener(ListDataListener l)
Adds a listener to the list that's notified each time a change to the data model
occurs.
l
- the ListDataListener
to be added
clear
public void clear()
Removes all entries from the model.
findElementIndex
public int findElementIndex(Object key)
Tries to find the index of element with the given key. The key must not be null.
key
- the key for the element to be searched.
- the index of the key, or -1 if not found.
fireListDataEvent
protected void fireListDataEvent(ListDataEvent evt)
Notifies all registered list data listener of the given event.
getElementAt
public Object getElementAt(int index)
Returns the value at the specified index.
index
- the requested index
getKeyAt
public Object getKeyAt(int index)
Returns the key from the given index.
index
- the index of the key.
- the the key at the specified index.
getSelectedItem
public Object getSelectedItem()
Returns the selected item.
- The selected item or
null
if there is no selection
getSelectedKey
public Object getSelectedKey()
Returns the selected data element or null if none is set.
- the selected data element.
getSize
public int getSize()
Returns the length of the list.
removeDataElement
public void removeDataElement(Object key)
Removes an entry from the model.
removeListDataListener
public void removeListDataListener(ListDataListener l)
Removes a listener from the list that's notified each time a change to the data model
occurs.
l
- the ListDataListener
to be removed
setData
public void setData(Object[] keys,
Object[] values)
Replaces the data in this combobox model. The number of keys must be equals to the
number of values.
keys
- the keysvalues
- the values
setSelectedItem
public void setSelectedItem(Object anItem)
Set the selected item. The implementation of this method should notify all
registered ListDataListener
s that the contents have changed.
anItem
- the list object to select or null
to clear the selection
setSelectedKey
public void setSelectedKey(Object anItem)
Defines the selected key. If the object is not in the list of values, no item
gets selected.
anItem
- the new selected item.