jdk/src/share/classes/javax/swing/JCheckBox.java
author malenkov
Wed, 07 May 2008 23:20:32 +0400
changeset 466 6acd5ec503a8
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE Summary: Add the Transient annotation and support it (JSR-273) Reviewed-by: peterz, loneid
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.beans.*;
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.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * An implementation of a check box -- an item that can be selected or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * deselected, and which displays its state to the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * By convention, any number of check boxes in a group can be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * See <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/button.html">How to Use Buttons, Check Boxes, and Radio Buttons</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * in <em>The Java Tutorial</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * for examples and information on using check boxes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Buttons can be configured, and to some degree controlled, by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <code><a href="Action.html">Action</a></code>s.  Using an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <code>Action</code> with a button has many benefits beyond directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * configuring a button.  Refer to <a href="Action.html#buttonActions">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Swing Components Supporting <code>Action</code></a> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * details, and you can find more information in <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * href="http://java.sun.com/docs/books/tutorial/uiswing/misc/action.html">How
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * to Use Actions</a>, a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @see JRadioButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *   attribute: isContainer false
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * description: A component which can be selected or deselected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * @author Jeff Dinkins
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
public class JCheckBox extends JToggleButton implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /** Identifies a change to the flat property. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public static final String BORDER_PAINTED_FLAT_CHANGED_PROPERTY = "borderPaintedFlat";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private boolean flat = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static final String uiClassID = "CheckBoxUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Creates an initially unselected check box button with no text, no icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public JCheckBox () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        this(null, null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Creates an initially unselected check box with an icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param icon  the Icon image to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public JCheckBox(Icon icon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        this(null, icon, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * Creates a check box with an icon and specifies whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * or not it is initially selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @param icon  the Icon image to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @param selected a boolean value indicating the initial selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *        state. If <code>true</code> the check box is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public JCheckBox(Icon icon, boolean selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        this(null, icon, selected);
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 an initially unselected check box with text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param text the text of the check box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public JCheckBox (String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        this(text, null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Creates a check box where properties are taken from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Action supplied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public JCheckBox(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        this();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        setAction(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Creates a check box with text and specifies whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * or not it is initially selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @param text the text of the check box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param selected a boolean value indicating the initial selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *        state. If <code>true</code> the check box is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public JCheckBox (String text, boolean selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        this(text, null, selected);
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 an initially unselected check box with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * the specified text and icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param text the text of the check box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @param icon  the Icon image to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public JCheckBox(String text, Icon icon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        this(text, icon, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Creates a check box with text and icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * and specifies whether or not it is initially selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @param text the text of the check box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @param icon  the Icon image to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @param selected a boolean value indicating the initial selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *        state. If <code>true</code> the check box is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public JCheckBox (String text, Icon icon, boolean selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        super(text, icon, selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        setUIProperty("borderPainted", Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        setHorizontalAlignment(LEADING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Sets the <code>borderPaintedFlat</code> property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * which gives a hint to the look and feel as to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * appearance of the check box border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * This is usually set to <code>true</code> when a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * <code>JCheckBox</code> instance is used as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * renderer in a component such as a <code>JTable</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * <code>JTree</code>.  The default value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * <code>borderPaintedFlat</code> property is <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * This method fires a property changed event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Some look and feels might not implement flat borders;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * they will ignore this property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @param b <code>true</code> requests that the border be painted flat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *          <code>false</code> requests normal borders
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @see #isBorderPaintedFlat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *  description: Whether the border is painted flat.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public void setBorderPaintedFlat(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        boolean oldValue = flat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        flat = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        firePropertyChange(BORDER_PAINTED_FLAT_CHANGED_PROPERTY, oldValue, flat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (b != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Gets the value of the <code>borderPaintedFlat</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @return the value of the <code>borderPaintedFlat</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @see #setBorderPaintedFlat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public boolean isBorderPaintedFlat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return flat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Resets the UI property to a value from the current look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        setUI((ButtonUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
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
     * Returns a string that specifies the name of the L&F class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @return the string "CheckBoxUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *        expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *   description: A string that specifies the name of the L&F class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return uiClassID;
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
     * The icon for checkboxs comes from the look and feel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * not the Action; this is overriden to do nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    void setIconFromAction(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
      * See readObject and writeObject in JComponent for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
      * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            }
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * See JComponent.readObject() for information about serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Returns a string representation of this JCheckBox. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * specific new aspects of the JFC components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @return  a string representation of this JCheckBox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return super.paramString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Gets the AccessibleContext associated with this JCheckBox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * For JCheckBoxes, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * AccessibleJCheckBox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * A new AccessibleJCheckBox instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @return an AccessibleJCheckBox that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *         AccessibleContext of this JCheckBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *       expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *  description: The AccessibleContext associated with this CheckBox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            accessibleContext = new AccessibleJCheckBox();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * <code>JCheckBox</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * Java Accessibility API appropriate to check box user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    protected class AccessibleJCheckBox extends AccessibleJToggleButton {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
         * @return an instance of AccessibleRole describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            return AccessibleRole.CHECK_BOX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    } // inner class AccessibleJCheckBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
}