public final class SingleListSelectionAdapter extends Object implements ListSelectionModel
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()));
ValueModel,
JList,
JTableMULTIPLE_INTERVAL_SELECTION, SINGLE_INTERVAL_SELECTION, SINGLE_SELECTION| Constructor and Description |
|---|
SingleListSelectionAdapter(ValueModel selectionIndexHolder)
Constructs a
SingleListSelectionAdapter with
the given selection index holder. |
| Modifier and Type | Method and Description |
|---|---|
void |
addListSelectionListener(ListSelectionListener listener)
Add a listener to the list that's notified each time a change
to the selection occurs.
|
void |
addSelectionInterval(int index0,
int index1)
Sets the selection interval using the given indices.
|
void |
clearSelection()
Changes the selection to have no index selected.
|
int |
getAnchorSelectionIndex()
Returns the selection index.
|
int |
getLeadSelectionIndex()
Returns the selection index.
|
ListSelectionListener[] |
getListSelectionListeners()
Returns an array of all the list selection listeners
registered on this
DefaultListSelectionModel. |
int |
getMaxSelectionIndex()
Returns the selection index.
|
int |
getMinSelectionIndex()
Returns the selection index.
|
int |
getSelectionMode()
Returns the fixed selection mode
SINGLE_SELECTION. |
boolean |
getValueIsAdjusting()
Returns true if the value is undergoing a series of changes.
|
void |
insertIndexInterval(int index,
int length,
boolean before)
Inserts length indices beginning before/after index.
|
boolean |
isSelectedIndex(int index)
Checks and answers if the given index is selected or not.
|
boolean |
isSelectionEmpty()
Returns true if no index is selected.
|
void |
removeIndexInterval(int index0,
int index1)
Remove the indices in the interval index0,index1 (inclusive) from
the selection model.
|
void |
removeListSelectionListener(ListSelectionListener listener)
Remove a listener from the list that's notified each time a
change to the selection occurs.
|
void |
removeSelectionInterval(int index0,
int index1)
Clears the selection if it is equals to index0.
|
void |
setAnchorSelectionIndex(int newSelectionIndex)
Sets the selection index.
|
void |
setLeadSelectionIndex(int newSelectionIndex)
Sets the selection index.
|
void |
setSelectionInterval(int index0,
int index1)
Sets the selection index to
index1. |
void |
setSelectionMode(int selectionMode)
Sets the selection mode.
|
void |
setValueIsAdjusting(boolean newValueIsAdjusting)
This property is true if upcoming changes to the value
of the model should be considered a single event.
|
public SingleListSelectionAdapter(ValueModel selectionIndexHolder)
SingleListSelectionAdapter with
the given selection index holder.selectionIndexHolder - holds the selection indexpublic void setSelectionInterval(int index0,
int index1)
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.
setSelectionInterval in interface ListSelectionModelindex0 - one end of the interval.index1 - other end of the intervaladdListSelectionListener(ListSelectionListener)public void addSelectionInterval(int index0,
int index1)
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.
addSelectionInterval in interface ListSelectionModelindex0 - one end of the interval.index1 - other end of the intervaladdListSelectionListener(ListSelectionListener)public void removeSelectionInterval(int index0,
int index1)
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.
removeSelectionInterval in interface ListSelectionModelindex0 - one end of the interval.index1 - other end of the intervaladdListSelectionListener(ListSelectionListener)public int getMinSelectionIndex()
getMinSelectionIndex in interface ListSelectionModelgetMinSelectionIndex(),
setSelectionInterval(int, int),
addSelectionInterval(int, int)public int getMaxSelectionIndex()
getMaxSelectionIndex in interface ListSelectionModelgetMinSelectionIndex(),
setSelectionInterval(int, int),
addSelectionInterval(int, int)public boolean isSelectedIndex(int index)
isSelectedIndex in interface ListSelectionModelindex - the index to be checkedListSelectionModel.isSelectedIndex(int)public int getAnchorSelectionIndex()
getAnchorSelectionIndex in interface ListSelectionModelgetAnchorSelectionIndex(),
setSelectionInterval(int, int),
addSelectionInterval(int, int)public void setAnchorSelectionIndex(int newSelectionIndex)
setAnchorSelectionIndex in interface ListSelectionModelnewSelectionIndex - the new selection indexgetLeadSelectionIndex()public int getLeadSelectionIndex()
getLeadSelectionIndex in interface ListSelectionModelgetAnchorSelectionIndex(),
setSelectionInterval(int, int),
addSelectionInterval(int, int)public void setLeadSelectionIndex(int newSelectionIndex)
setLeadSelectionIndex in interface ListSelectionModelnewSelectionIndex - the new selection indexgetLeadSelectionIndex()public void clearSelection()
clearSelection in interface ListSelectionModeladdListSelectionListener(ListSelectionListener)public boolean isSelectionEmpty()
isSelectionEmpty in interface ListSelectionModelpublic void insertIndexInterval(int index,
int length,
boolean before)
insertIndexInterval in interface ListSelectionModelindex - the index to start the insertionlength - the length of the inserted intervalbefore - true to insert before the start indexpublic void removeIndexInterval(int index0,
int index1)
Clears the selection if it is in the specified interval.
removeIndexInterval in interface ListSelectionModelindex0 - the first index to remove from the selectionindex1 - the last index to remove from the selectionIndexOutOfBoundsException - if either index0
or index1 are less than -1ListSelectionModel.removeSelectionInterval(int, int),
setSelectionInterval(int, int),
addSelectionInterval(int, int),
addListSelectionListener(ListSelectionListener)public void setValueIsAdjusting(boolean newValueIsAdjusting)
setValueIsAdjusting in interface ListSelectionModelnewValueIsAdjusting - The new value of the property.getValueIsAdjusting()public boolean getValueIsAdjusting()
getValueIsAdjusting in interface ListSelectionModelsetValueIsAdjusting(boolean)public void setSelectionMode(int selectionMode)
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.
setSelectionMode in interface ListSelectionModelselectionMode - the mode to be setgetSelectionMode(),
ListSelectionModel.setSelectionMode(int)public int getSelectionMode()
SINGLE_SELECTION.getSelectionMode in interface ListSelectionModelSINGLE_SELECTIONsetSelectionMode(int)public void addListSelectionListener(ListSelectionListener listener)
addListSelectionListener in interface ListSelectionModellistener - the ListSelectionListenerremoveListSelectionListener(ListSelectionListener),
setSelectionInterval(int, int),
addSelectionInterval(int, int),
removeSelectionInterval(int, int),
clearSelection(),
insertIndexInterval(int, int, boolean),
removeIndexInterval(int, int)public void removeListSelectionListener(ListSelectionListener listener)
removeListSelectionListener in interface ListSelectionModellistener - the ListSelectionListeneraddListSelectionListener(ListSelectionListener)public ListSelectionListener[] getListSelectionListeners()
DefaultListSelectionModel.ListSelectionListeners
or an empty
array if no list selection listeners are currently registeredaddListSelectionListener(ListSelectionListener),
removeListSelectionListener(ListSelectionListener)Copyright © 2002-2015 JGoodies Software GmbH. All Rights Reserved.