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