jdk/src/java.desktop/share/classes/javax/swing/JButton.java
author aghaisas
Mon, 10 Jul 2017 14:55:29 +0530
changeset 47151 362dcbee0613
parent 33253 78e735319356
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
import java.beans.ConstructorProperties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * An implementation of a "push" button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Buttons can be configured, and to some degree controlled, by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <code><a href="Action.html">Action</a></code>s.  Using an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <code>Action</code> with a button has many benefits beyond directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * configuring a button.  Refer to <a href="Action.html#buttonActions">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Swing Components Supporting <code>Action</code></a> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * 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
    46
 * href="http://docs.oracle.com/javase/tutorial/uiswing/misc/action.html">How
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * to Use Actions</a>, a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
    49
 * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/button.html">How to Use Buttons, Check Boxes, and Radio Buttons</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * in <em>The Java Tutorial</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * for information and examples of using buttons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * 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
    63
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @author Jeff Dinkins
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 23010
diff changeset
    68
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
    70
@JavaBean(defaultProperty = "UIClassID", description = "An implementation of a \"push\" button.")
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
    71
@SwingContainer(false)
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
    72
@SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
public class JButton extends AbstractButton implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static final String uiClassID = "ButtonUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Creates a button with no set text or icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public JButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        this(null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Creates a button with an icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param icon  the Icon image to display on the button
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public JButton(Icon icon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        this(null, icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Creates a button with text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @param text  the text of the button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    @ConstructorProperties({"text"})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public JButton(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        this(text, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Creates a button where properties are taken from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * <code>Action</code> supplied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @param a the <code>Action</code> used to specify the new button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public JButton(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        this();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        setAction(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Creates a button with initial text and an icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param text  the text of the button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @param icon  the Icon image to display on the button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public JButton(String text, Icon icon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        // Create the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        setModel(new DefaultButtonModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        // initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        init(text, icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Resets the UI property to a value from the current look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        setUI((ButtonUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 11268
diff changeset
   146
     * Returns a string that specifies the name of the L&amp;F class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @return the string "ButtonUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   153
    @BeanProperty(bound = false, expert = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   154
            = "A string that specifies the name of the L&amp;F class.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Gets the value of the <code>defaultButton</code> property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * which if <code>true</code> means that this button is the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * default button for its <code>JRootPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * Most look and feels render the default button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * differently, and may potentially provide bindings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * to access the default button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @return the value of the <code>defaultButton</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @see JRootPane#setDefaultButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @see #isDefaultCapable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   172
    @BeanProperty(bound = false, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   173
            = "Whether or not this button is the default button")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public boolean isDefaultButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        JRootPane root = SwingUtilities.getRootPane(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (root != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            return root.getDefaultButton() == this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Gets the value of the <code>defaultCapable</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @return the value of the <code>defaultCapable</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @see #setDefaultCapable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @see #isDefaultButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @see JRootPane#setDefaultButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public boolean isDefaultCapable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        return defaultCapable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Sets the <code>defaultCapable</code> property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * which determines whether this button can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * made the default button for its root pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * The default value of the <code>defaultCapable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * property is <code>true</code> unless otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * specified by the look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @param defaultCapable <code>true</code> if this button will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *        capable of being the default button on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *        <code>RootPane</code>; otherwise <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @see #isDefaultCapable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   207
    @BeanProperty(visualUpdate = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   208
            = "Whether or not this button can be the default button")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public void setDefaultCapable(boolean defaultCapable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        boolean oldDefaultCapable = this.defaultCapable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        this.defaultCapable = defaultCapable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        firePropertyChange("defaultCapable", oldDefaultCapable, defaultCapable);
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
     * Overrides <code>JComponent.removeNotify</code> to check if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * this button is currently set as the default button on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * <code>RootPane</code>, and if so, sets the <code>RootPane</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * default button to <code>null</code> to ensure the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <code>RootPane</code> doesn't hold onto an invalid button reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        JRootPane root = SwingUtilities.getRootPane(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (root != null && root.getDefaultButton() == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            root.setDefaultButton(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        super.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * See readObject() and writeObject() in JComponent for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * Returns a string representation of this <code>JButton</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * This method is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @return  a string representation of this <code>JButton</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        String defaultCapableString = (defaultCapable ? "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            ",defaultCapable=" + defaultCapableString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Gets the <code>AccessibleContext</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * <code>JButton</code>. For <code>JButton</code>s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * the <code>AccessibleContext</code> takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * <code>AccessibleJButton</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * A new <code>AccessibleJButton</code> instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @return an <code>AccessibleJButton</code> that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *         <code>AccessibleContext</code> of this <code>JButton</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   277
    @BeanProperty(bound = false, expert = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   278
            = "The AccessibleContext associated with this Button.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            accessibleContext = new AccessibleJButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * <code>JButton</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * Java Accessibility API appropriate to button user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * 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
   297
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
   301
    @SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    protected class AccessibleJButton extends AccessibleAbstractButton {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            return AccessibleRole.PUSH_BUTTON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    } // inner class AccessibleJButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
}