jdk/src/share/classes/java/awt/CheckboxMenuItem.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 13604 31089af1a447
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
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: 2
diff changeset
     2
 * Copyright (c) 1995, 2006, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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.awt.peer.CheckboxMenuItemPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.EventListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * This class represents a check box that can be included in a menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Selecting the check box in the menu changes its state from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * "on" to "off" or from "off" to "on."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The following picture depicts a menu which contains an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * of <code>CheckBoxMenuItem</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <img src="doc-files/MenuBar-1.gif"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * alt="Menu labeled Examples, containing items Basic, Simple, Check, and More Examples. The Check item is a CheckBoxMenuItem instance, in the off state."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * ALIGN=center HSPACE=10 VSPACE=7>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * The item labeled <code>Check</code> shows a check box menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * in its "off" state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * When a check box menu item is selected, AWT sends an item event to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * the item. Since the event is an instance of <code>ItemEvent</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * the <code>processEvent</code> method examines the event and passes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * it along to <code>processItemEvent</code>. The latter method redirects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * the event to any <code>ItemListener</code> objects that have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * registered an interest in item events generated by this menu item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author      Sami Shaio
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @see         java.awt.event.ItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @see         java.awt.event.ItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @since       JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
public class CheckboxMenuItem extends MenuItem implements ItemSelectable, Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        Toolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    * The state of a checkbox menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    * @see #getState()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    * @see #setState(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    boolean state = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    transient ItemListener itemListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static final String base = "chkmenuitem";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private static int nameCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     private static final long serialVersionUID = 6190621106981774043L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Create a check box menu item with an empty label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * The item's state is initially set to "off."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public CheckboxMenuItem() throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this("", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Create a check box menu item with the specified label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * The item's state is initially set to "off."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @param     label   a string label for the check box menu item,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *                or <code>null</code> for an unlabeled menu item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public CheckboxMenuItem(String label) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        this(label, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Create a check box menu item with the specified label and state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @param      label   a string label for the check box menu item,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *                     or <code>null</code> for an unlabeled menu item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param      state   the initial state of the menu item, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *                     <code>true</code> indicates "on" and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *                     <code>false</code> indicates "off."
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
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public CheckboxMenuItem(String label, boolean state)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        super(label);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        this.state = state;
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
     * Construct a name for this MenuComponent.  Called by getName() when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * the name is null.
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 (CheckboxMenuItem.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 peer of the checkbox item.  This peer allows us to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * change the look of the checkbox item without changing its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * functionality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Most applications do not call this method directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @see     java.awt.Toolkit#createCheckboxMenuItem(java.awt.CheckboxMenuItem)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @see     java.awt.Component#getToolkit()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            if (peer == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                peer = Toolkit.getDefaultToolkit().createCheckboxMenuItem(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            super.addNotify();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * Determines whether the state of this check box menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * is "on" or "off."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @return      the state of this check box menu item, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *                     <code>true</code> indicates "on" and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *                     <code>false</code> indicates "off"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @see        #setState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public boolean getState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Sets this check box menu item to the specifed state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * The boolean value <code>true</code> indicates "on" while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * <code>false</code> indicates "off."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * <p>Note that this method should be primarily used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * initialize the state of the check box menu item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Programmatically setting the state of the check box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * menu item will <i>not</i> trigger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * an <code>ItemEvent</code>.  The only way to trigger an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * <code>ItemEvent</code> is by user interaction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @param      b   <code>true</code> if the check box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *             menu item is on, otherwise <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @see        #getState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public synchronized void setState(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        state = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        CheckboxMenuItemPeer peer = (CheckboxMenuItemPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            peer.setState(b);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Returns the an array (length 1) containing the checkbox menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * label or null if the checkbox is not selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @see ItemSelectable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public synchronized Object[] getSelectedObjects() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            Object[] items = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            items[0] = label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            return items;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Adds the specified item listener to receive item events from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * this check box menu item.  Item events are sent in response to user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * actions, but not in response to calls to setState().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * If l is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @param         l the item listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @see           #removeItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @see           #getItemListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @see           #setState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @see           java.awt.event.ItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @see           java.awt.event.ItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @since         JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public synchronized void addItemListener(ItemListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        itemListener = AWTEventMulticaster.add(itemListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Removes the specified item listener so that it no longer receives
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * item events from this check box menu item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * If l is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @param         l the item listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @see           #addItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @see           #getItemListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @see           java.awt.event.ItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @see           java.awt.event.ItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @since         JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public synchronized void removeItemListener(ItemListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        itemListener = AWTEventMulticaster.remove(itemListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * Returns an array of all the item listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * registered on this checkbox menuitem.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @return all of this checkbox menuitem's <code>ItemListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *         or an empty array if no item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @see           #addItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @see           #removeItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @see           java.awt.event.ItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @see           java.awt.event.ItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public synchronized ItemListener[] getItemListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return (ItemListener[])(getListeners(ItemListener.class));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Returns an array of all the objects currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * as <code><em>Foo</em>Listener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * upon this <code>CheckboxMenuItem</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * <code><em>Foo</em>Listener</code>s are registered using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * <code>add<em>Foo</em>Listener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * You can specify the <code>listenerType</code> argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * with a class literal, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * <code><em>Foo</em>Listener.class</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * For example, you can query a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * <code>CheckboxMenuItem</code> <code>c</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * for its item listeners with the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * <pre>ItemListener[] ils = (ItemListener[])(c.getListeners(ItemListener.class));</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * If no such listeners exist, this method returns an empty array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @param listenerType the type of listeners requested; this parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *          should specify an interface that descends from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *          <code>java.util.EventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @return an array of all objects registered as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *          <code><em>Foo</em>Listener</code>s on this checkbox menuitem,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *          or an empty array if no such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *          listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @exception ClassCastException if <code>listenerType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *          doesn't specify a class or interface that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *          <code>java.util.EventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @see #getItemListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        EventListener l = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        if  (listenerType == ItemListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            l = itemListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            return super.getListeners(listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return AWTEventMulticaster.getListeners(l, listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    // REMIND: remove when filtering is done at lower level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    boolean eventEnabled(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        if (e.id == ItemEvent.ITEM_STATE_CHANGED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            if ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                itemListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return super.eventEnabled(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Processes events on this check box menu item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * If the event is an instance of <code>ItemEvent</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * this method invokes the <code>processItemEvent</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * If the event is not an item event,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * it invokes <code>processEvent</code> on the superclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * Check box menu items currently support only item events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @param        e the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @see          java.awt.event.ItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @see          #processItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * @since        JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    protected void processEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (e instanceof ItemEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            processItemEvent((ItemEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        super.processEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * Processes item events occurring on this check box menu item by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * dispatching them to any registered <code>ItemListener</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * This method is not called unless item events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * enabled for this menu item. Item events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * when one of the following occurs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * <p><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * <li>An <code>ItemListener</code> object is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * via <code>addItemListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * <li>Item events are enabled via <code>enableEvents</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @param       e the item event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @see         java.awt.event.ItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @see         java.awt.event.ItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @see         #addItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @see         java.awt.MenuItem#enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    protected void processItemEvent(ItemEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        ItemListener listener = itemListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            listener.itemStateChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Post an ItemEvent and toggle state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    void doMenuEvent(long when, int modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        setState(!state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        Toolkit.getEventQueue().postEvent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                          getLabel(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                          state ? ItemEvent.SELECTED :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                                  ItemEvent.DESELECTED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * Returns a string representing the state of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * <code>CheckBoxMenuItem</code>. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * method is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * implementations. The returned string may be empty but may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @return     the parameter string of this check box menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    public String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        return super.paramString() + ",state=" + state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    /* Serialization support.
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
     * Serial Data Version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    private int checkboxMenuItemSerializedDataVersion = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * Writes default serializable fields to stream.  Writes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * a list of serializable <code>ItemListeners</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * as optional data.  The non-serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * <code>ItemListeners</code> are detected and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * no attempt is made to serialize them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @param s the <code>ObjectOutputStream</code> to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @serialData <code>null</code> terminated sequence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *  0 or more pairs; the pair consists of a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *  and an <code>Object</code>; the <code>String</code> indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *  the type of object and is one of the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *  <code>itemListenerK</code> indicating an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *    <code>ItemListener</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @see java.awt.Component#itemListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @see #readObject(ObjectInputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    private void writeObject(ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
      throws java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
      s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
      AWTEventMulticaster.save(s, itemListenerK, itemListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
      s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * Reads the <code>ObjectInputStream</code> and if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * isn't <code>null</code> adds a listener to receive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * item events fired by the <code>Checkbox</code> menu item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * Unrecognized keys or values will be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @param s the <code>ObjectInputStream</code> to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @see removeActionListener()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @see addActionListener()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @see #writeObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
      throws ClassNotFoundException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
      s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
      Object keyOrNull;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
      while(null != (keyOrNull = s.readObject())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        String key = ((String)keyOrNull).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        if (itemListenerK == key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
          addItemListener((ItemListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        else // skip value for unrecognized key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
          s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * Initialize JNI field and method IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * Gets the AccessibleContext associated with this CheckboxMenuItem.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * For checkbox menu items, the AccessibleContext takes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * form of an AccessibleAWTCheckboxMenuItem.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * A new AccessibleAWTCheckboxMenuItem is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @return an AccessibleAWTCheckboxMenuItem that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *         AccessibleContext of this CheckboxMenuItem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            accessibleContext = new AccessibleAWTCheckboxMenuItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * Inner class of CheckboxMenuItem used to provide default support for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * accessibility.  This class is not meant to be used directly by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * application developers, but is instead meant only to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * subclassed by menu component developers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * <code>CheckboxMenuItem</code> class.  It provides an implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * of the Java Accessibility API appropriate to checkbox menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    protected class AccessibleAWTCheckboxMenuItem extends AccessibleAWTMenuItem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        implements AccessibleAction, AccessibleValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
         * JDK 1.3 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        private static final long serialVersionUID = -1122642964303476L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
         * Get the AccessibleAction associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
         * AccessibleAction interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        public AccessibleAction getAccessibleAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
         * Get the AccessibleValue associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
         * AccessibleValue interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
         * Returns the number of Actions available in this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
         * If there is more than one, the first one is the "default"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
         * action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
         * @return the number of Actions in this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        public int getAccessibleActionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            return 0;  //  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
         * Return a description of the specified action of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
         * @param i zero-based index of the actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        public String getAccessibleActionDescription(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            return null;  //  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
         * Perform the specified Action on the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
         * @param i zero-based index of actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
         * @return true if the action was performed; otherwise false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        public boolean doAccessibleAction(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            return false;    //  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
         * Get the value of this object as a Number.  If the value has not been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
         * set, the return value will be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
         * @return value of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
         * @see #setCurrentAccessibleValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        public Number getCurrentAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            return null;  //  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
         * Set the value of this object as a Number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
         * @return true if the value was set; otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
         * @see #getCurrentAccessibleValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        public boolean setCurrentAccessibleValue(Number n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            return false;  //  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
         * Get the minimum value of this object as a Number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
         * @return Minimum value of the object; null if this object does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
         * have a minimum value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
         * @see #getMaximumAccessibleValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        public Number getMinimumAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            return null;  //  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
         * Get the maximum value of this object as a Number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
         * @return Maximum value of the object; null if this object does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
         * have a maximum value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
         * @see #getMinimumAccessibleValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        public Number getMaximumAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            return null;  //  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            return AccessibleRole.CHECK_BOX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    } // class AccessibleAWTMenuItem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
}