|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.swing.AbstractListModel com.jidesoft.list.DefaultListModelWrapper com.jidesoft.list.SortableListModel
public class SortableListModel
SortableListModel is a list model wrapper which can do the sorting. Given any existing list model, you can wrap it
into SortableListModel
and use it later on any JList.
SortableListModel sortableListModel = new SortableListModel(listModel);
JList sortableList = new JList(sortableListModel);
To sort the list, you just call
sortableListModel.sort(); // or sort(SortableListModel.SORT_DESCENDING) to sort descending.
Field Summary | |
---|---|
static int |
SORT_ASCENDING
|
static int |
SORT_DESCENDING
|
static int |
UNSORTED
|
Fields inherited from class com.jidesoft.list.DefaultListModelWrapper |
---|
_adjustingIndexes, _indexes, _model |
Fields inherited from class javax.swing.AbstractListModel |
---|
listenerList |
Constructor Summary | |
---|---|
SortableListModel()
|
|
SortableListModel(ListModel model)
Creates a SortableListModel from any list model. |
Method Summary | |
---|---|
void |
addSortListener(SortListener l)
Adds the specified listener to receive collapsible pane events from this collapsible frame. |
protected int |
compare(int row1,
int row2)
Compares two rows to decide the order. |
protected int |
compare(Object o1,
Object o2)
Compares its two arguments for order. |
void |
contentsChanged(ListDataEvent e)
|
void |
fireSortEvent()
Fires an collapsible pane event. |
void |
fireSortingEvent()
Fires sort event. |
Comparator |
getComparator()
Gets the comparator. |
ComparatorContext |
getComparatorContext()
Gets the comparator context. |
static SortableListModel |
getSortableListModel(ListModel model)
Gets the sortable table model. |
SortListener[] |
getSortListeners()
Returns an array of all the SortListener s added to this CollapsiblePane with
addSortListener . |
int |
getSortOrder()
Gets the sort order. |
protected int[] |
getSortRanges()
Gets the row index range that will be sorted. |
void |
intervalAdded(ListDataEvent e)
|
void |
intervalRemoved(ListDataEvent e)
|
boolean |
isAlwaysUseComparators()
Checks if the alwaysUseComparators flag value. |
boolean |
isAutoResort()
Checks if the table is automatically resorted when data changes. |
boolean |
isOptimized()
Checks if the sortable table model is in optimized mode. |
void |
removeSortListener(SortListener l)
Removes the specified collapsible pane listener so that it no longer receives collapsible pane events from this collapsible pane . |
void |
reset()
Resets. |
void |
resort()
Resort the table. |
protected int |
search(int[] indexes,
int row)
Searches the specified array of rows for the specified value using binary search. |
void |
setAlwaysUseComparators(boolean alwaysUseComparators)
Sets the alwaysUseComparators flag. |
void |
setAutoResort(boolean autoResort)
AutoResort is a feature that automatically resort the table when table data changes. |
void |
setComparator(Comparator comparator)
Sets the comparator. |
void |
setComparatorContext(ComparatorContext comparatorContext)
Sets the comparator context. |
void |
setIndexes(int[] indexes)
Overrides the method in DefaultListModelWrapper to clear up any sort order. |
void |
setOptimized(boolean optimized)
If optimized flag is true and the table is already sorted, SortableListModel will do incremental sorting when data is only partially changed. |
void |
setSortOrder(int sortOrder)
Sets the sort order. |
void |
sort()
Sort the list model ascending. |
void |
sort(int order)
Sort the list model. |
protected void |
sort(int[] from,
int[] to,
int low,
int high)
Sorts the rows. |
void |
unsort()
Unsorts the list model. |
Methods inherited from class com.jidesoft.list.DefaultListModelWrapper |
---|
addIndexChangeListener, createCompoundListDataEvent, fireEvents, fireIndexChanged, fireListDataEvent, getActualIndexAt, getActualModel, getElementAt, getIndexAt, getIndexChangeListeners, getIndexes, getSize, reallocateIndexes, removeIndexChangeListener, setActualModel |
Methods inherited from class javax.swing.AbstractListModel |
---|
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SORT_ASCENDING
public static final int SORT_DESCENDING
public static final int UNSORTED
Constructor Detail |
---|
public SortableListModel()
public SortableListModel(ListModel model)
model
- the actual list modelMethod Detail |
---|
public void intervalAdded(ListDataEvent e)
intervalAdded
in interface ListDataListener
intervalAdded
in class DefaultListModelWrapper
public void intervalRemoved(ListDataEvent e)
intervalRemoved
in interface ListDataListener
intervalRemoved
in class DefaultListModelWrapper
public void contentsChanged(ListDataEvent e)
contentsChanged
in interface ListDataListener
contentsChanged
in class DefaultListModelWrapper
protected int[] getSortRanges()
protected int search(int[] indexes, int row)
indexes
- the array of row to be searched.row
- the index of the row to be searched for.
protected void sort(int[] from, int[] to, int low, int high)
from
- an int array of row indices to be sortedto
- an int array of row indices to store the result after sortinglow
- the start index of the row in the array to be sortedhigh
- the end index of the row in the array to be sortedprotected int compare(int row1, int row2)
getActualModel().getElement(rowIndex)
since SortableListModel is also a
ListModelWrapper.
row1
- index of the first row to be comparedrow2
- index of the second row to be compared
protected int compare(Object o1, Object o2)
setComparator(java.util.Comparator)
or setComparatorContext(com.jidesoft.comparator.ComparatorContext)
,
we will try to use it without doing the extra checking steps. There is also a setter called setAlwaysUseComparators(boolean)
. If yes, we will also skip the checking of String and Comparable, and use
getComparator or ObjectComparatorManager.
o1
- the first object to be comparedo2
- the second object to be compared
public Comparator getComparator()
public void setComparator(Comparator comparator)
comparator
- the comparatorpublic ComparatorContext getComparatorContext()
ObjectComparatorManager
. In most cases, comparator context is null. Only if the type is
the same but you want to compare differently, you can use comparator context to break the tie.
public void setComparatorContext(ComparatorContext comparatorContext)
ObjectComparatorManager
.
comparatorContext
- the comparator contextpublic int getSortOrder()
UNSORTED
, SORT_DESCENDING
, or SORT_ASCENDING
.public void setSortOrder(int sortOrder)
sortOrder
- the new sort order. The value could be UNSORTED
, SORT_DESCENDING
, or SORT_ASCENDING
.public void sort()
public void sort(int order)
SORT_ASCENDING
or SORT_DESCENDING
. You can also
pass in UNSORTED
, which will be the same as unsort()
.
order
- the new sort order.public void unsort()
public void reset()
unsort()
.
public void setIndexes(int[] indexes)
setIndexes
in interface ListModelWrapper
setIndexes
in class DefaultListModelWrapper
indexes
- the indexespublic static SortableListModel getSortableListModel(ListModel model)
model
- the outer list model
public boolean isOptimized()
public void setOptimized(boolean optimized)
optimized
- the flagpublic boolean isAutoResort()
public void setAutoResort(boolean autoResort)
resort()
to resort the table.
Note: this flag is only used when optimized flag is true. If optimized is false, autoResort is always true.
autoResort
- the flagpublic void resort()
public void addSortListener(SortListener l)
l
- the collapsible pane listenerpublic void removeSortListener(SortListener l)
l
- the collapsible pane listenerpublic SortListener[] getSortListeners()
SortListener
s added to this CollapsiblePane
with
addSortListener
.
SortListener
s added or an empty array if no listeners have been addedaddSortListener(com.jidesoft.grid.SortListener)
public void fireSortingEvent()
public void fireSortEvent()
public boolean isAlwaysUseComparators()
public void setAlwaysUseComparators(boolean alwaysUseComparators)
Comparable.compareTo(Object)
to compare. This is the default preferred way because this gives
developer a finer control of the comparison result.
alwaysUseComparators
- true or false.
|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |