public class ListSelectionModel
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.util.ArrayList<SelectionListener> |
listeners
List of listeners.
|
private int |
mode
Active selection mode.
|
static int |
MULTIPLE_INTERVAL_SELECTION
Multiple intervals selection mode.
|
private java.util.TreeSet<java.lang.Integer> |
selection
Selected item index storage.
|
static int |
SINGLE_INTERVAL_SELECTION
Single interval selection mode.
|
static int |
SINGLE_SELECTION
Single item selection mode.
|
Constructor and Description |
---|
ListSelectionModel() |
Modifier and Type | Method and Description |
---|---|
void |
add(SelectionListener listener)
Add selection item listener.
|
private static java.util.TreeSet<java.lang.Integer> |
asSet(int from,
int to)
Convert index range into set.
|
boolean |
clear()
Clear model and remove selection.
|
boolean |
deselect(int from,
int to)
Remove specified range of items from selection.
|
int |
first()
Get first selected index.
|
boolean |
isEmpty()
Check if selection is empty.
|
int |
last()
Get last selected index.
|
int |
mode()
Get current selection mode.
|
void |
notifyListeners()
Trigger notification of listeners.
|
boolean |
select(int from,
int to)
Add specified range of items to the current selection.
|
boolean |
selected(int index)
Test if specified index is selected.
|
int[] |
selection()
Get all selected indices as array.
|
boolean |
set(int from,
int to)
Set selection to specified interval.
|
boolean |
setMode(int mode)
Set selection mode.
|
private void |
setSelectionNoCheck(java.util.TreeSet<java.lang.Integer> newSel)
Set new selection and notify listeners.
|
int |
size()
Number of selected items.
|
public static final int SINGLE_SELECTION
public static final int SINGLE_INTERVAL_SELECTION
public static final int MULTIPLE_INTERVAL_SELECTION
private java.util.ArrayList<SelectionListener> listeners
private int mode
private java.util.TreeSet<java.lang.Integer> selection
public final boolean select(int from, int to)
from
- Start index in the range.to
- End index in the range.true
if selection was changed as the result of the callpublic void add(SelectionListener listener)
listener
- Listener to add.public boolean clear()
true
if this list was changed as the result of the callpublic boolean isEmpty()
true
if selection is empty.public int size()
public int first()
public int last()
public int mode()
public int[] selection()
public final boolean deselect(int from, int to)
from
- Start index in the range.to
- End index in the range.true
if selection was changedpublic boolean selected(int index)
index
- Index to test.true
if index is in one of selected ranges.public boolean set(int from, int to)
from
- Start index in the range.to
- End index in the range.true
if selection was changed by this callpublic boolean setMode(int mode)
mode
- Selection mode.true
if mode was changed by this callpublic void notifyListeners()
private static java.util.TreeSet<java.lang.Integer> asSet(int from, int to)
from
- Initial index.to
- Final index.private final void setSelectionNoCheck(java.util.TreeSet<java.lang.Integer> newSel)
newSel
- the new selection, assumed to differ from the current one.