jdk/src/share/classes/javax/swing/plaf/basic/BasicButtonUI.java
author darcy
Wed, 02 Jul 2014 23:03:27 -0700
changeset 25565 ce603b34c98d
parent 23715 54ae9dd9df73
child 25763 51d1f910f68d
permissions -rw-r--r--
8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.* 8042849: Fix raw and unchecked warnings in com.sun.java.swing Reviewed-by: pchelko, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4225
diff changeset
     2
 * Copyright (c) 1997, 2008, 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.basic;
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: 1299
diff changeset
    29
import sun.awt.AppContext;
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1299
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 java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.swing.plaf.ButtonUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.plaf.UIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.plaf.ComponentUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.text.View;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * BasicButton implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author Jeff Dinkins
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class BasicButtonUI extends ButtonUI{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    // Visual constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    // NOTE: This is not used or set any where. Were we allowed to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    // fields, this would be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    protected int defaultTextIconGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // Amount to offset text, the value of this comes from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    // defaultTextShiftOffset once setTextShiftOffset has been invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private int shiftOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    // Value that is set in shiftOffset once setTextShiftOffset has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // invoked. The value of this comes from the defaults table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    protected int defaultTextShiftOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private final static String propertyPrefix = "Button" + ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
4225
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1299
diff changeset
    63
    private static final Object BASIC_BUTTON_UI_KEY = new Object();
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1299
diff changeset
    64
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    //          Create PLAF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public static ComponentUI createUI(JComponent c) {
4225
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1299
diff changeset
    69
        AppContext appContext = AppContext.getAppContext();
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1299
diff changeset
    70
        BasicButtonUI buttonUI =
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1299
diff changeset
    71
                (BasicButtonUI) appContext.get(BASIC_BUTTON_UI_KEY);
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1299
diff changeset
    72
        if (buttonUI == null) {
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1299
diff changeset
    73
            buttonUI = new BasicButtonUI();
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1299
diff changeset
    74
            appContext.put(BASIC_BUTTON_UI_KEY, buttonUI);
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 1299
diff changeset
    75
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        return buttonUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    protected String getPropertyPrefix() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return propertyPrefix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    //          Install PLAF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        installDefaults((AbstractButton) c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        installListeners((AbstractButton) c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        installKeyboardActions((AbstractButton) c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        BasicHTML.updateRenderer(c, ((AbstractButton) c).getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    protected void installDefaults(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        // load shared instance defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        String pp = getPropertyPrefix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        defaultTextShiftOffset = UIManager.getInt(pp + "textShiftOffset");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        // set the following defaults on the button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        if (b.isContentAreaFilled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            LookAndFeel.installProperty(b, "opaque", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            LookAndFeel.installProperty(b, "opaque", Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if(b.getMargin() == null || (b.getMargin() instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            b.setMargin(UIManager.getInsets(pp + "margin"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        LookAndFeel.installColorsAndFont(b, pp + "background",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                         pp + "foreground", pp + "font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        LookAndFeel.installBorder(b, pp + "border");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        Object rollover = UIManager.get(pp + "rollover");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (rollover != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            LookAndFeel.installProperty(b, "rolloverEnabled", rollover);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   120
        LookAndFeel.installProperty(b, "iconTextGap", Integer.valueOf(4));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    protected void installListeners(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        BasicButtonListener listener = createButtonListener(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if(listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            b.addMouseListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            b.addMouseMotionListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            b.addFocusListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            b.addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            b.addChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    protected void installKeyboardActions(AbstractButton b){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        BasicButtonListener listener = getButtonListener(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if(listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            listener.installKeyboardActions(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    //         Uninstall PLAF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        uninstallKeyboardActions((AbstractButton) c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        uninstallListeners((AbstractButton) c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        uninstallDefaults((AbstractButton) c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        BasicHTML.updateRenderer(c, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    protected void uninstallKeyboardActions(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        BasicButtonListener listener = getButtonListener(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        if(listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            listener.uninstallKeyboardActions(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    protected void uninstallListeners(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        BasicButtonListener listener = getButtonListener(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        if(listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            b.removeMouseListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            b.removeMouseMotionListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            b.removeFocusListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            b.removeChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            b.removePropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    protected void uninstallDefaults(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        LookAndFeel.uninstallBorder(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    //        Create Listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    protected BasicButtonListener createButtonListener(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return new BasicButtonListener(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public int getDefaultTextIconGap(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        return defaultTextIconGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /* These rectangles/insets are allocated once for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * ButtonUI.paint() calls.  Re-using rectangles rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * allocating them in each paint call substantially reduced the time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * it took paint to run.  Obviously, this method can't be re-entered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    private static Rectangle viewRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    private static Rectangle textRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    private static Rectangle iconRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    //          Paint Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public void paint(Graphics g, JComponent c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        AbstractButton b = (AbstractButton) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        String text = layout(b, SwingUtilities2.getFontMetrics(b, g),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
               b.getWidth(), b.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        clearTextShiftOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        // perform UI specific press action, e.g. Windows L&F shifts text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (model.isArmed() && model.isPressed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            paintButtonPressed(g,b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        // Paint the Icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        if(b.getIcon() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            paintIcon(g,c,iconRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if (text != null && !text.equals("")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            View v = (View) c.getClientProperty(BasicHTML.propertyKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                v.paint(g, textRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                paintText(g, b, textRect, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        if (b.isFocusPainted() && b.hasFocus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            // paint UI specific focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            paintFocus(g,b,viewRect,textRect,iconRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            AbstractButton b = (AbstractButton) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            Icon icon = b.getIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            Icon tmpIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            if(icon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
               return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            Icon selectedIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            /* the fallback icon should be based on the selected state */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            if (model.isSelected()) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   248
                selectedIcon = b.getSelectedIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                if (selectedIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    icon = selectedIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            if(!model.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                if(model.isSelected()) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   256
                   tmpIcon = b.getDisabledSelectedIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                   if (tmpIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                       tmpIcon = selectedIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                if (tmpIcon == null) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   263
                    tmpIcon = b.getDisabledIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            } else if(model.isPressed() && model.isArmed()) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   266
                tmpIcon = b.getPressedIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                if(tmpIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    // revert back to 0 offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    clearTextShiftOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            } else if(b.isRolloverEnabled() && model.isRollover()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                if(model.isSelected()) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   273
                   tmpIcon = b.getRolloverSelectedIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                   if (tmpIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                       tmpIcon = selectedIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                if (tmpIcon == null) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   280
                    tmpIcon = b.getRolloverIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            if(tmpIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                icon = tmpIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            if(model.isPressed() && model.isArmed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                        iconRect.y + getTextShiftOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                icon.paintIcon(c, g, iconRect.x, iconRect.y);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * As of Java 2 platform v 1.4 this method should not be used or overriden.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * Use the paintText method which takes the AbstractButton argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        AbstractButton b = (AbstractButton) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        FontMetrics fm = SwingUtilities2.getFontMetrics(c, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        int mnemonicIndex = b.getDisplayedMnemonicIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        /* Draw the Text */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if(model.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            /*** paint the text normally */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            g.setColor(b.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            SwingUtilities2.drawStringUnderlineCharAt(c, g,text, mnemonicIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                                          textRect.x + getTextShiftOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                                          textRect.y + fm.getAscent() + getTextShiftOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            /*** paint the text disabled ***/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            g.setColor(b.getBackground().brighter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            SwingUtilities2.drawStringUnderlineCharAt(c, g,text, mnemonicIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                                          textRect.x, textRect.y + fm.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            g.setColor(b.getBackground().darker());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            SwingUtilities2.drawStringUnderlineCharAt(c, g,text, mnemonicIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                                          textRect.x - 1, textRect.y + fm.getAscent() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * Method which renders the text of the current button.
23715
54ae9dd9df73 8039074: Tidy warnings cleanup for javax.swing
yan
parents: 5506
diff changeset
   328
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @param g Graphics context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @param b Current button to render
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @param textRect Bounding rectangle to render the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @param text String to render
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        paintText(g, (JComponent)b, textRect, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    // Method signature defined here overriden in subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    // Perhaps this class should be abstract?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    protected void paintFocus(Graphics g, AbstractButton b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                              Rectangle viewRect, Rectangle textRect, Rectangle iconRect){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    protected void paintButtonPressed(Graphics g, AbstractButton b){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    protected void clearTextShiftOffset(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        this.shiftOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    protected void setTextShiftOffset(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        this.shiftOffset = defaultTextShiftOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    protected int getTextShiftOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        return shiftOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    //          Layout Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    public Dimension getMinimumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        Dimension d = getPreferredSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            d.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        return BasicGraphicsUtils.getPreferredButtonSize(b, b.getIconTextGap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    public Dimension getMaximumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        Dimension d = getPreferredSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            d.width += v.getMaximumSpan(View.X_AXIS) - v.getPreferredSpan(View.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * Returns the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @throws IllegalArgumentException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    public int getBaseline(JComponent c, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        super.getBaseline(c, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        String text = b.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (text == null || "".equals(text)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        FontMetrics fm = b.getFontMetrics(b.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        layout(b, fm, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        return BasicHTML.getBaseline(b, textRect.y, fm.getAscent(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                                     textRect.width, textRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * Returns an enum indicating how the baseline of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * changes as the size changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    public Component.BaselineResizeBehavior getBaselineResizeBehavior(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        super.getBaselineResizeBehavior(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if (c.getClientProperty(BasicHTML.propertyKey) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            return Component.BaselineResizeBehavior.OTHER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        switch(((AbstractButton)c).getVerticalAlignment()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        case AbstractButton.TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        case AbstractButton.BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            return Component.BaselineResizeBehavior.CONSTANT_DESCENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        case AbstractButton.CENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            return Component.BaselineResizeBehavior.CENTER_OFFSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        return Component.BaselineResizeBehavior.OTHER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    private String layout(AbstractButton b, FontMetrics fm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                          int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        Insets i = b.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        viewRect.x = i.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        viewRect.y = i.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        viewRect.width = width - (i.right + viewRect.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        viewRect.height = height - (i.bottom + viewRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        textRect.x = textRect.y = textRect.width = textRect.height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        // layout the text and icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        return SwingUtilities.layoutCompoundLabel(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            b, fm, b.getText(), b.getIcon(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            b.getVerticalAlignment(), b.getHorizontalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            viewRect, iconRect, textRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            b.getText() == null ? 0 : b.getIconTextGap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Returns the ButtonListener for the passed in Button, or null if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * could not be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    private BasicButtonListener getButtonListener(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        MouseMotionListener[] listeners = b.getMouseMotionListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        if (listeners != null) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   462
            for (MouseMotionListener listener : listeners) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   463
                if (listener instanceof BasicButtonListener) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   464
                    return (BasicButtonListener) listener;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
}