|
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.combobox.DefaultComboBoxModelWrapper com.jidesoft.combobox.SortableComboBoxModel
public class SortableComboBoxModel
SortableComboBoxModel
is a combobox model wrapper which can do the sorting. Given any existing combobox
model, you can wrap it into SortableComboBoxModel
and use it later on any JComboBox.
SortableComboBoxModel sortableComboBoxModel = new SortableComboBoxModel(comboBoxModel);
JComboBox comboBox = new JComboBox(sortableComboBoxModel);
To sort the list, you just call
sortableComboBoxModel.sort(); // or sort(SortableComboBoxModel.SORT_DESCENDING) to sort descending.
Field Summary | |
---|---|
protected EventListenerList |
listenerList
|
static int |
SORT_ASCENDING
|
static int |
SORT_DESCENDING
|
static int |
UNSORTED
|
Fields inherited from class com.jidesoft.combobox.DefaultComboBoxModelWrapper |
---|
_indexes, _model |
Constructor Summary | |
---|---|
SortableComboBoxModel()
|
|
SortableComboBoxModel(ComboBoxModel 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)
The event handler when items are updated in the underlying combo box model. |
void |
fireSortEvent()
Fires an collapsible pane event. |
Comparator |
getComparator()
Gets the comparator. |
ComparatorContext |
getComparatorContext()
Gets the comparator context. |
static SortableComboBoxModel |
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. |
void |
intervalAdded(ListDataEvent e)
The event handler when new items are added in the underlying combo box model. |
void |
intervalRemoved(ListDataEvent e)
The event handler when items are removed in the underlying combo box model. |
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 |
setActualModel(ComboBoxModel model)
Sets the actual list model. |
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.combobox.DefaultComboBoxModelWrapper |
---|
getActualIndexAt, getActualModel, getElementAt, getIndexAt, getIndexes, getSelectedItem, getSize, reallocateIndexes, setSelectedItem |
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 |
Methods inherited from interface javax.swing.ListModel |
---|
addListDataListener, removeListDataListener |
Field Detail |
---|
public static final int SORT_ASCENDING
public static final int SORT_DESCENDING
public static final int UNSORTED
protected EventListenerList listenerList
Constructor Detail |
---|
public SortableComboBoxModel()
public SortableComboBoxModel(ComboBoxModel model)
model
- the underlying combo box modelMethod Detail |
---|
public void setActualModel(ComboBoxModel model)
DefaultComboBoxModelWrapper
setActualModel
in interface ComboBoxModelWrapper
setActualModel
in class DefaultComboBoxModelWrapper
model
- the list model.public void intervalAdded(ListDataEvent e)
DefaultComboBoxModelWrapper
intervalAdded
in interface ListDataListener
intervalAdded
in class DefaultComboBoxModelWrapper
e
- the eventpublic void intervalRemoved(ListDataEvent e)
DefaultComboBoxModelWrapper
intervalRemoved
in interface ListDataListener
intervalRemoved
in class DefaultComboBoxModelWrapper
e
- the eventpublic void contentsChanged(ListDataEvent e)
DefaultComboBoxModelWrapper
contentsChanged
in interface ListDataListener
contentsChanged
in class DefaultComboBoxModelWrapper
e
- the eventprotected 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)
By default, we took several steps to improve the performance. First we will check if either objects is null. If both are null, we return 0. If one is null, we return 1 or -1. Then we will check if the objects are String. If yes,we will use String#compareToIgnoreCase. Then we will check if the objects are Comparable and if yes, we will ues Comparable#compareTo method. At last, we will check if getComparator returns a non-null value and use it. If the getComparator() is null, we will try to get a Comparator from ObjectComparatorManager based on the object type and the ComparatorContext and use it. Subclass can override it to provide your own way to compare. If you ever call
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
- public 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
- public 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 ComboBoxModelWrapper
setIndexes
in class DefaultComboBoxModelWrapper
indexes
- public static SortableComboBoxModel getSortableListModel(ListModel model)
public boolean isOptimized()
public void setOptimized(boolean optimized)
optimized
- public 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
- public 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 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 |