src/java.desktop/share/classes/javax/swing/JComboBox.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 43722 jdk/src/java.desktop/share/classes/javax/swing/JComboBox.java@25ba19c20260
child 52248 2e330da7cbf4
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
39521
c169f36c9a4b 8041909: Uncaught exceptions in JComboBox listeners cause listener not to receive events
aghaisas
parents: 33253
diff changeset
     2
 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2658
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2658
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2658
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2658
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2658
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
    27
import java.beans.JavaBean;
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
    28
import java.beans.BeanProperty;
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    29
import java.beans.PropertyChangeEvent;
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    30
import java.beans.PropertyChangeListener;
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    31
import java.beans.Transient;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * A component that combines a button or editable field and a drop-down list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * The user can select a value from the drop-down list, which appears at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * user's request. If you make the combo box editable, then the combo box
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * includes an editable field into which the user can type a value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
    62
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <p>
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
    67
 * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html">How to Use Combo Boxes</a>
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
    68
 * in <a href="http://docs.oracle.com/javase/tutorial/"><em>The Java Tutorial</em></a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * for further information.
23715
54ae9dd9df73 8039074: Tidy warnings cleanup for javax.swing
yan
parents: 23689
diff changeset
    70
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * @see ComboBoxModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @see DefaultComboBoxModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
    74
 * @param <E> the type of the elements of this combo box
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
    75
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * @author Arnaud Weber
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * @author Mark Davidson
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 25144
diff changeset
    78
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
    80
@JavaBean(defaultProperty = "UI", description = "A combination of a text field and a drop-down list.")
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
    81
@SwingContainer(false)
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 22260
diff changeset
    82
@SuppressWarnings("serial") // Same-version serialization only
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
    83
public class JComboBox<E> extends JComponent
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
implements ItemSelectable,ListDataListener,ActionListener, Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static final String uiClassID = "ComboBoxUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * or override. Use the accessor methods instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @see #getModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @see #setModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
    98
    protected ComboBoxModel<E>    dataModel;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * or override. Use the accessor methods instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @see #getRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @see #setRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   106
    protected ListCellRenderer<? super E> renderer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * or override. Use the accessor methods instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @see #getEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @see #setEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    protected ComboBoxEditor       editor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * or override. Use the accessor methods instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @see #getMaximumRowCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @see #setMaximumRowCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    protected int maximumRowCount = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * or override. Use the accessor methods instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @see #isEditable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @see #setEditable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    protected boolean isEditable  = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * or override. Use the accessor methods instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @see #setKeySelectionManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @see #getKeySelectionManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    protected KeySelectionManager keySelectionManager = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * or override. Use the accessor methods instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @see #setActionCommand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @see #getActionCommand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    protected String actionCommand = "comboBoxChanged";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * or override. Use the accessor methods instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @see #setLightWeightPopupEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @see #isLightWeightPopupEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    protected boolean lightWeightPopupEnabled = JPopupMenu.getDefaultLightWeightPopupEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * or override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    protected Object selectedItemReminder = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   163
    private E prototypeDisplayValue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    // Flag to ensure that infinite loops do not occur with ActionEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    private boolean firingActionEvent = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    // Flag to ensure the we don't get multiple ActionEvents on item selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    private boolean selectingItem = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
39858
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents: 39521
diff changeset
   171
    // Flag to indicate UI update is in progress
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents: 39521
diff changeset
   172
    private transient boolean updateInProgress;
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents: 39521
diff changeset
   173
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Creates a <code>JComboBox</code> that takes its items from an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * existing <code>ComboBoxModel</code>.  Since the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * <code>ComboBoxModel</code> is provided, a combo box created using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * this constructor does not create a default combo box model and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * may impact how the insert, remove and add methods behave.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param aModel the <code>ComboBoxModel</code> that provides the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *          displayed list of items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @see DefaultComboBoxModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   185
    public JComboBox(ComboBoxModel<E> aModel) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        setModel(aModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Creates a <code>JComboBox</code> that contains the elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * in the specified array.  By default the first item in the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * (and therefore the data model) becomes selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @param items  an array of objects to insert into the combo box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @see DefaultComboBoxModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   199
    public JComboBox(E[] items) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        super();
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   201
        setModel(new DefaultComboBoxModel<E>(items));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Creates a <code>JComboBox</code> that contains the elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * in the specified Vector.  By default the first item in the vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * (and therefore the data model) becomes selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @param items  an array of vectors to insert into the combo box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @see DefaultComboBoxModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   213
    public JComboBox(Vector<E> items) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        super();
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   215
        setModel(new DefaultComboBoxModel<E>(items));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * Creates a <code>JComboBox</code> with a default data model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * The default data model is an empty list of objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Use <code>addItem</code> to add items.  By default the first item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * in the data model becomes selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @see DefaultComboBoxModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public JComboBox() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        super();
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   229
        setModel(new DefaultComboBoxModel<E>());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    private void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        installAncestorListener();
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   235
        setUIProperty("opaque",true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
24982
37fe99dfd9e9 8046595: fix doclint issues in swing classes, part 2 of 4
yan
parents: 23715
diff changeset
   239
    /**
37fe99dfd9e9 8046595: fix doclint issues in swing classes, part 2 of 4
yan
parents: 23715
diff changeset
   240
     * Registers ancestor listener so that it will receive
37fe99dfd9e9 8046595: fix doclint issues in swing classes, part 2 of 4
yan
parents: 23715
diff changeset
   241
     * {@code AncestorEvents} when it or any of its ancestors
37fe99dfd9e9 8046595: fix doclint issues in swing classes, part 2 of 4
yan
parents: 23715
diff changeset
   242
     * move or are made visible or invisible.
37fe99dfd9e9 8046595: fix doclint issues in swing classes, part 2 of 4
yan
parents: 23715
diff changeset
   243
     * Events are also sent when the component or its ancestors are added
37fe99dfd9e9 8046595: fix doclint issues in swing classes, part 2 of 4
yan
parents: 23715
diff changeset
   244
     * or removed from the containment hierarchy.
37fe99dfd9e9 8046595: fix doclint issues in swing classes, part 2 of 4
yan
parents: 23715
diff changeset
   245
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    protected void installAncestorListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        addAncestorListener(new AncestorListener(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                public void ancestorAdded(AncestorEvent event){ hidePopup();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                                public void ancestorRemoved(AncestorEvent event){ hidePopup();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                                public void ancestorMoved(AncestorEvent event){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                                    if (event.getSource() != JComboBox.this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                        hidePopup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 9665
diff changeset
   257
     * Sets the L&amp;F object that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 9665
diff changeset
   259
     * @param ui  the <code>ComboBoxUI</code> L&amp;F object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   262
    @BeanProperty(hidden = true, visualUpdate = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   263
            = "The UI object that implements the Component's LookAndFeel.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public void setUI(ComboBoxUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Resets the UI property to a value from the current look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public void updateUI() {
39858
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents: 39521
diff changeset
   274
        if (!updateInProgress) {
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents: 39521
diff changeset
   275
            updateInProgress = true;
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents: 39521
diff changeset
   276
            try {
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents: 39521
diff changeset
   277
                setUI((ComboBoxUI)UIManager.getUI(this));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
39858
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents: 39521
diff changeset
   279
                ListCellRenderer<? super E> renderer = getRenderer();
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents: 39521
diff changeset
   280
                if (renderer instanceof Component) {
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents: 39521
diff changeset
   281
                    SwingUtilities.updateComponentTreeUI((Component)renderer);
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents: 39521
diff changeset
   282
                }
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents: 39521
diff changeset
   283
            } finally {
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents: 39521
diff changeset
   284
                updateInProgress = false;
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents: 39521
diff changeset
   285
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 9665
diff changeset
   291
     * Returns the name of the L&amp;F class that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @return the string "ComboBoxUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   297
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 9665
diff changeset
   304
     * Returns the L&amp;F object that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @return the ComboBoxUI object that renders this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    public ComboBoxUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        return(ComboBoxUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * Sets the data model that the <code>JComboBox</code> uses to obtain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * the list of items.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @param aModel the <code>ComboBoxModel</code> that provides the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *  displayed list of items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   319
    @BeanProperty(description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   320
            = "Model that the combo box uses to get data to display.")
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   321
    public void setModel(ComboBoxModel<E> aModel) {
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   322
        ComboBoxModel<E> oldModel = dataModel;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if (oldModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            oldModel.removeListDataListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        dataModel = aModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        dataModel.addListDataListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        // set the current selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        selectedItemReminder = dataModel.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        firePropertyChange( "model", oldModel, dataModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * Returns the data model currently used by the <code>JComboBox</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @return the <code>ComboBoxModel</code> that provides the displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *                  list of items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   341
    public ComboBoxModel<E> getModel() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        return dataModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * Sets the <code>lightWeightPopupEnabled</code> property, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * provides a hint as to whether or not a lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * <code>Component</code> should be used to contain the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * <code>JComboBox</code>, versus a heavyweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * <code>Component</code> such as a <code>Panel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * or a <code>Window</code>.  The decision of lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * versus heavyweight is ultimately up to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * <code>JComboBox</code>.  Lightweight windows are more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * efficient than heavyweight windows, but lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * and heavyweight components do not mix well in a GUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * If your application mixes lightweight and heavyweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * components, you should disable lightweight popups.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * The default value for the <code>lightWeightPopupEnabled</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * property is <code>true</code>, unless otherwise specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * by the look and feel.  Some look and feels always use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * heavyweight popups, no matter what the value of this property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * <p>
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
   367
     * See the article <a href="http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html">Mixing Heavy and Light Components</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * This method fires a property changed event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @param aFlag if <code>true</code>, lightweight popups are desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   372
    @BeanProperty(expert = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   373
            = "Set to <code>false</code> to require heavyweight popups.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public void setLightWeightPopupEnabled(boolean aFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        boolean oldFlag = lightWeightPopupEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        lightWeightPopupEnabled = aFlag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        firePropertyChange("lightWeightPopupEnabled", oldFlag, lightWeightPopupEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * Gets the value of the <code>lightWeightPopupEnabled</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @return the value of the <code>lightWeightPopupEnabled</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *    property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @see #setLightWeightPopupEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    public boolean isLightWeightPopupEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        return lightWeightPopupEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * Determines whether the <code>JComboBox</code> field is editable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * An editable <code>JComboBox</code> allows the user to type into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * field or selected an item from the list to initialize the field,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * after which it can be edited. (The editing affects only the field,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * the list item remains intact.) A non editable <code>JComboBox</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * displays the selected item in the field,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * but the selection cannot be modified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @param aFlag a boolean value, where true indicates that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *                  field is editable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   404
    @BeanProperty(preferred = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   405
            = "If true, the user can type a new value in the combo box.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    public void setEditable(boolean aFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        boolean oldFlag = isEditable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        isEditable = aFlag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        firePropertyChange( "editable", oldFlag, isEditable );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * Returns true if the <code>JComboBox</code> is editable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * By default, a combo box is not editable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @return true if the <code>JComboBox</code> is editable, else false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    public boolean isEditable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        return isEditable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * Sets the maximum number of rows the <code>JComboBox</code> displays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * If the number of objects in the model is greater than count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * the combo box uses a scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @param count an integer specifying the maximum number of items to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *              display in the list before using a scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   430
    @BeanProperty(preferred = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   431
            = "The maximum number of rows the popup should have")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    public void setMaximumRowCount(int count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        int oldCount = maximumRowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        maximumRowCount = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        firePropertyChange( "maximumRowCount", oldCount, maximumRowCount );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * Returns the maximum number of items the combo box can display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * without a scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * @return an integer specifying the maximum number of items that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *         displayed in the list before using a scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    public int getMaximumRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        return maximumRowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * Sets the renderer that paints the list items and the item selected from the list in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * the JComboBox field. The renderer is used if the JComboBox is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * editable. If it is editable, the editor is used to render and edit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * the selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * The default renderer displays a string or an icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * Other renderers can handle graphic images and composite items.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * To display the selected item,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * <code>aRenderer.getListCellRendererComponent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * is called, passing the list object and an index of -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @param aRenderer  the <code>ListCellRenderer</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *                  displays the selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @see #setEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   466
    @BeanProperty(expert = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   467
            = "The renderer that paints the item selected in the list.")
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   468
    public void setRenderer(ListCellRenderer<? super E> aRenderer) {
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   469
        ListCellRenderer<? super E> oldRenderer = renderer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        renderer = aRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        firePropertyChange( "renderer", oldRenderer, renderer );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * Returns the renderer used to display the selected item in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * <code>JComboBox</code> field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @return  the <code>ListCellRenderer</code> that displays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *                  the selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     */
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   482
    public ListCellRenderer<? super E> getRenderer() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return renderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * Sets the editor used to paint and edit the selected item in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * <code>JComboBox</code> field.  The editor is used only if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * receiving <code>JComboBox</code> is editable. If not editable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * the combo box uses the renderer to paint the selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @param anEditor  the <code>ComboBoxEditor</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     *                  displays the selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @see #setRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   496
    @BeanProperty(expert = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   497
            = "The editor that combo box uses to edit the current value")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    public void setEditor(ComboBoxEditor anEditor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        ComboBoxEditor oldEditor = editor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        if ( editor != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            editor.removeActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        editor = anEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        if ( editor != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            editor.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        firePropertyChange( "editor", oldEditor, editor );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * Returns the editor used to paint and edit the selected item in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * <code>JComboBox</code> field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @return the <code>ComboBoxEditor</code> that displays the selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    public ComboBoxEditor getEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        return editor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    // Selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * Sets the selected item in the combo box display area to the object in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * If <code>anObject</code> is in the list, the display area shows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * <code>anObject</code> selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * If <code>anObject</code> is <i>not</i> in the list and the combo box is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * uneditable, it will not change the current selection. For editable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * combo boxes, the selection will change to <code>anObject</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * If this constitutes a change in the selected item,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * <code>ItemListener</code>s added to the combo box will be notified with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * one or two <code>ItemEvent</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * If there is a current selected item, an <code>ItemEvent</code> will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * fired and the state change will be <code>ItemEvent.DESELECTED</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * If <code>anObject</code> is in the list and is not currently selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * then an <code>ItemEvent</code> will be fired and the state change will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * be <code>ItemEvent.SELECTED</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * <code>ActionListener</code>s added to the combo box will be notified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * with an <code>ActionEvent</code> when this method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * @param anObject  the list object to select; use <code>null</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                        clear the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   550
    @BeanProperty(bound = false, preferred = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   551
            = "Sets the selected item in the JComboBox.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    public void setSelectedItem(Object anObject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        Object oldSelection = selectedItemReminder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        Object objectToSelect = anObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        if (oldSelection == null || !oldSelection.equals(anObject)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            if (anObject != null && !isEditable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                // For non editable combo boxes, an invalid selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                // will be rejected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                for (int i = 0; i < dataModel.getSize(); i++) {
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   562
                    E element = dataModel.getElementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                    if (anObject.equals(element)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                        found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                        objectToSelect = element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                if (!found) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                }
30463
06e0b7759125 8072767: DefaultCellEditor for comboBox creates ActionEvent with wrong source object
alexsch
parents: 28089
diff changeset
   572
06e0b7759125 8072767: DefaultCellEditor for comboBox creates ActionEvent with wrong source object
alexsch
parents: 28089
diff changeset
   573
                getEditor().setItem(anObject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            // Must toggle the state of this flag since this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            // call may result in ListDataEvents being fired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            selectingItem = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            dataModel.setSelectedItem(objectToSelect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            selectingItem = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            if (selectedItemReminder != dataModel.getSelectedItem()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                // in case a users implementation of ComboBoxModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                // doesn't fire a ListDataEvent when the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                // changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                selectedItemChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        fireActionEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * Returns the current selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * If the combo box is editable, then this value may not have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * to the combo box with <code>addItem</code>, <code>insertItemAt</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * or the data constructors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @return the current selected Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * @see #setSelectedItem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    public Object getSelectedItem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        return dataModel.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * Selects the item at index <code>anIndex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * @param anIndex an integer specifying the list item to select,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     *                  where 0 specifies the first item in the list and -1 indicates no selection
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 9665
diff changeset
   611
     * @exception IllegalArgumentException if <code>anIndex</code> &lt; -1 or
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     *                  <code>anIndex</code> is greater than or equal to size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   614
    @BeanProperty(bound = false, preferred = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   615
            = "The item at index is selected.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    public void setSelectedIndex(int anIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        int size = dataModel.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        if ( anIndex == -1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            setSelectedItem( null );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        } else if ( anIndex < -1 || anIndex >= size ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            throw new IllegalArgumentException("setSelectedIndex: " + anIndex + " out of bounds");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            setSelectedItem(dataModel.getElementAt(anIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * Returns the first item in the list that matches the given item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * The result is not always defined if the <code>JComboBox</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * allows selected items that are not in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * Returns -1 if there is no selected item or if the user specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * an item which is not in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * @return an integer specifying the currently selected list item,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     *                  where 0 specifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     *                  the first item in the list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     *                  or -1 if no item is selected or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     *                  the currently selected item is not in the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   641
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    public int getSelectedIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        Object sObject = dataModel.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        int i,c;
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   645
        E obj;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        for ( i=0,c=dataModel.getSize();i<c;i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            obj = dataModel.getElementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            if ( obj != null && obj.equals(sObject) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * Returns the "prototypical display" value - an Object used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * for the calculation of the display height and width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @return the value of the <code>prototypeDisplayValue</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * @see #setPrototypeDisplayValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     */
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   663
    public E getPrototypeDisplayValue() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        return prototypeDisplayValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * Sets the prototype display value used to calculate the size of the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * for the UI portion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * If a prototype display value is specified, the preferred size of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * the combo box is calculated by configuring the renderer with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * prototype display value and obtaining its preferred size. Specifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * the preferred display value is often useful when the combo box will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * displaying large amounts of data. If no prototype display value has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * been specified, the renderer must be configured for each value from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * the model and its preferred size obtained, which can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * relatively expensive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     *
22260
c9185e010e03 8031082: Fix non-missing doclint problems in client libraries
darcy
parents: 21278
diff changeset
   680
     * @param prototypeDisplayValue the prototype display value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * @see #getPrototypeDisplayValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   684
    @BeanProperty(visualUpdate = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   685
            = "The display prototype value, used to compute display width and height.")
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   686
    public void setPrototypeDisplayValue(E prototypeDisplayValue) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        Object oldValue = this.prototypeDisplayValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        this.prototypeDisplayValue = prototypeDisplayValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        firePropertyChange("prototypeDisplayValue", oldValue, prototypeDisplayValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * Adds an item to the item list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * This method works only if the <code>JComboBox</code> uses a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * mutable data model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * Focus and keyboard navigation problems may arise if you add duplicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * String objects. A workaround is to add new objects instead of String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * objects and make sure that the toString() method is defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     *   comboBox.addItem(makeObj("Item 1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     *   comboBox.addItem(makeObj("Item 1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     *   ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     *   private Object makeObj(final String item)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     *     return new Object() { public String toString() { return item; } };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     *
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   711
     * @param item the item to add to the list
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * @see MutableComboBoxModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     */
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   714
    public void addItem(E item) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        checkMutableComboBoxModel();
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   716
        ((MutableComboBoxModel<E>)dataModel).addElement(item);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * Inserts an item into the item list at a given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * This method works only if the <code>JComboBox</code> uses a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * mutable data model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     *
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   724
     * @param item the item to add to the list
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * @param index    an integer specifying the position at which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     *                  to add the item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * @see MutableComboBoxModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     */
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   729
    public void insertItemAt(E item, int index) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        checkMutableComboBoxModel();
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   731
        ((MutableComboBoxModel<E>)dataModel).insertElementAt(item,index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * Removes an item from the item list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * This method works only if the <code>JComboBox</code> uses a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * mutable data model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * @param anObject  the object to remove from the item list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * @see MutableComboBoxModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    public void removeItem(Object anObject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        checkMutableComboBoxModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        ((MutableComboBoxModel)dataModel).removeElement(anObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * Removes the item at <code>anIndex</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * This method works only if the <code>JComboBox</code> uses a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * mutable data model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * @param anIndex  an int specifying the index of the item to remove,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     *                  where 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     *                  indicates the first item in the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * @see MutableComboBoxModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    public void removeItemAt(int anIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        checkMutableComboBoxModel();
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   759
        ((MutableComboBoxModel<E>)dataModel).removeElementAt( anIndex );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * Removes all items from the item list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    public void removeAllItems() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        checkMutableComboBoxModel();
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   767
        MutableComboBoxModel<E> model = (MutableComboBoxModel<E>)dataModel;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        int size = model.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        if ( model instanceof DefaultComboBoxModel ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            ((DefaultComboBoxModel)model).removeAllElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            for ( int i = 0; i < size; ++i ) {
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   775
                E element = model.getElementAt( 0 );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                model.removeElement( element );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        selectedItemReminder = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        if (isEditable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            editor.setItem(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * Checks that the <code>dataModel</code> is an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * <code>MutableComboBoxModel</code>.  If not, it throws an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * @exception RuntimeException if <code>dataModel</code> is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     *          instance of <code>MutableComboBoxModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    void checkMutableComboBoxModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        if ( !(dataModel instanceof MutableComboBoxModel) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            throw new RuntimeException("Cannot use this method with a non-Mutable data model.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * Causes the combo box to display its popup window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @see #setPopupVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    public void showPopup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        setPopupVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * Causes the combo box to close its popup window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * @see #setPopupVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    public void hidePopup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        setPopupVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * Sets the visibility of the popup.
24982
37fe99dfd9e9 8046595: fix doclint issues in swing classes, part 2 of 4
yan
parents: 23715
diff changeset
   814
     *
37fe99dfd9e9 8046595: fix doclint issues in swing classes, part 2 of 4
yan
parents: 23715
diff changeset
   815
     * @param v if {@code true} shows the popup, otherwise, hides the popup.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    public void setPopupVisible(boolean v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        getUI().setPopupVisible(this, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * Determines the visibility of the popup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * @return true if the popup is visible, otherwise returns false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    public boolean isPopupVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        return getUI().isPopupVisible(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    /** Selection **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * Adds an <code>ItemListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * <code>aListener</code> will receive one or two <code>ItemEvent</code>s when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * the selected item changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * @param aListener the <code>ItemListener</code> that is to be notified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * @see #setSelectedItem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    public void addItemListener(ItemListener aListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        listenerList.add(ItemListener.class,aListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    /** Removes an <code>ItemListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * @param aListener  the <code>ItemListener</code> to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    public void removeItemListener(ItemListener aListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        listenerList.remove(ItemListener.class,aListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * Returns an array of all the <code>ItemListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * to this JComboBox with addItemListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * @return all of the <code>ItemListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   861
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    public ItemListener[] getItemListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   863
        return listenerList.getListeners(ItemListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * Adds an <code>ActionListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * The <code>ActionListener</code> will receive an <code>ActionEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * when a selection has been made. If the combo box is editable, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * an <code>ActionEvent</code> will be fired when editing has stopped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * @param l  the <code>ActionListener</code> that is to be notified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * @see #setSelectedItem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    public void addActionListener(ActionListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        listenerList.add(ActionListener.class,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    /** Removes an <code>ActionListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * @param l  the <code>ActionListener</code> to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    public void removeActionListener(ActionListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        if ((l != null) && (getAction() == l)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            setAction(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            listenerList.remove(ActionListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * Returns an array of all the <code>ActionListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * to this JComboBox with addActionListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * @return all of the <code>ActionListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   900
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    public ActionListener[] getActionListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   902
        return listenerList.getListeners(ActionListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * Adds a <code>PopupMenu</code> listener which will listen to notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * messages from the popup portion of the combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * For all standard look and feels shipped with Java, the popup list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * portion of combo box is implemented as a <code>JPopupMenu</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * A custom look and feel may not implement it this way and will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * therefore not receive the notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * @param l  the <code>PopupMenuListener</code> to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    public void addPopupMenuListener(PopupMenuListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        listenerList.add(PopupMenuListener.class,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * Removes a <code>PopupMenuListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * @param l  the <code>PopupMenuListener</code> to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * @see #addPopupMenuListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    public void removePopupMenuListener(PopupMenuListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        listenerList.remove(PopupMenuListener.class,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * Returns an array of all the <code>PopupMenuListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * to this JComboBox with addPopupMenuListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * @return all of the <code>PopupMenuListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
   940
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    public PopupMenuListener[] getPopupMenuListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   942
        return listenerList.getListeners(PopupMenuListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * Notifies <code>PopupMenuListener</code>s that the popup portion of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * combo box will become visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * This method is public but should not be called by anything other than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * the UI delegate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * @see #addPopupMenuListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    public void firePopupMenuWillBecomeVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        PopupMenuEvent e=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            if (listeners[i]==PopupMenuListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                    e = new PopupMenuEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                ((PopupMenuListener)listeners[i+1]).popupMenuWillBecomeVisible(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * Notifies <code>PopupMenuListener</code>s that the popup portion of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * combo box has become invisible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * This method is public but should not be called by anything other than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * the UI delegate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * @see #addPopupMenuListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    public void firePopupMenuWillBecomeInvisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        PopupMenuEvent e=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            if (listeners[i]==PopupMenuListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                    e = new PopupMenuEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                ((PopupMenuListener)listeners[i+1]).popupMenuWillBecomeInvisible(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * Notifies <code>PopupMenuListener</code>s that the popup portion of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * combo box has been canceled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * This method is public but should not be called by anything other than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * the UI delegate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * @see #addPopupMenuListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    public void firePopupMenuCanceled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        PopupMenuEvent e=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            if (listeners[i]==PopupMenuListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                    e = new PopupMenuEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                ((PopupMenuListener)listeners[i+1]).popupMenuCanceled(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * Sets the action command that should be included in the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * sent to action listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * @param aCommand  a string containing the "command" that is sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     *                  to action listeners; the same listener can then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     *                  do different things depending on the command it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     *                  receives
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    public void setActionCommand(String aCommand) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        actionCommand = aCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * Returns the action command that is included in the event sent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * action listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * @return  the string containing the "command" that is sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     *          to action listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    public String getActionCommand() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        return actionCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    private Action action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
    private PropertyChangeListener actionPropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * Sets the <code>Action</code> for the <code>ActionEvent</code> source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     * The new <code>Action</code> replaces any previously set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * <code>Action</code> but does not affect <code>ActionListeners</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * independently added with <code>addActionListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * If the <code>Action</code> is already a registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     * <code>ActionListener</code> for the <code>ActionEvent</code> source,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     * it is not re-registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * Setting the <code>Action</code> results in immediately changing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * all the properties described in <a href="Action.html#buttonActions">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * Swing Components Supporting <code>Action</code></a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * Subsequently, the combobox's properties are automatically updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * as the <code>Action</code>'s properties change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * This method uses three other methods to set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * and help track the <code>Action</code>'s property values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * It uses the <code>configurePropertiesFromAction</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * to immediately change the combobox's properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * To track changes in the <code>Action</code>'s property values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     * this method registers the <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * returned by <code>createActionPropertyChangeListener</code>. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * default {@code PropertyChangeListener} invokes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * {@code actionPropertyChanged} method when a property in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * {@code Action} changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * @param a the <code>Action</code> for the <code>JComboBox</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     *                  or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * @see #getAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * @see #configurePropertiesFromAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * @see #createActionPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * @see #actionPropertyChanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
  1070
    @BeanProperty(visualUpdate = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
  1071
            = "the Action instance connected with this ActionEvent source")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
    public void setAction(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        Action oldValue = getAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        if (action==null || !action.equals(a)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            action = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            if (oldValue!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                removeActionListener(oldValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                oldValue.removePropertyChangeListener(actionPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                actionPropertyChangeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            configurePropertiesFromAction(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            if (action!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                // Don't add if it is already a listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                if (!isListener(ActionListener.class, action)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                    addActionListener(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                // Reverse linkage:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                actionPropertyChangeListener = createActionPropertyChangeListener(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                action.addPropertyChangeListener(actionPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            firePropertyChange("action", oldValue, action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 25201
diff changeset
  1095
    private boolean isListener(Class<?> c, ActionListener a) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        boolean isListener = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            if (listeners[i]==c && listeners[i+1]==a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                    isListener=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        return isListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * Returns the currently set <code>Action</code> for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * <code>ActionEvent</code> source, or <code>null</code> if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * <code>Action</code> is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     * @return the <code>Action</code> for this <code>ActionEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     *          source; or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     * @see #setAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    public Action getAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        return action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     * Sets the properties on this combobox to match those in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     * <code>Action</code>.  Refer to <a href="Action.html#buttonActions">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     * Swing Components Supporting <code>Action</code></a> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     * details as to which properties this sets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * @param a the <code>Action</code> from which to get the properties,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     *          or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     * @see #setAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    protected void configurePropertiesFromAction(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        AbstractAction.setEnabledFromAction(this, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        AbstractAction.setToolTipTextFromAction(this, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        setActionCommandFromAction(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * Creates and returns a <code>PropertyChangeListener</code> that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * responsible for listening for changes from the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * <code>Action</code> and updating the appropriate properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * <b>Warning:</b> If you subclass this do not create an anonymous
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * inner class.  If you do the lifetime of the combobox will be tied to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     * that of the <code>Action</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * @param a the combobox's action
24982
37fe99dfd9e9 8046595: fix doclint issues in swing classes, part 2 of 4
yan
parents: 23715
diff changeset
  1149
     * @return the {@code PropertyChangeListener}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * @see #setAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    protected PropertyChangeListener createActionPropertyChangeListener(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        return new ComboBoxActionPropertyChangeListener(this, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * Updates the combobox's state in response to property changes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     * associated action. This method is invoked from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * {@code PropertyChangeListener} returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * {@code createActionPropertyChangeListener}. Subclasses do not normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * need to invoke this. Subclasses that support additional {@code Action}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * properties should override this and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * {@code configurePropertiesFromAction}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * Refer to the table at <a href="Action.html#buttonActions">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * Swing Components Supporting <code>Action</code></a> for a list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * the properties this method sets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * @param action the <code>Action</code> associated with this combobox
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * @param propertyName the name of the property that changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * @see #configurePropertiesFromAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    protected void actionPropertyChanged(Action action, String propertyName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        if (propertyName == Action.ACTION_COMMAND_KEY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            setActionCommandFromAction(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        } else if (propertyName == "enabled") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            AbstractAction.setEnabledFromAction(this, action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        } else if (Action.SHORT_DESCRIPTION == propertyName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            AbstractAction.setToolTipTextFromAction(this, action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
    private void setActionCommandFromAction(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        setActionCommand((a != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                             (String)a.getValue(Action.ACTION_COMMAND_KEY) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                             null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
    private static class ComboBoxActionPropertyChangeListener
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
  1195
                 extends ActionPropertyChangeListener<JComboBox<?>> {
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
  1196
        ComboBoxActionPropertyChangeListener(JComboBox<?> b, Action a) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            super(b, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        }
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
  1199
        protected void actionPropertyChanged(JComboBox<?> cb,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                                             Action action,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                                             PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
            if (AbstractAction.shouldReconfigure(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                cb.configurePropertiesFromAction(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                cb.actionPropertyChanged(action, e.getPropertyName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     * notification on this event type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     * @param e  the event of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    protected void fireItemStateChanged(ItemEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        for ( int i = listeners.length-2; i>=0; i-=2 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            if ( listeners[i]==ItemListener.class ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                // if (changeEvent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                // changeEvent = new ChangeEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
                ((ItemListener)listeners[i+1]).itemStateChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * notification on this event type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     */
43722
25ba19c20260 8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents: 39858
diff changeset
  1238
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    protected void fireActionEvent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        if (!firingActionEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
            // Set flag to ensure that an infinite loop is not created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            firingActionEvent = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
            ActionEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            long mostRecentEventTime = EventQueue.getMostRecentEventTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            int modifiers = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            AWTEvent currentEvent = EventQueue.getCurrentEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            if (currentEvent instanceof InputEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                modifiers = ((InputEvent)currentEvent).getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            } else if (currentEvent instanceof ActionEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                modifiers = ((ActionEvent)currentEvent).getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
            }
39521
c169f36c9a4b 8041909: Uncaught exceptions in JComboBox listeners cause listener not to receive events
aghaisas
parents: 33253
diff changeset
  1254
            try {
c169f36c9a4b 8041909: Uncaught exceptions in JComboBox listeners cause listener not to receive events
aghaisas
parents: 33253
diff changeset
  1255
                // Process the listeners last to first, notifying
c169f36c9a4b 8041909: Uncaught exceptions in JComboBox listeners cause listener not to receive events
aghaisas
parents: 33253
diff changeset
  1256
                // those that are interested in this event
c169f36c9a4b 8041909: Uncaught exceptions in JComboBox listeners cause listener not to receive events
aghaisas
parents: 33253
diff changeset
  1257
                for ( int i = listeners.length-2; i>=0; i-=2 ) {
c169f36c9a4b 8041909: Uncaught exceptions in JComboBox listeners cause listener not to receive events
aghaisas
parents: 33253
diff changeset
  1258
                    if ( listeners[i]==ActionListener.class ) {
c169f36c9a4b 8041909: Uncaught exceptions in JComboBox listeners cause listener not to receive events
aghaisas
parents: 33253
diff changeset
  1259
                        // Lazily create the event:
c169f36c9a4b 8041909: Uncaught exceptions in JComboBox listeners cause listener not to receive events
aghaisas
parents: 33253
diff changeset
  1260
                        if ( e == null )
c169f36c9a4b 8041909: Uncaught exceptions in JComboBox listeners cause listener not to receive events
aghaisas
parents: 33253
diff changeset
  1261
                            e = new ActionEvent(this,ActionEvent.ACTION_PERFORMED,
c169f36c9a4b 8041909: Uncaught exceptions in JComboBox listeners cause listener not to receive events
aghaisas
parents: 33253
diff changeset
  1262
                                                getActionCommand(),
c169f36c9a4b 8041909: Uncaught exceptions in JComboBox listeners cause listener not to receive events
aghaisas
parents: 33253
diff changeset
  1263
                                                mostRecentEventTime, modifiers);
c169f36c9a4b 8041909: Uncaught exceptions in JComboBox listeners cause listener not to receive events
aghaisas
parents: 33253
diff changeset
  1264
                        ((ActionListener)listeners[i+1]).actionPerformed(e);
c169f36c9a4b 8041909: Uncaught exceptions in JComboBox listeners cause listener not to receive events
aghaisas
parents: 33253
diff changeset
  1265
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                }
39521
c169f36c9a4b 8041909: Uncaught exceptions in JComboBox listeners cause listener not to receive events
aghaisas
parents: 33253
diff changeset
  1267
            } finally {
c169f36c9a4b 8041909: Uncaught exceptions in JComboBox listeners cause listener not to receive events
aghaisas
parents: 33253
diff changeset
  1268
                firingActionEvent = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     * This protected method is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     * or override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    protected void selectedItemChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        if (selectedItemReminder != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            fireItemStateChanged(new ItemEvent(this,ItemEvent.ITEM_STATE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                                               selectedItemReminder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                                               ItemEvent.DESELECTED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        // set the new selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        selectedItemReminder = dataModel.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        if (selectedItemReminder != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            fireItemStateChanged(new ItemEvent(this,ItemEvent.ITEM_STATE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                                               selectedItemReminder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                                               ItemEvent.SELECTED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
     * Returns an array containing the selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     * This method is implemented for compatibility with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     * <code>ItemSelectable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * @return an array of <code>Objects</code> containing one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     *          element -- the selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
  1302
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    public Object[] getSelectedObjects() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        Object selectedObject = getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
        if ( selectedObject == null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            return new Object[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            Object result[] = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            result[0] = selectedObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     * This method is public as an implementation side effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     * do not call or override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
    public void actionPerformed(ActionEvent e) {
30463
06e0b7759125 8072767: DefaultCellEditor for comboBox creates ActionEvent with wrong source object
alexsch
parents: 28089
diff changeset
  1319
        setPopupVisible(false);
06e0b7759125 8072767: DefaultCellEditor for comboBox creates ActionEvent with wrong source object
alexsch
parents: 28089
diff changeset
  1320
        getModel().setSelectedItem(getEditor().getItem());
06e0b7759125 8072767: DefaultCellEditor for comboBox creates ActionEvent with wrong source object
alexsch
parents: 28089
diff changeset
  1321
        String oldCommand = getActionCommand();
06e0b7759125 8072767: DefaultCellEditor for comboBox creates ActionEvent with wrong source object
alexsch
parents: 28089
diff changeset
  1322
        setActionCommand("comboBoxEdited");
06e0b7759125 8072767: DefaultCellEditor for comboBox creates ActionEvent with wrong source object
alexsch
parents: 28089
diff changeset
  1323
        fireActionEvent();
06e0b7759125 8072767: DefaultCellEditor for comboBox creates ActionEvent with wrong source object
alexsch
parents: 28089
diff changeset
  1324
        setActionCommand(oldCommand);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     * This method is public as an implementation side effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     * do not call or override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
    public void contentsChanged(ListDataEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        Object oldSelection = selectedItemReminder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        Object newSelection = dataModel.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        if (oldSelection == null || !oldSelection.equals(newSelection)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            selectedItemChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
            if (!selectingItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                fireActionEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
     * This method is public as an implementation side effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
     * do not call or override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
    public void intervalAdded(ListDataEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        if (selectedItemReminder != dataModel.getSelectedItem()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            selectedItemChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     * This method is public as an implementation side effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     * do not call or override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
    public void intervalRemoved(ListDataEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
        contentsChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
     * Selects the list item that corresponds to the specified keyboard
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     * character and returns true, if there is an item corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     * to that character.  Otherwise, returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
     * @param keyChar a char, typically this is a keyboard key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
     *                  typed by the user
24982
37fe99dfd9e9 8046595: fix doclint issues in swing classes, part 2 of 4
yan
parents: 23715
diff changeset
  1367
     * @return {@code true} if there is an item corresponding to that character.
37fe99dfd9e9 8046595: fix doclint issues in swing classes, part 2 of 4
yan
parents: 23715
diff changeset
  1368
     *         Otherwise, returns {@code false}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
    public boolean selectWithKeyChar(char keyChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        if ( keySelectionManager == null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
            keySelectionManager = createDefaultKeySelectionManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        index = keySelectionManager.selectionForKey(keyChar,getModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        if ( index != -1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
            setSelectedIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     * Enables the combo box so that items can be selected. When the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     * combo box is disabled, items cannot be selected and values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * cannot be typed into its field (if it is editable).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     * @param b a boolean value, where true enables the component and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     *          false disables it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
  1393
    @BeanProperty(preferred = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
  1394
            = "The enabled state of the component.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
    public void setEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
        super.setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        firePropertyChange( "enabled", !isEnabled(), isEnabled() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     * Initializes the editor with the specified item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     * @param anEditor the <code>ComboBoxEditor</code> that displays
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     *                  the list item in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     *                  combo box field and allows it to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * @param anItem   the object to display and edit in the field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
    public void configureEditor(ComboBoxEditor anEditor, Object anItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        anEditor.setItem(anItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * Handles <code>KeyEvent</code>s, looking for the Tab key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * If the Tab key is found, the popup window is closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     * @param e  the <code>KeyEvent</code> containing the keyboard
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     *          key that was pressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    public void processKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        if ( e.getKeyCode() == KeyEvent.VK_TAB ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
            hidePopup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
        super.processKeyEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
    /**
23689
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1427
     * {@inheritDoc}
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1428
     */
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1429
    @Override
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1430
    protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1431
        if (super.processKeyBinding(ks, e, condition, pressed)) {
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1432
            return true;
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1433
        }
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1434
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1435
        if (!isEditable() || condition != WHEN_FOCUSED || getEditor() == null
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1436
                || !Boolean.TRUE.equals(getClientProperty("JComboBox.isTableCellEditor"))) {
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1437
            return false;
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1438
        }
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1439
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1440
        Component editorComponent = getEditor().getEditorComponent();
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1441
        if (editorComponent instanceof JComponent) {
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1442
            JComponent component = (JComponent) editorComponent;
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1443
            return component.processKeyBinding(ks, e, WHEN_FOCUSED, pressed);
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1444
        }
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1445
        return false;
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1446
    }
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1447
5571891e9b68 8032878: Editable combos in table do not behave as expected
alitvinov
parents: 22574
diff changeset
  1448
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     * Sets the object that translates a keyboard character into a list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
     * selection. Typically, the first selection with a matching first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     * character becomes the selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     *
24982
37fe99dfd9e9 8046595: fix doclint issues in swing classes, part 2 of 4
yan
parents: 23715
diff changeset
  1453
     * @param aManager a key selection manager
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
  1455
    @BeanProperty(bound = false, expert = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
  1456
            = "The objects that changes the selection when a key is pressed.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    public void setKeySelectionManager(KeySelectionManager aManager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        keySelectionManager = aManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
     * Returns the list's key-selection manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
     * @return the <code>KeySelectionManager</code> currently in use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
    public KeySelectionManager getKeySelectionManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        return keySelectionManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
    /* Accessing the model */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     * Returns the number of items in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     * @return an integer equal to the number of items in the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
  1476
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
    public int getItemCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
        return dataModel.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
     * Returns the list item at the specified index.  If <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
     * is out of range (less than zero or greater than or equal to size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     * it will return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
     * @param index  an integer indicating the list position, where the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
     *               item starts at zero
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
  1488
     * @return the item at that list position; or
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
     *                  <code>null</code> if out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
     */
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
  1491
    public E getItemAt(int index) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        return dataModel.getElementAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
     * Returns an instance of the default key-selection manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
     * @return the <code>KeySelectionManager</code> currently used by the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
     * @see #setKeySelectionManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
    protected KeySelectionManager createDefaultKeySelectionManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        return new DefaultKeySelectionManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
     * The interface that defines a <code>KeySelectionManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
     * To qualify as a <code>KeySelectionManager</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
     * the class needs to implement the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     * that identifies the list index given a character and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
     * combo box data model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
    public interface KeySelectionManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
        /** Given <code>aKey</code> and the model, returns the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
         *  that should become selected. Return -1 if no match was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
         *  found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
         * @param  aKey  a char value, usually indicating a keyboard key that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
         *               was pressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
         * @param aModel a ComboBoxModel -- the component's data model, containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
         *               the list of selectable items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
         * @return an int equal to the selected row, where 0 is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
         *         first item and -1 is none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
         */
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 25201
diff changeset
  1525
        int selectionForKey(char aKey,ComboBoxModel<?> aModel);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
    class DefaultKeySelectionManager implements KeySelectionManager, Serializable {
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 25201
diff changeset
  1529
        public int selectionForKey(char aKey,ComboBoxModel<?> aModel) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
            int i,c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
            int currentSelection = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
            Object selectedItem = aModel.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
            String v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
            String pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
            if ( selectedItem != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                for ( i=0,c=aModel.getSize();i<c;i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
                    if ( selectedItem == aModel.getElementAt(i) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                        currentSelection  =  i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
            pattern = ("" + aKey).toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
            aKey = pattern.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
            for ( i = ++currentSelection, c = aModel.getSize() ; i < c ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                Object elem = aModel.getElementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                if (elem != null && elem.toString() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                    v = elem.toString().toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                    if ( v.length() > 0 && v.charAt(0) == aKey )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                        return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
            for ( i = 0 ; i < currentSelection ; i ++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                Object elem = aModel.getElementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                if (elem != null && elem.toString() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                    v = elem.toString().toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                    if ( v.length() > 0 && v.charAt(0) == aKey )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                        return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
     * See <code>readObject</code> and <code>writeObject</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
     * <code>JComponent</code> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     * Returns a string representation of this <code>JComboBox</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
     * This method is intended to be used only for debugging purposes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
     * and the content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
     * @return  a string representation of this <code>JComboBox</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
        String selectedItemReminderString = (selectedItemReminder != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                                             selectedItemReminder.toString() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
                                             "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
        String isEditableString = (isEditable ? "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
        String lightWeightPopupEnabledString = (lightWeightPopupEnabled ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                                                "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
        ",isEditable=" + isEditableString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
        ",lightWeightPopupEnabled=" + lightWeightPopupEnabledString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
        ",maximumRowCount=" + maximumRowCount +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
        ",selectedItemReminder=" + selectedItemReminderString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
///////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
///////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
     * Gets the AccessibleContext associated with this JComboBox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
     * For combo boxes, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
     * AccessibleJComboBox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
     * A new AccessibleJComboBox instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
     * @return an AccessibleJComboBox that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
     *         AccessibleContext of this JComboBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
  1625
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
        if ( accessibleContext == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
            accessibleContext = new AccessibleJComboBox();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
     * <code>JComboBox</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
     * Java Accessibility API appropriate to Combo Box user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
     * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
  1643
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
     */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 22260
diff changeset
  1647
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
    protected class AccessibleJComboBox extends AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
    implements AccessibleAction, AccessibleSelection {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 25201
diff changeset
  1652
        private JList<?> popupList; // combo box popup list
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
        private Accessible previousSelectedAccessible = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
         * Returns an AccessibleJComboBox instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
        public AccessibleJComboBox() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
            // set the combo box editor's accessible name and description
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
            JComboBox.this.addPropertyChangeListener(new AccessibleJComboBoxPropertyChangeListener());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
            setEditorNameAndDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
            // Get the popup list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
            Accessible a = getUI().getAccessibleChild(JComboBox.this, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
            if (a instanceof javax.swing.plaf.basic.ComboPopup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
                // Listen for changes to the popup menu selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                popupList = ((javax.swing.plaf.basic.ComboPopup)a).getList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
                popupList.addListSelectionListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
                    new AccessibleJComboBoxListSelectionListener());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
            // Listen for popup menu show/hide events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
            JComboBox.this.addPopupMenuListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
              new AccessibleJComboBoxPopupMenuListener());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
         * JComboBox PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
        private class AccessibleJComboBoxPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
            implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
            public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                if (e.getPropertyName() == "editor") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                    // set the combo box editor's accessible name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                    // and description
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                    setEditorNameAndDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
         * Sets the combo box editor's accessible name and descripton
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
        private void setEditorNameAndDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
            ComboBoxEditor editor = JComboBox.this.getEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
            if (editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
                Component comp = editor.getEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
                if (comp instanceof Accessible) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
  1700
                    AccessibleContext ac = comp.getAccessibleContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
                    if (ac != null) { // may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
                        ac.setAccessibleName(getAccessibleName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
                        ac.setAccessibleDescription(getAccessibleDescription());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
         * Listener for combo box popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
         * TIGER - 4669379 4894434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
        private class AccessibleJComboBoxPopupMenuListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
            implements PopupMenuListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
             *  This method is called before the popup menu becomes visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
                // save the initial selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
                if (popupList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
                int selectedIndex = popupList.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
                if (selectedIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
                previousSelectedAccessible =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
                    popupList.getAccessibleContext().getAccessibleChild(selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
             * This method is called before the popup menu becomes invisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
             * Note that a JPopupMenu can become invisible any time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
                // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
             * This method is called when the popup menu is canceled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
            public void popupMenuCanceled(PopupMenuEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
                // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
         * Handles changes to the popup list selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
         * TIGER - 4669379 4894434 4933143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
        private class AccessibleJComboBoxListSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
            implements ListSelectionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
            public void valueChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
                if (popupList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
                // Get the selected popup list item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                int selectedIndex = popupList.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
                if (selectedIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
                Accessible selectedAccessible =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
                    popupList.getAccessibleContext().getAccessibleChild(selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
                if (selectedAccessible == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
                // Fire a FOCUSED lost PropertyChangeEvent for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
                // previously selected list item.
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
  1773
                PropertyChangeEvent pce;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
                if (previousSelectedAccessible != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
                    pce = new PropertyChangeEvent(previousSelectedAccessible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
                        AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
                        AccessibleState.FOCUSED, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
                    firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
                                       null, pce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
                // Fire a FOCUSED gained PropertyChangeEvent for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
                // currently selected list item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
                pce = new PropertyChangeEvent(selectedAccessible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                    null, AccessibleState.FOCUSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
                firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                                   null, pce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
                // Fire the ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
                // for the combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
                firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
                                   previousSelectedAccessible, selectedAccessible);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
                // Save the previous selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
                previousSelectedAccessible = selectedAccessible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
         * Returns the number of accessible children in the object.  If all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
         * of the children of this object implement Accessible, than this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
         * method should return the number of children of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
         * @return the number of accessible children in the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
        public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
            // Always delegate to the UI if it exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
            if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
                return ui.getAccessibleChildrenCount(JComboBox.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
                return super.getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
         * Returns the nth Accessible child of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
         * The child at index zero represents the popup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
         * If the combo box is editable, the child at index one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
         * represents the editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
         * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
         * @return the nth Accessible child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
        public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
            // Always delegate to the UI if it exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
            if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                return ui.getAccessibleChild(JComboBox.this, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
               return super.getAccessibleChild(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
            return AccessibleRole.COMBO_BOX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
         * Gets the state set of this object.  The AccessibleStateSet of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
         * an object is composed of a set of unique AccessibleStates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
         * A change in the AccessibleStateSet of an object will cause a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
         * PropertyChangeEvent to be fired for the ACCESSIBLE_STATE_PROPERTY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
         * property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
         * @return an instance of AccessibleStateSet containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
         * current state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
         * @see AccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
         * @see #addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
            // TIGER - 4489748
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
            AccessibleStateSet ass = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
            if (ass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
                ass = new AccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
            if (JComboBox.this.isPopupVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
                ass.add(AccessibleState.EXPANDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
                ass.add(AccessibleState.COLLAPSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
            return ass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
         * Get the AccessibleAction associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
         * AccessibleAction interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
        public AccessibleAction getAccessibleAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
         * Return a description of the specified action of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
         * @param i zero-based index of the actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
        public String getAccessibleActionDescription(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
            if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
                return UIManager.getString("ComboBox.togglePopupText");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
         * Returns the number of Actions available in this object.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
         * default behavior of a combo box is to have one action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
         * @return 1, the number of Actions in this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
        public int getAccessibleActionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
         * Perform the specified Action on the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
         * @param i zero-based index of actions
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 27505
diff changeset
  1914
         * @return true if the action was performed; else false.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
        public boolean doAccessibleAction(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
            if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
                setPopupVisible(!isPopupVisible());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
         * Get the AccessibleSelection associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
         * AccessibleSelection interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
        public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
         * Returns the number of Accessible children currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
         * If no children are selected, the return value will be 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
         * @return the number of items currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
        public int getAccessibleSelectionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
            Object o = JComboBox.this.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
            if (o != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
         * Returns an Accessible representing the specified selected child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
         * in the popup.  If there isn't a selection, or there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
         * fewer children selected than the integer passed in, the return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
         * value will be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
         * <p>Note that the index represents the i-th selected child, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
         * is different from the i-th child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
         * @param i the zero-based index of selected children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
         * @return the i-th selected child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
         * @see #getAccessibleSelectionCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
        public Accessible getAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
            // Get the popup
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
            Accessible a =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
                JComboBox.this.getUI().getAccessibleChild(JComboBox.this, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
            if (a != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
                a instanceof javax.swing.plaf.basic.ComboPopup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
                // get the popup list
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 25201
diff changeset
  1976
                JList<?> list = ((javax.swing.plaf.basic.ComboPopup)a).getList();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
                // return the i-th selection in the popup list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
                AccessibleContext ac = list.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
                    AccessibleSelection as = ac.getAccessibleSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
                    if (as != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
                        return as.getAccessibleSelection(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
         * Determines if the current child of this object is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
         * @return true if the current child of this object is selected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
         *              else false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
         * @param i the zero-based index of the child in this Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
         * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
         * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
        public boolean isAccessibleChildSelected(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
            return JComboBox.this.getSelectedIndex() == i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
         * Adds the specified Accessible child of the object to the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
         * selection.  If the object supports multiple selections,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
         * the specified child is added to any existing selection, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
         * it replaces any existing selection in the object.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
         * specified child is already selected, this method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
         * @param i the zero-based index of the child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
         * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
        public void addAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
            // TIGER - 4856195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
            clearAccessibleSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
            JComboBox.this.setSelectedIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
         * Removes the specified child of the object from the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
         * selection.  If the specified item isn't currently selected, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
         * method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
         * @param i the zero-based index of the child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
         * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
        public void removeAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
            if (JComboBox.this.getSelectedIndex() == i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
                clearAccessibleSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
         * Clears the selection in the object, so that no children in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
         * object are selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
        public void clearAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
            JComboBox.this.setSelectedIndex(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
         * Causes every child of the object to be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
         * if the object supports multiple selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
        public void selectAllAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
            // do nothing since multiple selection is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
//        public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
//            Accessible a = getAccessibleChild(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
//            if ( a != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
//                return a; // the editor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
//            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
//            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
//                return getAccessibleChild(0); // the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
//            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
//        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
        private EditorAccessibleContext editorAccessibleContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
        private class AccessibleEditor implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
            public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
                if (editorAccessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
                    Component c = JComboBox.this.getEditor().getEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
                    if (c instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
                        editorAccessibleContext =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
                            new EditorAccessibleContext((Accessible)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
                return editorAccessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
         * Wrapper class for the AccessibleContext implemented by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
         * combo box editor.  Delegates all method calls except
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
         * getAccessibleIndexInParent to the editor.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
         * getAccessibleIndexInParent method returns the selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
         * index in the combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
        private class EditorAccessibleContext extends AccessibleContext {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
            private AccessibleContext ac;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
            private EditorAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
             * @param a the AccessibleContext implemented by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
             * combo box editor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
            EditorAccessibleContext(Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
                this.ac = a.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
             * Gets the accessibleName property of this object.  The accessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
             * property of an object is a localized String that designates the purpose
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
             * of the object.  For example, the accessibleName property of a label
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
             * or button might be the text of the label or button itself.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
             * case of an object that doesn't display its name, the accessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
             * should still be set.  For example, in the case of a text field used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
             * to enter the name of a city, the accessibleName for the en_US locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
             * could be 'city.'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
             * @return the localized name of the object; null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
             * object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
             * @see #setAccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
            public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
                return ac.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
             * Sets the localized accessible name of this object.  Changing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
             * name will cause a PropertyChangeEvent to be fired for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
             * ACCESSIBLE_NAME_PROPERTY property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
             * @param s the new localized name of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
             * @see #getAccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
             * @see #addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
             */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
  2129
            @BeanProperty(preferred = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
  2130
                    = "Sets the accessible name for the component.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
            public void setAccessibleName(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
                ac.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
             * Gets the accessibleDescription property of this object.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
             * accessibleDescription property of this object is a short localized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
             * phrase describing the purpose of the object.  For example, in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
             * case of a 'Cancel' button, the accessibleDescription could be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
             * 'Ignore changes and close dialog box.'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
             * @return the localized description of the object; null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
             * this object does not have a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
             * @see #setAccessibleDescription
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
            public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
                return ac.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
             * Sets the accessible description of this object.  Changing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
             * name will cause a PropertyChangeEvent to be fired for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
             * ACCESSIBLE_DESCRIPTION_PROPERTY property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
             * @param s the new localized description of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
             * @see #setAccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
             * @see #addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
             */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
  2161
            @BeanProperty(preferred = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 30463
diff changeset
  2162
                    = "Sets the accessible description for the component.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
            public void setAccessibleDescription(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
                ac.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
             * Gets the role of this object.  The role of the object is the generic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
             * purpose or use of the class of this object.  For example, the role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
             * of a push button is AccessibleRole.PUSH_BUTTON.  The roles in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
             * AccessibleRole are provided so component developers can pick from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
             * a set of predefined roles.  This enables assistive technologies to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
             * provide a consistent interface to various tweaked subclasses of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
             * components (e.g., use AccessibleRole.PUSH_BUTTON for all components
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20458
diff changeset
  2175
             * that act like a push button) as well as distinguish between subclasses
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
             * that behave differently (e.g., AccessibleRole.CHECK_BOX for check boxes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
             * and AccessibleRole.RADIO_BUTTON for radio buttons).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
             * <p>Note that the AccessibleRole class is also extensible, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
             * custom component developers can define their own AccessibleRole's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
             * if the set of predefined roles is inadequate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
             * @return an instance of AccessibleRole describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
             * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
            public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
                return ac.getAccessibleRole();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
             * Gets the state set of this object.  The AccessibleStateSet of an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
             * is composed of a set of unique AccessibleStates.  A change in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
             * AccessibleStateSet of an object will cause a PropertyChangeEvent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
             * be fired for the ACCESSIBLE_STATE_PROPERTY property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
             * @return an instance of AccessibleStateSet containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
             * current state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
             * @see AccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
             * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
             * @see #addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
            public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
                return ac.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
             * Gets the Accessible parent of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
             * @return the Accessible parent of this object; null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
             * object does not have an Accessible parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
            public Accessible getAccessibleParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
                return ac.getAccessibleParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
             * Sets the Accessible parent of this object.  This is meant to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
             * only in the situations where the actual component's parent should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
             * not be treated as the component's accessible parent and is a method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
             * that should only be called by the parent of the accessible child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
             * @param a - Accessible to be set as the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
            public void setAccessibleParent(Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
                ac.setAccessibleParent(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
             * Gets the 0-based index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
             * @return the 0-based index of this object in its parent; -1 if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
             * object does not have an accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
             * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
             * @see #getAccessibleChildrenCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
             * @see #getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
            public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
                return JComboBox.this.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
             * Returns the number of accessible children of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
             * @return the number of accessible children of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
            public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
                return ac.getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
             * Returns the specified Accessible child of the object.  The Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
             * children of an Accessible object are zero-based, so the first child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
             * of an Accessible child is at index 0, the second child is at index 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
             * and so on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
             * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
             * @return the Accessible child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
             * @see #getAccessibleChildrenCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
            public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
                return ac.getAccessibleChild(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
             * Gets the locale of the component. If the component does not have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
             * locale, then the locale of its parent is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
             * @return this component's locale.  If this component does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
             * a locale, the locale of its parent is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
             * @exception IllegalComponentStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
             * If the Component does not have its own locale and has not yet been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
             * added to a containment hierarchy such that the locale can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
             * determined from the containing parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
            public Locale getLocale() throws IllegalComponentStateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
                return ac.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
             * Adds a PropertyChangeListener to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
             * The listener is registered for all Accessible properties and will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
             * be called when those properties change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
             * @see #ACCESSIBLE_NAME_PROPERTY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
             * @see #ACCESSIBLE_DESCRIPTION_PROPERTY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
             * @see #ACCESSIBLE_STATE_PROPERTY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
             * @see #ACCESSIBLE_VALUE_PROPERTY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
             * @see #ACCESSIBLE_SELECTION_PROPERTY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
             * @see #ACCESSIBLE_TEXT_PROPERTY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
             * @see #ACCESSIBLE_VISIBLE_DATA_PROPERTY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
             * @param listener  The PropertyChangeListener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
            public void addPropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
                ac.addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
             * Removes a PropertyChangeListener from the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
             * This removes a PropertyChangeListener that was registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
             * for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
             * @param listener  The PropertyChangeListener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
            public void removePropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
                ac.removePropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
             * Gets the AccessibleAction associated with this object that supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
             * one or more actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
             * @return AccessibleAction if supported by object; else return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
             * @see AccessibleAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
            public AccessibleAction getAccessibleAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
                return ac.getAccessibleAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
             * Gets the AccessibleComponent associated with this object that has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
             * graphical representation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
             * @return AccessibleComponent if supported by object; else return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
             * @see AccessibleComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
            public AccessibleComponent getAccessibleComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
                return ac.getAccessibleComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
             * Gets the AccessibleSelection associated with this object which allows its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
             * Accessible children to be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
             * @return AccessibleSelection if supported by object; else return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
             * @see AccessibleSelection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
            public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
                return ac.getAccessibleSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
             * Gets the AccessibleText associated with this object presenting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
             * text on the display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
             * @return AccessibleText if supported by object; else return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
             * @see AccessibleText
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
            public AccessibleText getAccessibleText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
                return ac.getAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
             * Gets the AccessibleEditableText associated with this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
             * presenting editable text on the display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
             * @return AccessibleEditableText if supported by object; else return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
             * @see AccessibleEditableText
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
            public AccessibleEditableText getAccessibleEditableText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
                return ac.getAccessibleEditableText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
             * Gets the AccessibleValue associated with this object that supports a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
             * Numerical value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
             * @return AccessibleValue if supported by object; else return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
             * @see AccessibleValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
            public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
                return ac.getAccessibleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
             * Gets the AccessibleIcons associated with an object that has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
             * one or more associated icons
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
             * @return an array of AccessibleIcon if supported by object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
             * otherwise return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
             * @see AccessibleIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
            public AccessibleIcon [] getAccessibleIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
                return ac.getAccessibleIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
             * Gets the AccessibleRelationSet associated with an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
             * @return an AccessibleRelationSet if supported by object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
             * otherwise return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
             * @see AccessibleRelationSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
            public AccessibleRelationSet getAccessibleRelationSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
                return ac.getAccessibleRelationSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
             * Gets the AccessibleTable associated with an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
             * @return an AccessibleTable if supported by object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
             * otherwise return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
             * @see AccessibleTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
            public AccessibleTable getAccessibleTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
                return ac.getAccessibleTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
             * Support for reporting bound property changes.  If oldValue and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
             * newValue are not equal and the PropertyChangeEvent listener list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
             * is not empty, then fire a PropertyChange event to each listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
             * In general, this is for use by the Accessible objects themselves
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
             * and should not be called by an application program.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
             * @param propertyName  The programmatic name of the property that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
             * was changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
             * @param oldValue  The old value of the property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
             * @param newValue  The new value of the property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
             * @see java.beans.PropertyChangeSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
             * @see #addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
             * @see #removePropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
             * @see #ACCESSIBLE_NAME_PROPERTY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
             * @see #ACCESSIBLE_DESCRIPTION_PROPERTY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
             * @see #ACCESSIBLE_STATE_PROPERTY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
             * @see #ACCESSIBLE_VALUE_PROPERTY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
             * @see #ACCESSIBLE_SELECTION_PROPERTY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
             * @see #ACCESSIBLE_TEXT_PROPERTY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
             * @see #ACCESSIBLE_VISIBLE_DATA_PROPERTY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
            public void firePropertyChange(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
                                           Object oldValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
                                           Object newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
                ac.firePropertyChange(propertyName, oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
    } // innerclass AccessibleJComboBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
}