jdk/src/share/classes/javax/swing/plaf/metal/MetalRadioButtonUI.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: 1639
diff changeset
    29
import sun.awt.AppContext;
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1639
diff changeset
    30
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.swing.text.View;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * RadioButtonUI implementation for MetalRadioButtonUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * 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
    49
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author Michael C. Albers (Metal modifications)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @author Jeff Dinkins (original BasicRadioButtonCode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
    56
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
public class MetalRadioButtonUI extends BasicRadioButtonUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
4225
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1639
diff changeset
    59
    private static final Object METAL_RADIO_BUTTON_UI_KEY = new Object();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    61
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    62
     * The color of the focused radio button.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    63
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    protected Color focusColor;
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    65
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    66
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    67
     * The color of the selected radio button.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    68
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    protected Color selectColor;
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    70
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    71
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    72
     * The color of a disabled text.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    73
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    protected Color disabledTextColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private boolean defaults_initialized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    //        Create PlAF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    // ********************************
25178
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
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    83
     * Returns an instance of {@code MetalRadioButtonUI}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    84
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    85
     * @param c a component
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    86
     * @return an instance of {@code MetalRadioButtonUI}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    87
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static ComponentUI createUI(JComponent c) {
4225
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1639
diff changeset
    89
        AppContext appContext = AppContext.getAppContext();
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1639
diff changeset
    90
        MetalRadioButtonUI metalRadioButtonUI =
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1639
diff changeset
    91
                (MetalRadioButtonUI) appContext.get(METAL_RADIO_BUTTON_UI_KEY);
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1639
diff changeset
    92
        if (metalRadioButtonUI == null) {
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1639
diff changeset
    93
            metalRadioButtonUI = new MetalRadioButtonUI();
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1639
diff changeset
    94
            appContext.put(METAL_RADIO_BUTTON_UI_KEY, metalRadioButtonUI);
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1639
diff changeset
    95
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        return metalRadioButtonUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    //        Install Defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public void installDefaults(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        super.installDefaults(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if(!defaults_initialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            focusColor = UIManager.getColor(getPropertyPrefix() + "focus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            selectColor = UIManager.getColor(getPropertyPrefix() + "select");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            disabledTextColor = UIManager.getColor(getPropertyPrefix() + "disabledText");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            defaults_initialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        LookAndFeel.installProperty(b, "opaque", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    protected void uninstallDefaults(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        super.uninstallDefaults(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        defaults_initialized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    //         Default Accessors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    // ********************************
25178
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
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   123
     * Returns the color of the selected {@code JRadioButton}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   124
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   125
     * @return the color of the selected {@code JRadioButton}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   126
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    protected Color getSelectColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return selectColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
25178
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
     * Returns the color of the disabled text.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   133
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   134
     * @return the color of the disabled text
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   135
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    protected Color getDisabledTextColor() {
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 {@code JRadioButton}.
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 {@code JRadioButton}
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
        return focusColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
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 Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public synchronized void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        AbstractButton b = (AbstractButton) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        Dimension size = c.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        int w = size.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        int h = size.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        Font f = c.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        g.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        Rectangle viewRect = new Rectangle(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        Rectangle iconRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        Rectangle textRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        Insets i = c.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        viewRect.x += i.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        viewRect.y += i.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        viewRect.width -= (i.right + viewRect.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        viewRect.height -= (i.bottom + viewRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        Icon altIcon = b.getIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        Icon selectedIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        Icon disabledIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        String text = SwingUtilities.layoutCompoundLabel(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            c, fm, b.getText(), altIcon != null ? altIcon : getDefaultIcon(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            b.getVerticalAlignment(), b.getHorizontalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            viewRect, iconRect, textRect, b.getIconTextGap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        // fill background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if(c.isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            g.setColor(b.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            g.fillRect(0,0, size.width, size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        // Paint the radio button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if(altIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            if(!model.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                if(model.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                   altIcon = b.getDisabledSelectedIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                   altIcon = b.getDisabledIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            } else if(model.isPressed() && model.isArmed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                altIcon = b.getPressedIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                if(altIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    // Use selected icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    altIcon = b.getSelectedIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            } else if(model.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                if(b.isRolloverEnabled() && model.isRollover()) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   211
                        altIcon = b.getRolloverSelectedIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                        if (altIcon == null) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   213
                                altIcon = b.getSelectedIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                } else {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   216
                        altIcon = b.getSelectedIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            } else if(b.isRolloverEnabled() && model.isRollover()) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   219
                altIcon = b.getRolloverIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            if(altIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                altIcon = b.getIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            altIcon.paintIcon(c, g, iconRect.x, iconRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            getDefaultIcon().paintIcon(c, g, iconRect.x, iconRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        // Draw the Text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if(text != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            View v = (View) c.getClientProperty(BasicHTML.propertyKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                v.paint(g, textRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
               int mnemIndex = b.getDisplayedMnemonicIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
               if(model.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                   // *** paint the text normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                   g.setColor(b.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
               } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                   // *** paint the text disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                   g.setColor(getDisabledTextColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
               SwingUtilities2.drawStringUnderlineCharAt(c,g,text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                       mnemIndex, textRect.x, textRect.y + fm.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
           if(b.hasFocus() && b.isFocusPainted() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
              textRect.width > 0 && textRect.height > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
               paintFocus(g,textRect,size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    protected void paintFocus(Graphics g, Rectangle t, Dimension d){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        g.setColor(getFocusColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        g.drawRect(t.x-1, t.y-1, t.width+1, t.height+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
}