public class ListSelection<E> extends Object implements ListEventListener<E>
EventList
:
Selected
- an EventList
that contains only the selected
values.Deselected
- an EventList
that contains only the deselected
values.This design is intended to allow the sharing of selection logic between all supported GUI toolkits as well as being available for use in non-GUI applications and for index-based filtering.
Warning: This class is thread ready but not thread
safe. See EventList
for an example of thread safe code.
Modifier and Type | Class and Description |
---|---|
static interface |
ListSelection.Listener
A generic interface to respond to changes in selection that doesn't require including a
particular GUI toolkit.
|
Modifier and Type | Field and Description |
---|---|
static int |
MULTIPLE_INTERVAL_SELECTION
A selection mode where any element may be selected and elements added adjacent to selected
elements are selected.
|
static int |
MULTIPLE_INTERVAL_SELECTION_DEFENSIVE
A selection mode where any element may be selected and freshly added elements are always
deselected.
|
static int |
SINGLE_INTERVAL_SELECTION
A selection mode where at most one range of elements may be selected at one time.
|
static int |
SINGLE_SELECTION
A selection mode where at most one element may be selected at one time.
|
Constructor and Description |
---|
ListSelection(EventList<E> source)
Creates a new ListSelection that listens to changes on the given source.
|
ListSelection(EventList<E> source,
int[] initialSelection)
Creates a new ListSelection that listens to changes on the given source and initializes
selection with the given array of indices.
|
Modifier and Type | Method and Description |
---|---|
void |
addSelectionListener(ListSelection.Listener selectionListener)
Register a
Listener that will be notified when selection is changed. |
void |
addValidSelectionMatcher(Matcher<E> validSelectionMatcher)
Add a matcher which decides when source elements are valid for selection.
|
void |
deselect(int index)
Deselects the element at the given index.
|
void |
deselect(int[] indices)
Deselects all of the elements in the given array of indices.
|
void |
deselect(int start,
int end)
Deselects all of the elements within the given range.
|
void |
deselectAll()
Deselect all elements.
|
void |
dispose()
Disposes of this ListSelection freeing up it's resources for garbage collection.
|
int |
getAnchorSelectionIndex()
Return the anchor of the current selection.
|
EventList<E> |
getDeselected()
Gets an
EventList that contains only deselected values add modifies the source list on
mutation. |
int |
getLeadSelectionIndex()
Return the lead of the current selection.
|
int |
getMaxSelectionIndex()
Returns the last selected index or -1 if nothing is selected.
|
int |
getMinSelectionIndex()
Returns the first selected index or -1 if nothing is selected.
|
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> |
getSource()
Get the
EventList that selection is being managed for. |
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. |
void |
invertSelection()
Inverts the current selection.
|
boolean |
isSelected(int sourceIndex)
Returns whether or not the item with the given source index is selected.
|
void |
listChanged(ListEvent<E> listChanges)
Handle changes to the source list by adjusting our selection state and the contents of the
selected and deselected lists.
|
void |
removeSelectionListener(ListSelection.Listener selectionListener)
Remove a
Listener so that it will no longer be notified when selection
changes. |
void |
removeValidSelectionMatcher(Matcher<E> validSelectionMatcher)
Remove a matcher which decides when source elements are valid for selection.
|
boolean |
select(Collection<E> values)
Select all of the specified values.
|
int |
select(E value)
Select the specified element, if it exists.
|
void |
select(int index)
Selects the element at the given index.
|
void |
select(int[] indices)
Selects all of the elements in the given array of indices.
|
void |
select(int start,
int end)
Selects all of the elements within the given range.
|
void |
selectAll()
Selects all elements.
|
void |
setAnchorSelectionIndex(int anchorSelectionIndex)
Set the anchor selection index.
|
void |
setLeadSelectionIndex(int leadSelectionIndex)
Set the lead selection index.
|
void |
setSelection(int index)
Sets the selection to be only the element at the given index.
|
void |
setSelection(int[] indices)
Sets the selection to be only the element in the given array of indices.
|
void |
setSelection(int start,
int end)
Sets the selection to be only elements within the given range.
|
void |
setSelectionMode(int selectionMode)
Set the selection mode.
|
public static final int SINGLE_SELECTION
ListSelectionModel.SINGLE_SELECTION
.public static final int SINGLE_INTERVAL_SELECTION
ListSelectionModel.SINGLE_INTERVAL_SELECTION
.public static final int MULTIPLE_INTERVAL_SELECTION
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
.public static final int MULTIPLE_INTERVAL_SELECTION_DEFENSIVE
ListSelectionModel
public ListSelection(EventList<E> source)
public void listChanged(ListEvent<E> listChanges)
listChanged
in interface ListEventListener<E>
listChanges
- a ListEvent
describing the changes to the listpublic void addValidSelectionMatcher(Matcher<E> validSelectionMatcher)
validSelectionMatcher
- returns true
if a source elements can be selected;
false
otherwisepublic void removeValidSelectionMatcher(Matcher<E> validSelectionMatcher)
validSelectionMatcher
- returns true
if a source elements can be selected;
false
otherwisepublic 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.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. This list does not support
the set
method.
public EventList<E> getDeselected()
EventList
that contains only deselected values add modifies the source list on
mutation.
Adding and removing items from this list performs the same operation on the source list.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. This list does not support
the set
method.
public void invertSelection()
public boolean isSelected(int sourceIndex)
public void deselect(int index)
public void deselect(int start, int end)
public void deselect(int[] indices)
public void deselectAll()
public void select(int index)
public void select(int start, int end)
public void select(int[] indices)
public int select(E value)
public boolean select(Collection<E> values)
true
if the selection changed as a result of the call.public void selectAll()
public void setSelection(int index)
public void setSelection(int start, int end)
public void setSelection(int[] indices)
setSelection(int)
and setSelection(int,int)
, providing a value of -1 is an
error. The array must contain indices in sorted, ascending order.public int getAnchorSelectionIndex()
public void setAnchorSelectionIndex(int anchorSelectionIndex)
public int getLeadSelectionIndex()
public void setLeadSelectionIndex(int leadSelectionIndex)
public int getSelectionMode()
public void setSelectionMode(int selectionMode)
public int getMinSelectionIndex()
public int getMaxSelectionIndex()
public void addSelectionListener(ListSelection.Listener selectionListener)
Listener
that will be notified when selection is changed.public void removeSelectionListener(ListSelection.Listener selectionListener)
Listener
so that it will no longer be notified when selection
changes.public void dispose()
Copyright © 2024 levigo holding gmbh. All rights reserved.