javax.swing
Class DefaultListSelectionModel

java.lang.Object
  |
  +--javax.swing.DefaultListSelectionModel
All Implemented Interfaces:
Cloneable, ListSelectionModel, Serializable

public class DefaultListSelectionModel
extends Object
implements ListSelectionModel, Cloneable, Serializable

Safe:

See Also:
Serialized Form

Field Summary
private  int anchorIndex
           
private  int firstAdjustedIndex
           
private  int firstChangedIndex
           
private  boolean isAdjusting
           
private  int lastAdjustedIndex
           
private  int lastChangedIndex
           
protected  boolean leadAnchorNotificationEnabled
           
private  int leadIndex
           
protected  EventListenerList listenerList
           
private static int MAX
           
private  int maxIndex
           
private static int MIN
           
private  int minIndex
           
private  int selectionMode
           
private  BitSet value
           
 
Fields inherited from interface javax.swing.ListSelectionModel
MULTIPLE_INTERVAL_SELECTION, SINGLE_INTERVAL_SELECTION, SINGLE_SELECTION
 
Constructor Summary
DefaultListSelectionModel()
          Enabled:
 
Method Summary
 void addListSelectionListener(ListSelectionListener l)
          Enabled:
 void addSelectionInterval(int index0, int index1)
          Enabled:
private  void changeSelection(int clearMin, int clearMax, int setMin, int setMax)
          Change the selection with the effect of first clearing the values in the inclusive range [clearMin, clearMax] then setting the values in the inclusive range [setMin, setMax].
private  void changeSelection(int clearMin, int clearMax, int setMin, int setMax, boolean clearFirst)
           
private  void clear(int r)
           
 void clearSelection()
          Enabled:
 Object clone()
          Suppressed: Returns a clone of this selection model with the same selection.
private  boolean contains(int a, int b, int i)
           
private  void fireValueChanged()
           
protected  void fireValueChanged(boolean isAdjusting)
          Notifies listeners that we have ended a series of adjustments.
protected  void fireValueChanged(int firstIndex, int lastIndex)
          Notifies ListSelectionListeners that the value of the selection, in the closed interval firstIndex, lastIndex, has changed.
protected  void fireValueChanged(int firstIndex, int lastIndex, boolean isAdjusting)
           
 int getAnchorSelectionIndex()
          Enabled:
 int getLeadSelectionIndex()
          Enabled:
 EventListener[] getListeners(Class listenerType)
          Suppressed: Returns an array of all the objects currently registered as FooListeners upon this model.
 ListSelectionListener[] getListSelectionListeners()
          Suppressed: Returns an array of all the list selection listeners registered on this DefaultListSelectionModel.
 int getMaxSelectionIndex()
          Enabled:
 int getMinSelectionIndex()
          Enabled:
 int getSelectionMode()
          Enabled: Returns the selection mode.
 boolean getValueIsAdjusting()
          Enabled:
 void insertIndexInterval(int index, int length, boolean before)
          Enabled: Insert length indices beginning before/after index.
 boolean isLeadAnchorNotificationEnabled()
          Enabled: Returns the value of the leadAnchorNotificationEnabled flag.
 boolean isSelectedIndex(int index)
          Enabled:
 boolean isSelectionEmpty()
          Enabled:
private  void markAsDirty(int r)
           
 void removeIndexInterval(int index0, int index1)
          Enabled: Remove the indices in the interval index0,index1 (inclusive) from the selection model.
 void removeListSelectionListener(ListSelectionListener l)
          Enabled:
 void removeSelectionInterval(int index0, int index1)
          Enabled:
private  void set(int r)
           
 void setAnchorSelectionIndex(int anchorIndex)
          Enabled: Set the anchor selection index, leaving all selection values unchanged.
 void setLeadAnchorNotificationEnabled(boolean flag)
          Enabled: Sets the value of the leadAnchorNotificationEnabled flag.
 void setLeadSelectionIndex(int leadIndex)
          Enabled: Sets the lead selection index, ensuring that values between the anchor and the new lead are either all selected or all deselected.
 void setSelectionInterval(int index0, int index1)
          Enabled:
 void setSelectionMode(int selectionMode)
          Enabled: Sets the selection mode.
private  void setState(int index, boolean state)
           
 void setValueIsAdjusting(boolean isAdjusting)
          Enabled:
 String toString()
          Suppressed: Returns a string that displays and identifies this object's properties.
private  void updateLeadAnchorIndices(int anchorIndex, int leadIndex)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN

private static final int MIN

MAX

private static final int MAX

selectionMode

private int selectionMode

minIndex

private int minIndex

maxIndex

private int maxIndex

anchorIndex

private int anchorIndex

leadIndex

private int leadIndex

firstAdjustedIndex

private int firstAdjustedIndex

lastAdjustedIndex

private int lastAdjustedIndex

isAdjusting

private boolean isAdjusting

firstChangedIndex

private int firstChangedIndex

lastChangedIndex

private int lastChangedIndex

value

private BitSet value

listenerList

protected EventListenerList listenerList

leadAnchorNotificationEnabled

protected boolean leadAnchorNotificationEnabled
Constructor Detail

DefaultListSelectionModel

public DefaultListSelectionModel()
Enabled:

Method Detail

getMinSelectionIndex

public int getMinSelectionIndex()
Enabled:

Specified by:
getMinSelectionIndex in interface ListSelectionModel

getMaxSelectionIndex

public int getMaxSelectionIndex()
Enabled:

Specified by:
getMaxSelectionIndex in interface ListSelectionModel

getValueIsAdjusting

public boolean getValueIsAdjusting()
Enabled:

Specified by:
getValueIsAdjusting in interface ListSelectionModel
Returns:
true if the value is currently adjusting
See Also:
ListSelectionModel.setValueIsAdjusting(boolean)

getSelectionMode

public int getSelectionMode()
Enabled: Returns the selection mode.

Specified by:
getSelectionMode in interface ListSelectionModel
Returns:
one of the these values:
  • SINGLE_SELECTION
  • SINGLE_INTERVAL_SELECTION
  • MULTIPLE_INTERVAL_SELECTION
See Also:
getSelectionMode()

setSelectionMode

public void setSelectionMode(int selectionMode)
Enabled: Sets the selection mode. The default is MULTIPLE_INTERVAL_SELECTION.

Specified by:
setSelectionMode in interface ListSelectionModel
Parameters:
selectionMode - one of three values:
  • SINGLE_SELECTION
  • SINGLE_INTERVAL_SELECTION
  • MULTIPLE_INTERVAL_SELECTION
See Also:
setSelectionMode(int)

isSelectedIndex

public boolean isSelectedIndex(int index)
Enabled:

Specified by:
isSelectedIndex in interface ListSelectionModel

isSelectionEmpty

public boolean isSelectionEmpty()
Enabled:

Specified by:
isSelectionEmpty in interface ListSelectionModel

addListSelectionListener

public void addListSelectionListener(ListSelectionListener l)
Enabled:

Specified by:
addListSelectionListener in interface ListSelectionModel
See Also:
ListSelectionModel.removeListSelectionListener(javax.swing.event.ListSelectionListener), ListSelectionModel.setSelectionInterval(int, int), ListSelectionModel.addSelectionInterval(int, int), ListSelectionModel.removeSelectionInterval(int, int), ListSelectionModel.clearSelection(), ListSelectionModel.insertIndexInterval(int, int, boolean), ListSelectionModel.removeIndexInterval(int, int)

removeListSelectionListener

public void removeListSelectionListener(ListSelectionListener l)
Enabled:

Specified by:
removeListSelectionListener in interface ListSelectionModel
See Also:
ListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)

getListSelectionListeners

public ListSelectionListener[] getListSelectionListeners()
Suppressed: Returns an array of all the list selection listeners registered on this DefaultListSelectionModel.

Returns:
all of this model's ListSelectionListeners or an empty array if no list selection listeners are currently registered
Since:
1.4
See Also:
addListSelectionListener(javax.swing.event.ListSelectionListener), removeListSelectionListener(javax.swing.event.ListSelectionListener)

fireValueChanged

protected void fireValueChanged(boolean isAdjusting)
Notifies listeners that we have ended a series of adjustments.


fireValueChanged

protected void fireValueChanged(int firstIndex,
                                int lastIndex)
Notifies ListSelectionListeners that the value of the selection, in the closed interval firstIndex, lastIndex, has changed.


fireValueChanged

protected void fireValueChanged(int firstIndex,
                                int lastIndex,
                                boolean isAdjusting)
Parameters:
firstIndex - the first index in the interval
lastIndex - the last index in the interval
isAdjusting - true if this is the final change in a series of adjustments
See Also:
EventListenerList

fireValueChanged

private void fireValueChanged()

getListeners

public EventListener[] getListeners(Class listenerType)
Suppressed: Returns an array of all the objects currently registered as FooListeners upon this model. FooListeners are registered using the addFooListener method.

You can specify the listenerType argument with a class literal, such as FooListener.class. For example, you can query a DefaultListSelectionModel instance m for its list selection listeners with the following code:

ListSelectionListener[] lsls = (ListSelectionListener[])(m.getListeners(ListSelectionListener.class));
If no such listeners exist, this method returns an empty array.

Parameters:
listenerType - the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
Returns:
an array of all objects registered as FooListeners on this model, or an empty array if no such listeners have been added
Since:
1.3
See Also:
getListSelectionListeners()

markAsDirty

private void markAsDirty(int r)

set

private void set(int r)

clear

private void clear(int r)

setLeadAnchorNotificationEnabled

public void setLeadAnchorNotificationEnabled(boolean flag)
Enabled: Sets the value of the leadAnchorNotificationEnabled flag.

See Also:
isLeadAnchorNotificationEnabled()

isLeadAnchorNotificationEnabled

public boolean isLeadAnchorNotificationEnabled()
Enabled: Returns the value of the leadAnchorNotificationEnabled flag. When leadAnchorNotificationEnabled is true the model generates notification events with bounds that cover all the changes to the selection plus the changes to the lead and anchor indices. Setting the flag to false causes a narrowing of the event's bounds to include only the elements that have been selected or deselected since the last change. Either way, the model continues to maintain the lead and anchor variables internally. The default is true.

Returns:
the value of the leadAnchorNotificationEnabled flag
See Also:
setLeadAnchorNotificationEnabled(boolean)

updateLeadAnchorIndices

private void updateLeadAnchorIndices(int anchorIndex,
                                     int leadIndex)

contains

private boolean contains(int a,
                         int b,
                         int i)

changeSelection

private void changeSelection(int clearMin,
                             int clearMax,
                             int setMin,
                             int setMax,
                             boolean clearFirst)

changeSelection

private void changeSelection(int clearMin,
                             int clearMax,
                             int setMin,
                             int setMax)
Change the selection with the effect of first clearing the values in the inclusive range [clearMin, clearMax] then setting the values in the inclusive range [setMin, setMax]. Do this in one pass so that no values are cleared if they would later be set.


clearSelection

public void clearSelection()
Enabled:

Specified by:
clearSelection in interface ListSelectionModel
See Also:
ListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)

setSelectionInterval

public void setSelectionInterval(int index0,
                                 int index1)
Enabled:

Specified by:
setSelectionInterval in interface ListSelectionModel
Parameters:
index0 - one end of the interval.
index1 - other end of the interval
See Also:
ListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)

addSelectionInterval

public void addSelectionInterval(int index0,
                                 int index1)
Enabled:

Specified by:
addSelectionInterval in interface ListSelectionModel
Parameters:
index0 - one end of the interval.
index1 - other end of the interval
See Also:
ListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)

removeSelectionInterval

public void removeSelectionInterval(int index0,
                                    int index1)
Enabled:

Specified by:
removeSelectionInterval in interface ListSelectionModel
Parameters:
index0 - one end of the interval.
index1 - other end of the interval
See Also:
ListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)

setState

private void setState(int index,
                      boolean state)

insertIndexInterval

public void insertIndexInterval(int index,
                                int length,
                                boolean before)
Enabled: Insert length indices beginning before/after index. If the value at index is itself selected and the selection mode is not SINGLE_SELECTION, set all of the newly inserted items as selected. Otherwise leave them unselected. This method is typically called to sync the selection model with a corresponding change in the data model.

Specified by:
insertIndexInterval in interface ListSelectionModel

removeIndexInterval

public void removeIndexInterval(int index0,
                                int index1)
Enabled: Remove the indices in the interval index0,index1 (inclusive) from the selection model. This is typically called to sync the selection model width a corresponding change in the data model. Note that (as always) index0 need not be <= index1.

Specified by:
removeIndexInterval in interface ListSelectionModel

setValueIsAdjusting

public void setValueIsAdjusting(boolean isAdjusting)
Enabled:

Specified by:
setValueIsAdjusting in interface ListSelectionModel
Parameters:
isAdjusting - The new value of the property.
See Also:
ListSelectionModel.getValueIsAdjusting()

toString

public String toString()
Suppressed: Returns a string that displays and identifies this object's properties.

Overrides:
toString in class Object
Returns:
a String representation of this object

clone

public Object clone()
             throws CloneNotSupportedException
Suppressed: Returns a clone of this selection model with the same selection. listenerLists are not duplicated.

Overrides:
clone in class Object
Returns:
a clone of this instance.
CloneNotSupportedException
See Also:
java.lang.Cloneable

getAnchorSelectionIndex

public int getAnchorSelectionIndex()
Enabled:

Specified by:
getAnchorSelectionIndex in interface ListSelectionModel
See Also:
ListSelectionModel.getLeadSelectionIndex(), ListSelectionModel.setSelectionInterval(int, int), ListSelectionModel.addSelectionInterval(int, int)

getLeadSelectionIndex

public int getLeadSelectionIndex()
Enabled:

Specified by:
getLeadSelectionIndex in interface ListSelectionModel
See Also:
ListSelectionModel.getAnchorSelectionIndex(), ListSelectionModel.setSelectionInterval(int, int), ListSelectionModel.addSelectionInterval(int, int)

setAnchorSelectionIndex

public void setAnchorSelectionIndex(int anchorIndex)
Enabled: Set the anchor selection index, leaving all selection values unchanged. If leadAnchorNotificationEnabled is true, send a notification covering the old and new anchor cells.

Specified by:
setAnchorSelectionIndex in interface ListSelectionModel
See Also:
getAnchorSelectionIndex(), setLeadSelectionIndex(int)

setLeadSelectionIndex

public void setLeadSelectionIndex(int leadIndex)
Enabled: Sets the lead selection index, ensuring that values between the anchor and the new lead are either all selected or all deselected. If the value at the anchor index is selected, first clear all the values in the range [anchor, oldLeadIndex], then select all the values values in the range [anchor, newLeadIndex], where oldLeadIndex is the old leadIndex and newLeadIndex is the new one.

If the value at the anchor index is not selected, do the same thing in reverse selecting values in the old range and deslecting values in the new one.

Generate a single event for this change and notify all listeners. For the purposes of generating minimal bounds in this event, do the operation in a single pass; that way the first and last index inside the ListSelectionEvent that is broadcast will refer to cells that actually changed value because of this method. If, instead, this operation were done in two steps the effect on the selection state would be the same but two events would be generated and the bounds around the changed values would be wider, including cells that had been first cleared only to later be set.

This method can be used in the mouseDragged method of a UI class to extend a selection.

Specified by:
setLeadSelectionIndex in interface ListSelectionModel
See Also:
getLeadSelectionIndex(), setAnchorSelectionIndex(int)


comments?