jdk/src/share/classes/javax/swing/AbstractButton.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7959 2e05332a8f5c
child 10409 560001064c49
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7959
diff changeset
     2
 * Copyright (c) 1997, 2011, 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: 2473
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: 2473
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: 2473
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2473
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2473
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
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.awt.image.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.geom.*;
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    32
import java.beans.PropertyChangeEvent;
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    33
import java.beans.PropertyChangeListener;
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    34
import java.beans.Transient;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.swing.text.html.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Defines common behaviors for buttons and menu items.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * Buttons can be configured, and to some degree controlled, by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <code><a href="Action.html">Action</a></code>s.  Using an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <code>Action</code> with a button has many benefits beyond directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * configuring a button.  Refer to <a href="Action.html#buttonActions">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * Swing Components Supporting <code>Action</code></a> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * details, and you can find more information in <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * href="http://java.sun.com/docs/books/tutorial/uiswing/misc/action.html">How
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * to Use Actions</a>, a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * For further information see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 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
    62
 * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * @author Jeff Dinkins
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
public abstract class AbstractButton extends JComponent implements ItemSelectable, SwingConstants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // *********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    // ******* Button properties *******
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    // *********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /** Identifies a change in the button model. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public static final String MODEL_CHANGED_PROPERTY = "model";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /** Identifies a change in the button's text. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public static final String TEXT_CHANGED_PROPERTY = "text";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /** Identifies a change to the button's mnemonic. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public static final String MNEMONIC_CHANGED_PROPERTY = "mnemonic";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    // Text positioning and alignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /** Identifies a change in the button's margins. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public static final String MARGIN_CHANGED_PROPERTY = "margin";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /** Identifies a change in the button's vertical alignment. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public static final String VERTICAL_ALIGNMENT_CHANGED_PROPERTY = "verticalAlignment";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /** Identifies a change in the button's horizontal alignment. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public static final String HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY = "horizontalAlignment";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /** Identifies a change in the button's vertical text position. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public static final String VERTICAL_TEXT_POSITION_CHANGED_PROPERTY = "verticalTextPosition";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /** Identifies a change in the button's horizontal text position. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public static final String HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY = "horizontalTextPosition";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    // Paint options
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Identifies a change to having the border drawn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * or having it not drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public static final String BORDER_PAINTED_CHANGED_PROPERTY = "borderPainted";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Identifies a change to having the border highlighted when focused,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public static final String FOCUS_PAINTED_CHANGED_PROPERTY = "focusPainted";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Identifies a change from rollover enabled to disabled or back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * to enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public static final String ROLLOVER_ENABLED_CHANGED_PROPERTY = "rolloverEnabled";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Identifies a change to having the button paint the content area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public static final String CONTENT_AREA_FILLED_CHANGED_PROPERTY = "contentAreaFilled";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    // Icons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /** Identifies a change to the icon that represents the button. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public static final String ICON_CHANGED_PROPERTY = "icon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Identifies a change to the icon used when the button has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * pressed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public static final String PRESSED_ICON_CHANGED_PROPERTY = "pressedIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Identifies a change to the icon used when the button has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * been selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public static final String SELECTED_ICON_CHANGED_PROPERTY = "selectedIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Identifies a change to the icon used when the cursor is over
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public static final String ROLLOVER_ICON_CHANGED_PROPERTY = "rolloverIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Identifies a change to the icon used when the cursor is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * over the button and it has been selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public static final String ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY = "rolloverSelectedIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Identifies a change to the icon used when the button has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * been disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public static final String DISABLED_ICON_CHANGED_PROPERTY = "disabledIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Identifies a change to the icon used when the button has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * disabled and selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public static final String DISABLED_SELECTED_ICON_CHANGED_PROPERTY = "disabledSelectedIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /** The data model that determines the button's state. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    protected ButtonModel model                = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    private String     text                    = ""; // for BeanBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    private Insets     margin                  = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    private Insets     defaultMargin           = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    // Button icons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    // PENDING(jeff) - hold icons in an array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    private Icon       defaultIcon             = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    private Icon       pressedIcon             = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    private Icon       disabledIcon            = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    private Icon       selectedIcon            = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    private Icon       disabledSelectedIcon    = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    private Icon       rolloverIcon            = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    private Icon       rolloverSelectedIcon    = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    // Display properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    private boolean    paintBorder             = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    private boolean    paintFocus              = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    private boolean    rolloverEnabled         = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    private boolean    contentAreaFilled         = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    // Icon/Label Alignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    private int        verticalAlignment       = CENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    private int        horizontalAlignment     = CENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    private int        verticalTextPosition    = CENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    private int        horizontalTextPosition  = TRAILING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    private int        iconTextGap             = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    private int        mnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    private int        mnemonicIndex           = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    private long       multiClickThreshhold    = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    private boolean    borderPaintedSet        = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    private boolean    rolloverEnabledSet      = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private boolean    iconTextGapSet          = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    private boolean    contentAreaFilledSet    = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    // Whether or not we've set the LayoutManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    private boolean setLayout = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    // This is only used by JButton, promoted to avoid an extra
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    // boolean field in JButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    boolean defaultCapable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Combined listeners: ActionListener, ChangeListener, ItemListener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    private Handler handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * The button model's <code>changeListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    protected ChangeListener changeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * The button model's <code>ActionListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    protected ActionListener actionListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * The button model's <code>ItemListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    protected ItemListener itemListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Only one <code>ChangeEvent</code> is needed per button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * instance since the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * event's only state is the source property.  The source of events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * generated is always "this".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    protected transient ChangeEvent changeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    private boolean hideActionText = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Sets the <code>hideActionText</code> property, which determines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * whether the button displays text from the <code>Action</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * This is useful only if an <code>Action</code> has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * installed on the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @param hideActionText <code>true</code> if the button's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *                       <code>text</code> property should not reflect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *                       that of the <code>Action</code>; the default is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *                       <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @see <a href="Action.html#buttonActions">Swing Components Supporting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *      <code>Action</code></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *    expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *  description: Whether the text of the button should come from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *               the <code>Action</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public void setHideActionText(boolean hideActionText) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        if (hideActionText != this.hideActionText) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            this.hideActionText = hideActionText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            if (getAction() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                setTextFromAction(getAction(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            firePropertyChange("hideActionText", !hideActionText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                               hideActionText);
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
     * Returns the value of the <code>hideActionText</code> property, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * determines whether the button displays text from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * <code>Action</code>.  This is useful only if an <code>Action</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * has been installed on the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @return <code>true</code> if the button's <code>text</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *         property should not reflect that of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *         <code>Action</code>; the default is <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public boolean getHideActionText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return hideActionText;
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
     * Returns the button's text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @return the buttons text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @see #setText
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public String getText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        return text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * Sets the button's text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @param text the string used to set the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @see #getText
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *  description: The button's text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public void setText(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        String oldValue = this.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        this.text = text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        firePropertyChange(TEXT_CHANGED_PROPERTY, oldValue, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        updateDisplayedMnemonicIndex(text, getMnemonic());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                oldValue, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (text == null || oldValue == null || !text.equals(oldValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * Returns the state of the button. True if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * toggle button is selected, false if it's not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @return true if the toggle button is selected, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public boolean isSelected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return model.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Sets the state of the button. Note that this method does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * trigger an <code>actionEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * Call <code>doClick</code> to perform a programatic action change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @param b  true if the button is selected, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public void setSelected(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        boolean oldValue = isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        // TIGER - 4840653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        // Removed code which fired an AccessibleState.SELECTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        // PropertyChangeEvent since this resulted in two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        // identical events being fired since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        // AbstractButton.fireItemStateChanged also fires the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        // same event. This caused screen readers to speak the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        // name of the item twice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        model.setSelected(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * Programmatically perform a "click". This does the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * thing as if the user had pressed and released the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    public void doClick() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        doClick(68);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * Programmatically perform a "click". This does the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * thing as if the user had pressed and released the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * The button stays visually "pressed" for <code>pressTime</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *  milliseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @param pressTime the time to "hold down" the button, in milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    public void doClick(int pressTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        Dimension size = getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        model.setArmed(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        model.setPressed(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        paintImmediately(new Rectangle(0,0, size.width, size.height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            Thread.currentThread().sleep(pressTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        } catch(InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        model.setPressed(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        model.setArmed(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * Sets space for margin between the button's border and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * the label. Setting to <code>null</code> will cause the button to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * use the default margin.  The button's default <code>Border</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * object will use this value to create the proper margin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * However, if a non-default border is set on the button,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * it is that <code>Border</code> object's responsibility to create the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * appropriate margin space (else this property will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * effectively be ignored).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @param m the space between the border and the label
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *  description: The space between the button's border and the label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    public void setMargin(Insets m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        // Cache the old margin if it comes from the UI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        if(m instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            defaultMargin = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        } else if(margin instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            defaultMargin = margin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        // If the client passes in a null insets, restore the margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        // from the UI if possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        if(m == null && defaultMargin != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            m = defaultMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        Insets old = margin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        margin = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        firePropertyChange(MARGIN_CHANGED_PROPERTY, old, m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (old == null || !old.equals(m)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * Returns the margin between the button's border and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * the label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @return an <code>Insets</code> object specifying the margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *          between the botton's border and the label
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @see #setMargin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    public Insets getMargin() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        return (margin == null) ? null : (Insets) margin.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * Returns the default icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @return the default <code>Icon</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @see #setIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    public Icon getIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        return defaultIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * Sets the button's default icon. This icon is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * also used as the "pressed" and "disabled" icon if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * there is no explicitly set pressed icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @param defaultIcon the icon used as the default image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @see #getIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @see #setPressedIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *           bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *       attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *     description: The button's default icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    public void setIcon(Icon defaultIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        Icon oldValue = this.defaultIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        this.defaultIcon = defaultIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        /* If the default icon has really changed and we had
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
         * generated the disabled icon for this component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
         * (i.e. setDisabledIcon() was never called) then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
         * clear the disabledIcon field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        if (defaultIcon != oldValue && (disabledIcon instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            disabledIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        firePropertyChange(ICON_CHANGED_PROPERTY, oldValue, defaultIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                oldValue, defaultIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        if (defaultIcon != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            if (defaultIcon == null || oldValue == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                defaultIcon.getIconWidth() != oldValue.getIconWidth() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                defaultIcon.getIconHeight() != oldValue.getIconHeight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * Returns the pressed icon for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * @return the <code>pressedIcon</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @see #setPressedIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    public Icon getPressedIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        return pressedIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * Sets the pressed icon for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @param pressedIcon the icon used as the "pressed" image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @see #getPressedIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *  description: The pressed icon for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    public void setPressedIcon(Icon pressedIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        Icon oldValue = this.pressedIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        this.pressedIcon = pressedIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        firePropertyChange(PRESSED_ICON_CHANGED_PROPERTY, oldValue, pressedIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                oldValue, pressedIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        if (pressedIcon != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            if (getModel().isPressed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * Returns the selected icon for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @return the <code>selectedIcon</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @see #setSelectedIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    public Icon getSelectedIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        return selectedIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * Sets the selected icon for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @param selectedIcon the icon used as the "selected" image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @see #getSelectedIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     *  description: The selected icon for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    public void setSelectedIcon(Icon selectedIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        Icon oldValue = this.selectedIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        this.selectedIcon = selectedIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        /* If the default selected icon has really changed and we had
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
         * generated the disabled selected icon for this component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
         * (i.e. setDisabledSelectedIcon() was never called) then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
         * clear the disabledSelectedIcon field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        if (selectedIcon != oldValue &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            disabledSelectedIcon instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            disabledSelectedIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        firePropertyChange(SELECTED_ICON_CHANGED_PROPERTY, oldValue, selectedIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                oldValue, selectedIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        if (selectedIcon != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            if (isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * Returns the rollover icon for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * @return the <code>rolloverIcon</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * @see #setRolloverIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    public Icon getRolloverIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        return rolloverIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * Sets the rollover icon for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * @param rolloverIcon the icon used as the "rollover" image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * @see #getRolloverIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *  description: The rollover icon for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    public void setRolloverIcon(Icon rolloverIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        Icon oldValue = this.rolloverIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        this.rolloverIcon = rolloverIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        firePropertyChange(ROLLOVER_ICON_CHANGED_PROPERTY, oldValue, rolloverIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                oldValue, rolloverIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        setRolloverEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        if (rolloverIcon != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            // No way to determine whether we are currently in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            // a rollover state, so repaint regardless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * Returns the rollover selection icon for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @return the <code>rolloverSelectedIcon</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @see #setRolloverSelectedIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    public Icon getRolloverSelectedIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        return rolloverSelectedIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * Sets the rollover selected icon for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @param rolloverSelectedIcon the icon used as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     *          "selected rollover" image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @see #getRolloverSelectedIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     *  description: The rollover selected icon for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    public void setRolloverSelectedIcon(Icon rolloverSelectedIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        Icon oldValue = this.rolloverSelectedIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        this.rolloverSelectedIcon = rolloverSelectedIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        firePropertyChange(ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, oldValue, rolloverSelectedIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                oldValue, rolloverSelectedIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        setRolloverEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        if (rolloverSelectedIcon != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            // No way to determine whether we are currently in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            // a rollover state, so repaint regardless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            if (isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * Returns the icon used by the button when it's disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * If no disabled icon has been set this will forward the call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * the look and feel to construct an appropriate disabled Icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * Some look and feels might not render the disabled Icon, in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * case they will ignore this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * @return the <code>disabledIcon</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @see #getPressedIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @see #setDisabledIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @see javax.swing.LookAndFeel#getDisabledIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   650
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    public Icon getDisabledIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        if (disabledIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            disabledIcon = UIManager.getLookAndFeel().getDisabledIcon(this, getIcon());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            if (disabledIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                firePropertyChange(DISABLED_ICON_CHANGED_PROPERTY, null, disabledIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        return disabledIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * Sets the disabled icon for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * @param disabledIcon the icon used as the disabled image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * @see #getDisabledIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     *  description: The disabled icon for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    public void setDisabledIcon(Icon disabledIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        Icon oldValue = this.disabledIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        this.disabledIcon = disabledIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        firePropertyChange(DISABLED_ICON_CHANGED_PROPERTY, oldValue, disabledIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                oldValue, disabledIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        if (disabledIcon != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            if (!isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                repaint();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * Returns the icon used by the button when it's disabled and selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * If no disabled selection icon has been set, this will forward
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * the call to the LookAndFeel to construct an appropriate disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * Icon from the selection icon if it has been set and to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * <code>getDisabledIcon()</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * Some look and feels might not render the disabled selected Icon, in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * which case they will ignore this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * @return the <code>disabledSelectedIcon</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * @see #getDisabledIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * @see #setDisabledSelectedIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * @see javax.swing.LookAndFeel#getDisabledSelectedIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    public Icon getDisabledSelectedIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        if (disabledSelectedIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
             if (selectedIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                 disabledSelectedIcon = UIManager.getLookAndFeel().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                         getDisabledSelectedIcon(this, getSelectedIcon());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
             } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                 return getDisabledIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        return disabledSelectedIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * Sets the disabled selection icon for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * @param disabledSelectedIcon the icon used as the disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     *          selection image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * @see #getDisabledSelectedIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     *  description: The disabled selection icon for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    public void setDisabledSelectedIcon(Icon disabledSelectedIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        Icon oldValue = this.disabledSelectedIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        this.disabledSelectedIcon = disabledSelectedIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        firePropertyChange(DISABLED_SELECTED_ICON_CHANGED_PROPERTY, oldValue, disabledSelectedIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                oldValue, disabledSelectedIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        if (disabledSelectedIcon != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            if (disabledSelectedIcon == null || oldValue == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                disabledSelectedIcon.getIconWidth() != oldValue.getIconWidth() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                disabledSelectedIcon.getIconHeight() != oldValue.getIconHeight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            if (!isEnabled() && isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * Returns the vertical alignment of the text and icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * @return the <code>verticalAlignment</code> property, one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     *          following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * <li>{@code SwingConstants.CENTER} (the default)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * <li>{@code SwingConstants.TOP}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * <li>{@code SwingConstants.BOTTOM}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    public int getVerticalAlignment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        return verticalAlignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * Sets the vertical alignment of the icon and text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * @param alignment one of the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * <li>{@code SwingConstants.CENTER} (the default)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * <li>{@code SwingConstants.TOP}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * <li>{@code SwingConstants.BOTTOM}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * @throws IllegalArgumentException if the alignment is not one of the legal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     *         values listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     *         enum: TOP    SwingConstants.TOP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     *               CENTER SwingConstants.CENTER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     *               BOTTOM  SwingConstants.BOTTOM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     *  description: The vertical alignment of the icon and text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    public void setVerticalAlignment(int alignment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        if (alignment == verticalAlignment) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        int oldValue = verticalAlignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        verticalAlignment = checkVerticalKey(alignment, "verticalAlignment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        firePropertyChange(VERTICAL_ALIGNMENT_CHANGED_PROPERTY, oldValue, verticalAlignment);         repaint();
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
     * Returns the horizontal alignment of the icon and text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * {@code AbstractButton}'s default is {@code SwingConstants.CENTER},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * but subclasses such as {@code JCheckBox} may use a different default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * @return the <code>horizontalAlignment</code> property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     *             one of the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     *   <li>{@code SwingConstants.RIGHT}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     *   <li>{@code SwingConstants.LEFT}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     *   <li>{@code SwingConstants.CENTER}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     *   <li>{@code SwingConstants.LEADING}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     *   <li>{@code SwingConstants.TRAILING}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    public int getHorizontalAlignment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        return horizontalAlignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * Sets the horizontal alignment of the icon and text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * {@code AbstractButton}'s default is {@code SwingConstants.CENTER},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * but subclasses such as {@code JCheckBox} may use a different default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * @param alignment the alignment value, one of the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     *   <li>{@code SwingConstants.RIGHT}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     *   <li>{@code SwingConstants.LEFT}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     *   <li>{@code SwingConstants.CENTER}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     *   <li>{@code SwingConstants.LEADING}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     *   <li>{@code SwingConstants.TRAILING}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * @throws IllegalArgumentException if the alignment is not one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     *         valid values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     *         enum: LEFT     SwingConstants.LEFT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     *               CENTER   SwingConstants.CENTER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     *               RIGHT    SwingConstants.RIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     *               LEADING  SwingConstants.LEADING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     *               TRAILING SwingConstants.TRAILING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     *  description: The horizontal alignment of the icon and text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    public void setHorizontalAlignment(int alignment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        if (alignment == horizontalAlignment) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        int oldValue = horizontalAlignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        horizontalAlignment = checkHorizontalKey(alignment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                                                 "horizontalAlignment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        firePropertyChange(HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                           oldValue, horizontalAlignment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * Returns the vertical position of the text relative to the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * @return the <code>verticalTextPosition</code> property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     *          one of the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * <li>{@code SwingConstants.CENTER} (the default)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * <li>{@code SwingConstants.TOP}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * <li>{@code SwingConstants.BOTTOM}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    public int getVerticalTextPosition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        return verticalTextPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * Sets the vertical position of the text relative to the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * @param textPosition  one of the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * <li>{@code SwingConstants.CENTER} (the default)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * <li>{@code SwingConstants.TOP}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * <li>{@code SwingConstants.BOTTOM}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     *         enum: TOP    SwingConstants.TOP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     *               CENTER SwingConstants.CENTER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     *               BOTTOM SwingConstants.BOTTOM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     *  description: The vertical position of the text relative to the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    public void setVerticalTextPosition(int textPosition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        if (textPosition == verticalTextPosition) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        int oldValue = verticalTextPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        verticalTextPosition = checkVerticalKey(textPosition, "verticalTextPosition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        firePropertyChange(VERTICAL_TEXT_POSITION_CHANGED_PROPERTY, oldValue, verticalTextPosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * Returns the horizontal position of the text relative to the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * @return the <code>horizontalTextPosition</code> property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     *          one of the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * <li>{@code SwingConstants.RIGHT}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * <li>{@code SwingConstants.LEFT}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * <li>{@code SwingConstants.CENTER}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * <li>{@code SwingConstants.LEADING}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * <li>{@code SwingConstants.TRAILING} (the default)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    public int getHorizontalTextPosition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        return horizontalTextPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * Sets the horizontal position of the text relative to the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * @param textPosition one of the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * <li>{@code SwingConstants.RIGHT}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * <li>{@code SwingConstants.LEFT}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * <li>{@code SwingConstants.CENTER}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * <li>{@code SwingConstants.LEADING}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * <li>{@code SwingConstants.TRAILING} (the default)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * @exception IllegalArgumentException if <code>textPosition</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     *          is not one of the legal values listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     *         enum: LEFT     SwingConstants.LEFT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     *               CENTER   SwingConstants.CENTER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     *               RIGHT    SwingConstants.RIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     *               LEADING  SwingConstants.LEADING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     *               TRAILING SwingConstants.TRAILING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     *  description: The horizontal position of the text relative to the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    public void setHorizontalTextPosition(int textPosition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        if (textPosition == horizontalTextPosition) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        int oldValue = horizontalTextPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        horizontalTextPosition = checkHorizontalKey(textPosition,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                                                    "horizontalTextPosition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        firePropertyChange(HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                           oldValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                           horizontalTextPosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * Returns the amount of space between the text and the icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * displayed in this button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * @return an int equal to the number of pixels between the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     *         and the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * @see #setIconTextGap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    public int getIconTextGap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        return iconTextGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * If both the icon and text properties are set, this property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * defines the space between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * The default value of this property is 4 pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * This is a JavaBeans bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * @see #getIconTextGap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     *  description: If both the icon and text properties are set, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     *               property defines the space between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    public void setIconTextGap(int iconTextGap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        int oldValue = this.iconTextGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        this.iconTextGap = iconTextGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        iconTextGapSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        firePropertyChange("iconTextGap", oldValue, iconTextGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        if (iconTextGap != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * Verify that the {@code key} argument is a legal value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * {@code horizontalAlignment} and {@code horizontalTextPosition}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * properties. Valid values are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     *   <li>{@code SwingConstants.RIGHT}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     *   <li>{@code SwingConstants.LEFT}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     *   <li>{@code SwingConstants.CENTER}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     *   <li>{@code SwingConstants.LEADING}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     *   <li>{@code SwingConstants.TRAILING}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * @param key the property value to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * @param exception the message to use in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     *        {@code IllegalArgumentException} that is thrown for an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     *        value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * @exception IllegalArgumentException if key is not one of the legal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     *            values listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * @see #setHorizontalTextPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * @see #setHorizontalAlignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    protected int checkHorizontalKey(int key, String exception) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        if ((key == LEFT) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            (key == CENTER) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            (key == RIGHT) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            (key == LEADING) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            (key == TRAILING)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            return key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            throw new IllegalArgumentException(exception);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * Verify that the {@code key} argument is a legal value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * vertical properties. Valid values are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     *   <li>{@code SwingConstants.CENTER}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     *   <li>{@code SwingConstants.TOP}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     *   <li>{@code SwingConstants.BOTTOM}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * @param key the property value to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * @param exception the message to use in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     *        {@code IllegalArgumentException} that is thrown for an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     *        value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * @exception IllegalArgumentException if key is not one of the legal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     *            values listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    protected int checkVerticalKey(int key, String exception) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        if ((key == TOP) || (key == CENTER) || (key == BOTTOM)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            return key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            throw new IllegalArgumentException(exception);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     *{@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    public void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        super.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        if(isRolloverEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            getModel().setRollover(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * Sets the action command for this button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * @param actionCommand the action command for this button
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    public void setActionCommand(String actionCommand) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        getModel().setActionCommand(actionCommand);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * Returns the action command for this button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * @return the action command for this button
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    public String getActionCommand() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        String ac = getModel().getActionCommand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        if(ac == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            ac = getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        return ac;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    private Action action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    private PropertyChangeListener actionPropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * Sets the <code>Action</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * The new <code>Action</code> replaces any previously set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * <code>Action</code> but does not affect <code>ActionListeners</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * independently added with <code>addActionListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * If the <code>Action</code> is already a registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * <code>ActionListener</code> for the button, it is not re-registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * Setting the <code>Action</code> results in immediately changing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * all the properties described in <a href="Action.html#buttonActions">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * Swing Components Supporting <code>Action</code></a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * Subsequently, the button's properties are automatically updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * as the <code>Action</code>'s properties change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * This method uses three other methods to set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * and help track the <code>Action</code>'s property values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * It uses the <code>configurePropertiesFromAction</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * to immediately change the button's properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * To track changes in the <code>Action</code>'s property values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     * this method registers the <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * returned by <code>createActionPropertyChangeListener</code>. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * default {@code PropertyChangeListener} invokes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     * {@code actionPropertyChanged} method when a property in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     * {@code Action} changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     * @param a the <code>Action</code> for the <code>AbstractButton</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     *          or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     * @see #getAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     * @see #configurePropertiesFromAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     * @see #createActionPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     * @see #actionPropertyChanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     *  description: the Action instance connected with this ActionEvent source
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    public void setAction(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        Action oldValue = getAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        if (action==null || !action.equals(a)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            action = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            if (oldValue!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                removeActionListener(oldValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                oldValue.removePropertyChangeListener(actionPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                actionPropertyChangeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            configurePropertiesFromAction(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            if (action!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                // Don't add if it is already a listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                if (!isListener(ActionListener.class, action)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                    addActionListener(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                // Reverse linkage:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                actionPropertyChangeListener = createActionPropertyChangeListener(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                action.addPropertyChangeListener(actionPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            firePropertyChange("action", oldValue, action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    private boolean isListener(Class c, ActionListener a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        boolean isListener = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            if (listeners[i]==c && listeners[i+1]==a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                    isListener=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        return isListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * Returns the currently set <code>Action</code> for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * <code>ActionEvent</code> source, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * if no <code>Action</code> is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * @return the <code>Action</code> for this <code>ActionEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     *          source, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * @see #setAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
    public Action getAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        return action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * Sets the properties on this button to match those in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * <code>Action</code>.  Refer to <a href="Action.html#buttonActions">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * Swing Components Supporting <code>Action</code></a> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * details as to which properties this sets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     * @param a the <code>Action</code> from which to get the properties,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     *          or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     * @see #setAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
    protected void configurePropertiesFromAction(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        setMnemonicFromAction(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        setTextFromAction(a, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        AbstractAction.setToolTipTextFromAction(this, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        setIconFromAction(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        setActionCommandFromAction(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        AbstractAction.setEnabledFromAction(this, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        if (AbstractAction.hasSelectedKey(a) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                shouldUpdateSelectedStateFromAction()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            setSelectedFromAction(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        setDisplayedMnemonicIndexFromAction(a, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    void clientPropertyChanged(Object key, Object oldValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                               Object newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        if (key == "hideActionText") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            boolean current = (newValue instanceof Boolean) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                                (Boolean)newValue : false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            if (getHideActionText() != current) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                setHideActionText(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     * Button subclasses that support mirroring the selected state from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     * the action should override this to return true.  AbstractButton's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * implementation returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    boolean shouldUpdateSelectedStateFromAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * Updates the button's state in response to property changes in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * associated action. This method is invoked from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     * {@code PropertyChangeListener} returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     * {@code createActionPropertyChangeListener}. Subclasses do not normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     * need to invoke this. Subclasses that support additional {@code Action}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     * properties should override this and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     * {@code configurePropertiesFromAction}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     * Refer to the table at <a href="Action.html#buttonActions">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * Swing Components Supporting <code>Action</code></a> for a list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * the properties this method sets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     * @param action the <code>Action</code> associated with this button
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * @param propertyName the name of the property that changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     * @see #configurePropertiesFromAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    protected void actionPropertyChanged(Action action, String propertyName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        if (propertyName == Action.NAME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            setTextFromAction(action, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        } else if (propertyName == "enabled") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            AbstractAction.setEnabledFromAction(this, action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        } else if (propertyName == Action.SHORT_DESCRIPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            AbstractAction.setToolTipTextFromAction(this, action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        } else if (propertyName == Action.SMALL_ICON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            smallIconChanged(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        } else if (propertyName == Action.MNEMONIC_KEY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            setMnemonicFromAction(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        } else if (propertyName == Action.ACTION_COMMAND_KEY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            setActionCommandFromAction(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        } else if (propertyName == Action.SELECTED_KEY &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                   AbstractAction.hasSelectedKey(action) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
                   shouldUpdateSelectedStateFromAction()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            setSelectedFromAction(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        } else if (propertyName == Action.DISPLAYED_MNEMONIC_INDEX_KEY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
            setDisplayedMnemonicIndexFromAction(action, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        } else if (propertyName == Action.LARGE_ICON_KEY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            largeIconChanged(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
    private void setDisplayedMnemonicIndexFromAction(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            Action a, boolean fromPropertyChange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        Integer iValue = (a == null) ? null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                (Integer)a.getValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        if (fromPropertyChange || iValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
            int value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            if (iValue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                value = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                value = iValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                String text = getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                if (text == null || value >= text.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                    value = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            setDisplayedMnemonicIndex(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    private void setMnemonicFromAction(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        Integer n = (a == null) ? null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                                  (Integer)a.getValue(Action.MNEMONIC_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        setMnemonic((n == null) ? '\0' : n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    private void setTextFromAction(Action a, boolean propertyChange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        boolean hideText = getHideActionText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        if (!propertyChange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            setText((a != null && !hideText) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                        (String)a.getValue(Action.NAME) : null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        else if (!hideText) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
            setText((String)a.getValue(Action.NAME));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    void setIconFromAction(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        Icon icon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        if (a != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            icon = (Icon)a.getValue(Action.LARGE_ICON_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
            if (icon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                icon = (Icon)a.getValue(Action.SMALL_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        setIcon(icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
    void smallIconChanged(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        if (a.getValue(Action.LARGE_ICON_KEY) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            setIconFromAction(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    void largeIconChanged(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        setIconFromAction(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    private void setActionCommandFromAction(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        setActionCommand((a != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                             (String)a.getValue(Action.ACTION_COMMAND_KEY) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                             null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * Sets the seleted state of the button from the action.  This is defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * here, but not wired up.  Subclasses like JToggleButton and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     * JCheckBoxMenuItem make use of it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     * @param a the Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    private void setSelectedFromAction(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        boolean selected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
        if (a != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            selected = AbstractAction.isSelected(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        if (selected != isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
            // This won't notify ActionListeners, but that should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            // ok as the change is coming from the Action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
            setSelected(selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
            // Make sure the change actually took effect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            if (!selected && isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                if (getModel() instanceof DefaultButtonModel) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 467
diff changeset
  1318
                    ButtonGroup group = ((DefaultButtonModel)getModel()).getGroup();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                    if (group != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                        group.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     * Creates and returns a <code>PropertyChangeListener</code> that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     * responsible for listening for changes from the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
     * <code>Action</code> and updating the appropriate properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
     * <b>Warning:</b> If you subclass this do not create an anonymous
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
     * inner class.  If you do the lifetime of the button will be tied to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
     * that of the <code>Action</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
     * @param a the button's action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
     * @see #setAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
    protected PropertyChangeListener createActionPropertyChangeListener(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        return createActionPropertyChangeListener0(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
    PropertyChangeListener createActionPropertyChangeListener0(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        return new ButtonActionPropertyChangeListener(this, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    private static class ButtonActionPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
                 extends ActionPropertyChangeListener<AbstractButton> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
        ButtonActionPropertyChangeListener(AbstractButton b, Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
            super(b, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        protected void actionPropertyChanged(AbstractButton button,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                                             Action action,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
                                             PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
            if (AbstractAction.shouldReconfigure(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
                button.configurePropertiesFromAction(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
                button.actionPropertyChanged(action, e.getPropertyName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
     * Gets the <code>borderPainted</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
     * @return the value of the <code>borderPainted</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     * @see #setBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
    public boolean isBorderPainted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        return paintBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     * Sets the <code>borderPainted</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
     * If <code>true</code> and the button has a border,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     * the border is painted. The default value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
     * <code>borderPainted</code> property is <code>true</code>.
7261
055384958326 6939227: Nimbus: 6597895 for JCheckBox, JButton and JToggleButton JCK tests
alexp
parents: 5506
diff changeset
  1381
     * <p/>
055384958326 6939227: Nimbus: 6597895 for JCheckBox, JButton and JToggleButton JCK tests
alexp
parents: 5506
diff changeset
  1382
     * Some look and feels might not support
055384958326 6939227: Nimbus: 6597895 for JCheckBox, JButton and JToggleButton JCK tests
alexp
parents: 5506
diff changeset
  1383
     * the <code>borderPainted</code> property,
055384958326 6939227: Nimbus: 6597895 for JCheckBox, JButton and JToggleButton JCK tests
alexp
parents: 5506
diff changeset
  1384
     * in which case they ignore this.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     * @param b if true and border property is not <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     *          the border is painted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * @see #isBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
     *  description: Whether the border should be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
    public void setBorderPainted(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        boolean oldValue = paintBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
        paintBorder = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        borderPaintedSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
        firePropertyChange(BORDER_PAINTED_CHANGED_PROPERTY, oldValue, paintBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
        if (b != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * Paint the button's border if <code>BorderPainted</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * property is true and the button has a border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * @param g the <code>Graphics</code> context in which to paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * @see #paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * @see #setBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
    protected void paintBorder(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
        if (isBorderPainted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
            super.paintBorder(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     * Gets the <code>paintFocus</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * @return the <code>paintFocus</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     * @see #setFocusPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
    public boolean isFocusPainted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        return paintFocus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     * Sets the <code>paintFocus</code> property, which must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     * be <code>true</code> for the focus state to be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
     * The default value for the <code>paintFocus</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
     * is <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     * Some look and feels might not paint focus state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     * they will ignore this property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
     * @param b if <code>true</code>, the focus state should be painted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     * @see #isFocusPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     *  description: Whether focus should be painted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
    public void setFocusPainted(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        boolean oldValue = paintFocus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
        paintFocus = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
        firePropertyChange(FOCUS_PAINTED_CHANGED_PROPERTY, oldValue, paintFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
        if (b != oldValue && isFocusOwner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     * Gets the <code>contentAreaFilled</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
     * @return the <code>contentAreaFilled</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
     * @see #setContentAreaFilled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
    public boolean isContentAreaFilled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        return contentAreaFilled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
     * Sets the <code>contentAreaFilled</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
     * If <code>true</code> the button will paint the content
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
     * area.  If you wish to have a transparent button, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
     * an icon only button, for example, then you should set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     * this to <code>false</code>. Do not call <code>setOpaque(false)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
     * The default value for the the <code>contentAreaFilled</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
     * property is <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     * This function may cause the component's opaque property to change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * The exact behavior of calling this function varies on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     * component-by-component and L&F-by-L&F basis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
     * @param b if true, the content should be filled; if false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
     *          the content area is not filled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     * @see #isContentAreaFilled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     * @see #setOpaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     *  description: Whether the button should paint the content area
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
     *               or leave it transparent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
    public void setContentAreaFilled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        boolean oldValue = contentAreaFilled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        contentAreaFilled = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        contentAreaFilledSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        firePropertyChange(CONTENT_AREA_FILLED_CHANGED_PROPERTY, oldValue, contentAreaFilled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        if (b != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
     * Gets the <code>rolloverEnabled</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
     * @return the value of the <code>rolloverEnabled</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
     * @see #setRolloverEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
    public boolean isRolloverEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
        return rolloverEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
     * Sets the <code>rolloverEnabled</code> property, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     * must be <code>true</code> for rollover effects to occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
     * The default value for the <code>rolloverEnabled</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     * property is <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
     * Some look and feels might not implement rollover effects;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
     * they will ignore this property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
     * @param b if <code>true</code>, rollover effects should be painted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
     * @see #isRolloverEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
     *  description: Whether rollover effects should be enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
    public void setRolloverEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        boolean oldValue = rolloverEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
        rolloverEnabled = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        rolloverEnabledSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        firePropertyChange(ROLLOVER_ENABLED_CHANGED_PROPERTY, oldValue, rolloverEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
        if (b != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
     * Returns the keyboard mnemonic from the the current model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
     * @return the keyboard mnemonic from the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
    public int getMnemonic() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
        return mnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
     * Sets the keyboard mnemonic on the current model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
     * The mnemonic is the key which when combined with the look and feel's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
     * mouseless modifier (usually Alt) will activate this button
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
     * if focus is contained somewhere within this button's ancestor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
     * window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
     * A mnemonic must correspond to a single key on the keyboard
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
     * and should be specified using one of the <code>VK_XXX</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
     * keycodes defined in <code>java.awt.event.KeyEvent</code>.
2473
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  1551
     * These codes and the wider array of codes for international
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  1552
     * keyboards may be obtained through
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  1553
     * <code>java.awt.event.KeyEvent.getExtendedKeyCodeForChar</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
     * Mnemonics are case-insensitive, therefore a key event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
     * with the corresponding keycode would cause the button to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
     * activated whether or not the Shift modifier was pressed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
     * If the character defined by the mnemonic is found within
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
     * the button's label string, the first occurrence of it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
     * will be underlined to indicate the mnemonic to the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
     * @param mnemonic the key code which represents the mnemonic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
     * @see     java.awt.event.KeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
     * @see     #setDisplayedMnemonicIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
     *  description: the keyboard character mnemonic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
    public void setMnemonic(int mnemonic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
        int oldValue = getMnemonic();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
        model.setMnemonic(mnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
        updateMnemonicProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
     * This method is now obsolete, please use <code>setMnemonic(int)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
     * to set the mnemonic for a button.  This method is only designed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
     * to handle character values which fall between 'a' and 'z' or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
     * 'A' and 'Z'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
     * @param mnemonic  a char specifying the mnemonic value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
     * @see #setMnemonic(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     *  description: the keyboard character mnemonic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
    public void setMnemonic(char mnemonic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
        int vk = (int) mnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
        if(vk >= 'a' && vk <='z')
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
            vk -= ('a' - 'A');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        setMnemonic(vk);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
     * Provides a hint to the look and feel as to which character in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
     * text should be decorated to represent the mnemonic. Not all look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
     * feels may support this. A value of -1 indicates either there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
     * mnemonic, the mnemonic character is not contained in the string, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
     * the developer does not wish the mnemonic to be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
     * The value of this is updated as the properties relating to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
     * mnemonic change (such as the mnemonic itself, the text...).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
     * You should only ever have to call this if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
     * you do not wish the default character to be underlined. For example, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
     * the text was 'Save As', with a mnemonic of 'a', and you wanted the 'A'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
     * to be decorated, as 'Save <u>A</u>s', you would have to invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
     * <code>setDisplayedMnemonicIndex(5)</code> after invoking
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
     * <code>setMnemonic(KeyEvent.VK_A)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
     * @param index Index into the String to underline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
     * @exception IllegalArgumentException will be thrown if <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
     *            is &gt;= length of the text, or &lt; -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
     * @see #getDisplayedMnemonicIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
     *  description: the index into the String to draw the keyboard character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
     *               mnemonic at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
    public void setDisplayedMnemonicIndex(int index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                                          throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
        int oldValue = mnemonicIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
        if (index == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
            mnemonicIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
            String text = getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
            int textLength = (text == null) ? 0 : text.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
            if (index < -1 || index >= textLength) {  // index out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                throw new IllegalArgumentException("index == " + index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
        mnemonicIndex = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
        firePropertyChange("displayedMnemonicIndex", oldValue, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
        if (index != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
     * Returns the character, as an index, that the look and feel should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
     * provide decoration for as representing the mnemonic character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
     * @return index representing mnemonic character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
     * @see #setDisplayedMnemonicIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
    public int getDisplayedMnemonicIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
        return mnemonicIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
     * Update the displayedMnemonicIndex property. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
     * is called when either text or mnemonic changes. The new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
     * value of the displayedMnemonicIndex property is the index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
     * of the first occurrence of mnemonic in text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
    private void updateDisplayedMnemonicIndex(String text, int mnemonic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
        setDisplayedMnemonicIndex(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
            SwingUtilities.findDisplayedMnemonicIndex(text, mnemonic));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
     * Brings the mnemonic property in accordance with model's mnemonic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
     * This is called when model's mnemonic changes. Also updates the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
     * displayedMnemonicIndex property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
    private void updateMnemonicProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
        int newMnemonic = model.getMnemonic();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
        if (mnemonic != newMnemonic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
            int oldValue = mnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
            mnemonic = newMnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
            firePropertyChange(MNEMONIC_CHANGED_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                               oldValue, mnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
            updateDisplayedMnemonicIndex(getText(), mnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
     * Sets the amount of time (in milliseconds) required between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
     * mouse press events for the button to generate the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
     * action events.  After the initial mouse press occurs (and action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
     * event generated) any subsequent mouse press events which occur
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
     * on intervals less than the threshhold will be ignored and no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
     * corresponding action event generated.  By default the threshhold is 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
     * which means that for each mouse press, an action event will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
     * fired, no matter how quickly the mouse clicks occur.  In buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
     * where this behavior is not desirable (for example, the "OK" button
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
     * in a dialog), this threshhold should be set to an appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
     * positive value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
     * @see #getMultiClickThreshhold
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
     * @param threshhold the amount of time required between mouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
     *        press events to generate corresponding action events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
     * @exception   IllegalArgumentException if threshhold < 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
    public void setMultiClickThreshhold(long threshhold) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
        if (threshhold < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
            throw new IllegalArgumentException("threshhold must be >= 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
        this.multiClickThreshhold = threshhold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
     * Gets the amount of time (in milliseconds) required between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
     * mouse press events for the button to generate the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
     * action events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
     * @see #setMultiClickThreshhold
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
     * @return the amount of time required between mouse press events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
     *         to generate corresponding action events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
    public long getMultiClickThreshhold() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
        return multiClickThreshhold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
     * Returns the model that this button represents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
     * @return the <code>model</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
     * @see #setModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
    public ButtonModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
        return model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
     * Sets the model that this button represents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
     * @param newModel the new <code>ButtonModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
     * @see #getModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
     *  description: Model that the Button uses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
    public void setModel(ButtonModel newModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
        ButtonModel oldModel = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
        if (oldModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
            oldModel.removeChangeListener(changeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
            oldModel.removeActionListener(actionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
            oldModel.removeItemListener(itemListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
            changeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
            actionListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
            itemListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
        model = newModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
        if (newModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
            changeListener = createChangeListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
            actionListener = createActionListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
            itemListener = createItemListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
            newModel.addChangeListener(changeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
            newModel.addActionListener(actionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
            newModel.addItemListener(itemListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
            updateMnemonicProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
            //We invoke setEnabled() from JComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
            //because setModel() can be called from a constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
            //when the button is not fully initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
            super.setEnabled(newModel.isEnabled());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
            mnemonic = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
        updateDisplayedMnemonicIndex(getText(), mnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
        firePropertyChange(MODEL_CHANGED_PROPERTY, oldModel, newModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
        if (newModel != oldModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
     * Returns the L&F object that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
     * @return the ButtonUI object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
     * @see #setUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
    public ButtonUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
        return (ButtonUI) ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
     * Sets the L&F object that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
     * @param ui the <code>ButtonUI</code> L&F object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
     * @see #getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
     *  description: The UI object that implements the LookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
    public void setUI(ButtonUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
        super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
        // disabled icons are generated by the LF so they should be unset here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
        if (disabledIcon instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
            setDisabledIcon(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
        if (disabledSelectedIcon instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
            setDisabledSelectedIcon(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
     * Resets the UI property to a value from the current look
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
     * and feel.  Subtypes of <code>AbstractButton</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
     * should override this to update the UI. For
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
     * example, <code>JButton</code> might do the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
     *      setUI((ButtonUI)UIManager.getUI(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
     *          "ButtonUI", "javax.swing.plaf.basic.BasicButtonUI", this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
     * Adds the specified component to this container at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
     * index, refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
     * {@link java.awt.Container#addImpl(Component, Object, int)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
     * for a complete description of this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
     * @param     comp the component to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
     * @param     constraints an object expressing layout constraints
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
     *                 for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
     * @param     index the position in the container's list at which to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
     *                 insert the component, where <code>-1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
     *                 means append to the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
     * @exception IllegalArgumentException if <code>index</code> is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
     * @exception IllegalArgumentException if adding the container's parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
     *                  to itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
     * @exception IllegalArgumentException if adding a window to a container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
    protected void addImpl(Component comp, Object constraints, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
        if (!setLayout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
            setLayout(new OverlayLayout(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
        super.addImpl(comp, constraints, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
     * Sets the layout manager for this container, refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     * {@link java.awt.Container#setLayout(LayoutManager)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     * for a complete description of this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
     * @param mgr the specified layout manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
    public void setLayout(LayoutManager mgr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
        setLayout = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
        super.setLayout(mgr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
     * Adds a <code>ChangeListener</code> to the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
     * @param l the listener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
    public void addChangeListener(ChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
        listenerList.add(ChangeListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
     * Removes a ChangeListener from the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
     * @param l the listener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
    public void removeChangeListener(ChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
        listenerList.remove(ChangeListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
     * Returns an array of all the <code>ChangeListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
     * to this AbstractButton with addChangeListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
     * @return all of the <code>ChangeListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
    public ChangeListener[] getChangeListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 467
diff changeset
  1894
        return listenerList.getListeners(ChangeListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
     * is lazily created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
    protected void fireStateChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
            if (listeners[i]==ChangeListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
                if (changeEvent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
                    changeEvent = new ChangeEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
                ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
     * Adds an <code>ActionListener</code> to the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
     * @param l the <code>ActionListener</code> to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
    public void addActionListener(ActionListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
        listenerList.add(ActionListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
     * Removes an <code>ActionListener</code> from the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
     * If the listener is the currently set <code>Action</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
     * for the button, then the <code>Action</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
     * is set to <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
     * @param l the listener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
    public void removeActionListener(ActionListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
        if ((l != null) && (getAction() == l)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
            setAction(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
            listenerList.remove(ActionListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
     * Returns an array of all the <code>ActionListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
     * to this AbstractButton with addActionListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
     * @return all of the <code>ActionListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
    public ActionListener[] getActionListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 467
diff changeset
  1951
        return listenerList.getListeners(ActionListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
     * Subclasses that want to handle <code>ChangeEvents</code> differently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
     * can override this to return another <code>ChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
     * implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
     * @return the new <code>ChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
    protected ChangeListener createChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
     * Extends <code>ChangeListener</code> to be serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
    protected class ButtonChangeListener implements ChangeListener, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
        // NOTE: This class is NOT used, instead the functionality has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
        // been moved to Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
        ButtonChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
            getHandler().stateChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
     * is lazily created using the <code>event</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
     * parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
     * @param event  the <code>ActionEvent</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
    protected void fireActionPerformed(ActionEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
        ActionEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
            if (listeners[i]==ActionListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
                if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
                      String actionCommand = event.getActionCommand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
                      if(actionCommand == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
                         actionCommand = getActionCommand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
                      e = new ActionEvent(AbstractButton.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
                                          ActionEvent.ACTION_PERFORMED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
                                          actionCommand,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
                                          event.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
                                          event.getModifiers());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
                ((ActionListener)listeners[i+1]).actionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
     * is lazily created using the <code>event</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
     * @param event  the <code>ItemEvent</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
    protected void fireItemStateChanged(ItemEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
        ItemEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
            if (listeners[i]==ItemListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
                if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
                    e = new ItemEvent(AbstractButton.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
                                      ItemEvent.ITEM_STATE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
                                      AbstractButton.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
                                      event.getStateChange());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
                ((ItemListener)listeners[i+1]).itemStateChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
            if (event.getStateChange() == ItemEvent.SELECTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
                accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
                    null, AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
                accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
                    AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  2056
                    Integer.valueOf(0), Integer.valueOf(1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
                accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
                    AccessibleState.SELECTED, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
                accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
                    AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  2063
                    Integer.valueOf(1), Integer.valueOf(0));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
    protected ActionListener createActionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
    protected ItemListener createItemListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
     * Enables (or disables) the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
     * @param b  true to enable the button, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
    public void setEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
        if (!b && model.isRollover()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
            model.setRollover(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
        super.setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
        model.setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
    // *** Deprecated java.awt.Button APIs below *** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
     * Returns the label text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
     * @return a <code>String</code> containing the label
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
     * @deprecated - Replaced by <code>getText</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
    public String getLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
        return getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
     * Sets the label text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
     * @param label  a <code>String</code> containing the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
     * @deprecated - Replaced by <code>setText(text)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
     *  description: Replace by setText(text)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
    public void setLabel(String label) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
        setText(label);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
     * Adds an <code>ItemListener</code> to the <code>checkbox</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
     * @param l  the <code>ItemListener</code> to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
    public void addItemListener(ItemListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
        listenerList.add(ItemListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
     * Removes an <code>ItemListener</code> from the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
     * @param l the <code>ItemListener</code> to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
    public void removeItemListener(ItemListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
        listenerList.remove(ItemListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
     * Returns an array of all the <code>ItemListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
     * to this AbstractButton with addItemListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
     * @return all of the <code>ItemListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
    public ItemListener[] getItemListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 467
diff changeset
  2143
        return listenerList.getListeners(ItemListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
     * Returns an array (length 1) containing the label or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
     * <code>null</code> if the button is not selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
     * @return an array containing 1 Object: the text of the button,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
     *         if the item is selected; otherwise <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
    public Object[] getSelectedObjects() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
        if (isSelected() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
        Object[] selectedObjects = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
        selectedObjects[0] = getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
        return selectedObjects;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
    protected void init(String text, Icon icon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
        if(text != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
            setText(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
        if(icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
            setIcon(icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
        // Set the UI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
        setAlignmentX(LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
        setAlignmentY(CENTER_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
     * This is overridden to return false if the current <code>Icon</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
     * <code>Image</code> is not equal to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
     * passed in <code>Image</code> <code>img</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
     * @param img  the <code>Image</code> to be compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
     * @param infoflags flags used to repaint the button when the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
     *          is updated and which determine how much is to be painted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
     * @param x  the x coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
     * @param y  the y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
     * @param w  the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
     * @param h  the height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
     * @see     java.awt.image.ImageObserver
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
     * @see     java.awt.Component#imageUpdate(java.awt.Image, int, int, int, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
    public boolean imageUpdate(Image img, int infoflags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
                               int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
        Icon iconDisplayed = getIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
        if (iconDisplayed == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
        if (!model.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
            if (model.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
                iconDisplayed = getDisabledSelectedIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
                iconDisplayed = getDisabledIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
        } else if (model.isPressed() && model.isArmed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
            iconDisplayed = getPressedIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
        } else if (isRolloverEnabled() && model.isRollover()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
            if (model.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
                iconDisplayed = getRolloverSelectedIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
                iconDisplayed = getRolloverIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
        } else if (model.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
            iconDisplayed = getSelectedIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
        if (!SwingUtilities.doesIconReferenceImage(iconDisplayed, img)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
            // We don't know about this image, disable the notification so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
            // we don't keep repainting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
        return super.imageUpdate(img, infoflags, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
    void setUIProperty(String propertyName, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
        if (propertyName == "borderPainted") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
            if (!borderPaintedSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
                setBorderPainted(((Boolean)value).booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
                borderPaintedSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
        } else if (propertyName == "rolloverEnabled") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
            if (!rolloverEnabledSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
                setRolloverEnabled(((Boolean)value).booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
                rolloverEnabledSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
        } else if (propertyName == "iconTextGap") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
            if (!iconTextGapSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
                setIconTextGap(((Number)value).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
                iconTextGapSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
        } else if (propertyName == "contentAreaFilled") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
            if (!contentAreaFilledSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
                setContentAreaFilled(((Boolean)value).booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
                contentAreaFilledSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
            super.setUIProperty(propertyName, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
     * Returns a string representation of this <code>AbstractButton</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
     * This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
     * Overriding <code>paramString</code> to provide information about the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
     * specific new aspects of the JFC components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
     * @return  a string representation of this <code>AbstractButton</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
        String defaultIconString = ((defaultIcon != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
                                    && (defaultIcon != this) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
                                    defaultIcon.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
        String pressedIconString = ((pressedIcon != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
                                    && (pressedIcon != this) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
                                    pressedIcon.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
        String disabledIconString = ((disabledIcon != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
                                     && (disabledIcon != this) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
                                     disabledIcon.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
        String selectedIconString = ((selectedIcon != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
                                     && (selectedIcon != this) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
                                     selectedIcon.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
        String disabledSelectedIconString = ((disabledSelectedIcon != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
                                             (disabledSelectedIcon != this) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
                                             disabledSelectedIcon.toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
                                             : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
        String rolloverIconString = ((rolloverIcon != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
                                     && (rolloverIcon != this) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
                                     rolloverIcon.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
        String rolloverSelectedIconString = ((rolloverSelectedIcon != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
                                             (rolloverSelectedIcon != this) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
                                             rolloverSelectedIcon.toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
                                             : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
        String paintBorderString = (paintBorder ? "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
        String paintFocusString = (paintFocus ? "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
        String rolloverEnabledString = (rolloverEnabled ? "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
        ",defaultIcon=" + defaultIconString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
        ",disabledIcon=" + disabledIconString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
        ",disabledSelectedIcon=" + disabledSelectedIconString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
        ",margin=" + margin +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
        ",paintBorder=" + paintBorderString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
        ",paintFocus=" + paintFocusString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
        ",pressedIcon=" + pressedIconString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
        ",rolloverEnabled=" + rolloverEnabledString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
        ",rolloverIcon=" + rolloverIconString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
        ",rolloverSelectedIcon=" + rolloverSelectedIconString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
        ",selectedIcon=" + selectedIconString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
        ",text=" + text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
    private Handler getHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
            handler = new Handler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
    // Listeners that are added to model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
    class Handler implements ActionListener, ChangeListener, ItemListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
                             Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
        // ChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
            updateMnemonicProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
            if (isEnabled() != model.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
                setEnabled(model.isEnabled());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
            fireStateChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
        // ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
        public void actionPerformed(ActionEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
            fireActionPerformed(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
        // ItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
        public void itemStateChanged(ItemEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
            fireItemStateChanged(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
            if (shouldUpdateSelectedStateFromAction()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
                Action action = getAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
                if (action != null && AbstractAction.hasSelectedKey(action)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
                    boolean selected = isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
                    boolean isActionSelected = AbstractAction.isSelected(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
                              action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
                    if (isActionSelected != selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
                        action.putValue(Action.SELECTED_KEY, selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
///////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
///////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
     * <code>AbstractButton</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
     * Java Accessibility API appropriate to button and menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
     * user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
    protected abstract class AccessibleAbstractButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
        extends AccessibleJComponent implements AccessibleAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
        AccessibleValue, AccessibleText, AccessibleExtendedComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
         * Returns the accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
         * @return the localized name of the object -- can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
         *              <code>null</code> if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
         *              object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
        public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
            String name = accessibleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
            if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
                name = (String)getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
            if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
                name = AbstractButton.this.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
            if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
                name = super.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
         * Get the AccessibleIcons associated with this object if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
         * or more exist.  Otherwise return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
        public AccessibleIcon [] getAccessibleIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
            Icon defaultIcon = getIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
            if (defaultIcon instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
                AccessibleContext ac =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
                    ((Accessible)defaultIcon).getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
                if (ac != null && ac instanceof AccessibleIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
                    return new AccessibleIcon[] { (AccessibleIcon)ac };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
         * Get the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
         * @return an instance of AccessibleState containing the current state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
         * of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
        AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
            if (getModel().isArmed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
                states.add(AccessibleState.ARMED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
            if (isFocusOwner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
                states.add(AccessibleState.FOCUSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
            if (getModel().isPressed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
                states.add(AccessibleState.PRESSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
            if (isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
                states.add(AccessibleState.CHECKED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
         * Get the AccessibleRelationSet associated with this object if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
         * exists.  Otherwise return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
         * @see AccessibleRelation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
        public AccessibleRelationSet getAccessibleRelationSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
            // Check where the AccessibleContext's relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
            // set already contains a MEMBER_OF relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
            AccessibleRelationSet relationSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
                = super.getAccessibleRelationSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
            if (!relationSet.contains(AccessibleRelation.MEMBER_OF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
                // get the members of the button group if one exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
                ButtonModel model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
                if (model != null && model instanceof DefaultButtonModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
                    ButtonGroup group = ((DefaultButtonModel)model).getGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
                    if (group != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
                        // set the target of the MEMBER_OF relation to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
                        // the members of the button group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
                        int len = group.getButtonCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
                        Object [] target = new Object[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
                        Enumeration elem = group.getElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
                        for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
                            if (elem.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
                                target[i] = elem.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
                        AccessibleRelation relation =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
                            new AccessibleRelation(AccessibleRelation.MEMBER_OF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
                        relation.setTarget(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
                        relationSet.add(relation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
            return relationSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
         * Get the AccessibleAction associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
         * AccessibleAction interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
        public AccessibleAction getAccessibleAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
         * Get the AccessibleValue associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
         * AccessibleValue interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
        public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
         * Returns the number of Actions available in this object.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
         * default behavior of a button is to have one action - toggle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
         * the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
         * @return 1, the number of Actions in this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
        public int getAccessibleActionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
         * Return a description of the specified action of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
         * @param i zero-based index of the actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
        public String getAccessibleActionDescription(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
            if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
                return UIManager.getString("AbstractButton.clickText");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
         * Perform the specified Action on the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
         * @param i zero-based index of actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
         * @return true if the the action was performed; else false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
        public boolean doAccessibleAction(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
            if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
                doClick();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
         * Get the value of this object as a Number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
         * @return An Integer of 0 if this isn't selected or an Integer of 1 if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
         * this is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
         * @see AbstractButton#isSelected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
        public Number getCurrentAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
            if (isSelected()) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  2561
                return Integer.valueOf(1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
            } else {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  2563
                return Integer.valueOf(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
         * Set the value of this object as a Number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
         * @return True if the value was set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
        public boolean setCurrentAccessibleValue(Number n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
            // TIGER - 4422535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
            if (n == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
            int i = n.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
            if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
                setSelected(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
                setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
         * Get the minimum value of this object as a Number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
         * @return an Integer of 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
        public Number getMinimumAccessibleValue() {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  2592
            return Integer.valueOf(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
         * Get the maximum value of this object as a Number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
         * @return An Integer of 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
        public Number getMaximumAccessibleValue() {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  2601
            return Integer.valueOf(1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
        /* AccessibleText ---------- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
        public AccessibleText getAccessibleText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
            View view = (View)AbstractButton.this.getClientProperty("html");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
            if (view != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
         * Given a point in local coordinates, return the zero-based index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
         * of the character under that Point.  If the point is invalid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
         * this method returns -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
         * Note: the AbstractButton must have a valid size (e.g. have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
         * been added to a parent container whose ancestor container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
         * is a valid top-level window) for this method to be able
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
         * to return a meaningful value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
         * @param p the Point in local coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
         * @return the zero-based index of the character under Point p; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
         * Point is invalid returns -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
        public int getIndexAtPoint(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
            View view = (View) AbstractButton.this.getClientProperty("html");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
            if (view != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
                Rectangle r = getTextRectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
                if (r == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
                    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
                Rectangle2D.Float shape =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
                    new Rectangle2D.Float(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
                Position.Bias bias[] = new Position.Bias[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
                return view.viewToModel(p.x, p.y, shape, bias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
         * Determine the bounding box of the character at the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
         * index into the string.  The bounds are returned in local
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
         * coordinates.  If the index is invalid an empty rectangle is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
         * returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
         * Note: the AbstractButton must have a valid size (e.g. have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
         * been added to a parent container whose ancestor container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
         * is a valid top-level window) for this method to be able
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
         * to return a meaningful value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
         * @param i the index into the String
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
         * @return the screen coordinates of the character's the bounding box,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
         * if index is invalid returns an empty rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
        public Rectangle getCharacterBounds(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
            View view = (View) AbstractButton.this.getClientProperty("html");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
            if (view != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
                Rectangle r = getTextRectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
                if (r == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
                Rectangle2D.Float shape =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
                    new Rectangle2D.Float(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
                    Shape charShape =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
                        view.modelToView(i, shape, Position.Bias.Forward);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
                    return charShape.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
         * Return the number of characters (valid indicies)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
         * @return the number of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
        public int getCharCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
            View view = (View) AbstractButton.this.getClientProperty("html");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
            if (view != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
                Document d = view.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
                if (d instanceof StyledDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
                    StyledDocument doc = (StyledDocument)d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
                    return doc.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
            return accessibleContext.getAccessibleName().length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
         * Return the zero-based offset of the caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
         * Note: That to the right of the caret will have the same index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
         * value as the offset (the caret is between two characters).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
         * @return the zero-based offset of the caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
        public int getCaretPosition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
            // There is no caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
         * Returns the String at a given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
         * @param part the AccessibleText.CHARACTER, AccessibleText.WORD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
         * or AccessibleText.SENTENCE to retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
         * @param index an index within the text >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
         * @return the letter, word, or sentence,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
         *   null for an invalid index or part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
        public String getAtIndex(int part, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
            if (index < 0 || index >= getCharCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
            switch (part) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
            case AccessibleText.CHARACTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
                    return getText(index, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
            case AccessibleText.WORD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
                    String s = getText(0, getCharCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
                    BreakIterator words = BreakIterator.getWordInstance(getLocale());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
                    words.setText(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
                    int end = words.following(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
                    return s.substring(words.previous(), end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
            case AccessibleText.SENTENCE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
                    String s = getText(0, getCharCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
                    BreakIterator sentence =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
                        BreakIterator.getSentenceInstance(getLocale());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
                    sentence.setText(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
                    int end = sentence.following(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
                    return s.substring(sentence.previous(), end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
         * Returns the String after a given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
         * @param part the AccessibleText.CHARACTER, AccessibleText.WORD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
         * or AccessibleText.SENTENCE to retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
         * @param index an index within the text >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
         * @return the letter, word, or sentence, null for an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
         *  index or part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
        public String getAfterIndex(int part, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
            if (index < 0 || index >= getCharCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
            switch (part) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
            case AccessibleText.CHARACTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
                if (index+1 >= getCharCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
                   return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
                    return getText(index+1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
            case AccessibleText.WORD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
                    String s = getText(0, getCharCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
                    BreakIterator words = BreakIterator.getWordInstance(getLocale());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
                    words.setText(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
                    int start = words.following(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
                    if (start == BreakIterator.DONE || start >= s.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
                    int end = words.following(start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
                    if (end == BreakIterator.DONE || end >= s.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
                    return s.substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
            case AccessibleText.SENTENCE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
                    String s = getText(0, getCharCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
                    BreakIterator sentence =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
                        BreakIterator.getSentenceInstance(getLocale());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
                    sentence.setText(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
                    int start = sentence.following(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
                    if (start == BreakIterator.DONE || start > s.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
                    int end = sentence.following(start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
                    if (end == BreakIterator.DONE || end > s.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
                    return s.substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
         * Returns the String before a given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
         * @param part the AccessibleText.CHARACTER, AccessibleText.WORD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
         *   or AccessibleText.SENTENCE to retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
         * @param index an index within the text >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
         * @return the letter, word, or sentence, null for an invalid index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
         *  or part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
        public String getBeforeIndex(int part, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
            if (index < 0 || index > getCharCount()-1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
            switch (part) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
            case AccessibleText.CHARACTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
                if (index == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
                    return getText(index-1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
            case AccessibleText.WORD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
                    String s = getText(0, getCharCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
                    BreakIterator words = BreakIterator.getWordInstance(getLocale());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
                    words.setText(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
                    int end = words.following(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
                    end = words.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
                    int start = words.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
                    if (start == BreakIterator.DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
                    return s.substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
            case AccessibleText.SENTENCE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
                    String s = getText(0, getCharCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
                    BreakIterator sentence =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
                        BreakIterator.getSentenceInstance(getLocale());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
                    sentence.setText(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
                    int end = sentence.following(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
                    end = sentence.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
                    int start = sentence.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
                    if (start == BreakIterator.DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
                    return s.substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
         * Return the AttributeSet for a given character at a given index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
         * @param i the zero-based index into the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
         * @return the AttributeSet of the character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
        public AttributeSet getCharacterAttribute(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
            View view = (View) AbstractButton.this.getClientProperty("html");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
            if (view != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
                Document d = view.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
                if (d instanceof StyledDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
                    StyledDocument doc = (StyledDocument)d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
                    Element elem = doc.getCharacterElement(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
                    if (elem != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
                        return elem.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
         * Returns the start offset within the selected text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
         * If there is no selection, but there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
         * a caret, the start and end offsets will be the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
         * @return the index into the text of the start of the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
        public int getSelectionStart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
            // Text cannot be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
         * Returns the end offset within the selected text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
         * If there is no selection, but there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
         * a caret, the start and end offsets will be the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
         * @return the index into teh text of the end of the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
        public int getSelectionEnd() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
            // Text cannot be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
         * Returns the portion of the text that is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
         * @return the String portion of the text that is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
        public String getSelectedText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
            // Text cannot be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
         * Returns the text substring starting at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
         * offset with the specified length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
        private String getText(int offset, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
            throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
            View view = (View) AbstractButton.this.getClientProperty("html");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
            if (view != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
                Document d = view.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
                if (d instanceof StyledDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
                    StyledDocument doc = (StyledDocument)d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
                    return doc.getText(offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
         * Returns the bounding rectangle for the component text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
        private Rectangle getTextRectangle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
            String text = AbstractButton.this.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
            Icon icon = (AbstractButton.this.isEnabled()) ? AbstractButton.this.getIcon() : AbstractButton.this.getDisabledIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
            if ((icon == null) && (text == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
            Rectangle paintIconR = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
            Rectangle paintTextR = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
            Rectangle paintViewR = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
            Insets paintViewInsets = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
            paintViewInsets = AbstractButton.this.getInsets(paintViewInsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
            paintViewR.x = paintViewInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
            paintViewR.y = paintViewInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
            paintViewR.width = AbstractButton.this.getWidth() - (paintViewInsets.left + paintViewInsets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
            paintViewR.height = AbstractButton.this.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
            String clippedText = SwingUtilities.layoutCompoundLabel(
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 467
diff changeset
  2987
                AbstractButton.this,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
                getFontMetrics(getFont()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
                text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
                icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
                AbstractButton.this.getVerticalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
                AbstractButton.this.getHorizontalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
                AbstractButton.this.getVerticalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
                AbstractButton.this.getHorizontalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
                paintViewR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
                paintIconR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
                paintTextR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
                0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
            return paintTextR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
        // ----- AccessibleExtendedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
         * Returns the AccessibleExtendedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
         * @return the AccessibleExtendedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
        AccessibleExtendedComponent getAccessibleExtendedComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
         * Returns the tool tip text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
         * @return the tool tip text, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
         * otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
        public String getToolTipText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
            return AbstractButton.this.getToolTipText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
         * Returns the titled border text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
         * @return the titled border text, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
         * otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
        public String getTitledBorderText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
            return super.getTitledBorderText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
         * Returns key bindings associated with this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
         * @return the key bindings, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
         * otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
         * @see AccessibleKeyBinding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
        public AccessibleKeyBinding getAccessibleKeyBinding() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
            int mnemonic = AbstractButton.this.getMnemonic();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
            if (mnemonic == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
            return new ButtonKeyBinding(mnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
        class ButtonKeyBinding implements AccessibleKeyBinding {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
            int mnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
            ButtonKeyBinding(int mnemonic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
                this.mnemonic = mnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
             * Returns the number of key bindings for this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
             * @return the zero-based number of key bindings for this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
            public int getAccessibleKeyBindingCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
             * Returns a key binding for this object.  The value returned is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
             * java.lang.Object which must be cast to appropriate type depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
             * on the underlying implementation of the key.  For example, if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
             * Object returned is a javax.swing.KeyStroke, the user of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
             * method should do the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
             * <nf><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
             * Component c = <get the component that has the key bindings>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
             * AccessibleContext ac = c.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
             * AccessibleKeyBinding akb = ac.getAccessibleKeyBinding();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
             * for (int i = 0; i < akb.getAccessibleKeyBindingCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
             *     Object o = akb.getAccessibleKeyBinding(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
             *     if (o instanceof javax.swing.KeyStroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
             *         javax.swing.KeyStroke keyStroke = (javax.swing.KeyStroke)o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
             *         <do something with the key binding>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
             *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
             * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
             * </code></nf>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
             * @param i zero-based index of the key bindings
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
             * @return a javax.lang.Object which specifies the key binding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
             * @exception IllegalArgumentException if the index is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
             * out of bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
             * @see #getAccessibleKeyBindingCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
            public java.lang.Object getAccessibleKeyBinding(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
                if (i != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
                    throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
                return KeyStroke.getKeyStroke(mnemonic, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
}