ca.odell.glazedlists

Class ListSelection<E>


public class ListSelection<E>
extends java.lang.Object

An EventList to provide index-based selection features. This EventList does not perform a transformation on the source, but instead provides two additional EventLists:

This design is intended to allow the sharing of selection logic between both of our 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.

Author:
Kevin Maltby

Nested Class Summary

static interface
ListSelection.Listener
A generic interface to respond to changes in selection that doesn't require including a particular GUI toolkit.

Field Summary

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 Summary

ListSelection(EventList source)
Creates a new ListSelection that listens to changes on the given source.
ListSelection(EventList source, int[] initialSelection)
Creates a new ListSelection that listens to changes on the given source and initializes selection with the given array of indices.

Method Summary

void
addSelectionListener(ListSelection.Listener selectionListener)
Register a Listener that will be notified when selection is changed.
void
deselect(int index)
Deselects the element at the given index.
void
deselect(int start, int end)
Deselects all of the elements within the given range.
void
deselect(int[] indices)
Deselects all of the elements in the given array of indices.
void
deselectAll()
Deselects 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
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
getSelected()
Gets an EventList that contains only selected values and modifies the source list on mutation.
int
getSelectionMode()
Returns the current selection mode.
EventList
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
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
removeSelectionListener(ListSelection.Listener selectionListener)
Remove a Listener so that it will no longer be notified when selection changes.
boolean
select(Collection 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 start, int end)
Selects all of the elements within the given range.
void
select(int[] indices)
Selects all of the elements in the given array of indices.
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 start, int end)
Sets the selection to be only elements within the given range.
void
setSelection(int[] indices)
Sets the selection to be only the element in the given array of indices.
void
setSelectionMode(int selectionMode)
Set the selection mode.

Field Details

MULTIPLE_INTERVAL_SELECTION

public static final int MULTIPLE_INTERVAL_SELECTION
A selection mode where any element may be selected and elements added adjacent to selected elements are selected. For convenience, this value equals javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION.
Field Value:
2

MULTIPLE_INTERVAL_SELECTION_DEFENSIVE

public static final int MULTIPLE_INTERVAL_SELECTION_DEFENSIVE
A selection mode where any element may be selected and freshly added elements are always deselected. No equivalent policy exists in javax.swing.ListSelectionModel
Field Value:
103

SINGLE_INTERVAL_SELECTION

public static final int SINGLE_INTERVAL_SELECTION
A selection mode where at most one range of elements may be selected at one time. For convenience, this value equals javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION.
Field Value:
1

SINGLE_SELECTION

public static final int SINGLE_SELECTION
A selection mode where at most one element may be selected at one time. For convenience, this value equals javax.swing.ListSelectionModel.SINGLE_SELECTION.
Field Value:
0

Constructor Details

ListSelection

public ListSelection(EventList source)
Creates a new ListSelection that listens to changes on the given source. When using this constructor, all elements are deselected by default.

ListSelection

public ListSelection(EventList source,
                     int[] initialSelection)
Creates a new ListSelection that listens to changes on the given source and initializes selection with the given array of indices.

Method Details

addSelectionListener

public void addSelectionListener(ListSelection.Listener selectionListener)
Register a Listener that will be notified when selection is changed.

deselect

public void deselect(int index)
Deselects the element at the given index.

deselect

public void deselect(int start,
                     int end)
Deselects all of the elements within the given range.

deselect

public void deselect(int[] indices)
Deselects all of the elements in the given array of indices. The array must contain indices in sorted, ascending order.

deselectAll

public void deselectAll()
Deselects all elements.

dispose

public void dispose()
Disposes of this ListSelection freeing up it's resources for garbage collection. It is an error to use a ListSelection after dispose() has been called.

getAnchorSelectionIndex

public int getAnchorSelectionIndex()
Return the anchor of the current selection.

getDeselected

public EventList getDeselected()
Gets an 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.

getLeadSelectionIndex

public int getLeadSelectionIndex()
Return the lead of the current selection.

getMaxSelectionIndex

public int getMaxSelectionIndex()
Returns the last selected index or -1 if nothing is selected.

getMinSelectionIndex

public int getMinSelectionIndex()
Returns the first selected index or -1 if nothing is selected.

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.

getSource

public EventList getSource()
Get the EventList that selection is being managed for.

getTogglingDeselected

public EventList<E> 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. This list does not support the set method.


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. This list does not support the set method.


invertSelection

public void invertSelection()
Inverts the current selection.

isSelected

public boolean isSelected(int sourceIndex)
Returns whether or not the item with the given source index is selected.

removeSelectionListener

public void removeSelectionListener(ListSelection.Listener selectionListener)
Remove a Listener so that it will no longer be notified when selection changes.

select

public boolean select(Collection values)
Select all of the specified values.
Returns:
true if the selection changed as a result of the call.

select

public int select(E value)
Select the specified element, if it exists.
Returns:
the index of the newly selected element, or -1 if no element was found.

select

public void select(int index)
Selects the element at the given index.

select

public void select(int start,
                   int end)
Selects all of the elements within the given range.

select

public void select(int[] indices)
Selects all of the elements in the given array of indices. The array must contain indices in sorted, ascending order.

selectAll

public void selectAll()
Selects all elements.

setAnchorSelectionIndex

public void setAnchorSelectionIndex(int anchorSelectionIndex)
Set the anchor selection index.

setLeadSelectionIndex

public void setLeadSelectionIndex(int leadSelectionIndex)
Set the lead selection index.

setSelection

public void setSelection(int index)
Sets the selection to be only the element at the given index. If the given index is -1, the selection will be cleared.

setSelection

public void setSelection(int start,
                         int end)
Sets the selection to be only elements within the given range. If the endpoints of the range are -1, the selection will be cleared.

setSelection

public void setSelection(int[] indices)
Sets the selection to be only the element in the given array of indices. Unlike setSelection(int) and setSelection(int,int), providing a value of -1 is an error. The array must contain indices in sorted, ascending order.

setSelectionMode

public void setSelectionMode(int selectionMode)
Set the selection mode.

Glazed Lists, Copyright © 2003-2006 publicobject.com, O'Dell Engineering.
Documentation build by buildd at 2008-01-04 14:38