public final class ListSortUI extends Object
This implementation is an adaption of JTable.SortManager fit to the needs of a ListUI. In contrast to JTable tradition, the ui delegate has full control about listening to model/selection changes and updating the list accordingly. So it's role is that of a helper to the ui-delgate (vs. as a helper of the JTable). It's still up to the ListUI itself to listen to model/selection and propagate the notification to this class, if a sorter is installed, but still do the usual updates (layout, repaint) itself. On the other hand, listening to the sorter and updating list state accordingly is completely done by this.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
ListSortUI.ModelChange
ModelChange is used when sorting to restore state, it corresponds
to data from a TableModelEvent.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
ignoreSortChange |
private int[] |
lastModelSelection |
private JXList |
list |
private int |
modelLeadIndex |
private ListSelectionModel |
modelSelection |
private RowSorter<? extends ListModel> |
sorter |
private boolean |
sorterChanged |
private RowSorterListener |
sorterListener |
private boolean |
syncingSelection |
Constructor and Description |
---|
ListSortUI(JXList list,
RowSorter<? extends ListModel> sorter)
Intanstiates a SortUI on the list which has the given RowSorter.
|
Modifier and Type | Method and Description |
---|---|
private void |
allChanged()
Invoked when the underlying model has completely changed.
|
private void |
cacheModelSelection(RowSorterEvent sortEvent) |
private int |
convertRowIndexToModel(RowSorterEvent e,
int viewIndex) |
private int |
convertRowIndexToView(ListSortUI.ModelChange change,
int modelIndex)
Converts a model index to view index.
|
private int[] |
convertSelectionToModel(RowSorterEvent e)
Converts the selection to model coordinates.
|
protected RowSorterListener |
createRowSorterListener()
Creates and returns a RowSorterListener.
|
void |
dispose()
Disposes any resources used by this SortManager.
|
private ListSelectionModel |
getViewSelectionModel() |
void |
modelChanged(ListDataEvent e)
Called after notification from ListModel.
|
private void |
notifySorter(ListSortUI.ModelChange change)
Notifies the sorter of a change in the underlying model.
|
private void |
prepareForChange(ListSortUI.ModelChange change)
Invoked when the list model has changed.
|
private void |
prepareForChange(RowSorterEvent sortEvent)
Invoked when the RowSorter has changed.
|
private void |
processChange(ListSortUI.ModelChange change)
Inovked when either the table has changed or the sorter has changed
and after the sorter has been notified.
|
private void |
restoreSelection(ListSortUI.ModelChange change)
Restores the selection from that in terms of the model.
|
private void |
restoreSortingSelection(int[] selection,
int lead,
ListSortUI.ModelChange change)
Restores the selection after a model event/sort order changes.
|
protected void |
sortedChanged(RowSorterEvent e)
Called after notification from RowSorter.
|
void |
viewSelectionChanged(ListSelectionEvent e)
Called after notification from selectionModel.
|
private ListSelectionModel modelSelection
private int modelLeadIndex
private boolean syncingSelection
private int[] lastModelSelection
private boolean sorterChanged
private boolean ignoreSortChange
private RowSorterListener sorterListener
public ListSortUI(JXList list, RowSorter<? extends ListModel> sorter)
list
- the list to control, must not be nullsorter
- the rowSorter of the list, must not be nullNullPointerException
- if either the list or the sorter is nullIllegalStateException
- if the sorter is not the sorter installed
on the listpublic void dispose()
public void modelChanged(ListDataEvent e)
e
- the change event from the listModel.public void viewSelectionChanged(ListSelectionEvent e)
protected void sortedChanged(RowSorterEvent e)
e
- RowSorter event of type SORTED.private void prepareForChange(RowSorterEvent sortEvent)
sortEvent
- the notificationNullPointerException
- if the given event is null.private void prepareForChange(ListSortUI.ModelChange change)
change
- the notificationNullPointerException
- if the given event is null.private void cacheModelSelection(RowSorterEvent sortEvent)
private void processChange(ListSortUI.ModelChange change)
private void restoreSelection(ListSortUI.ModelChange change)
private void restoreSortingSelection(int[] selection, int lead, ListSortUI.ModelChange change)
private int convertRowIndexToView(ListSortUI.ModelChange change, int modelIndex)
change
- describes the TableModelEvent that initiated the change;
will be null if called as the result of a sortprivate int convertRowIndexToModel(RowSorterEvent e, int viewIndex)
private int[] convertSelectionToModel(RowSorterEvent e)
private void notifySorter(ListSortUI.ModelChange change)
private ListSelectionModel getViewSelectionModel()
private void allChanged()
protected RowSorterListener createRowSorterListener()
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses