Class BasicSortedListModel

java.lang.Object
javax.swing.AbstractListModel
be.gaudry.swing.component.jlist.BasicSortedListModel
All Implemented Interfaces:
Serializable, ListModel

public class BasicSortedListModel extends AbstractListModel
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
  • Constructor Details

    • BasicSortedListModel

      public BasicSortedListModel(ListModel model)
      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

      public BasicSortedListModel(ListModel model, BasicSortedListModel.SortOrder sortOrder)
      Creates a SortedListModel from an existing model using a specific comparator and sort order. Uses a default text comparator.
      Parameters:
      model - the unsorted list model
      sortOrder - 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

      public Object getElementAt(int index) throws IndexOutOfBoundsException
      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

      protected int toUnsortedModelIndex(int index) throws IndexOutOfBoundsException
      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

      public void setComparator(Comparator comp)
      Sets the comparator
      Parameters:
      comp - comparator to set(null allowed)
    • setSortOrder

      public void setSortOrder(BasicSortedListModel.SortOrder sortOrder)
      Changes the sort order of the model at runtime
      Parameters:
      sortOrder -