javax.swing
public class DefaultListSelectionModel extends Object implements Cloneable, ListSelectionModel, Serializable
ListSelectionModel
,
which is used by JList
and
similar classes to manage the selection status of a number of data
elements.
The class is organized abstractly as a set of intervals of integers. Each interval indicates an inclusive range of indices in a list -- held by some other object and unknown to this class -- which is considered "selected". There are various accessors for querying and modifying the set of intervals, with simplified forms accepting a single index, representing an interval with only one element.
Modifier and Type | Field and Description |
---|---|
protected boolean |
leadAnchorNotificationEnabled
controls the range of indices provided in any
ListSelectionEvent fired by the selectionModel. |
protected EventListenerList |
listenerList
The list of ListSelectionListeners subscribed to this selection model.
|
MULTIPLE_INTERVAL_SELECTION, SINGLE_INTERVAL_SELECTION, SINGLE_SELECTION
Constructor and Description |
---|
DefaultListSelectionModel() |
Modifier and Type | Method and Description |
---|---|
void |
addListSelectionListener(ListSelectionListener listener)
Adds a listener.
|
void |
addSelectionInterval(int index0,
int index1)
If the
selectionMode property is equal to
SINGLE_SELECTION equivalent to calling
setSelectionInterval(index1, index2) ;
If the selectionMode property is equal to
SINGLE_INTERVAL_SELECTION and the interval being
added is not adjacent to an already selected interval,
equivalent to setSelectionInterval(index1, index2) . |
void |
clearSelection()
Removes all intervals in the selection set.
|
Object |
clone()
Returns a clone of this object.
|
protected void |
fireValueChanged(boolean isAdjusting)
Fires a
ListSelectionEvent to all the listeners of type ListSelectionListener registered with this selection model to
indicate that a series of adjustment has just ended. |
protected void |
fireValueChanged(int firstIndex,
int lastIndex)
Fires a
ListSelectionEvent to all the listeners of type ListSelectionListener registered with this selection model. |
protected void |
fireValueChanged(int firstIndex,
int lastIndex,
boolean isAdjusting)
Fires a
ListSelectionEvent to all the listeners of type ListSelectionListener registered with this selection model. |
int |
getAnchorSelectionIndex()
Gets the value of the
anchorSelectionIndex property. |
int |
getLeadSelectionIndex()
Gets the value of the
leadSelectionIndex property. |
<T extends EventListener> |
getListeners(Class<T> listenerType)
Returns an array of all registerers listeners.
|
ListSelectionListener[] |
getListSelectionListeners()
Returns an array of all registerd list selection listeners.
|
int |
getMaxSelectionIndex()
Gets the largest index which is currently a member of a selection
interval.
|
int |
getMinSelectionIndex()
Gets the smallest index which is currently a member of a selection
interval.
|
int |
getSelectionMode()
Returns the selection mode, which is one of
ListSelectionModel.SINGLE_SELECTION ,
ListSelectionModel.SINGLE_INTERVAL_SELECTION and
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION . |
boolean |
getValueIsAdjusting()
Gets the value of the
valueIsAdjusting property. |
void |
insertIndexInterval(int index,
int length,
boolean before)
Inserts a number of indices either before or after a particular
position in the set of indices.
|
boolean |
isLeadAnchorNotificationEnabled()
Gets the value of the
leadAnchorNotificationEnabled property. |
boolean |
isSelectedIndex(int a)
Determines whether a particular index is a member of a selection
interval.
|
boolean |
isSelectionEmpty()
Determines whether the selection is empty.
|
void |
moveLeadSelectionIndex(int leadIndex)
Moves the lead selection index to
leadIndex without
changing the selection values. |
void |
removeIndexInterval(int index0,
int index1)
Removes a range from the set of indices.
|
void |
removeListSelectionListener(ListSelectionListener listener)
Removes a registered listener.
|
void |
removeSelectionInterval(int index0,
int index1)
Deselects all indices in the inclusive range
[index0,index1] . |
void |
setAnchorSelectionIndex(int index)
Sets the value of the
anchorSelectionIndex property. |
void |
setLeadAnchorNotificationEnabled(boolean l)
Sets the value of the
leadAnchorNotificationEnabled property. |
void |
setLeadSelectionIndex(int leadIndex)
Sets the value of the
anchorSelectionIndex property. |
void |
setSelectionInterval(int anchor,
int lead)
Clears the current selection and marks a given interval as "selected".
|
void |
setSelectionMode(int mode)
Sets the value of the
selectionMode property. |
void |
setValueIsAdjusting(boolean v)
Sets the value of the
valueIsAdjusting property. |
protected EventListenerList listenerList
protected boolean leadAnchorNotificationEnabled
ListSelectionEvent
fired by the selectionModel. Let
[A,L]
be the range of indices between anchorSelectionIndex
and leadSelectionIndex
inclusive, and
let [i0,i1]
be the range of indices changed in a given
call which generates a ListSelectionEvent
. Then when this
property is true
, the ListSelectionEvent
contains
the range [A,L] union [i0,i1]
; when false
it
will contain only [i0,i1]
. The default is
true
.public DefaultListSelectionModel()
public int getSelectionMode()
ListSelectionModel.SINGLE_SELECTION
,
ListSelectionModel.SINGLE_INTERVAL_SELECTION
and
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
. The default value is
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
.getSelectionMode
in interface ListSelectionModel
setSelectionMode(int)
public void setSelectionMode(int mode)
selectionMode
property.setSelectionMode
in interface ListSelectionModel
mode
- The new value of the propertyListSelectionModel.getSelectionMode()
public int getAnchorSelectionIndex()
anchorSelectionIndex
property.getAnchorSelectionIndex
in interface ListSelectionModel
setAnchorSelectionIndex(int)
public void setAnchorSelectionIndex(int index)
anchorSelectionIndex
property.setAnchorSelectionIndex
in interface ListSelectionModel
index
- The new property valuegetAnchorSelectionIndex()
public int getLeadSelectionIndex()
leadSelectionIndex
property.getLeadSelectionIndex
in interface ListSelectionModel
setLeadSelectionIndex(int)
public void setLeadSelectionIndex(int leadIndex)
Sets the value of the anchorSelectionIndex
property. As a
side effect, alters the selection status of two ranges of indices. Let
OL
be the old lead selection index, NL
be
the new lead selection index, and A
be the anchor
selection index. Then if A
is a valid selection index,
one of two things happens depending on the seleciton status of
A
:
isSelectedIndex(A) == true
: set [A,OL]
to deselected, then set [A,NL]
to
selected.isSelectedIndex(A) == false
: set [A,OL]
to selected, then set [A,NL]
to
deselected.This method generates at most a single ListSelectionEvent
despite changing multiple ranges. The range of values provided to the
ListSelectionEvent
includes only the minimum range of values
which changed selection status between the beginning and end of the
method.
setLeadSelectionIndex
in interface ListSelectionModel
leadIndex
- The new property valuegetAnchorSelectionIndex()
public void moveLeadSelectionIndex(int leadIndex)
leadIndex
without
changing the selection values.
If leadAnchorNotificationEnabled is true, send a notification covering the
old and new lead cells.leadIndex
- the new lead selection indexpublic boolean isLeadAnchorNotificationEnabled()
leadAnchorNotificationEnabled
property.setLeadAnchorNotificationEnabled(boolean)
public void setLeadAnchorNotificationEnabled(boolean l)
leadAnchorNotificationEnabled
property.l
- The new property valueisLeadAnchorNotificationEnabled()
public boolean getValueIsAdjusting()
valueIsAdjusting
property.getValueIsAdjusting
in interface ListSelectionModel
setValueIsAdjusting(boolean)
public void setValueIsAdjusting(boolean v)
valueIsAdjusting
property.setValueIsAdjusting
in interface ListSelectionModel
v
- The new property valuegetValueIsAdjusting()
public boolean isSelectionEmpty()
isSelectionEmpty
in interface ListSelectionModel
true
if the selection is empty, otherwise
false
public int getMinSelectionIndex()
getMinSelectionIndex
in interface ListSelectionModel
i
such that i >=
0
and i
is a member of a selected interval, or
-1
if there are no selected intervalsgetMaxSelectionIndex()
public int getMaxSelectionIndex()
getMaxSelectionIndex
in interface ListSelectionModel
i
such that i >=
0
and i
is a member of a selected interval, or
-1
if there are no selected intervalsgetMinSelectionIndex()
public boolean isSelectedIndex(int a)
isSelectedIndex
in interface ListSelectionModel
a
- The index to search fortrue
if the index is a member of a selection interval,
otherwise false
public void addSelectionInterval(int index0, int index1)
selectionMode
property is equal to
SINGLE_SELECTION
equivalent to calling
setSelectionInterval(index1, index2)
;
If the selectionMode
property is equal to
SINGLE_INTERVAL_SELECTION
and the interval being
added is not adjacent to an already selected interval,
equivalent to setSelectionInterval(index1, index2)
.
Otherwise adds the range [index0, index1]
to the selection interval set.addSelectionInterval
in interface ListSelectionModel
index0
- The beginning of the range of indices to selectindex1
- The end of the range of indices to selectsetSelectionInterval(int, int)
,
removeSelectionInterval(int, int)
public void removeSelectionInterval(int index0, int index1)
[index0,index1]
.removeSelectionInterval
in interface ListSelectionModel
index0
- The beginning of the range of indices to deselectindex1
- The end of the range of indices to deselectaddSelectionInterval(int, int)
,
setSelectionInterval(int, int)
public void clearSelection()
clearSelection
in interface ListSelectionModel
public void setSelectionInterval(int anchor, int lead)
SINGLE_SELECTION
only the
index index2
is selected.setSelectionInterval
in interface ListSelectionModel
anchor
- the anchor selection index.lead
- the lead selection index.public void insertIndexInterval(int index, int length, boolean before)
ListModel
.insertIndexInterval
in interface ListSelectionModel
index
- The position to insert indices atlength
- The number of indices to insertbefore
- Indicates whether to insert the indices before the index
or after itListSelectionModel.removeIndexInterval(int, int)
public void removeIndexInterval(int index0, int index1)
ListModel
.removeIndexInterval
in interface ListSelectionModel
index0
- The first index to remove (inclusive)index1
- The last index to remove (inclusive)ListSelectionModel.insertIndexInterval(int, int, boolean)
protected void fireValueChanged(boolean isAdjusting)
ListSelectionEvent
to all the listeners of type ListSelectionListener
registered with this selection model to
indicate that a series of adjustment has just ended.
The values of getMinSelectionIndex()
and
getMaxSelectionIndex()
are used in the ListSelectionEvent
that gets fired.isAdjusting
- true
if this is the final change
in a series of adjustments, false/code> otherwise
protected void fireValueChanged(int firstIndex, int lastIndex)
ListSelectionEvent
to all the listeners of type ListSelectionListener
registered with this selection model.firstIndex
- The low index of the changed rangelastIndex
- The high index of the changed rangeprotected void fireValueChanged(int firstIndex, int lastIndex, boolean isAdjusting)
ListSelectionEvent
to all the listeners of type ListSelectionListener
registered with this selection model.firstIndex
- The low index of the changed rangelastIndex
- The high index of the changed rangeisAdjusting
- Whether this change is part of a seqence of adjustments
made to the selection, such as during interactive scrollingpublic void addListSelectionListener(ListSelectionListener listener)
addListSelectionListener
in interface ListSelectionModel
listener
- The listener to addremoveListSelectionListener(javax.swing.event.ListSelectionListener)
,
getListSelectionListeners()
public void removeListSelectionListener(ListSelectionListener listener)
removeListSelectionListener
in interface ListSelectionModel
listener
- The listener to removeaddListSelectionListener(javax.swing.event.ListSelectionListener)
,
getListSelectionListeners()
public <T extends EventListener> T[] getListeners(Class<T> listenerType)
listenerType
- The type of listener to retrievegetListSelectionListeners()
public ListSelectionListener[] getListSelectionListeners()
addListSelectionListener(javax.swing.event.ListSelectionListener)
,
removeListSelectionListener(javax.swing.event.ListSelectionListener)
,
getListeners(java.lang.Class)
public Object clone() throws CloneNotSupportedException
listenerList
don't gets duplicated.clone
in class Object
CloneNotSupportedException
- if an error occursCloneable