public class SimpleListModel<E> extends AbstractListModel<E> implements Sortable<E>, ListSubModel<E>, java.io.Serializable
ListModel
.
Note: It assumes the content is immutable. If not, use ListModelList
or ListModelArray
instead.
In additions, it stores the data in the array format, so if the original
data is not an array. It is better not to use this class.
Also notice that SimpleListModel
also implements
ListSubModel
. It means when it is used with Combobox
,
only the data that matches what the user typed will be shown.
ListModelArray
,
ListModelSet
,
ListModelList
,
ListModelMap
,
(since 3.0.2)
,
Serialized FormAbstractListModel.DefaultSelectionControl<E>
_selection
INTERNAL_EVENT
Constructor and Description |
---|
SimpleListModel(E[] data)
Constructor.
|
SimpleListModel(E[] data,
boolean live)
Constructor.
|
SimpleListModel(java.util.List<? extends E> data)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addSelection(E obj)
Deprecated.
As of release 6.0.0, replaced with
AbstractListModel.addToSelection(E) . |
java.lang.Object |
clone() |
protected void |
fireSelectionEvent(E e)
Selectable's implementor use only.
|
E |
getElementAt(int j)
Returns the value at the specified index.
|
protected int |
getMaxNumberInSubModel(int nRows)
Returns the maximal allowed number of matched items in the sub-model
returned by
getSubModel(java.lang.Object, int) . |
int |
getSize()
Returns the length of the list.
|
java.lang.String |
getSortDirection(java.util.Comparator<E> cmpr)
Returns the sort direction of this model for the given comparator.
|
ListModel<E> |
getSubModel(java.lang.Object value,
int nRows)
Returns the subset of the list model data that matches
the specified value.
|
protected boolean |
inSubModel(java.lang.Object key,
java.lang.Object value)
Compares if the given value shall belong to the submodel represented
by the key.
|
protected java.lang.String |
objectToString(java.lang.Object value)
Deprecated.
As of release 5.0.4, replaced with
inSubModel(java.lang.Object, java.lang.Object) . |
void |
removeSelection(java.lang.Object obj)
Deprecated.
As of release 6.0.0, replaced with
AbstractListModel.removeFromSelection(java.lang.Object) . |
void |
sort(java.util.Comparator<E> cmpr,
boolean ascending)
Sorts the data.
|
addListDataListener, addPagingEventListener, addToSelection, clearSelection, fireEvent, getActivePage, getPageCount, getPageSize, getSelection, getSelectionControl, isMultiple, isSelected, isSelectionEmpty, newEmptySelection, readSelection, removeAllSelection, removeFromSelection, removeListDataListener, removePagingEventListener, retainAllSelection, setActivePage, setMultiple, setPageSize, setSelection, setSelectionControl, writeSelection
public SimpleListModel(E[] data, boolean live)
data
- the array to representlive
- whether to have a 'live' ListModel
on top of
the specified list.
If false, the content of the specified list is copied.
If true, this object is a 'facade' of the specified list,
i.e., when you add or remove items from this ListModelList,
the inner "live" list would be changed accordingly.
However, it is not a good idea to modify data
once it is passed to this method with live is true,
since Listbox
is not smart enough to handle it.public SimpleListModel(E[] data)
data
).
Notice that if the data is static or not shared, it is better to
use SimpleListModelMap(data, true)
instead, since
making a copy is slower.
public SimpleListModel(java.util.List<? extends E> data)
ListModelList
instead
if the data is huge.public int getSize()
ListModel
public E getElementAt(int j)
ListModel
getElementAt
in interface ListModel<E>
public void sort(java.util.Comparator<E> cmpr, boolean ascending)
public java.lang.String getSortDirection(java.util.Comparator<E> cmpr)
Sortable
Default: "natural".
getSortDirection
in interface Sortable<E>
public ListModel<E> getSubModel(java.lang.Object value, int nRows)
The implementation uses inSubModel(java.lang.Object, java.lang.Object)
to check if
the returned object of getElementAt(int)
shall be in
the sub model.
Notice the maximal allowed number of items is decided by
getMaxNumberInSubModel(int)
, which, by default, returns 15
if nRows is negative.
getSubModel
in interface ListSubModel<E>
value
- the value to retrieve the subset of the list model.
It is the key argument when invoking inSubModel(java.lang.Object, java.lang.Object)
.
this string.nRows
- the maximal allowed number of matched items.
If negative, it means the caller allows any number, but the implementation
usually limits to a certain number (for better performance).inSubModel(java.lang.Object, java.lang.Object)
,
getMaxNumberInSubModel(int)
protected int getMaxNumberInSubModel(int nRows)
getSubModel(java.lang.Object, int)
.
Default: nRows < 0 ? 15: nRows
.
protected boolean inSubModel(java.lang.Object key, java.lang.Object value)
Default: converts both key and value to String objects and then return true if the String object of value starts with the String object
key
- the key representing the submodel. In autocomplete,
it is the value entered by user.value
- the value in this model.getSubModel(java.lang.Object, int)
protected java.lang.String objectToString(java.lang.Object value)
inSubModel(java.lang.Object, java.lang.Object)
.public java.lang.Object clone()
clone
in class AbstractListModel<E>
protected void fireSelectionEvent(E e)
AbstractListModel
Fires a selection event for component to scroll into view. The override
subclass must put the index0 of AbstractListModel.fireEvent(int, int, int)
as
the view index to scroll. By default, the value -1 is assumed which means
no scroll into view.
The method is invoked when both methods are invoked. AbstractListModel.addToSelection(Object)
and AbstractListModel.setSelection(Collection)
.
fireSelectionEvent
in class AbstractListModel<E>
e
- selected object.public void addSelection(E obj)
AbstractListModel.addToSelection(E)
.public void removeSelection(java.lang.Object obj)
AbstractListModel.removeFromSelection(java.lang.Object)
.Copyright © 2005-2011 Potix Corporation. All Rights Reserved.