1 /*
2 * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
25 package javax.swing.text.html;
26
27 import javax.swing.*;
28 import javax.swing.event.*;
29 import java.util.BitSet;
30 import java.io.Serializable;
31
32
33 /**
34 * This class extends DefaultListModel, and also implements
35 * the ListSelectionModel interface, allowing for it to store state
36 * relevant to a SELECT form element which is implemented as a List.
37 * If SELECT has a size attribute whose value is greater than 1,
38 * or if allows multiple selection then a JList is used to
39 * represent it and the OptionListModel is used as its model.
40 * It also stores the initial state of the JList, to ensure an
41 * accurate reset, if the user requests a reset of the form.
42 *
43 @author Sunita Mani
44 */
45
46 class OptionListModel<E> extends DefaultListModel<E> implements ListSelectionModel, Serializable {
47
48
49 private static final int MIN = -1;
50 private static final int MAX = Integer.MAX_VALUE;
51 private int selectionMode = SINGLE_SELECTION;
52 private int minIndex = MAX;
53 private int maxIndex = MIN;
54 private int anchorIndex = -1;
55 private int leadIndex = -1;
56 private int firstChangedIndex = MAX;
57 private int lastChangedIndex = MIN;
58 private boolean isAdjusting = false;
59 private BitSet value = new BitSet(32);
60 private BitSet initialValue = new BitSet(32);
61 protected EventListenerList listenerList = new EventListenerList();
62
63 protected boolean leadAnchorNotificationEnabled = true;
64
65 public int getMinSelectionIndex() { return isSelectionEmpty() ? -1 : minIndex; }
|
1 /*
2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
25 package javax.swing.text.html;
26
27 import javax.swing.*;
28 import javax.swing.event.*;
29 import java.util.BitSet;
30 import java.io.Serializable;
31
32
33 /**
34 * This class extends DefaultListModel, and also implements
35 * the ListSelectionModel interface, allowing for it to store state
36 * relevant to a SELECT form element which is implemented as a List.
37 * If SELECT has a size attribute whose value is greater than 1,
38 * or if allows multiple selection then a JList is used to
39 * represent it and the OptionListModel is used as its model.
40 * It also stores the initial state of the JList, to ensure an
41 * accurate reset, if the user requests a reset of the form.
42 *
43 @author Sunita Mani
44 */
45 @SuppressWarnings("serial") // Superclass is not serializable across versions
46 class OptionListModel<E> extends DefaultListModel<E> implements ListSelectionModel, Serializable {
47
48
49 private static final int MIN = -1;
50 private static final int MAX = Integer.MAX_VALUE;
51 private int selectionMode = SINGLE_SELECTION;
52 private int minIndex = MAX;
53 private int maxIndex = MIN;
54 private int anchorIndex = -1;
55 private int leadIndex = -1;
56 private int firstChangedIndex = MAX;
57 private int lastChangedIndex = MIN;
58 private boolean isAdjusting = false;
59 private BitSet value = new BitSet(32);
60 private BitSet initialValue = new BitSet(32);
61 protected EventListenerList listenerList = new EventListenerList();
62
63 protected boolean leadAnchorNotificationEnabled = true;
64
65 public int getMinSelectionIndex() { return isSelectionEmpty() ? -1 : minIndex; }
|