src/java.desktop/share/classes/java/awt/Choice.java
author serb
Mon, 09 Sep 2019 12:23:22 -0700
changeset 58325 d32a3b1ca84a
parent 47216 71c04702a3d5
permissions -rw-r--r--
8225372: accessibility errors in tables in java.desktop files Reviewed-by: aivanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58325
d32a3b1ca84a 8225372: accessibility errors in tables in java.desktop files
serb
parents: 47216
diff changeset
     2
 * Copyright (c) 1995, 2019, 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: 1964
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: 1964
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: 1964
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1964
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1964
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.peer.ChoicePeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.EventListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 5506
diff changeset
    37
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
    39
 * The {@code Choice} class presents a pop-up menu of choices.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * The current choice is displayed as the title of the menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * The following code example produces a pop-up menu:
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 21278
diff changeset
    43
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <hr><blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Choice ColorChooser = new Choice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * ColorChooser.add("Green");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * ColorChooser.add("Red");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * ColorChooser.add("Blue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * </pre></blockquote><hr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * After this choice menu has been added to a panel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * it appears as follows in its normal state:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>
58325
d32a3b1ca84a 8225372: accessibility errors in tables in java.desktop files
serb
parents: 47216
diff changeset
    54
 * <img src="doc-files/Choice-1.gif" alt="The following text describes the
d32a3b1ca84a 8225372: accessibility errors in tables in java.desktop files
serb
parents: 47216
diff changeset
    55
 * graphic" style="margin: 7px 10px;">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
    57
 * In the picture, {@code "Green"} is the current choice.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Pushing the mouse button down on the object causes a menu to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * appear with the current choice highlighted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * Some native platforms do not support arbitrary resizing of
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
    62
 * {@code Choice} components and the behavior of
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
    63
 * {@code setSize()/getSize()} is bound by
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * such limitations.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
    65
 * Native GUI {@code Choice} components' size are often bound by such
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * attributes as font size and length of items contained within
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
    67
 * the {@code Choice}.
23717
6457189cd574 8039259: Tidy warnings cleanup for java.awt
yan
parents: 21957
diff changeset
    68
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * @author      Sami Shaio
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @author      Arthur van Hoff
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23717
diff changeset
    71
 * @since       1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
public class Choice extends Component implements ItemSelectable, Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
    75
     * The items for the {@code Choice}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
    76
     * This can be a {@code null} value.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @see #add(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @see #addItem(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @see #getItem(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @see #getItemCount()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @see #insert(String, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @see #remove(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 13997
diff changeset
    85
    Vector<String> pItems;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
    88
     * The index of the current choice for this {@code Choice}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * or -1 if nothing is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @see #getSelectedItem()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @see #select(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    int selectedIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    transient ItemListener itemListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private static final String base = "choice";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private static int nameCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
13997
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 12813
diff changeset
   104
    private static final long serialVersionUID = -4075310674757313071L;
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 12813
diff changeset
   105
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 12813
diff changeset
   106
    static {
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 12813
diff changeset
   107
        /* ensure that the necessary native libraries are loaded */
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 12813
diff changeset
   108
        Toolkit.loadLibraries();
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 12813
diff changeset
   109
        /* initialize JNI field and method ids */
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 12813
diff changeset
   110
        if (!GraphicsEnvironment.isHeadless()) {
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 12813
diff changeset
   111
            initIDs();
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 12813
diff changeset
   112
        }
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 12813
diff changeset
   113
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Creates a new choice menu. The menu initially has no items in it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * By default, the first item added to the choice menu becomes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * selected item, until a different selection is made by the user
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   120
     * by calling one of the {@code select} methods.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @see       java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @see       #select(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @see       #select(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public Choice() throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        GraphicsEnvironment.checkHeadless();
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 13997
diff changeset
   129
        pItems = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Constructs a name for this component.  Called by
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   134
     * {@code getName} when the name is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    String constructComponentName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        synchronized (Choice.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            return base + nameCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   143
     * Creates the {@code Choice}'s peer.  This peer allows us
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * to change the look
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   145
     * of the {@code Choice} without changing its functionality.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @see     java.awt.Component#getToolkit()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            if (peer == null)
30471
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 25859
diff changeset
   151
                peer = getComponentFactory().createChoice(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            super.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   157
     * Returns the number of items in this {@code Choice} menu.
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   158
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   159
     * @return the number of items in this {@code Choice} menu
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @see     #getItem
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23717
diff changeset
   161
     * @since   1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public int getItemCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return countItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   168
     * Returns the number of items in this {@code Choice} menu.
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   169
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   170
     * @return the number of items in this {@code Choice} menu
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @deprecated As of JDK version 1.1,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   172
     * replaced by {@code getItemCount()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public int countItems() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        return pItems.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Gets the string at the specified index in this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   181
     * {@code Choice} menu.
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   182
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   183
     * @param  index the index at which to begin
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   184
     * @return the item at the specified index
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   185
     * @see    #getItemCount
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public String getItem(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return getItemImpl(index);
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
     * This is called by the native code, so client code can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * be called on the toolkit thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    final String getItemImpl(int index) {
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 13997
diff changeset
   196
        return pItems.elementAt(index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   200
     * Adds an item to this {@code Choice} menu.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param      item    the item to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @exception  NullPointerException   if the item's value is
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   203
     *                  {@code null}
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23717
diff changeset
   204
     * @since      1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public void add(String item) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        addItem(item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Obsolete as of Java 2 platform v1.1.  Please use the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   212
     * {@code add} method instead.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   214
     * Adds an item to this {@code Choice} menu.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param item the item to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @exception NullPointerException if the item's value is equal to
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   217
     *          {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public void addItem(String item) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            insertNoInvalidate(item, pItems.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        // This could change the preferred size of the Component.
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 2
diff changeset
   225
        invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   229
     * Inserts an item to this {@code Choice},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   230
     * but does not invalidate the {@code Choice}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Client methods must provide their own synchronization before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * invoking this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @param item the item to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @param index the new item position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @exception NullPointerException if the item's value is equal to
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   236
     *          {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    private void insertNoInvalidate(String item, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (item == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                NullPointerException("cannot add null item to Choice");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        pItems.insertElementAt(item, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        ChoicePeer peer = (ChoicePeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (peer != null) {
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1183
diff changeset
   246
            peer.add(item, index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        // no selection or selection shifted up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (selectedIndex < 0 || selectedIndex >= index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            select(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
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
     * Inserts the item into this choice at the specified position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Existing items at an index greater than or equal to
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   258
     * {@code index} are shifted up by one to accommodate
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   259
     * the new item.  If {@code index} is greater than or
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * equal to the number of items in this choice,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   261
     * {@code item} is added to the end of this choice.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * If the item is the first one being added to the choice,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * then the item becomes selected.  Otherwise, if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * selected item was one of the items shifted, the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * item in the choice becomes the selected item.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * selected item was no among those shifted, it remains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * the selected item.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   269
     * @param item the non-{@code null} item to be inserted
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @param index the position at which the item should be inserted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @exception IllegalArgumentException if index is less than 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public void insert(String item, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            if (index < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                throw new IllegalArgumentException("index less than zero.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            /* if the index greater than item count, add item to the end */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            index = Math.min(index, pItems.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            insertNoInvalidate(item, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        // This could change the preferred size of the Component.
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 2
diff changeset
   285
        invalidateIfValid();
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
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   289
     * Removes the first occurrence of {@code item}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   290
     * from the {@code Choice} menu.  If the item
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * being removed is the currently selected item,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * then the first item in the choice becomes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * selected item.  Otherwise, the currently selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * item remains selected (and the selected index is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * updated accordingly).
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   296
     * @param      item  the item to remove from this {@code Choice} menu
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @exception  IllegalArgumentException  if the item doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *                     exist in the choice menu
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23717
diff changeset
   299
     * @since      1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public void remove(String item) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            int index = pItems.indexOf(item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            if (index < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                throw new IllegalArgumentException("item " + item +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                                                   " not found in choice");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                removeNoInvalidate(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        // This could change the preferred size of the Component.
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 2
diff changeset
   313
        invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Removes an item from the choice menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * at the specified position.  If the item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * being removed is the currently selected item,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * then the first item in the choice becomes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * selected item.  Otherwise, the currently selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * item remains selected (and the selected index is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * updated accordingly).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @param      position the position of the item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @throws IndexOutOfBoundsException if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *          position is out of bounds
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23717
diff changeset
   327
     * @since      1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    public void remove(int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            removeNoInvalidate(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        // This could change the preferred size of the Component.
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 2
diff changeset
   335
        invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   339
     * Removes an item from the {@code Choice} at the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   340
     * specified position, but does not invalidate the {@code Choice}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * Client methods must provide their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * own synchronization before invoking this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @param      position   the position of the item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    private void removeNoInvalidate(int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        pItems.removeElementAt(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        ChoicePeer peer = (ChoicePeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            peer.remove(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        /* Adjust selectedIndex if selected item was removed. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (pItems.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            selectedIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        } else if (selectedIndex == position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            select(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        } else if (selectedIndex > position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            select(selectedIndex-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * Removes all items from the choice menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @see       #remove
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23717
diff changeset
   365
     * @since     1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    public void removeAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                ((ChoicePeer)peer).removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            pItems.removeAllElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            selectedIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        // This could change the preferred size of the Component.
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 2
diff changeset
   377
        invalidateIfValid();
2
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 a representation of the current choice as a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @return    a string representation of the currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *                     selected item in this choice menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @see       #getSelectedIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    public synchronized String getSelectedItem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        return (selectedIndex >= 0) ? getItem(selectedIndex) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * Returns an array (length 1) containing the currently selected
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   392
     * item.  If this choice has no items, returns {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @see ItemSelectable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    public synchronized Object[] getSelectedObjects() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        if (selectedIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            Object[] items = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            items[0] = getItem(selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            return items;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Returns the index of the currently selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * If nothing is selected, returns -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @return the index of the currently selected item, or -1 if nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *  is currently selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * @see #getSelectedItem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    public int getSelectedIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        return selectedIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   417
     * Sets the selected item in this {@code Choice} menu to be the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * item at the specified position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * <p>Note that this method should be primarily used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * initially select an item in this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * Programmatically calling this method will <i>not</i> trigger
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   423
     * an {@code ItemEvent}.  The only way to trigger an
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   424
     * {@code ItemEvent} is by user interaction.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20451
diff changeset
   426
     * @param      pos      the position of the selected item
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @exception  IllegalArgumentException if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *                            position is greater than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *                            number of items or less than zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * @see        #getSelectedItem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * @see        #getSelectedIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    public synchronized void select(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        if ((pos >= pItems.size()) || (pos < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            throw new IllegalArgumentException("illegal Choice item position: " + pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        if (pItems.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            selectedIndex = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            ChoicePeer peer = (ChoicePeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                peer.select(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   447
     * Sets the selected item in this {@code Choice} menu
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * to be the item whose name is equal to the specified string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * If more than one item matches (is equal to) the specified string,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * the one with the smallest index is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * <p>Note that this method should be primarily used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * initially select an item in this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * Programmatically calling this method will <i>not</i> trigger
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   455
     * an {@code ItemEvent}.  The only way to trigger an
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   456
     * {@code ItemEvent} is by user interaction.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @param       str     the specified string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @see         #getSelectedItem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @see         #getSelectedIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    public synchronized void select(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        int index = pItems.indexOf(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            select(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * Adds the specified item listener to receive item events from
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   471
     * this {@code Choice} menu.  Item events are sent in response
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   472
     * to user input, but not in response to calls to {@code select}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   473
     * If l is {@code null}, no exception is thrown and no action
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * @param         l    the item listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * @see           #removeItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @see           #getItemListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @see           #select
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @see           java.awt.event.ItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * @see           java.awt.event.ItemListener
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23717
diff changeset
   483
     * @since         1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    public synchronized void addItemListener(ItemListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
           return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        itemListener = AWTEventMulticaster.add(itemListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * Removes the specified item listener so that it no longer receives
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   495
     * item events from this {@code Choice} menu.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   496
     * If l is {@code null}, no exception is thrown and no
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @param         l    the item listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @see           #addItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @see           #getItemListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @see           java.awt.event.ItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @see           java.awt.event.ItemListener
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23717
diff changeset
   505
     * @since         1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    public synchronized void removeItemListener(ItemListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        itemListener = AWTEventMulticaster.remove(itemListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * Returns an array of all the item listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * registered on this choice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   518
     * @return all of this choice's {@code ItemListener}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *         or an empty array if no item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @see           #addItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @see           #removeItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * @see           java.awt.event.ItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * @see           java.awt.event.ItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    public synchronized ItemListener[] getItemListeners() {
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 13997
diff changeset
   529
        return getListeners(ItemListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * Returns an array of all the objects currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * as <code><em>Foo</em>Listener</code>s
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   535
     * upon this {@code Choice}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * <code><em>Foo</em>Listener</code>s are registered using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * <code>add<em>Foo</em>Listener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   540
     * You can specify the {@code listenerType} argument
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * with a class literal, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * <code><em>Foo</em>Listener.class</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * For example, you can query a
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   544
     * {@code Choice c}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * for its item listeners with the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * <pre>ItemListener[] ils = (ItemListener[])(c.getListeners(ItemListener.class));</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * If no such listeners exist, this method returns an empty array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * @param listenerType the type of listeners requested; this parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     *          should specify an interface that descends from
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   553
     *          {@code java.util.EventListener}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * @return an array of all objects registered as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     *          <code><em>Foo</em>Listener</code>s on this choice,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     *          or an empty array if no such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     *          listeners have been added
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   558
     * @exception ClassCastException if {@code listenerType}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *          doesn't specify a class or interface that implements
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   560
     *          {@code java.util.EventListener}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * @see #getItemListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        EventListener l = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        if  (listenerType == ItemListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            l = itemListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            return super.getListeners(listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        return AWTEventMulticaster.getListeners(l, listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    // REMIND: remove when filtering is done at lower level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    boolean eventEnabled(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        if (e.id == ItemEvent.ITEM_STATE_CHANGED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            if ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                itemListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        return super.eventEnabled(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * Processes events on this choice. If the event is an
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   589
     * instance of {@code ItemEvent}, it invokes the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   590
     * {@code processItemEvent} method. Otherwise, it calls its
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   591
     * superclass's {@code processEvent} method.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   592
     * <p>Note that if the event parameter is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * @param      e the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @see        java.awt.event.ItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * @see        #processItemEvent
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23717
diff changeset
   599
     * @since      1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    protected void processEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        if (e instanceof ItemEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            processItemEvent((ItemEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        super.processEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   610
     * Processes item events occurring on this {@code Choice}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * menu by dispatching them to any registered
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   612
     * {@code ItemListener} objects.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * This method is not called unless item events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * enabled for this component. Item events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * when one of the following occurs:
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 21278
diff changeset
   617
     * <ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   618
     * <li>An {@code ItemListener} object is registered
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   619
     * via {@code addItemListener}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   620
     * <li>Item events are enabled via {@code enableEvents}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * </ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   622
     * <p>Note that if the event parameter is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * @param       e the item event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * @see         java.awt.event.ItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * @see         java.awt.event.ItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * @see         #addItemListener(ItemListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * @see         java.awt.Component#enableEvents
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23717
diff changeset
   631
     * @since       1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    protected void processItemEvent(ItemEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        ItemListener listener = itemListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            listener.itemStateChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   641
     * Returns a string representing the state of this {@code Choice}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * menu. This method is intended to be used only for debugging purposes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * and the content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * implementations. The returned string may be empty but may not be
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   645
     * {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   647
     * @return    the parameter string of this {@code Choice} menu
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        return super.paramString() + ",current=" + getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    /* Serialization support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * Choice Serial Data Version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    private int choiceSerializedDataVersion = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * Writes default serializable fields to stream.  Writes
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   665
     * a list of serializable {@code ItemListeners}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * as optional data. The non-serializable
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   667
     * {@code ItemListeners} are detected and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * no attempt is made to serialize them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   670
     * @param s the {@code ObjectOutputStream} to write
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   671
     * @serialData {@code null} terminated sequence of 0
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   672
     *   or more pairs; the pair consists of a {@code String}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   673
     *   and an {@code Object}; the {@code String} indicates
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     *   the type of object and is one of the following:
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   675
     *   {@code itemListenerK} indicating an
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   676
     *     {@code ItemListener} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * @see java.awt.Component#itemListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * @see #readObject(ObjectInputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    private void writeObject(ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
      throws java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
      s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
      AWTEventMulticaster.save(s, itemListenerK, itemListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
      s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   692
     * Reads the {@code ObjectInputStream} and if it
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   693
     * isn't {@code null} adds a listener to receive
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   694
     * item events fired by the {@code Choice} item.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * Unrecognized keys or values will be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   697
     * @param s the {@code ObjectInputStream} to read
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * @exception HeadlessException if
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   699
     *   {@code GraphicsEnvironment.isHeadless} returns
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   700
     *   {@code true}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * @see #removeItemListener(ItemListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * @see #addItemListener(ItemListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * @see #writeObject(ObjectOutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
      throws ClassNotFoundException, IOException, HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
      GraphicsEnvironment.checkHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
      s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
      Object keyOrNull;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
      while(null != (keyOrNull = s.readObject())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        String key = ((String)keyOrNull).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        if (itemListenerK == key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
          addItemListener((ItemListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        else // skip value for unrecognized key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
          s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
13997
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 12813
diff changeset
   725
    /**
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 12813
diff changeset
   726
     * Initialize JNI field and method IDs
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 12813
diff changeset
   727
     */
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 12813
diff changeset
   728
    private static native void initIDs();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
// Accessibility support
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
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   736
     * Gets the {@code AccessibleContext} associated with this
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   737
     * {@code Choice}. For {@code Choice} components,
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   738
     * the {@code AccessibleContext} takes the form of an
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   739
     * {@code AccessibleAWTChoice}. A new {@code AccessibleAWTChoice}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   742
     * @return an {@code AccessibleAWTChoice} that serves as the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   743
     *         {@code AccessibleContext} of this {@code Choice}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            accessibleContext = new AccessibleAWTChoice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * This class implements accessibility support for the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   755
     * {@code Choice} class.  It provides an implementation of the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * Java Accessibility API appropriate to choice user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    protected class AccessibleAWTChoice extends AccessibleAWTComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        implements AccessibleAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
         * JDK 1.3 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        private static final long serialVersionUID = 7175603582428509322L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   767
        /**
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   768
         * Constructor for {@code AccessibleAWTChoice}
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   769
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        public AccessibleAWTChoice() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
         * Get the AccessibleAction associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
         * AccessibleAction interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
         * @see AccessibleAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        public AccessibleAction getAccessibleAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            return AccessibleRole.COMBO_BOX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
         * Returns the number of accessible actions available in this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
         * If there are more than one, the first one is considered the "default"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
         * action of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
         * @return the zero-based number of Actions in this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        public int getAccessibleActionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            return 0;  //  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
         * Returns a description of the specified action of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
         * @param i zero-based index of the actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
         * @return a String description of the action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
         * @see #getAccessibleActionCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        public String getAccessibleActionDescription(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            return null;  //  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
         * Perform the specified Action on the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
         * @param i zero-based index of actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
         * @return true if the action was performed; otherwise false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
         * @see #getAccessibleActionCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        public boolean doAccessibleAction(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            return false;  //  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    } // inner class AccessibleAWTChoice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
}