com.jgoodies.binding.adapter
Class SingleListSelectionAdapter
java.lang.Object
com.jgoodies.binding.adapter.SingleListSelectionAdapter
- ListSelectionModel
public final class SingleListSelectionAdapter
extends java.lang.Object
implements ListSelectionModel
A
ListSelectionModel
implementation that has the list index
bound to a
ValueModel
. Therefore this class supports only
the
SINGLE_SELECTION
mode where only one list index
can be selected at a time. In this mode the setSelectionInterval
and addSelectionInterval methods are equivalent, and only
the second index argument (the "lead index") is used.
Example:
SelectionInList selectionInList = new SelectionInList(...);
JList list = new JList();
list.setModel(selectionInList);
list.setSelectionModel(new SingleListSelectionAdapter(
selectionInList.getSelectionIndexHolder()));
- Karsten Lentzsch
- Jeanette Winzenburg
SingleListSelectionAdapter
public SingleListSelectionAdapter(ValueModel selectionIndexHolder)
Constructs a SingleListSelectionAdapter
with
the given selection index holder.
selectionIndexHolder
- holds the selection index
addListSelectionListener
public void addListSelectionListener(ListSelectionListener listener)
Add a listener to the list that's notified each time a change
to the selection occurs.
listener
- the ListSelectionListener
removeListSelectionListener(ListSelectionListener)
, setSelectionInterval(int,int)
, addSelectionInterval(int,int)
, removeSelectionInterval(int,int)
, clearSelection()
, insertIndexInterval(int,int,boolean)
, removeIndexInterval(int,int)
addSelectionInterval
public void addSelectionInterval(int index0,
int index1)
Sets the selection interval using the given indices.
If this represents a change to the current selection, then
notify each ListSelectionListener. Note that index0 doesn't have
to be less than or equal to index1.
index0
- one end of the interval.index1
- other end of the interval
clearSelection
public void clearSelection()
Changes the selection to have no index selected. If this represents
a change to the current selection then notify each ListSelectionListener.
getAnchorSelectionIndex
public int getAnchorSelectionIndex()
Returns the selection index.
getLeadSelectionIndex
public int getLeadSelectionIndex()
Returns the selection index.
getListSelectionListeners
public ListSelectionListener[] getListSelectionListeners()
Returns an array of all the list selection listeners
registered on this DefaultListSelectionModel
.
- all of this model's
ListSelectionListener
s
or an empty
array if no list selection listeners are currently registered
getMaxSelectionIndex
public int getMaxSelectionIndex()
Returns the selection index.
getMinSelectionIndex
public int getMinSelectionIndex()
Returns the selection index.
getSelectionMode
public int getSelectionMode()
Returns the fixed selection mode SINGLE_SELECTION
.
getValueIsAdjusting
public boolean getValueIsAdjusting()
Returns true if the value is undergoing a series of changes.
- true if the value is currently adjusting
insertIndexInterval
public void insertIndexInterval(int index,
int length,
boolean before)
Inserts length indices beginning before/after index. If the value
This method is typically called to synchronize the selection model
with a corresponding change in the data model.
index
- the index to start the insertionlength
- the length of the inserted intervalbefore
- true to insert before the start index
isSelectedIndex
public boolean isSelectedIndex(int index)
Checks and answers if the given index is selected or not.
index
- the index to be checked
- true if selected, false if deselected
javax.swing.ListSelectionModel.isSelectedIndex(int)
isSelectionEmpty
public boolean isSelectionEmpty()
Returns true if no index is selected.
- true if no index is selected
removeIndexInterval
public void removeIndexInterval(int index0,
int index1)
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.
Clears the selection if it is in the specified interval.
index0
- the first index to remove from the selectionindex1
- the last index to remove from the selection
removeListSelectionListener
public void removeListSelectionListener(ListSelectionListener listener)
Remove a listener from the list that's notified each time a
change to the selection occurs.
listener
- the ListSelectionListener
removeSelectionInterval
public void removeSelectionInterval(int index0,
int index1)
Clears the selection if it is equals to index0. Since this model
supports only a single selection index, the index1 can be ignored
for the selection.
If this represents a change to the current selection, then
notify each ListSelectionListener. Note that index0 doesn't have
to be less than or equal to index1.
index0
- one end of the interval.index1
- other end of the interval
setAnchorSelectionIndex
public void setAnchorSelectionIndex(int newSelectionIndex)
Sets the selection index.
newSelectionIndex
- the new selection index
setLeadSelectionIndex
public void setLeadSelectionIndex(int newSelectionIndex)
Sets the selection index.
newSelectionIndex
- the new selection index
setSelectionInterval
public void setSelectionInterval(int index0,
int index1)
Sets the selection index to
index1
. Since this model
supports only a single selection index, the index0 is ignored.
This is the behavior the
DefaultListSelectionModel
uses in single selection mode.
If this represents a change to the current selection, then
notify each ListSelectionListener. Note that index0 doesn't have
to be less than or equal to index1.
index0
- one end of the interval.index1
- other end of the interval
setSelectionMode
public void setSelectionMode(int selectionMode)
Sets the selection mode. Only
SINGLE_SELECTION
is allowed
in this implementation. Other modes are not supported and will throw
an
IllegalArgumentException
.
With
SINGLE_SELECTION
only one list index
can be selected at a time. In this mode the setSelectionInterval
and addSelectionInterval methods are equivalent, and only
the second index argument (the "lead index") is used.
selectionMode
- the mode to be set
setValueIsAdjusting
public void setValueIsAdjusting(boolean newValueIsAdjusting)
This property is true if upcoming changes to the value
of the model should be considered a single event. For example
if the model is being updated in response to a user drag,
the value of the valueIsAdjusting property will be set to true
when the drag is initiated and be set to false when
the drag is finished. This property allows listeners to
to update only when a change has been finalized, rather
than always handling all of the intermediate values.
newValueIsAdjusting
- The new value of the property.
Copyright © 2002-2007 JGoodies Karsten Lentzsch. All Rights Reserved.