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