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