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