2362N/A * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * This class extends DefaultListModel, and also implements 0N/A * the ListSelectionModel interface, allowing for it to store state 0N/A * relevant to a SELECT form element which is implemented as a List. 0N/A * If SELECT has a size attribute whose value is greater than 1, 0N/A * or if allows multiple selection then a JList is used to 0N/A * represent it and the OptionListModel is used as its model. 0N/A * It also stores the initial state of the JList, to ensure an 0N/A * accurate reset, if the user requests a reset of the form. 0N/A private static final int MIN = -
1;
0N/A * Returns an array of all the <code>ListSelectionListener</code>s added 0N/A * to this OptionListModel with addListSelectionListener(). 0N/A * @return all of the <code>ListSelectionListener</code>s added or an empty 0N/A * array if no listeners have been added 0N/A * Notify listeners that we are beginning or ending a 0N/A * series of value changes 0N/A * Notify ListSelectionListeners that the value of the selection, 0N/A * in the closed interval firstIndex,lastIndex, has changed. 0N/A * @param firstIndex The first index in the interval. 611N/A * @param lastIndex The last index in the interval. 0N/A * @param isAdjusting True if this is the final change in a series of them. 0N/A * @see EventListenerList 0N/A /* Change the values before sending the event to the 0N/A * listeners in case the event causes a listener to make 0N/A * another change to the selection. 0N/A // Update first and last change indices 0N/A // Set the state at this index and update all relevant state. 0N/A // Update minimum and maximum indices 0N/A // Clear the state at this index and update all relevant state. 0N/A // Update minimum and maximum indices 0N/A If (r > minIndex) the minimum has not changed. 0N/A The case (r < minIndex) is not possible because r'th value was set. 0N/A We only need to check for the case when lowest entry has been cleared, 0N/A and in this case we need to search for the first value set above it. 0N/A If (r < maxIndex) the maximum has not changed. 0N/A The case (r > maxIndex) is not possible because r'th value was set. 0N/A We only need to check for the case when highest entry has been cleared, 0N/A and in this case we need to search for the first value set below it. 0N/A /* Performance note: This method is called from inside a loop in 0N/A changeSelection() but we will only iterate in the loops 0N/A above on the basis of one iteration per deselected cell - in total. 0N/A Ie. the next time this method is called the work of the previous 0N/A deselection will not be repeated. 0N/A We also don't need to worry about the case when the min and max 0N/A values are in their unassigned states. This cannot happen because 0N/A this method's initial check ensures that the selection was not empty 0N/A and therefore that the minIndex and maxIndex had 'real' values. 0N/A If we have cleared the whole selection, set the minIndex and maxIndex 0N/A to their cannonical values so that the next set command always works 0N/A just by using Math.min and Math.max. 0N/A * Sets the value of the leadAnchorNotificationEnabled flag. 0N/A * @see #isLeadAnchorNotificationEnabled() 0N/A * Returns the value of the leadAnchorNotificationEnabled flag. 0N/A * When leadAnchorNotificationEnabled is true the model 0N/A * generates notification events with bounds that cover all the changes to 0N/A * the selection plus the changes to the lead and anchor indices. 0N/A * Setting the flag to false causes a norrowing of the event's bounds to 0N/A * include only the elements that have been selected or deselected since 0N/A * the last change. Either way, the model continues to maintain the lead 0N/A * and anchor variables internally. The default is true. 0N/A * @return the value of the leadAnchorNotificationEnabled flag 0N/A * @see #setLeadAnchorNotificationEnabled(boolean) 0N/A return (i >= a) && (i <= b);
0N/A /* Change the selection with the effect of first clearing the values 0N/A * in the inclusive range [clearMin, clearMax] then setting the values 0N/A * in the inclusive range [setMin, setMax]. Do this in one pass so 0N/A * that no values are cleared if they would later be set. 0N/A * at index is itself selected, set all of the newly inserted 0N/A * items, otherwise leave them unselected. This method is typically 0N/A * called to sync the selection model with a corresponding change 0N/A * in the data model. 0N/A /* The first new index will appear at insMinIndex and the last 0N/A * one will appear at insMaxIndex 0N/A /* Right shift the entire bitset by length, beginning with 0N/A * index-1 if before is true, index+1 if it's false (i.e. with 0N/A /* Initialize the newly inserted indices. 0N/A * Remove the indices in the interval index0,index1 (inclusive) from 0N/A * the selection model. This is typically called to sync the selection 0N/A * model width a corresponding change in the data model. Note 0N/A * that (as always) index0 can be greater than index1. 0N/A /* Shift the entire bitset to the left to close the index0, index1 0N/A * Returns a clone of the receiver with the same selection. 0N/A * <code>listenerLists</code> are not duplicated. 0N/A * @return a clone of the receiver 0N/A * @exception CloneNotSupportedException if the receiver does not 0N/A * both (a) implement the <code>Cloneable</code> interface 0N/A * and (b) define a <code>clone</code> method 0N/A * Set the anchor selection index, leaving all selection values unchanged. 0N/A * @see #getAnchorSelectionIndex 0N/A * @see #setLeadSelectionIndex 0N/A * Set the lead selection index, ensuring that values between the 0N/A * anchor and the new lead are either all selected or all deselected. 0N/A * If the value at the anchor index is selected, first clear all the 0N/A * values in the range [anchor, oldLeadIndex], then select all the values 0N/A * values in the range [anchor, newLeadIndex], where oldLeadIndex is the old 0N/A * leadIndex and newLeadIndex is the new one. 0N/A * If the value at the anchor index is not selected, do the same thing in reverse, 0N/A * selecting values in the old range and deslecting values in the new one. 0N/A * Generate a single event for this change and notify all listeners. 0N/A * For the purposes of generating minimal bounds in this event, do the 0N/A * operation in a single pass; that way the first and last index inside the 0N/A * ListSelectionEvent that is broadcast will refer to cells that actually 0N/A * changed value because of this method. If, instead, this operation were 0N/A * done in two steps the effect on the selection state would be the same 0N/A * but two events would be generated and the bounds around the changed values 0N/A * would be wider, including cells that had been first cleared and only 0N/A * This method can be used in the mouseDragged() method of a UI class 0N/A * to extend a selection. 0N/A * @see #getLeadSelectionIndex 0N/A * @see #setAnchorSelectionIndex 0N/A * This method is responsible for storing the state 0N/A * of the initial selection. If the selectionMode 0N/A * is the default, i.e allowing only for SINGLE_SELECTION, 0N/A * then the very last OPTION that has the selected 0N/A * attribute set wins. 0N/A * Fetches the BitSet that represents the initial 0N/A * set of selected items in the list.