Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
javax.swing.DefaultListSelectionModel
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.
Field Summary | |
protected boolean |
|
protected EventListenerList |
|
Fields inherited from interface javax.swing.ListSelectionModel | |
MULTIPLE_INTERVAL_SELECTION , SINGLE_INTERVAL_SELECTION , SINGLE_SELECTION |
Method Summary | |
void |
|
void |
|
void |
|
Object |
|
|
|
protected void |
|
protected void |
|
protected void |
|
int |
|
int |
|
ListSelectionListener[] |
|
int |
|
int |
|
int |
|
boolean |
|
void |
|
boolean |
|
boolean |
|
boolean |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
protected boolean leadAnchorNotificationEnabled
controls the range of indices provided in anyListSelectionEvent
fired by the selectionModel. Let[A,L]
be the range of indices betweenanchorSelectionIndex
andleadSelectionIndex
inclusive, and let[i0,i1]
be the range of indices changed in a given call which generates aListSelectionEvent
. Then when this property istrue
, theListSelectionEvent
contains the range[A,L] union [i0,i1]
; whenfalse
it will contain only[i0,i1]
. The default istrue
.
protected EventListenerList listenerList
The list of ListSelectionListeners subscribed to this selection model.
public void addListSelectionListener(ListSelectionListener listener)
Adds a listener.
- Specified by:
- addListSelectionListener in interface ListSelectionModel
- Parameters:
listener
- The listener to add
public void addSelectionInterval(int index0, int index1)
If theselectionMode
property is equal toSINGLE_SELECTION
equivalent to callingsetSelectionInterval(index1, index2)
; If theselectionMode
property is equal toSINGLE_INTERVAL_SELECTION
and the interval being added is not adjacent to an already selected interval, equivalent tosetSelectionInterval(index1, index2)
. Otherwise adds the range[index0, index1]
to the selection interval set.
- Specified by:
- addSelectionInterval in interface ListSelectionModel
- Parameters:
index0
- The beginning of the range of indices to selectindex1
- The end of the range of indices to select
public void clearSelection()
Removes all intervals in the selection set.
- Specified by:
- clearSelection in interface ListSelectionModel
public Object clone() throws CloneNotSupportedException
Returns a clone of this object.listenerList
don't gets duplicated.
- Returns:
- the cloned object
- Throws:
CloneNotSupportedException
- if an error occurs
publicextends EventListener> T[] getListeners (ClasslistenerType)
Returns an array of all registerers listeners.
- Parameters:
listenerType
- The type of listener to retrieve
- Returns:
- The array
- Since:
- 1.3
- See Also:
getListSelectionListeners()
protected void fireValueChanged(boolean isAdjusting)
Fires aListSelectionEvent
to all the listeners of typeListSelectionListener
registered with this selection model to indicate that a series of adjustment has just ended. The values ofgetMinSelectionIndex()
andgetMaxSelectionIndex()
are used in theListSelectionEvent
that gets fired.
- Parameters:
isAdjusting
-true
if this is the final change in a series of adjustments,false/code> otherwise
protected void fireValueChanged(int firstIndex, int lastIndex)
Fires aListSelectionEvent
to all the listeners of typeListSelectionListener
registered with this selection model.
- Parameters:
firstIndex
- The low index of the changed rangelastIndex
- The high index of the changed range
protected void fireValueChanged(int firstIndex, int lastIndex, boolean isAdjusting)
Fires aListSelectionEvent
to all the listeners of typeListSelectionListener
registered with this selection model.
- Parameters:
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 scrolling
public int getAnchorSelectionIndex()
Gets the value of theanchorSelectionIndex
property.
- Specified by:
- getAnchorSelectionIndex in interface ListSelectionModel
- Returns:
- The current property value
- See Also:
setAnchorSelectionIndex(int)
public int getLeadSelectionIndex()
Gets the value of theleadSelectionIndex
property.
- Specified by:
- getLeadSelectionIndex in interface ListSelectionModel
- Returns:
- The current property value
- See Also:
setLeadSelectionIndex(int)
public ListSelectionListener[] getListSelectionListeners()
Returns an array of all registerd list selection listeners.
- Returns:
- the array
- Since:
- 1.4
- See Also:
addListSelectionListener(ListSelectionListener)
,removeListSelectionListener(ListSelectionListener)
,DefaultListSelectionModel
public int getMaxSelectionIndex()
Gets the largest index which is currently a member of a selection interval.
- Specified by:
- getMaxSelectionIndex in interface ListSelectionModel
- Returns:
- The greatest integer
i
such thati >= 0
andi
is a member of a selected interval, or-1
if there are no selected intervals
- See Also:
getMinSelectionIndex()
public int getMinSelectionIndex()
Gets the smallest index which is currently a member of a selection interval.
- Specified by:
- getMinSelectionIndex in interface ListSelectionModel
- Returns:
- The least integer
i
such thati >= 0
andi
is a member of a selected interval, or-1
if there are no selected intervals
- See Also:
getMaxSelectionIndex()
public int getSelectionMode()
Returns the selection mode, which is one ofListSelectionModel.SINGLE_SELECTION
,ListSelectionModel.SINGLE_INTERVAL_SELECTION
andListSelectionModel.MULTIPLE_INTERVAL_SELECTION
. The default value isListSelectionModel.MULTIPLE_INTERVAL_SELECTION
.
- Specified by:
- getSelectionMode in interface ListSelectionModel
- Returns:
- The selection mode.
- See Also:
setSelectionMode(int)
public boolean getValueIsAdjusting()
Gets the value of thevalueIsAdjusting
property.
- Specified by:
- getValueIsAdjusting in interface ListSelectionModel
- Returns:
- The current property value
- See Also:
setValueIsAdjusting(boolean)
public 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. Renumbers all indices after the inserted range. The new indices in the inserted range are not selected. This method is typically called to synchronize the selection model with an inserted range of elements in aListModel
.
- Specified by:
- insertIndexInterval in interface ListSelectionModel
- Parameters:
index
- The position to insert indices atlength
- The number of indices to insertbefore
- Indicates whether to insert the indices before the index or after it
public boolean isLeadAnchorNotificationEnabled()
Gets the value of theleadAnchorNotificationEnabled
property.
- Returns:
- The current property value
public boolean isSelectedIndex(int a)
Determines whether a particular index is a member of a selection interval.
- Specified by:
- isSelectedIndex in interface ListSelectionModel
- Parameters:
a
- The index to search for
- Returns:
true
if the index is a member of a selection interval, otherwisefalse
public boolean isSelectionEmpty()
Determines whether the selection is empty.
- Specified by:
- isSelectionEmpty in interface ListSelectionModel
- Returns:
true
if the selection is empty, otherwisefalse
public void moveLeadSelectionIndex(int leadIndex)
Moves the lead selection index toleadIndex
without changing the selection values. If leadAnchorNotificationEnabled is true, send a notification covering the old and new lead cells.
- Parameters:
leadIndex
- the new lead selection index
- Since:
- 1.5
public void removeIndexInterval(int index0, int index1)
Removes a range from the set of indices. Renumbers all indices after the removed range. This method is typically called to synchronize the selection model with a deleted range of elements in aListModel
.
- Specified by:
- removeIndexInterval in interface ListSelectionModel
- Parameters:
index0
- The first index to remove (inclusive)index1
- The last index to remove (inclusive)
public void removeListSelectionListener(ListSelectionListener listener)
Removes a registered listener.
- Specified by:
- removeListSelectionListener in interface ListSelectionModel
- Parameters:
listener
- The listener to remove
public void removeSelectionInterval(int index0, int index1)
Deselects all indices in the inclusive range[index0,index1]
.
- Specified by:
- removeSelectionInterval in interface ListSelectionModel
- Parameters:
index0
- The beginning of the range of indices to deselectindex1
- The end of the range of indices to deselect
public void setAnchorSelectionIndex(int index)
Sets the value of theanchorSelectionIndex
property.
- Specified by:
- setAnchorSelectionIndex in interface ListSelectionModel
- Parameters:
index
- The new property value
- See Also:
getAnchorSelectionIndex()
public void setLeadAnchorNotificationEnabled(boolean l)
Sets the value of theleadAnchorNotificationEnabled
property.
- Parameters:
l
- The new property value
- See Also:
isLeadAnchorNotificationEnabled()
public void setLeadSelectionIndex(int leadIndex)
Sets the value of theanchorSelectionIndex
property. As a side effect, alters the selection status of two ranges of indices. LetOL
be the old lead selection index,NL
be the new lead selection index, andA
be the anchor selection index. Then ifA
is a valid selection index, one of two things happens depending on the seleciton status ofA
:
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 theListSelectionEvent
includes only the minimum range of values which changed selection status between the beginning and end of the method.
- Specified by:
- setLeadSelectionIndex in interface ListSelectionModel
- Parameters:
leadIndex
- The new property value
- See Also:
getAnchorSelectionIndex()
public void setSelectionInterval(int anchor, int lead)
Clears the current selection and marks a given interval as "selected". If the current selection mode isSINGLE_SELECTION
only the indexindex2
is selected.
- Specified by:
- setSelectionInterval in interface ListSelectionModel
- Parameters:
anchor
- the anchor selection index.lead
- the lead selection index.
public void setSelectionMode(int mode)
Sets the value of theselectionMode
property.
- Specified by:
- setSelectionMode in interface ListSelectionModel
- Parameters:
mode
- The new value of the property
public void setValueIsAdjusting(boolean v)
Sets the value of thevalueIsAdjusting
property.
- Specified by:
- setValueIsAdjusting in interface ListSelectionModel
- Parameters:
v
- The new property value
- See Also:
getValueIsAdjusting()