Class EventSelectionModel<E>
- java.lang.Object
-
- org.jadice.util.glazedlists.gui.EventSelectionModel<E>
-
- All Implemented Interfaces:
ListSelectionModel
public final class EventSelectionModel<E> extends Object implements ListSelectionModel
AnEventSelectionModel
is a class that performs two simulaneous services. It is aListSelectionModel
to provide selection tracking for aJTable
. It is also aEventList
that contains the table's selection.As elements are selected or deselected, the
EventList
aspect of thisEventSelectionModel
changes. Changes to thatList
will change the sourceEventList
. To modify only the selection, use theListSelectionModel
's methods.Alongside
MULTIPLE_INTERVAL_SELECTION
, thisListSelectionModel
supports an additional selection mode.MULTIPLE_INTERVAL_SELECTION_DEFENSIVE
is a new selection mode. It is identical toMULTIPLE_INTERVAL_SELECTION
in every way but one. When a row is inserted immediately before a selected row in theMULTIPLE_INTERVAL_SELECTION
mode, it becomes selected. But in theMULTIPLE_INTERVAL_SELECTION_DEFENSIVE
mode, it does not become selected. To set this mode, usesetSelectionMode(ListSelection.MULTIPLE_INTERVAL_SELECTION_DEFENSIVE)
.
-
-
Field Summary
-
Fields inherited from interface javax.swing.ListSelectionModel
MULTIPLE_INTERVAL_SELECTION, SINGLE_INTERVAL_SELECTION, SINGLE_SELECTION
-
-
Constructor Summary
Constructors Constructor Description EventSelectionModel(EventList<E> source)
Creates a new selection model that also presents a list of the selection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListSelectionListener(ListSelectionListener listener)
Add a listener to the list that's notified each time a change to the selection occurs.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 inclusivevoid
addValidSelectionMatcher(Matcher<E> validSelectionMatcher)
Add a matcher which decides when source elements are valid for selection.void
clearSelection()
Change the selection to the empty set.void
dispose()
Releases the resources consumed by thisEventSelectionModel
so that it may eventually be garbage collected.int
getAnchorSelectionIndex()
Return the first index argument from the most recent call to setSelectionInterval(), addSelectionInterval() or removeSelectionInterval().EventList<E>
getDeselected()
Gets anEventList
that contains only deselected values and modifies the source list on mutation.boolean
getEnabled()
Returns whether the EventSelectionModel is editable or not.int
getLeadSelectionIndex()
Return the second index argument from the most recent call to setSelectionInterval(), addSelectionInterval() or removeSelectionInterval().int
getMaxSelectionIndex()
Gets the index of the last selected element.int
getMinSelectionIndex()
Gets the index of the first selected element.EventList<E>
getSelected()
Gets anEventList
that contains only selected values and modifies the source list on mutation.int
getSelectionMode()
Returns the current selection mode.EventList<E>
getTogglingDeselected()
Gets anEventList
that contains only deselected values and modifies the selection state on mutation.EventList<E>
getTogglingSelected()
Gets anEventList
that contains only selected values and modifies the selection state on mutation.boolean
getValueIsAdjusting()
Returns true if the value is undergoing a series of changes.void
insertIndexInterval(int index, int length, boolean before)
Insert length indices beginning before/after index.void
invertSelection()
Inverts the current selection.boolean
isSelectedIndex(int index)
Returns true if the specified index is selected.boolean
isSelectionEmpty()
Returns true if no indices are selected.void
removeIndexInterval(int index0, int index1)
Remove the indices in the interval index0,index1 (inclusive) from the selection model.void
removeListSelectionListener(ListSelectionListener listener)
Remove a listener from the list that's notified each time a change to the selection occurs.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.void
removeValidSelectionMatcher(Matcher<E> validSelectionMatcher)
Remove a matcher which decides when source elements are valid for selection.void
setAnchorSelectionIndex(int anchorSelectionIndex)
Set the anchor selection index.void
setEnabled(boolean enabled)
Set the EventSelectionModel as editable or not.void
setLeadSelectionIndex(int leadSelectionIndex)
Set the lead selection index.void
setSelectionInterval(int index0, int index1)
Change the selection to be between index0 and index1 inclusive.void
setSelectionMode(int selectionMode)
Set the selection mode.void
setValueIsAdjusting(boolean valueIsAdjusting)
This property is true if upcoming changes to the value of the model should be considered a single event.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.swing.ListSelectionModel
getSelectedIndices, getSelectedItemsCount
-
-
-
-
Constructor Detail
-
EventSelectionModel
public EventSelectionModel(EventList<E> source)
Creates a new selection model that also presents a list of the selection. TheEventSelectionModel
listens to thisEventList
in order to adjust selection when theEventList
is modified. For example, when an element is added to theEventList
, this may offset the selection of the following elements.- Parameters:
source
- theEventList
whose selection will be managed. This should be the sameEventList
passed to the constructor of yourEventTableModel
orEventListModel
.
-
-
Method Detail
-
getSelected
public EventList<E> getSelected()
Gets anEventList
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.
-
getTogglingSelected
public EventList<E> getTogglingSelected()
Gets anEventList
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 anIllegalArgumentException
is thrown.
-
getDeselected
public EventList<E> getDeselected()
Gets anEventList
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.
-
getTogglingDeselected
public EventList<E> getTogglingDeselected()
Gets anEventList
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 anIllegalArgumentException
is thrown
-
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.
-
getEnabled
public boolean getEnabled()
Returns whether the EventSelectionModel is editable or not.
-
invertSelection
public void invertSelection()
Inverts the current selection.
-
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.
- Specified by:
setSelectionInterval
in interfaceListSelectionModel
-
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- Specified by:
addSelectionInterval
in interfaceListSelectionModel
-
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.- Specified by:
removeSelectionInterval
in interfaceListSelectionModel
-
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.- Specified by:
isSelectedIndex
in interfaceListSelectionModel
-
getAnchorSelectionIndex
public int getAnchorSelectionIndex()
Return the first index argument from the most recent call to setSelectionInterval(), addSelectionInterval() or removeSelectionInterval().- Specified by:
getAnchorSelectionIndex
in interfaceListSelectionModel
-
setAnchorSelectionIndex
public void setAnchorSelectionIndex(int anchorSelectionIndex)
Set the anchor selection index.- Specified by:
setAnchorSelectionIndex
in interfaceListSelectionModel
-
getLeadSelectionIndex
public int getLeadSelectionIndex()
Return the second index argument from the most recent call to setSelectionInterval(), addSelectionInterval() or removeSelectionInterval().- Specified by:
getLeadSelectionIndex
in interfaceListSelectionModel
-
setLeadSelectionIndex
public void setLeadSelectionIndex(int leadSelectionIndex)
Set the lead selection index.- Specified by:
setLeadSelectionIndex
in interfaceListSelectionModel
-
getMinSelectionIndex
public int getMinSelectionIndex()
Gets the index of the first selected element.- Specified by:
getMinSelectionIndex
in interfaceListSelectionModel
-
getMaxSelectionIndex
public int getMaxSelectionIndex()
Gets the index of the last selected element.- Specified by:
getMaxSelectionIndex
in interfaceListSelectionModel
-
clearSelection
public void clearSelection()
Change the selection to the empty set.- Specified by:
clearSelection
in interfaceListSelectionModel
-
isSelectionEmpty
public boolean isSelectionEmpty()
Returns true if no indices are selected.- Specified by:
isSelectionEmpty
in interfaceListSelectionModel
-
insertIndexInterval
public void insertIndexInterval(int index, int length, boolean before)
Insert length indices beginning before/after index.- Specified by:
insertIndexInterval
in interfaceListSelectionModel
-
removeIndexInterval
public void removeIndexInterval(int index0, int index1)
Remove the indices in the interval index0,index1 (inclusive) from the selection model.- Specified by:
removeIndexInterval
in interfaceListSelectionModel
-
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.- Specified by:
setValueIsAdjusting
in interfaceListSelectionModel
-
getValueIsAdjusting
public boolean getValueIsAdjusting()
Returns true if the value is undergoing a series of changes.- Specified by:
getValueIsAdjusting
in interfaceListSelectionModel
-
setSelectionMode
public void setSelectionMode(int selectionMode)
Set the selection mode.- Specified by:
setSelectionMode
in interfaceListSelectionModel
-
getSelectionMode
public int getSelectionMode()
Returns the current selection mode.- Specified by:
getSelectionMode
in interfaceListSelectionModel
-
addValidSelectionMatcher
public void addValidSelectionMatcher(Matcher<E> validSelectionMatcher)
Add a matcher which decides when source elements are valid for selection.- Parameters:
validSelectionMatcher
- returnstrue
if a source element can be selected;false
otherwise
-
removeValidSelectionMatcher
public void removeValidSelectionMatcher(Matcher<E> validSelectionMatcher)
Remove a matcher which decides when source elements are valid for selection.- Parameters:
validSelectionMatcher
- returnstrue
if a source element can be selected;false
otherwise
-
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 tofor()
through the changed range without also verifying that each row is still in the table.- Specified by:
addListSelectionListener
in interfaceListSelectionModel
-
removeListSelectionListener
public void removeListSelectionListener(ListSelectionListener listener)
Remove a listener from the list that's notified each time a change to the selection occurs.- Specified by:
removeListSelectionListener
in interfaceListSelectionModel
-
dispose
public void dispose()
Releases the resources consumed by thisEventSelectionModel
so that it may eventually be garbage collected.An
EventSelectionModel
will be garbage collected without a call todispose()
, but not before its sourceEventList
is garbage collected. By callingdispose()
, you allow theEventSelectionModel
to be garbage collected before its sourceEventList
. This is necessary for situations where anEventSelectionModel
is short-lived but its sourceEventList
is long-lived.Warning: It is an error to call any method on a
EventSelectionModel
after it has been disposed.
-
-