jdk/src/share/classes/javax/swing/plaf/metal/MetalButtonUI.java
author yan
Mon, 30 Jun 2014 16:32:36 +0400
changeset 25178 dbab904451e9
parent 22574 7f8ce0c8c20a
permissions -rw-r--r--
8046434: Fix doclint warnings from javax.swing.plaf.metal package Reviewed-by: alexsch Contributed-by: Andrei Eremeev <andrei.eremeev@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
     2
 * Copyright (c) 1998, 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: 4225
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: 4225
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: 4225
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4225
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4225
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.plaf.metal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.swing.SwingUtilities2;
4225
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    29
import sun.awt.AppContext;
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    30
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * MetalButtonUI implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * 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: 5506
diff changeset
    47
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author Tom Santos
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
    53
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public class MetalButtonUI extends BasicButtonUI {
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    55
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    // NOTE: These are not really needed, but at this point we can't pull
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    // them. Their values are updated purely for historical reasons.
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    58
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    59
     * The color of the focused button.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    60
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    protected Color focusColor;
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    62
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    63
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    64
     * The color of the selected button.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    65
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    protected Color selectColor;
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    67
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    68
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    69
     * The color of the disabled color.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    70
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    protected Color disabledTextColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
4225
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    73
    private static final Object METAL_BUTTON_UI_KEY = new Object();
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    74
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    //          Create PLAF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // ********************************
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    78
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    79
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    80
     * Returns an instance of {@code MetalButtonUI}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    81
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    82
     * @param c a component
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    83
     * @return an instance of {@code MetalButtonUI}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    84
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public static ComponentUI createUI(JComponent c) {
4225
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    86
        AppContext appContext = AppContext.getAppContext();
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    87
        MetalButtonUI metalButtonUI =
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    88
                (MetalButtonUI) appContext.get(METAL_BUTTON_UI_KEY);
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    89
        if (metalButtonUI == null) {
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    90
            metalButtonUI = new MetalButtonUI();
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    91
            appContext.put(METAL_BUTTON_UI_KEY, metalButtonUI);
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    92
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        return metalButtonUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    //          Install
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public void installDefaults(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        super.installDefaults(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public void uninstallDefaults(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        super.uninstallDefaults(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    //         Create Listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    protected BasicButtonListener createButtonListener(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return super.createButtonListener(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    //         Default Accessors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    // ********************************
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   118
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   119
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   120
     * Returns the color of the selected button.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   121
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   122
     * @return the color of the selected button
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   123
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    protected Color getSelectColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        selectColor = UIManager.getColor(getPropertyPrefix() + "select");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        return selectColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   129
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   130
     * Returns the color of a disabled text.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   131
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   132
     * @return the color of a disabled text
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   133
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    protected Color getDisabledTextColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        disabledTextColor = UIManager.getColor(getPropertyPrefix() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                                               "disabledText");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return disabledTextColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   140
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   141
     * Returns the color of the focused button.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   142
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   143
     * @return the color of the focused button
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   144
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    protected Color getFocusColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        focusColor = UIManager.getColor(getPropertyPrefix() + "focus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return focusColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    //          Paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * If necessary paints the background of the component, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * invokes <code>paint</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param g Graphics to paint to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @param c JComponent painting on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @throws NullPointerException if <code>g</code> or <code>c</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *         null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @see javax.swing.plaf.ComponentUI#update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @see javax.swing.plaf.ComponentUI#paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        AbstractButton button = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if ((c.getBackground() instanceof UIResource) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                  button.isContentAreaFilled() && c.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            ButtonModel model = button.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            if (!MetalUtils.isToolBarButton(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                if (!model.isArmed() && !model.isPressed() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                        MetalUtils.drawGradient(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                        c, g, "Button.gradient", 0, 0, c.getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                        c.getHeight(), true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    paint(g, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            else if (model.isRollover() && MetalUtils.drawGradient(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                        c, g, "Button.gradient", 0, 0, c.getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                        c.getHeight(), true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                paint(g, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        super.update(g, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    protected void paintButtonPressed(Graphics g, AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if ( b.isContentAreaFilled() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            Dimension size = b.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            g.setColor(getSelectColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            g.fillRect(0, 0, size.width, size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    protected void paintFocus(Graphics g, AbstractButton b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                              Rectangle viewRect, Rectangle textRect, Rectangle iconRect){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        Rectangle focusRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        String text = b.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        boolean isIcon = b.getIcon() != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        // If there is text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if ( text != null && !text.equals( "" ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            if ( !isIcon ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                focusRect.setBounds( textRect );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                focusRect.setBounds( iconRect.union( textRect ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        // If there is an icon and no text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        else if ( isIcon ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            focusRect.setBounds( iconRect );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        g.setColor(getFocusColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        g.drawRect((focusRect.x-1), (focusRect.y-1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                  focusRect.width+1, focusRect.height+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        AbstractButton b = (AbstractButton) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        FontMetrics fm = SwingUtilities2.getFontMetrics(c, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        int mnemIndex = b.getDisplayedMnemonicIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        /* Draw the Text */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if(model.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            /*** paint the text normally */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            g.setColor(b.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            /*** paint the text disabled ***/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            g.setColor(getDisabledTextColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        SwingUtilities2.drawStringUnderlineCharAt(c, g,text,mnemIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                                  textRect.x, textRect.y + fm.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
}