|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.swing.AbstractListModel javax.swing.DefaultListModel javax.swing.text.html.OptionListModel
This class extends DefaultListModel, and also implements the ListSelectionModel interface, allowing for it to store state relevant to a SELECT form element which is implemented as a List. If SELECT has a size attribute whose value is greater than 1, or if allows multiple selection then a JList is used to represent it and the OptionListModel is used as its model. It also stores the initial state of the JList, to ensure an accurate reset, if the user requests a reset of the form.
Field Summary | |
private int |
anchorIndex
|
private int |
firstChangedIndex
|
private BitSet |
initialValue
|
private boolean |
isAdjusting
|
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 class javax.swing.DefaultListModel |
|
Fields inherited from interface javax.swing.ListSelectionModel |
MULTIPLE_INTERVAL_SELECTION, SINGLE_INTERVAL_SELECTION, SINGLE_SELECTION |
Constructor Summary | |
(package private) |
OptionListModel()
|
Method Summary | |
void |
addListSelectionListener(ListSelectionListener l)
Add a listener to the list that's notified each time a change to the selection occurs. |
void |
addSelectionInterval(int index0,
int index1)
Change the selection to be the set union of the current selection and the indices between index0 and index1 inclusive. |
private void |
changeSelection(int clearMin,
int clearMax,
int setMin,
int setMax)
|
private void |
changeSelection(int clearMin,
int clearMax,
int setMin,
int setMax,
boolean clearFirst)
|
private void |
clear(int r)
|
void |
clearSelection()
Change the selection to the empty set. |
Object |
clone()
Returns a clone of the receiver with the same selection. |
private boolean |
contains(int a,
int b,
int i)
|
private void |
fireValueChanged()
|
protected void |
fireValueChanged(boolean isAdjusting)
Notify listeners that we are beginning or ending a series of value changes |
protected void |
fireValueChanged(int firstIndex,
int lastIndex)
Notify 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()
Return the first index argument from the most recent call to setSelectionInterval(), addSelectionInterval() or removeSelectionInterval(). |
BitSet |
getInitialSelection()
Fetches the BitSet that represents the initial set of selected items in the list. |
int |
getLeadSelectionIndex()
Return the second index argument from the most recent call to setSelectionInterval(), addSelectionInterval() or removeSelectionInterval(). |
ListSelectionListener[] |
getListSelectionListeners()
Returns an array of all the ListSelectionListener s added
to this OptionListModel with addListSelectionListener(). |
int |
getMaxSelectionIndex()
Returns the last selected index or -1 if the selection is empty. |
int |
getMinSelectionIndex()
Returns the first selected index or -1 if the selection is empty. |
int |
getSelectionMode()
Returns the current selection mode. |
boolean |
getValueIsAdjusting()
Returns true if the value is undergoing a series of changes. |
void |
insertIndexInterval(int index,
int length,
boolean before)
Insert length indices beginning before/after index. |
boolean |
isLeadAnchorNotificationEnabled()
Returns the value of the leadAnchorNotificationEnabled flag. |
boolean |
isSelectedIndex(int index)
Returns true if the specified index is selected. |
boolean |
isSelectionEmpty()
Returns true if no indices are selected. |
private void |
markAsDirty(int r)
|
void |
removeIndexInterval(int index0,
int index1)
Remove the indices in the interval index0,index1 (inclusive) from the selection model. |
void |
removeListSelectionListener(ListSelectionListener l)
Remove a listener from the list that's notified each time a change to the selection occurs. |
void |
removeSelectionInterval(int index0,
int index1)
Change the selection to be the set difference of the current selection and the indices between index0 and index1 inclusive. |
private void |
set(int r)
|
void |
setAnchorSelectionIndex(int anchorIndex)
Set the anchor selection index, leaving all selection values unchanged. |
void |
setInitialSelection(int i)
This method is responsible for storing the state of the initial selection. |
void |
setLeadAnchorNotificationEnabled(boolean flag)
Sets the value of the leadAnchorNotificationEnabled flag. |
void |
setLeadSelectionIndex(int leadIndex)
Set 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)
Change the selection to be between index0 and index1 inclusive. |
void |
setSelectionMode(int selectionMode)
Set the selection mode. |
private void |
setState(int index,
boolean state)
|
void |
setValueIsAdjusting(boolean isAdjusting)
This property is true if upcoming changes to the value of the model should be considered a single event. |
String |
toString()
Returns a string that displays and identifies this object's properties. |
private void |
updateLeadAnchorIndices(int anchorIndex,
int leadIndex)
|
Methods inherited from class javax.swing.DefaultListModel |
add, addElement, capacity, clear, contains, copyInto, elementAt, elements, ensureCapacity, firstElement, get, getElementAt, getSize, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, removeAllElements, removeElement, removeElementAt, removeRange, set, setElementAt, setSize, size, toArray, trimToSize |
Methods inherited from class javax.swing.AbstractListModel |
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private static final int MIN
private static final int MAX
private int selectionMode
private int minIndex
private int maxIndex
private int anchorIndex
private int leadIndex
private int firstChangedIndex
private int lastChangedIndex
private boolean isAdjusting
private BitSet value
private BitSet initialValue
protected EventListenerList listenerList
protected boolean leadAnchorNotificationEnabled
Constructor Detail |
OptionListModel()
Method Detail |
public int getMinSelectionIndex()
ListSelectionModel
getMinSelectionIndex
in interface ListSelectionModel
public int getMaxSelectionIndex()
ListSelectionModel
getMaxSelectionIndex
in interface ListSelectionModel
public boolean getValueIsAdjusting()
ListSelectionModel
getValueIsAdjusting
in interface ListSelectionModel
ListSelectionModel.setValueIsAdjusting(boolean)
public int getSelectionMode()
ListSelectionModel
getSelectionMode
in interface ListSelectionModel
ListSelectionModel.setSelectionMode(int)
public void setSelectionMode(int selectionMode)
ListSelectionModel
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.
SINGLE_INTERVAL_SELECTION
One contiguous index interval can be selected at a time.
In this mode setSelectionInterval and addSelectionInterval
are equivalent.
MULTIPLE_INTERVAL_SELECTION
In this mode, there's no restriction on what can be selected.
setSelectionMode
in interface ListSelectionModel
ListSelectionModel.getSelectionMode()
public boolean isSelectedIndex(int index)
ListSelectionModel
isSelectedIndex
in interface ListSelectionModel
public boolean isSelectionEmpty()
ListSelectionModel
isSelectionEmpty
in interface ListSelectionModel
public void addListSelectionListener(ListSelectionListener l)
ListSelectionModel
addListSelectionListener
in interface ListSelectionModel
l
- the ListSelectionListenerListSelectionModel.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)
public void removeListSelectionListener(ListSelectionListener l)
ListSelectionModel
removeListSelectionListener
in interface ListSelectionModel
l
- the ListSelectionListenerListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)
public ListSelectionListener[] getListSelectionListeners()
ListSelectionListener
s added
to this OptionListModel with addListSelectionListener().
ListSelectionListener
s added or an empty
array if no listeners have been addedprotected void fireValueChanged(boolean isAdjusting)
protected void fireValueChanged(int firstIndex, int lastIndex)
protected void fireValueChanged(int firstIndex, int lastIndex, boolean isAdjusting)
firstIndex
- The first index in the interval.isAdjusting
- True if this is the final change in a series of them.EventListenerList
private void fireValueChanged()
private void markAsDirty(int r)
private void set(int r)
private void clear(int r)
public void setLeadAnchorNotificationEnabled(boolean flag)
isLeadAnchorNotificationEnabled()
public boolean isLeadAnchorNotificationEnabled()
setLeadAnchorNotificationEnabled(boolean)
private void updateLeadAnchorIndices(int anchorIndex, int leadIndex)
private boolean contains(int a, int b, int i)
private void changeSelection(int clearMin, int clearMax, int setMin, int setMax, boolean clearFirst)
private void changeSelection(int clearMin, int clearMax, int setMin, int setMax)
public void clearSelection()
ListSelectionModel
clearSelection
in interface ListSelectionModel
ListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)
public void setSelectionInterval(int index0, int index1)
ListSelectionModel
setSelectionInterval
in interface ListSelectionModel
index0
- one end of the interval.index1
- other end of the intervalListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)
public void addSelectionInterval(int index0, int index1)
ListSelectionModel
addSelectionInterval
in interface ListSelectionModel
index0
- one end of the interval.index1
- other end of the intervalListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)
public void removeSelectionInterval(int index0, int index1)
ListSelectionModel
removeSelectionInterval
in interface ListSelectionModel
index0
- one end of the interval.index1
- other end of the intervalListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)
private void setState(int index, boolean state)
public void insertIndexInterval(int index, int length, boolean before)
insertIndexInterval
in interface ListSelectionModel
public void removeIndexInterval(int index0, int index1)
removeIndexInterval
in interface ListSelectionModel
public void setValueIsAdjusting(boolean isAdjusting)
ListSelectionModel
setValueIsAdjusting
in interface ListSelectionModel
isAdjusting
- The new value of the property.ListSelectionModel.getValueIsAdjusting()
public String toString()
DefaultListModel
toString
in class DefaultListModel
public Object clone() throws CloneNotSupportedException
listenerLists
are not duplicated.
clone
in class Object
CloneNotSupportedException
- if the receiver does not
both (a) implement the Cloneable
interface
and (b) define a clone
methodCloneable
public int getAnchorSelectionIndex()
ListSelectionModel
getAnchorSelectionIndex
in interface ListSelectionModel
ListSelectionModel.getLeadSelectionIndex()
,
ListSelectionModel.setSelectionInterval(int, int)
,
ListSelectionModel.addSelectionInterval(int, int)
public int getLeadSelectionIndex()
ListSelectionModel
getLeadSelectionIndex
in interface ListSelectionModel
ListSelectionModel.getAnchorSelectionIndex()
,
ListSelectionModel.setSelectionInterval(int, int)
,
ListSelectionModel.addSelectionInterval(int, int)
public void setAnchorSelectionIndex(int anchorIndex)
setAnchorSelectionIndex
in interface ListSelectionModel
getAnchorSelectionIndex()
,
setLeadSelectionIndex(int)
public void setLeadSelectionIndex(int leadIndex)
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 and only to later be set.
This method can be used in the mouseDragged() method of a UI class to extend a selection.
setLeadSelectionIndex
in interface ListSelectionModel
getLeadSelectionIndex()
,
setAnchorSelectionIndex(int)
public void setInitialSelection(int i)
public BitSet getInitialSelection()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |