| Method from javax.swing.text.html.OptionListModel Detail: |
public void addListSelectionListener(ListSelectionListener l) {
listenerList.add(ListSelectionListener.class, l);
}
|
public void addSelectionInterval(int index0,
int index1) {
if (index0 == -1 || index1 == -1) {
return;
}
if (getSelectionMode() != MULTIPLE_INTERVAL_SELECTION) {
setSelectionInterval(index0, index1);
return;
}
updateLeadAnchorIndices(index0, index1);
int clearMin = MAX;
int clearMax = MIN;
int setMin = Math.min(index0, index1);
int setMax = Math.max(index0, index1);
changeSelection(clearMin, clearMax, setMin, setMax);
}
|
public void clearSelection() {
removeSelectionInterval(minIndex, maxIndex);
}
|
public Object clone() throws CloneNotSupportedException {
OptionListModel clone = (OptionListModel)super.clone();
clone.value = (BitSet)value.clone();
clone.listenerList = new EventListenerList();
return clone;
}
Returns a clone of the receiver with the same selection.
listenerLists are not duplicated. |
protected void fireValueChanged(boolean isAdjusting) {
fireValueChanged(getMinSelectionIndex(), getMaxSelectionIndex(), isAdjusting);
}
Notify listeners that we are beginning or ending a
series of value changes |
protected void fireValueChanged(int firstIndex,
int lastIndex) {
fireValueChanged(firstIndex, lastIndex, getValueIsAdjusting());
}
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) {
Object[] listeners = listenerList.getListenerList();
ListSelectionEvent e = null;
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == ListSelectionListener.class) {
if (e == null) {
e = new ListSelectionEvent(this, firstIndex, lastIndex, isAdjusting);
}
((ListSelectionListener)listeners[i+1]).valueChanged(e);
}
}
}
|
public int getAnchorSelectionIndex() {
return anchorIndex;
}
|
public BitSet getInitialSelection() {
return initialValue;
}
Fetches the BitSet that represents the initial
set of selected items in the list. |
public int getLeadSelectionIndex() {
return leadIndex;
}
|
public ListSelectionListener[] getListSelectionListeners() {
return (ListSelectionListener[])listenerList.getListeners(
ListSelectionListener.class);
}
Returns an array of all the ListSelectionListeners added
to this OptionListModel with addListSelectionListener(). |
public int getMaxSelectionIndex() {
return maxIndex;
}
|
public int getMinSelectionIndex() {
return isSelectionEmpty() ? -1 : minIndex;
}
|
public int getSelectionMode() {
return selectionMode;
}
|
public boolean getValueIsAdjusting() {
return isAdjusting;
}
|
public void insertIndexInterval(int index,
int length,
boolean before) {
/* The first new index will appear at insMinIndex and the last
* one will appear at insMaxIndex
*/
int insMinIndex = (before) ? index : index + 1;
int insMaxIndex = (insMinIndex + length) - 1;
/* Right shift the entire bitset by length, beginning with
* index-1 if before is true, index+1 if it's false (i.e. with
* insMinIndex).
*/
for(int i = maxIndex; i >= insMinIndex; i--) {
setState(i + length, value.get(i));
}
/* Initialize the newly inserted indices.
*/
boolean setInsertedValues = value.get(index);
for(int i = insMinIndex; i < = insMaxIndex; i++) {
setState(i, setInsertedValues);
}
}
Insert length indices beginning before/after index. If the value
at index is itself selected, set all of the newly inserted
items, otherwise leave them unselected. This method is typically
called to sync the selection model with a corresponding change
in the data model. |
public boolean isLeadAnchorNotificationEnabled() {
return leadAnchorNotificationEnabled;
}
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 norrowing 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. |
public boolean isSelectedIndex(int index) {
return ((index < minIndex) || (index > maxIndex)) ? false : value.get(index);
}
|
public boolean isSelectionEmpty() {
return (minIndex > maxIndex);
}
|
public void removeIndexInterval(int index0,
int index1) {
int rmMinIndex = Math.min(index0, index1);
int rmMaxIndex = Math.max(index0, index1);
int gapLength = (rmMaxIndex - rmMinIndex) + 1;
/* Shift the entire bitset to the left to close the index0, index1
* gap.
*/
for(int i = rmMinIndex; i < = maxIndex; i++) {
setState(i, value.get(i + gapLength));
}
}
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 can be greater than index1. |
public void removeListSelectionListener(ListSelectionListener l) {
listenerList.remove(ListSelectionListener.class, l);
}
|
public void removeSelectionInterval(int index0,
int index1) {
if (index0 == -1 || index1 == -1) {
return;
}
updateLeadAnchorIndices(index0, index1);
int clearMin = Math.min(index0, index1);
int clearMax = Math.max(index0, index1);
int setMin = MAX;
int setMax = MIN;
changeSelection(clearMin, clearMax, setMin, setMax);
}
|
public void setAnchorSelectionIndex(int anchorIndex) {
this.anchorIndex = anchorIndex;
}
Set the anchor selection index, leaving all selection values unchanged. |
public void setInitialSelection(int i) {
if (initialValue.get(i)) {
return;
}
if (selectionMode == SINGLE_SELECTION) {
// reset to empty
initialValue.and(new BitSet());
}
initialValue.set(i);
}
This method is responsible for storing the state
of the initial selection. If the selectionMode
is the default, i.e allowing only for SINGLE_SELECTION,
then the very last OPTION that has the selected
attribute set wins. |
public void setLeadAnchorNotificationEnabled(boolean flag) {
leadAnchorNotificationEnabled = flag;
}
Sets the value of the leadAnchorNotificationEnabled flag. |
public void setLeadSelectionIndex(int leadIndex) {
int anchorIndex = this.anchorIndex;
if (getSelectionMode() == SINGLE_SELECTION) {
anchorIndex = leadIndex;
}
int oldMin = Math.min(this.anchorIndex, this.leadIndex);;
int oldMax = Math.max(this.anchorIndex, this.leadIndex);;
int newMin = Math.min(anchorIndex, leadIndex);
int newMax = Math.max(anchorIndex, leadIndex);
if (value.get(this.anchorIndex)) {
changeSelection(oldMin, oldMax, newMin, newMax);
}
else {
changeSelection(newMin, newMax, oldMin, oldMax, false);
}
this.anchorIndex = anchorIndex;
this.leadIndex = leadIndex;
}
Set 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 and only
to later be set.
This method can be used in the mouseDragged() method of a UI class
to extend a selection. |
public void setSelectionInterval(int index0,
int index1) {
if (index0 == -1 || index1 == -1) {
return;
}
if (getSelectionMode() == SINGLE_SELECTION) {
index0 = index1;
}
updateLeadAnchorIndices(index0, index1);
int clearMin = minIndex;
int clearMax = maxIndex;
int setMin = Math.min(index0, index1);
int setMax = Math.max(index0, index1);
changeSelection(clearMin, clearMax, setMin, setMax);
}
|
public void setSelectionMode(int selectionMode) {
switch (selectionMode) {
case SINGLE_SELECTION:
case SINGLE_INTERVAL_SELECTION:
case MULTIPLE_INTERVAL_SELECTION:
this.selectionMode = selectionMode;
break;
default:
throw new IllegalArgumentException("invalid selectionMode");
}
}
|
public void setValueIsAdjusting(boolean isAdjusting) {
if (isAdjusting != this.isAdjusting) {
this.isAdjusting = isAdjusting;
this.fireValueChanged(isAdjusting);
}
}
|
public String toString() {
String s = ((getValueIsAdjusting()) ? "~" : "=") + value.toString();
return getClass().getName() + " " + Integer.toString(hashCode()) + " " + s;
}
|