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