|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectca.odell.glazedlists.swing.DefaultEventSelectionModel<E>
public final class DefaultEventSelectionModel<E>
An DefaultEventSelectionModel
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
DefaultEventSelectionModel
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)
.
DefaultEventSelectionModel
is not thread-safe. Unless otherwise
noted, all methods are only safe to be called from the event dispatch thread.
To do this programmatically, use SwingUtilities.invokeAndWait(Runnable)
and
wrap the source list (or some part of the source list's pipeline) using
GlazedListsSwing#swingThreadProxyList(EventList).
Field Summary |
---|
Fields inherited from interface javax.swing.ListSelectionModel |
---|
MULTIPLE_INTERVAL_SELECTION, SINGLE_INTERVAL_SELECTION, SINGLE_SELECTION |
Constructor Summary | |
---|---|
DefaultEventSelectionModel(EventList<E> source)
Creates a new selection model that also presents a list of the selection. |
|
DefaultEventSelectionModel(EventList<E> source,
boolean disposeSource)
Creates a new selection model that also presents a list of the selection. |
Method Summary | |
---|---|
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 inclusive |
void |
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 this AdvancedListSelectionModel 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 an EventList 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 an EventList that contains only selected
values and modifies the source list on mutation. |
int |
getSelectionMode()
Returns the current selection mode. |
EventList<E> |
getTogglingDeselected()
Gets an EventList that contains only deselected values and
modifies the selection state on mutation. |
EventList<E> |
getTogglingSelected()
Gets an EventList 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 |
Constructor Detail |
---|
public DefaultEventSelectionModel(EventList<E> source)
DefaultEventSelectionModel
listens to this EventList
in order
to adjust selection when the EventList
is modified. For example,
when an element is added to the EventList
, this may offset the
selection of the following elements.
source
- the EventList
whose selection will be managed. This should
be the same EventList
passed to the constructor of your
DefaultEventTableModel
or DefaultEventListModel
.public DefaultEventSelectionModel(EventList<E> source, boolean disposeSource)
DefaultEventSelectionModel
listens to this EventList
in order to adjust
selection when the EventList
is modified. For example, when an element is added to
the EventList
, this may offset the selection of the following elements.
source
- the EventList
whose selection will be managed. This should be the
same EventList
passed to the constructor of your
DefaultEventTableModel
or DefaultEventListModel
.disposeSource
- true
if the source list should be disposed when disposing
this model, false
otherwiseMethod Detail |
---|
public EventList<E> getSelected()
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.
getSelected
in interface AdvancedListSelectionModel<E>
public EventList<E> getTogglingSelected()
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.
getTogglingSelected
in interface AdvancedListSelectionModel<E>
public EventList<E> getDeselected()
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.
getDeselected
in interface AdvancedListSelectionModel<E>
public EventList<E> getTogglingDeselected()
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
getTogglingDeselected
in interface AdvancedListSelectionModel<E>
public void setEnabled(boolean enabled)
Note that this will also disable the selection from being modified programatically. Therefore you must use setEnabled(true) to modify the selection in code.
setEnabled
in interface AdvancedListSelectionModel<E>
public boolean getEnabled()
getEnabled
in interface AdvancedListSelectionModel<E>
public void invertSelection()
invertSelection
in interface AdvancedListSelectionModel<E>
public void setSelectionInterval(int index0, int index1)
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.
setSelectionInterval
in interface ListSelectionModel
public void addSelectionInterval(int index0, int index1)
addSelectionInterval
in interface ListSelectionModel
public void removeSelectionInterval(int index0, int index1)
removeSelectionInterval
in interface ListSelectionModel
public boolean isSelectedIndex(int index)
isSelectedIndex
in interface ListSelectionModel
public int getAnchorSelectionIndex()
getAnchorSelectionIndex
in interface ListSelectionModel
public void setAnchorSelectionIndex(int anchorSelectionIndex)
setAnchorSelectionIndex
in interface ListSelectionModel
public int getLeadSelectionIndex()
getLeadSelectionIndex
in interface ListSelectionModel
public void setLeadSelectionIndex(int leadSelectionIndex)
setLeadSelectionIndex
in interface ListSelectionModel
public int getMinSelectionIndex()
getMinSelectionIndex
in interface ListSelectionModel
public int getMaxSelectionIndex()
getMaxSelectionIndex
in interface ListSelectionModel
public void clearSelection()
clearSelection
in interface ListSelectionModel
public boolean isSelectionEmpty()
isSelectionEmpty
in interface ListSelectionModel
public void insertIndexInterval(int index, int length, boolean before)
insertIndexInterval
in interface ListSelectionModel
public void removeIndexInterval(int index0, int index1)
removeIndexInterval
in interface ListSelectionModel
public void setValueIsAdjusting(boolean valueIsAdjusting)
setValueIsAdjusting
in interface ListSelectionModel
public boolean getValueIsAdjusting()
getValueIsAdjusting
in interface ListSelectionModel
public void setSelectionMode(int selectionMode)
setSelectionMode
in interface ListSelectionModel
public int getSelectionMode()
getSelectionMode
in interface ListSelectionModel
public void addValidSelectionMatcher(Matcher<E> validSelectionMatcher)
addValidSelectionMatcher
in interface AdvancedListSelectionModel<E>
validSelectionMatcher
- returns true if a source element
can be selected; false otherwisepublic void removeValidSelectionMatcher(Matcher<E> validSelectionMatcher)
removeValidSelectionMatcher
in interface AdvancedListSelectionModel<E>
validSelectionMatcher
- returns true if a source element
can be selected; false otherwisepublic void addListSelectionListener(ListSelectionListener listener)
for()
through the changed range without
also verifying that each row is still in the table.
addListSelectionListener
in interface ListSelectionModel
public void removeListSelectionListener(ListSelectionListener listener)
removeListSelectionListener
in interface ListSelectionModel
public void dispose()
AdvancedListSelectionModel
so that it
may eventually be garbage collected.
An AdvancedListSelectionModel
will be garbage collected without a call to
AdvancedListSelectionModel.dispose()
, but not before its source EventList
is garbage
collected. By calling AdvancedListSelectionModel.dispose()
, you allow the AdvancedListSelectionModel
to be garbage collected before its source EventList
. This is
necessary for situations where an AdvancedListSelectionModel
is short-lived but
its source EventList
is long-lived.
Warning: It is an error
to call any method on a AdvancedListSelectionModel
after it has been disposed.
dispose
in interface AdvancedListSelectionModel<E>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |