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