Package be.gaudry.swing.component.jlist
Class BasicSortedListModel
java.lang.Object
javax.swing.AbstractListModel
be.gaudry.swing.component.jlist.BasicSortedListModel
- All Implemented Interfaces:
Serializable
,ListModel
SortedListModel decorates an unsorted ListModel to provide
a sorted model. You can create a SortedListModel from models you
already have. Place the SortedListModel into a JList, for example, to provide
a sorted view of your underlying model.
Provided by the broldev.core.swing project.
- Since:
- 1.0 (Jun, 2006), broldev.core.swing 0.0.1-SNAPSHOT dependency
- Version:
- 1.1 (Oct 11, 2008)
- Author:
- Steph GAUDRY, Steph GAUDRY
- See Also:
- Serialized Form
-
Nested Class Summary
Modifier and TypeClassDescription(package private) class
static class
Enumeration of sort preferences -
Field Summary
Fields inherited from class javax.swing.AbstractListModel
listenerList
-
Constructor Summary
ConstructorDescriptionBasicSortedListModel(ListModel model)
Creates a SortedListModel from an existing model using a default text comparator for the default Locale.BasicSortedListModel(ListModel model, BasicSortedListModel.SortOrder sortOrder)
Creates a SortedListModel from an existing model using a specific comparator and sort order.BasicSortedListModel(ListModel model, BasicSortedListModel.SortOrder sortOrder, Comparator comp)
Creates a SortedListModel from an existing model. -
Method Summary
Modifier and TypeMethodDescriptiongetElementAt(int index)
Retrieves the sorted entry from the original modelint
getSize()
Retrieves the size of the underlying modelvoid
setComparator(Comparator comp)
Sets the comparatorvoid
setSortOrder(BasicSortedListModel.SortOrder sortOrder)
Changes the sort order of the model at runtimeprotected int
toSortedModelIndex(int unsortedIndex)
Converts an unsorted model index to a sorted model index.protected int[]
toSortedModelIndices(int[] unsortedModelIndices)
Converts an array of unsorted model selection indices to indices in the sorted model.protected int
toUnsortedModelIndex(int index)
Converts sorted model index to an unsorted model index.protected int[]
toUnsortedModelIndices(int[] sortedSelectedIndices)
Converts an array of sorted model indices to their unsorted model indices.Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
-
Constructor Details
-
BasicSortedListModel
Creates a SortedListModel from an existing model using a default text comparator for the default Locale. Sorts in ascending order.- Parameters:
model
- the underlying, unsorted ListModel
-
BasicSortedListModel
Creates a SortedListModel from an existing model using a specific comparator and sort order. Uses a default text comparator.- Parameters:
model
- the unsorted list modelsortOrder
- that should be used
-
BasicSortedListModel
public BasicSortedListModel(ListModel model, BasicSortedListModel.SortOrder sortOrder, Comparator comp)Creates a SortedListModel from an existing model. Sorts the model in the specified sort order using the given comparator.- Parameters:
model
-sortOrder
-comp
-
-
-
Method Details
-
getElementAt
Retrieves the sorted entry from the original model- Parameters:
index
- index of an entry in the sorted model- Returns:
- element in the original model to which our entry points
- Throws:
IndexOutOfBoundsException
-
getSize
public int getSize()Retrieves the size of the underlying model- Returns:
- size of the model
-
toUnsortedModelIndex
Converts sorted model index to an unsorted model index.- Parameters:
index
- an index in the sorted model- Returns:
- modelIndex an index in the unsorted model
- Throws:
IndexOutOfBoundsException
-
toUnsortedModelIndices
protected int[] toUnsortedModelIndices(int[] sortedSelectedIndices)Converts an array of sorted model indices to their unsorted model indices. Sorts the resulting set of indices.- Parameters:
sortedSelectedIndices
- indices of selected elements in the sorted model or sorted view- Returns:
- unsortedSelectedIndices selected indices in the unsorted model
-
toSortedModelIndex
protected int toSortedModelIndex(int unsortedIndex)Converts an unsorted model index to a sorted model index.- Parameters:
unsortedIndex
- an element index in the unsorted model- Returns:
- sortedIndex an element index in the sorted model
-
toSortedModelIndices
protected int[] toSortedModelIndices(int[] unsortedModelIndices)Converts an array of unsorted model selection indices to indices in the sorted model. Sorts the model indices from low to high to duplicate JList's getSelectedIndices method- Parameters:
unsortedModelIndices
-- Returns:
- an array of selected indices in the sorted model
-
setComparator
Sets the comparator- Parameters:
comp
- comparator to set(null allowed)
-
setSortOrder
Changes the sort order of the model at runtime- Parameters:
sortOrder
-
-