com.jgoodies.binding.internal
Class TableRowSorterListSelectionModel

java.lang.Object
  extended by javax.swing.DefaultListSelectionModel
      extended by com.jgoodies.binding.internal.TableRowSorterListSelectionModel
All Implemented Interfaces:
Serializable, Cloneable, ListSelectionModel

public final class TableRowSorterListSelectionModel
extends DefaultListSelectionModel

A ListSelectionModel for a sorted table that is synchronized with another delegate ListSelectionModel and converts its unsorted indices to the sorted indices provided by the table's row sorter.

If a JTable has a RowSorter, the indices in the table's ListSelectionModel reflect the table's sort state. In other words, sorting modifies the selection indices. This makes it difficult to share ListSelectionModels for multiple JLists/JTables - which is a fundamental feature of the Presentation Model pattern. For example, if the first row is selected in unsorted state, the ListSelectionModel has a minSelectionIndex of 0. Accessing a ListModel or TableModel at row index 0 will get you the first row. Let's say you sort the table and the first row is now displayed as the third row, then the ListSelectionModel gets a minSelectionIndex of 2.

This class is used to keep an unsorted ListSelectionModel (typically provided by a presentation model) in synch with the sorted indices of the table's sorted ListSelectionModel.

Instances of this class are automatically created when using Bindings.bind(JTable, javax.swing.ListModel, ListSelectionModel) on a sorted table.

Version:
$Revision: 1.1 $ $Date: 2013/01/30 18:35:09 $
Author:
Karsten Lentzsch
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.DefaultListSelectionModel
leadAnchorNotificationEnabled, listenerList
 
Fields inherited from interface javax.swing.ListSelectionModel
MULTIPLE_INTERVAL_SELECTION, SINGLE_INTERVAL_SELECTION, SINGLE_SELECTION
 
Constructor Summary
TableRowSorterListSelectionModel(ListSelectionModel listSelectionModel, JTable table)
           
 
Method Summary
 void addSelectionInterval(int index0, int index1)
          Changes the selection to be the set union of the current selection and the indices between index0 and index1 inclusive.
 void clearSelection()
          Change the selection to the empty set.
 int getSelectionMode()
          Returns the current selection mode.
 void insertIndexInterval(int index, int length, boolean before)
          Insert length indices beginning before/after index.
 void removeIndexInterval(int index0, int index1)
          Remove the indices in the interval index0,index1 (inclusive) from the selection model.
 void removeSelectionInterval(int index0, int index1)
          Changes the selection to be the set difference of the current selection and the indices between index0 and index1 inclusive.
 void setSelectionInterval(int index0, int index1)
          Changes the selection to be between index0 and index1 inclusive.
 void setSelectionMode(int selectionMode)
          Sets the selection mode.
 
Methods inherited from class javax.swing.DefaultListSelectionModel
addListSelectionListener, clone, fireValueChanged, fireValueChanged, fireValueChanged, getAnchorSelectionIndex, getLeadSelectionIndex, getListeners, getListSelectionListeners, getMaxSelectionIndex, getMinSelectionIndex, getValueIsAdjusting, isLeadAnchorNotificationEnabled, isSelectedIndex, isSelectionEmpty, moveLeadSelectionIndex, removeListSelectionListener, setAnchorSelectionIndex, setLeadAnchorNotificationEnabled, setLeadSelectionIndex, setValueIsAdjusting, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TableRowSorterListSelectionModel

public TableRowSorterListSelectionModel(ListSelectionModel listSelectionModel,
                                        JTable table)
Method Detail

setSelectionInterval

public void setSelectionInterval(int index0,
                                 int index1)
Changes the selection to be between index0 and index1 inclusive. index0 doesn't have to be less than or equal to index1.

In SINGLE_SELECTION selection mode, only the second index is used.

If this represents a change to the current selection, then each ListSelectionListener is notified of the change.

Specified by:
setSelectionInterval in interface ListSelectionModel
Overrides:
setSelectionInterval in class DefaultListSelectionModel
Parameters:
index0 - one end of the interval.
index1 - other end of the interval
See Also:
DefaultListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)

addSelectionInterval

public void addSelectionInterval(int index0,
                                 int index1)
Changes the selection to be the set union of the current selection and the indices between index0 and index1 inclusive. index0 doesn't have to be less than or equal to index1.

In SINGLE_SELECTION selection mode, this is equivalent to calling setSelectionInterval, and only the second index is used. In SINGLE_INTERVAL_SELECTION selection mode, this method behaves like setSelectionInterval, unless the given interval is immediately adjacent to or overlaps the existing selection, and can therefore be used to grow the selection.

If this represents a change to the current selection, then each ListSelectionListener is notified of the change.

Specified by:
addSelectionInterval in interface ListSelectionModel
Overrides:
addSelectionInterval in class DefaultListSelectionModel
Parameters:
index0 - one end of the interval.
index1 - other end of the interval
See Also:
DefaultListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener), setSelectionInterval(int, int)

removeSelectionInterval

public void removeSelectionInterval(int index0,
                                    int index1)
Changes the selection to be the set difference of the current selection and the indices between index0 and index1 inclusive. index0 doesn't have to be less than or equal to index1.

In SINGLE_INTERVAL_SELECTION selection mode, if the removal would produce two disjoint selections, the removal is extended through the greater end of the selection. For example, if the selection is 0-10 and you supply indices 5,6 (in any order) the resulting selection is 0-4.

If this represents a change to the current selection, then each ListSelectionListener is notified of the change.

Specified by:
removeSelectionInterval in interface ListSelectionModel
Overrides:
removeSelectionInterval in class DefaultListSelectionModel
Parameters:
index0 - one end of the interval.
index1 - other end of the interval
See Also:
DefaultListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)

clearSelection

public void clearSelection()
Change the selection to the empty set. If this represents a change to the current selection then notify each ListSelectionListener.

Specified by:
clearSelection in interface ListSelectionModel
Overrides:
clearSelection in class DefaultListSelectionModel
See Also:
DefaultListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)

insertIndexInterval

public void insertIndexInterval(int index,
                                int length,
                                boolean before)
Insert length indices beginning before/after index. This is typically called to sync the selection model with a corresponding change in the data model.

Specified by:
insertIndexInterval in interface ListSelectionModel
Overrides:
insertIndexInterval in class DefaultListSelectionModel

removeIndexInterval

public void removeIndexInterval(int index0,
                                int index1)
Remove the indices in the interval index0,index1 (inclusive) from the selection model. This is typically called to sync the selection model width a corresponding change in the data model.

Specified by:
removeIndexInterval in interface ListSelectionModel
Overrides:
removeIndexInterval in class DefaultListSelectionModel

setSelectionMode

public void setSelectionMode(int selectionMode)
Sets the selection mode. The following list describes the accepted selection modes:

Specified by:
setSelectionMode in interface ListSelectionModel
Overrides:
setSelectionMode in class DefaultListSelectionModel
Throws:
IllegalArgumentException - if the selection mode isn't one of those allowed
See Also:
getSelectionMode()

getSelectionMode

public int getSelectionMode()
Returns the current selection mode.

Specified by:
getSelectionMode in interface ListSelectionModel
Overrides:
getSelectionMode in class DefaultListSelectionModel
Returns:
the current selection mode
See Also:
setSelectionMode(int)


Copyright © 2002-2013 JGoodies Software GmbH. All Rights Reserved.