public class DefaultListModel<T> extends Object implements MultipleSelectionListModel<T>
Default implementation of the list model based on a List
of elements.
The list model is an observable set of objects that List
uses to pull
the data to display.
Constructor and Description |
---|
DefaultListModel()
Creates a new instance of DefaultListModel
|
DefaultListModel(Collection<T> items)
Creates a new instance of DefaultListModel
|
DefaultListModel(T... items)
Creates a new instance of DefaultListModel
|
DefaultListModel(Vector<T> items)
Creates a new instance of DefaultListModel
|
Modifier and Type | Method and Description |
---|---|
void |
addDataChangedListener(DataChangedListener l)
Invoked to indicate interest in future change events
|
void |
addItem(T item)
Adds the specified item to the end of this list.
|
void |
addItemAtIndex(T item,
int index)
Adding an item to list at given index
|
void |
addSelectedIndices(int... indices)
Adds indices to set of selected indices.
|
void |
addSelectionListener(SelectionListener l)
Invoked to indicate interest in future selection events
|
protected void |
fireDataChangedEvent(int status,
int index)
Broadcast a change event to all listeners
|
T |
getItemAt(int index)
Returns the item at the given offset
|
List<T> |
getList()
Returns the internal list of items which makes traversal using iterators easier.
|
int |
getSelectedIndex()
Returns the selected list offset
|
int[] |
getSelectedIndices()
Gets the selected indices in this model.
|
int |
getSize()
Returns the number of items in the list
|
boolean |
isMultiSelectionMode()
Checks to see if this list model is in multi-selection mode.
|
void |
removeAll()
Removes all elements from the model
|
void |
removeDataChangedListener(DataChangedListener l)
Invoked to indicate no further interest in future change events
|
void |
removeItem(int index)
Removes the item at the specified position in this list.
|
void |
removeSelectedIndices(int... indices)
Removes indices from the set of selected indices.
|
void |
removeSelectionListener(SelectionListener l)
Invoked to indicate no further interest in future selection events
|
void |
setItem(int index,
T item)
Change the item at the given index
|
void |
setMultiSelectionMode(boolean multiSelectionMode)
Enables or disables multi-selection mode.
|
void |
setSelectedIndex(int index)
Sets the selected list offset can be set to -1 to clear selection
|
void |
setSelectedIndices(int... indices)
For use with multi-selection mode.
|
public DefaultListModel()
public DefaultListModel(Vector<T> items)
items
- the items in the modelpublic DefaultListModel(Collection<T> items)
items
- the items in the modelpublic DefaultListModel(T... items)
items
- the items in the modelpublic T getItemAt(int index)
public int getSize()
public int getSelectedIndex()
getSelectedIndex
in interface ListModel<T>
public void addItem(T item)
public void setItem(int index, T item)
index
- the offset for the itemitem
- the value to setpublic void addItemAtIndex(T item, int index)
item
- - the item to addindex
- - the index position in the listpublic void removeItem(int index)
removeItem
in interface ListModel<T>
index
- the index of the item to removedpublic void removeAll()
public void setSelectedIndex(int index)
setSelectedIndex
in interface ListModel<T>
index
- an index into this listpublic void addDataChangedListener(DataChangedListener l)
addDataChangedListener
in interface ListModel<T>
l
- a data changed listenerpublic void removeDataChangedListener(DataChangedListener l)
removeDataChangedListener
in interface ListModel<T>
l
- a data changed listenerprotected void fireDataChangedEvent(int status, int index)
status
- the status of the eventindex
- the index changedpublic void addSelectionListener(SelectionListener l)
addSelectionListener
in interface ListModel<T>
l
- a selection listenerpublic void removeSelectionListener(SelectionListener l)
removeSelectionListener
in interface ListModel<T>
l
- a selection listenerpublic List<T> getList()
public void setSelectedIndices(int... indices)
Note: This may fire multiple selectionChange events. For each "deselected" index, it will fire an event with the (oldIndex, newIndex) being (index, -1) (i.e. selected index changes from the index to -1. And for each newly selected index, it will fire the event with (oldIndex, newIndex) being (-1, index).
setSelectedIndices
in interface MultipleSelectionListModel<T>
indices
- The indices to select.IllegalArgumentException
- If isMultiSelectionMode()
is false, and indices length is greater than 1.setMultiSelectionMode(boolean)
,
isMultiSelectionMode()
public void addSelectedIndices(int... indices)
addSelectedIndices
in interface MultipleSelectionListModel<T>
indices
- Indices to add to selected indices.public void removeSelectedIndices(int... indices)
removeSelectedIndices
in interface MultipleSelectionListModel<T>
indices
- Indices to remove from selected indices.public int[] getSelectedIndices()
getSelectedIndices
in interface MultipleSelectionListModel<T>
public boolean isMultiSelectionMode()
public void setMultiSelectionMode(boolean multiSelectionMode)
multiSelectionMode
- the multiSelectionMode to set