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