jdk/src/share/classes/java/awt/Checkbox.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 1183 80d6aafba03a
child 15318 607db339afcc
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1183
diff changeset
     2
 * Copyright (c) 1995, 2008, 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: 1183
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: 1183
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: 1183
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1183
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1183
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.peer.CheckboxPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.EventListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * A check box is a graphical component that can be in either an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * "on" (<code>true</code>) or "off" (<code>false</code>) state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Clicking on a check box changes its state from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * "on" to "off," or from "off" to "on."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * The following code example creates a set of check boxes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * a grid layout:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <hr><blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * setLayout(new GridLayout(3, 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * add(new Checkbox("one", null, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * add(new Checkbox("two"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * add(new Checkbox("three"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * </pre></blockquote><hr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * This image depicts the check boxes and grid layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * created by this code example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <img src="doc-files/Checkbox-1.gif" alt="The following context describes the graphic."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * ALIGN=center HSPACE=10 VSPACE=7>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * The button labeled <code>one</code> is in the "on" state, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * other two are in the "off" state. In this example, which uses the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <code>GridLayout</code> class, the states of the three check
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * boxes are set independently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Alternatively, several check boxes can be grouped together under
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * the control of a single object, using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <code>CheckboxGroup</code> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * In a check box group, at most one button can be in the "on"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * state at any given time. Clicking on a check box to turn it on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * forces any other check box in the same group that is on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * into the "off" state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * @author      Sami Shaio
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @see         java.awt.GridLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * @see         java.awt.CheckboxGroup
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @since       JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
public class Checkbox extends Component implements ItemSelectable, Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        Toolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * The label of the Checkbox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * This field can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @see #getLabel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @see #setLabel(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    String label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * The state of the <code>Checkbox</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @see #getState()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @see #setState(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    boolean state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * The check box group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
         * This field can be null indicating that the checkbox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
         * is not a group checkbox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @see #getCheckboxGroup()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @see #setCheckboxGroup(CheckboxGroup)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    CheckboxGroup group;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    transient ItemListener itemListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private static final String base = "checkbox";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private static int nameCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private static final long serialVersionUID = 7270714317450821763L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Helper function for setState and CheckboxGroup.setSelectedCheckbox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Should remain package-private.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    void setStateInternal(boolean state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        this.state = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        CheckboxPeer peer = (CheckboxPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            peer.setState(state);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Creates a check box with an empty string for its label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * The state of this check box is set to "off," and it is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * part of any check box group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public Checkbox() throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        this("", false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Creates a check box with the specified label.  The state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * of this check box is set to "off," and it is not part of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * any check box group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @param     label   a string label for this check box,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *                        or <code>null</code> for no label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *      <code>GraphicsEnvironment.isHeadless</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *      returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public Checkbox(String label) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        this(label, false, null);
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 with the specified label
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * and sets the specified state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * This check box is not part of any check box group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @param     label   a string label for this check box,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *                        or <code>null</code> for no label
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @param     state    the initial state of this check box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *     <code>GraphicsEnvironment.isHeadless</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *     returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public Checkbox(String label, boolean state) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        this(label, state, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Constructs a Checkbox with the specified label, set to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * specified state, and in the specified check box group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @param     label   a string label for this check box,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *                        or <code>null</code> for no label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @param     state   the initial state of this check box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @param     group   a check box group for this check box,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *                           or <code>null</code> for no group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *     <code>GraphicsEnvironment.isHeadless</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *     returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public Checkbox(String label, boolean state, CheckboxGroup group)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        GraphicsEnvironment.checkHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        this.label = label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        this.state = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        this.group = group;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (state && (group != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            group.setSelectedCheckbox(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Creates a check box with the specified label, in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * check box group, and set to the specified state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @param     label   a string label for this check box,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *                        or <code>null</code> for no label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @param     group   a check box group for this check box,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *                           or <code>null</code> for no group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param     state   the initial state of this check box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *    <code>GraphicsEnvironment.isHeadless</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *    returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public Checkbox(String label, CheckboxGroup group, boolean state)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        this(label, state, group);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Constructs a name for this component.  Called by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <code>getName</code> when the name is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @return a name for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    String constructComponentName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        synchronized (Checkbox.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            return base + nameCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Creates the peer of the Checkbox. The peer allows you to change the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * look of the Checkbox without changing its functionality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @see     java.awt.Toolkit#createCheckbox(java.awt.Checkbox)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @see     java.awt.Component#getToolkit()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            if (peer == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                peer = getToolkit().createCheckbox(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            super.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Gets the label of this check box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @return   the label of this check box, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *                  if this check box has no label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @see      #setLabel(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public String getLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Sets this check box's label to be the string argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @param    label   a string to set as the new label, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *                        <code>null</code> for no label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @see      #getLabel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public void setLabel(String label) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        boolean testvalid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            if (label != this.label && (this.label == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                                        !this.label.equals(label))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                this.label = label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                CheckboxPeer peer = (CheckboxPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    peer.setLabel(label);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                testvalid = true;
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
        // This could change the preferred size of the Component.
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 2
diff changeset
   287
        if (testvalid) {
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 2
diff changeset
   288
            invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Determines whether this check box is in the "on" or "off" state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * The boolean value <code>true</code> indicates the "on" state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * and <code>false</code> indicates the "off" state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @return    the state of this check box, as a boolean value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @see       #setState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    public boolean getState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * Sets the state of this check box to the specified state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * The boolean value <code>true</code> indicates the "on" state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * and <code>false</code> indicates the "off" state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * <p>Note that this method should be primarily used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * initialize the state of the checkbox.  Programmatically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * setting the state of the checkbox will <i>not</i> trigger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * an <code>ItemEvent</code>.  The only way to trigger an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * <code>ItemEvent</code> is by user interaction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @param     state   the boolean state of the check box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @see       #getState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    public void setState(boolean state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        /* Cannot hold check box lock when calling group.setSelectedCheckbox. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        CheckboxGroup group = this.group;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if (group != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            if (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                group.setSelectedCheckbox(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            } else if (group.getSelectedCheckbox() == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                state = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        setStateInternal(state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * Returns an array (length 1) containing the checkbox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * label or null if the checkbox is not selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @see ItemSelectable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    public Object[] getSelectedObjects() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        if (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            Object[] items = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            items[0] = label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            return items;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Determines this check box's group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @return     this check box's group, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     *               if the check box is not part of a check box group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * @see        #setCheckboxGroup(CheckboxGroup)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    public CheckboxGroup getCheckboxGroup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        return group;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * Sets this check box's group to the specified check box group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * If this check box is already in a different check box group,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * it is first taken out of that group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * If the state of this check box is <code>true</code> and the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * group already has a check box selected, this check box's state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * is changed to <code>false</code>.  If the state of this check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * box is <code>true</code> and the new group has no check box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * selected, this check box becomes the selected checkbox for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * the new group and its state is <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @param     g   the new check box group, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *                to remove this check box from any check box group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @see       #getCheckboxGroup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    public void setCheckboxGroup(CheckboxGroup g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        CheckboxGroup oldGroup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        boolean oldState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        /* Do nothing if this check box has already belonged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
         * to the check box group g.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        if (this.group == g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            oldGroup = this.group;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            oldState = getState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            this.group = g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            CheckboxPeer peer = (CheckboxPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                peer.setCheckboxGroup(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            if (this.group != null && getState()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                if (this.group.getSelectedCheckbox() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    setState(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    this.group.setSelectedCheckbox(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        /* Locking check box below could cause deadlock with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
         * CheckboxGroup's setSelectedCheckbox method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
         * Fix for 4726853 by kdm@sparc.spb.su
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
         * Here we should check if this check box was selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
         * in the previous group and set selected check box to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
         * null for that group if so.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        if (oldGroup != null && oldState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            oldGroup.setSelectedCheckbox(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * Adds the specified item listener to receive item events from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * this check box.  Item events are sent to listeners in response
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * to user input, but not in response to calls to setState().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * If l is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @param         l    the item listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @see           #removeItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @see           #getItemListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @see           #setState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @see           java.awt.event.ItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @see           java.awt.event.ItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @since         JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    public synchronized void addItemListener(ItemListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        itemListener = AWTEventMulticaster.add(itemListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * Removes the specified item listener so that the item listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * no longer receives item events from this check box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * If l is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @param         l    the item listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @see           #addItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @see           #getItemListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @see           java.awt.event.ItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @see           java.awt.event.ItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @since         JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    public synchronized void removeItemListener(ItemListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        itemListener = AWTEventMulticaster.remove(itemListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * Returns an array of all the item listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * registered on this checkbox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @return all of this checkbox's <code>ItemListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *         or an empty array if no item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @see           #addItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * @see           #removeItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @see           java.awt.event.ItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @see           java.awt.event.ItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    public synchronized ItemListener[] getItemListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        return (ItemListener[]) (getListeners(ItemListener.class));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * Returns an array of all the objects currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * as <code><em>Foo</em>Listener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * upon this <code>Checkbox</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * <code><em>Foo</em>Listener</code>s are registered using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * <code>add<em>Foo</em>Listener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * You can specify the <code>listenerType</code> argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * with a class literal, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * <code><em>Foo</em>Listener.class</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * For example, you can query a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * <code>Checkbox</code> <code>c</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * for its item listeners with the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * <pre>ItemListener[] ils = (ItemListener[])(c.getListeners(ItemListener.class));</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * If no such listeners exist, this method returns an empty array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @param listenerType the type of listeners requested; this parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *          should specify an interface that descends from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *          <code>java.util.EventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @return an array of all objects registered as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *          <code><em>Foo</em>Listener</code>s on this checkbox,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     *          or an empty array if no such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *          listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @exception ClassCastException if <code>listenerType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *          doesn't specify a class or interface that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *          <code>java.util.EventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @see #getItemListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        EventListener l = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        if  (listenerType == ItemListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            l = itemListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            return super.getListeners(listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        return AWTEventMulticaster.getListeners(l, listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    // REMIND: remove when filtering is done at lower level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    boolean eventEnabled(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        if (e.id == ItemEvent.ITEM_STATE_CHANGED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            if ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                itemListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        return super.eventEnabled(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * Processes events on this check box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * If the event is an instance of <code>ItemEvent</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * this method invokes the <code>processItemEvent</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * Otherwise, it calls its superclass's <code>processEvent</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * @param         e the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * @see           java.awt.event.ItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * @see           #processItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * @since         JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    protected void processEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        if (e instanceof ItemEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            processItemEvent((ItemEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        super.processEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * Processes item events occurring on this check box by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * dispatching them to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * <code>ItemListener</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * This method is not called unless item events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * enabled for this component. Item events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * when one of the following occurs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * <p><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * <li>An <code>ItemListener</code> object is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * via <code>addItemListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * <li>Item events are enabled via <code>enableEvents</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @param       e the item event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * @see         java.awt.event.ItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * @see         java.awt.event.ItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @see         #addItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * @see         java.awt.Component#enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    protected void processItemEvent(ItemEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        ItemListener listener = itemListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            listener.itemStateChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * Returns a string representing the state of this <code>Checkbox</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * This method is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * implementations. The returned string may be empty but may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * @return    the parameter string of this check box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        String str = super.paramString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        String label = this.label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        if (label != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            str += ",label=" + label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        return str + ",state=" + state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    /* Serialization support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * Serialized data version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    private int checkboxSerializedDataVersion = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * Writes default serializable fields to stream.  Writes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * a list of serializable <code>ItemListeners</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * as optional data.  The non-serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * <code>ItemListeners</code> are detected and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * no attempt is made to serialize them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * @param s the <code>ObjectOutputStream</code> to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * @serialData <code>null</code> terminated sequence of 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     *   or more pairs; the pair consists of a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     *   and an <code>Object</code>; the <code>String</code> indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     *   the type of object and is one of the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     *   <code>itemListenerK</code> indicating an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     *     <code>ItemListener</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * @see java.awt.Component#itemListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * @see #readObject(ObjectInputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    private void writeObject(ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
      throws java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
      s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
      AWTEventMulticaster.save(s, itemListenerK, itemListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
      s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * Reads the <code>ObjectInputStream</code> and if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * isn't <code>null</code> adds a listener to receive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * item events fired by the <code>Checkbox</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * Unrecognized keys or values will be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @param s the <code>ObjectInputStream</code> to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @see #removeItemListener(ItemListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * @see #addItemListener(ItemListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * @see #writeObject(ObjectOutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
      throws ClassNotFoundException, IOException, HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
      GraphicsEnvironment.checkHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
      s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
      Object keyOrNull;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
      while(null != (keyOrNull = s.readObject())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        String key = ((String)keyOrNull).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        if (itemListenerK == key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
          addItemListener((ItemListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        else // skip value for unrecognized key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
          s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * Initialize JNI field and method ids
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * Gets the AccessibleContext associated with this Checkbox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * For checkboxes, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * AccessibleAWTCheckbox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * A new AccessibleAWTCheckbox is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * @return an AccessibleAWTCheckbox that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     *         AccessibleContext of this Checkbox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            accessibleContext = new AccessibleAWTCheckbox();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * <code>Checkbox</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * Java Accessibility API appropriate to checkbox user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    protected class AccessibleAWTCheckbox extends AccessibleAWTComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        implements ItemListener, AccessibleAction, AccessibleValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
         * JDK 1.3 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        private static final long serialVersionUID = 7881579233144754107L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        public AccessibleAWTCheckbox() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            Checkbox.this.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
         * Fire accessible property change events when the state of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
         * toggle button changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        public void itemStateChanged(ItemEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            Checkbox cb = (Checkbox) e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            if (Checkbox.this.accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                if (cb.getState()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                    Checkbox.this.accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                            AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                            null, AccessibleState.CHECKED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                    Checkbox.this.accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                            AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                            AccessibleState.CHECKED, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
         * Get the AccessibleAction associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
         * AccessibleAction interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        public AccessibleAction getAccessibleAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
         * Get the AccessibleValue associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
         * AccessibleValue interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
         * Returns the number of Actions available in this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
         * If there is more than one, the first one is the "default"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
         * action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
         * @return the number of Actions in this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        public int getAccessibleActionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            return 0;  //  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
         * Return a description of the specified action of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
         * @param i zero-based index of the actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        public String getAccessibleActionDescription(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            return null;  //  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
         * Perform the specified Action on the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
         * @param i zero-based index of actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
         * @return true if the the action was performed; else false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        public boolean doAccessibleAction(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            return false;    //  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
         * Get the value of this object as a Number.  If the value has not been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
         * set, the return value will be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
         * @return value of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
         * @see #setCurrentAccessibleValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        public Number getCurrentAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            return null;  //  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
         * Set the value of this object as a Number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
         * @return True if the value was set; else False
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
         * @see #getCurrentAccessibleValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        public boolean setCurrentAccessibleValue(Number n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            return false;  //  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
         * Get the minimum value of this object as a Number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
         * @return Minimum value of the object; null if this object does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
         * have a minimum value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
         * @see #getMaximumAccessibleValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        public Number getMinimumAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            return null;  //  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
         * Get the maximum value of this object as a Number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
         * @return Maximum value of the object; null if this object does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
         * have a maximum value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
         * @see #getMinimumAccessibleValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        public Number getMaximumAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            return null;  //  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
         * @return an instance of AccessibleRole describing the role of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
         * the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            return AccessibleRole.CHECK_BOX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
         * Get the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
         * @return an instance of AccessibleState containing the current state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
         * of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            if (getState()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                states.add(AccessibleState.CHECKED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    } // inner class AccessibleAWTCheckbox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
}