jdk/src/java.desktop/share/classes/javax/swing/JCheckBoxMenuItem.java
author aghaisas
Mon, 10 Jul 2017 14:55:29 +0530
changeset 47151 362dcbee0613
parent 41407 ac6be88670ea
permissions -rw-r--r--
6919529: NPE from MultiUIDefaults.getUIError Reviewed-by: aghaisas, psadhukhan, serb Contributed-by: shashidhara.veerabhadraiah@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
     2
 * Copyright (c) 1997, 2015, 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 javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
    27
import java.beans.JavaBean;
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
    28
import java.beans.BeanProperty;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * A menu item that can be selected or deselected. If selected, the menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * item typically appears with a checkmark next to it. If unselected or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * deselected, the menu item appears without a checkmark. Like a regular
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * menu item, a check box menu item can have either text or a graphic
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * icon associated with it, or both.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Either <code>isSelected</code>/<code>setSelected</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <code>getState</code>/<code>setState</code> can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * to determine/specify the menu item's selection state. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * preferred methods are <code>isSelected</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <code>setSelected</code>, which work for all menus and buttons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * The <code>getState</code> and <code>setState</code> methods exist for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * compatibility with other component sets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * Menu items can be configured, and to some degree controlled, by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <code><a href="Action.html">Action</a></code>s.  Using an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <code>Action</code> with a menu item has many benefits beyond directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * configuring a menu item.  Refer to <a href="Action.html#buttonActions">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * Swing Components Supporting <code>Action</code></a> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * details, and you can find more information in <a
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
    56
 * href="http://docs.oracle.com/javase/tutorial/uiswing/misc/action.html">How
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * to Use Actions</a>, a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <p>
39542
1073ea3df2c7 8158566: Provide a Swing property to not close toggle menu items on mouse click
alexsch
parents: 33253
diff changeset
    59
 * Some times it is required to select several check box menu items from a menu.
1073ea3df2c7 8158566: Provide a Swing property to not close toggle menu items on mouse click
alexsch
parents: 33253
diff changeset
    60
 * In this case it is useful that clicking on one check box menu item does not
41407
ac6be88670ea 8165234: Provide a way to not close toggle menu items on mouse click on component level
alexsch
parents: 39542
diff changeset
    61
 * close the menu. Such behavior can be controlled either by client
ac6be88670ea 8165234: Provide a way to not close toggle menu items on mouse click on component level
alexsch
parents: 39542
diff changeset
    62
 * {@link JComponent#putClientProperty} or the Look and Feel
ac6be88670ea 8165234: Provide a way to not close toggle menu items on mouse click on component level
alexsch
parents: 39542
diff changeset
    63
 * {@link UIManager#put} property named
ac6be88670ea 8165234: Provide a way to not close toggle menu items on mouse click on component level
alexsch
parents: 39542
diff changeset
    64
 * {@code "CheckBoxMenuItem.doNotCloseOnMouseClick"}. The default value is
ac6be88670ea 8165234: Provide a way to not close toggle menu items on mouse click on component level
alexsch
parents: 39542
diff changeset
    65
 * {@code false}. Setting the property to {@code true} prevents the menu from
ac6be88670ea 8165234: Provide a way to not close toggle menu items on mouse click on component level
alexsch
parents: 39542
diff changeset
    66
 * closing when it is clicked by the mouse. If the client property is set its
ac6be88670ea 8165234: Provide a way to not close toggle menu items on mouse click on component level
alexsch
parents: 39542
diff changeset
    67
 * value is always used; otherwise the {@literal L&F} property is queried.
39542
1073ea3df2c7 8158566: Provide a Swing property to not close toggle menu items on mouse click
alexsch
parents: 33253
diff changeset
    68
 * Note: some {@code L&F}s may ignore this property. All built-in {@code L&F}s
1073ea3df2c7 8158566: Provide a Swing property to not close toggle menu items on mouse click
alexsch
parents: 33253
diff changeset
    69
 * inherit this behaviour.
1073ea3df2c7 8158566: Provide a Swing property to not close toggle menu items on mouse click
alexsch
parents: 33253
diff changeset
    70
 * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * For further information and examples of using check box menu items,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * see <a
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
    73
 href="http://docs.oracle.com/javase/tutorial/uiswing/components/menu.html">How to Use Menus</a>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * a section in <em>The Java Tutorial.</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
    86
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * @author Georges Saab
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * @author David Karlton
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 22574
diff changeset
    92
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
    94
@JavaBean(description = "A menu item which can be selected or deselected.")
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
    95
@SwingContainer(false)
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
    96
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
public class JCheckBoxMenuItem extends JMenuItem implements SwingConstants,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private static final String uiClassID = "CheckBoxMenuItemUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Creates an initially unselected check box menu item with no set text or icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public JCheckBoxMenuItem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        this(null, null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Creates an initially unselected check box menu item with an icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   116
     * @param icon the icon of the {@code JCheckBoxMenuItem}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public JCheckBoxMenuItem(Icon icon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        this(null, icon, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * Creates an initially unselected check box menu item with text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   125
     * @param text the text of the {@code JCheckBoxMenuItem}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public JCheckBoxMenuItem(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        this(text, null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Creates a menu item whose properties are taken from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Action supplied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   135
     * @param a the action of the {@code JCheckBoxMenuItem}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public JCheckBoxMenuItem(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        this();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        setAction(a);
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
     * Creates an initially unselected check box menu item with the specified text and icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   146
     * @param text the text of the {@code JCheckBoxMenuItem}
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   147
     * @param icon the icon of the {@code JCheckBoxMenuItem}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public JCheckBoxMenuItem(String text, Icon icon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        this(text, icon, false);
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 a check box menu item with the specified text and selection state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param text the text of the check box menu item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param b the selected state of the check box menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public JCheckBoxMenuItem(String text, boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        this(text, null, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * Creates a check box menu item with the specified text, icon, and selection state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @param text the text of the check box menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @param icon the icon of the check box menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @param b the selected state of the check box menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public JCheckBoxMenuItem(String text, Icon icon, boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        super(text, icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        setModel(new JToggleButton.ToggleButtonModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        setSelected(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        setFocusable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
   178
     * Returns the name of the L&amp;F class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @return "CheckBoxMenuItemUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   185
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
      * Returns the selected-state of the item. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
      * exists for AWT compatibility only.  New code should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
      * use isSelected() instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
      * @return true  if the item is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public boolean getState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        return isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Sets the selected-state of the item. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * exists for AWT compatibility only.  New code should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * use setSelected() instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @param b  a boolean value indicating the item's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *           selected-state, where true=selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   209
    @BeanProperty(bound = false, hidden = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   210
            = "The selection state of the check box menu item")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public synchronized void setState(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        setSelected(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Returns an array (length 1) containing the check box menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * label or null if the check box is not selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @return an array containing one Object -- the text of the menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *         -- if the item is selected; otherwise null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   223
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public Object[] getSelectedObjects() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (isSelected() == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        Object[] selectedObjects = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        selectedObjects[0] = getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return selectedObjects;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * See readObject() and writeObject() in JComponent for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Returns a string representation of this JCheckBoxMenuItem. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @return  a string representation of this JCheckBoxMenuItem.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return super.paramString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Overriden to return true, JCheckBoxMenuItem supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * the selected state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    boolean shouldUpdateSelectedStateFromAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Gets the AccessibleContext associated with this JCheckBoxMenuItem.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * For JCheckBoxMenuItems, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * AccessibleJCheckBoxMenuItem.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * A new AccessibleJCheckBoxMenuItem instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @return an AccessibleJCheckBoxMenuItem that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *         AccessibleContext of this AccessibleJCheckBoxMenuItem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   282
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            accessibleContext = new AccessibleJCheckBoxMenuItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        return accessibleContext;
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
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * <code>JCheckBoxMenuItem</code> class.  It provides an implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * of the Java Accessibility API appropriate to checkbox menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
   301
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
   305
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    protected class AccessibleJCheckBoxMenuItem extends AccessibleJMenuItem {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            return AccessibleRole.CHECK_BOX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    } // inner class AccessibleJCheckBoxMenuItem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
}