Class ListSortUI
java.lang.Object
org.jdesktop.swingx.plaf.basic.core.ListSortUI
ListSortUI provides support for managing the synchronization between
RowSorter, SelectionModel and ListModel if a JXList is sortable.
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 the role of this class is that of a helper to the ListUI (vs. as a helper of the JTable).
It's up to the ListUI 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
ModelChange is used when sorting to restore state, it corresponds to data from a TableModelEvent. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private int[]
private JXList
private int
private ListSelectionModel
private boolean
private RowSorterListener
private boolean
-
Constructor Summary
ConstructorsConstructorDescriptionListSortUI
(JXList list, RowSorter<? extends ListModel> sorter) Intanstiates a SortUI on the list which has the given RowSorter. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
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[]
Converts the selection to model coordinates.protected RowSorterListener
Creates and returns a RowSorterListener.void
dispose()
Disposes any resources used by this SortManager.private ListSelectionModel
void
Called after notification from ListModel.private void
notifySorter
(ListSortUI.ModelChange change) Notifies the sorter of a change in the underlying model.private void
prepareForChange
(RowSorterEvent sortEvent) Invoked when the RowSorter has changed.private void
Invoked when the list model 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
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
Called after notification from RowSorter.void
Called after notification from selectionModel.
-
Field Details
-
sorter
-
list
-
modelSelection
-
modelLeadIndex
private int modelLeadIndex -
syncingSelection
private boolean syncingSelection -
lastModelSelection
private int[] lastModelSelection -
sorterChanged
private boolean sorterChanged -
ignoreSortChange
private boolean ignoreSortChange -
sorterListener
-
-
Constructor Details
-
ListSortUI
Intanstiates a SortUI on the list which has the given RowSorter.- Parameters:
list
- the list to control, must not be nullsorter
- the rowSorter of the list, must not be null- Throws:
NullPointerException
- if either the list or the sorter is nullIllegalStateException
- if the sorter is not the sorter installed on the list
-
-
Method Details
-
dispose
public void dispose()Disposes any resources used by this SortManager. Note: this instance must not be used after dispose! -
modelChanged
Called after notification from ListModel.- Parameters:
e
- the change event from the listModel.
-
viewSelectionChanged
Called after notification from selectionModel. Invoked when the selection, on the view, has changed. -
sortedChanged
Called after notification from RowSorter.- Parameters:
e
- RowSorter event of type SORTED.
-
prepareForChange
Invoked when the RowSorter has changed. Updates the internal cache of the selection based on the change.- Parameters:
sortEvent
- the notification- Throws:
NullPointerException
- if the given event is null.
-
prepareForChange
Invoked when the list model has changed. This is invoked prior to notifying the sorter of the change. Updates the internal cache of the selection based on the change.- Parameters:
change
- the notification- Throws:
NullPointerException
- if the given event is null.
-
cacheModelSelection
-
processChange
Inovked when either the table has changed or the sorter has changed and after the sorter has been notified. If necessary this will reapply the selection and variable row heights. -
restoreSelection
Restores the selection from that in terms of the model. -
restoreSortingSelection
Restores the selection after a model event/sort order changes. All coordinates are in terms of the model. -
convertRowIndexToView
Converts a model index to view index. This is called when the sorter or model changes and sorting is enabled.- Parameters:
change
- describes the TableModelEvent that initiated the change; will be null if called as the result of a sort
-
convertRowIndexToModel
-
convertSelectionToModel
Converts the selection to model coordinates. This is used when the model changes or the sorter changes. -
notifySorter
Notifies the sorter of a change in the underlying model. -
getViewSelectionModel
-
allChanged
private void allChanged()Invoked when the underlying model has completely changed. -
createRowSorterListener
Creates and returns a RowSorterListener. This implementation calls sortedChanged if the event is of type SORTED.- Returns:
- rowSorterListener to install on sorter.
-