An
EventSelectionModel
is a class that performs two simulaneous
services. It is a
ListSelectionModel
to provide selection tracking for a
JTable
. It is also a
EventList
that contains the table's selection.
As elements are selected or deselected, the
EventList
aspect of this
EventSelectionModel
changes. Changes to that
List
will change the
source
EventList
. To modify only the selection, use the
ListSelectionModel
's methods.
Alongside
MULTIPLE_INTERVAL_SELECTION
, this
ListSelectionModel
supports an additional selection mode.
MULTIPLE_INTERVAL_SELECTION_DEFENSIVE
is a new selection mode.
It is identical to
MULTIPLE_INTERVAL_SELECTION
in every way but
one. When a row is inserted immediately before a selected row in the
MULTIPLE_INTERVAL_SELECTION
mode, it becomes selected. But in
the
MULTIPLE_INTERVAL_SELECTION_DEFENSIVE
mode, it does not
become selected. To set this mode, use
setSelectionMode(ListSelection.MULTIPLE_INTERVAL_SELECTION_DEFENSIVE)
.
addListSelectionListener
public void addListSelectionListener(ListSelectionListener listener)
Add a listener to the list that's notified each time a change to
the selection occurs.
Note that the change events fired by this class may include rows
that have been removed from the table. For this reason it is
advised not to for()
through the changed range without
also verifying that each row is still in the table.
addSelectionInterval
public void addSelectionInterval(int index0,
int index1)
Change the selection to be the set union of the current selection and the indices between index0 and index1 inclusive
clearSelection
public void clearSelection()
Change the selection to the empty set.
dispose
public void dispose()
getAnchorSelectionIndex
public int getAnchorSelectionIndex()
Return the first index argument from the most recent call to setSelectionInterval(), addSelectionInterval() or removeSelectionInterval().
getDeselected
public EventList getDeselected()
Gets an
EventList
that contains only deselected values and
modifies the source list on mutation.
Adding and removing items from this list performs the same operation on
the source list.
getEnabled
public boolean getEnabled()
Gets whether the EventSelectionModel is editable or not.
getEventList
public EventList getEventList()
As of 2005/02/18, the naming of this method became
ambiguous. Please use getSelected()
.
Gets the event list that always contains the current selection.
getLeadSelectionIndex
public int getLeadSelectionIndex()
Return the second index argument from the most recent call to setSelectionInterval(), addSelectionInterval() or removeSelectionInterval().
getListSelectionModel
public ListSelectionModel getListSelectionModel()
As of 2004/11/26, the EventSelectionModel
implements
ListSelectionModel
directly.
Gets the selection model that provides selection management for a table.
getMaxSelectionIndex
public int getMaxSelectionIndex()
Gets the index of the last selected element.
getMinSelectionIndex
public int getMinSelectionIndex()
Gets the index of the first selected element.
getSelected
public EventList getSelected()
Gets an
EventList
that contains only selected
values and modifies the source list on mutation.
Adding and removing items from this list performs the same operation on
the source list.
getSelectionMode
public int getSelectionMode()
Returns the current selection mode.
getTogglingDeselected
public EventList getTogglingDeselected()
Gets an
EventList
that contains only deselected values and
modifies the selection state on mutation.
Adding an item to this list deselects it and removing an item selects it.
If an item not in the source list is added an
IllegalArgumentException
is thrown
getTogglingSelected
public EventList getTogglingSelected()
Gets an
EventList
that contains only selected
values and modifies the selection state on mutation.
Adding an item to this list selects it and removing an item deselects it.
If an item not in the source list is added an
IllegalArgumentException
is thrown.
getValueIsAdjusting
public boolean getValueIsAdjusting()
Returns true if the value is undergoing a series of changes.
insertIndexInterval
public void insertIndexInterval(int index,
int length,
boolean before)
Insert length indices beginning before/after index.
invertSelection
public void invertSelection()
Inverts the current selection.
isSelectedIndex
public boolean isSelectedIndex(int index)
Returns true if the specified index is selected. If the specified
index has not been seen before, this will return false. This is
in the case where the table painting and selection have fallen
out of sync. Usually in this case there is an update event waiting
in the event queue that notifies this model of the change
in table size.
isSelectionEmpty
public boolean isSelectionEmpty()
Returns true if no indices are selected.
removeIndexInterval
public void removeIndexInterval(int index0,
int index1)
Remove the indices in the interval index0,index1 (inclusive) from the selection model.
removeListSelectionListener
public void removeListSelectionListener(ListSelectionListener listener)
Remove a listener from the list that's notified each time a change to the selection occurs.
removeSelectionInterval
public void removeSelectionInterval(int index0,
int index1)
Change the selection to be the set difference of the current selection and the indices between index0 and index1 inclusive.
setAnchorSelectionIndex
public void setAnchorSelectionIndex(int anchorSelectionIndex)
Set the anchor selection index.
setEnabled
public void setEnabled(boolean enabled)
Set the EventSelectionModel as editable or not. This means that the user cannot
manipulate the selection by clicking. The selection can still be changed as
the source list changes.
Note that this will also disable the selection from being modified
programatically. Therefore you must use setEnabled(true) to
modify the selection in code.
setLeadSelectionIndex
public void setLeadSelectionIndex(int leadSelectionIndex)
Set the lead selection index.
setSelectionInterval
public void setSelectionInterval(int index0,
int index1)
Change the selection to be between index0 and index1 inclusive.
First this calculates the smallest range where changes occur. This
includes the union of the selection range before and the selection
range specified. It then walks through the change and sets each
index as selected or not based on whether the index is in the
new range. Finally it fires events to both the listening lists and
selection listeners about what changes happened.
If the selection does not change, this will not fire any events.
setSelectionMode
public void setSelectionMode(int selectionMode)
Set the selection mode.
setValueIsAdjusting
public void setValueIsAdjusting(boolean valueIsAdjusting)
This property is true if upcoming changes to the value of the model should be considered a single event.