jdk/src/share/classes/javax/swing/plaf/basic/BasicRadioButtonUI.java
author xdono
Mon, 15 Dec 2008 16:55:25 -0800
changeset 1639 a97859015238
parent 1290 da8902cd496c
child 4225 57ec8171fcd5
permissions -rw-r--r--
6785258: Update copyright year Summary: Update copyright for files that have been modified starting July 2008 to Dec 2008 Reviewed-by: katleman, ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1639
a97859015238 6785258: Update copyright year
xdono
parents: 1290
diff changeset
     2
 * Copyright 1997-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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 java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.text.View;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * RadioButtonUI implementation for BasicRadioButtonUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @author Jeff Dinkins
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class BasicRadioButtonUI extends BasicToggleButtonUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private final static BasicRadioButtonUI radioButtonUI = new BasicRadioButtonUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    protected Icon icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private boolean defaults_initialized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private final static String propertyPrefix = "RadioButton" + ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    //        Create PLAF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public static ComponentUI createUI(JComponent b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        return radioButtonUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    protected String getPropertyPrefix() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        return propertyPrefix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    //        Install PLAF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    protected void installDefaults(AbstractButton b){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        super.installDefaults(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        if(!defaults_initialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            icon = UIManager.getIcon(getPropertyPrefix() + "icon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            defaults_initialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    //        Uninstall PLAF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    protected void uninstallDefaults(AbstractButton b){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        super.uninstallDefaults(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        defaults_initialized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public Icon getDefaultIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        return icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /* These Dimensions/Rectangles are allocated once for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * RadioButtonUI.paint() calls.  Re-using rectangles
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * rather than allocating them in each paint call substantially
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * reduced the time it took paint to run.  Obviously, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * method can't be re-entered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private static Dimension size = new Dimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private static Rectangle viewRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private static Rectangle iconRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private static Rectangle textRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * paint the radio button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public synchronized void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        AbstractButton b = (AbstractButton) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        Font f = c.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        g.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        Insets i = c.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        size = b.getSize(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        viewRect.x = i.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        viewRect.y = i.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        viewRect.width = size.width - (i.right + viewRect.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        viewRect.height = size.height - (i.bottom + viewRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        textRect.x = textRect.y = textRect.width = textRect.height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        Icon altIcon = b.getIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        Icon selectedIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        Icon disabledIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        String text = SwingUtilities.layoutCompoundLabel(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            c, fm, b.getText(), altIcon != null ? altIcon : getDefaultIcon(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            b.getVerticalAlignment(), b.getHorizontalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            viewRect, iconRect, textRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            b.getText() == null ? 0 : b.getIconTextGap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        // fill background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if(c.isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            g.setColor(b.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            g.fillRect(0,0, size.width, size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        // Paint the radio button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if(altIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            if(!model.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                if(model.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                   altIcon = b.getDisabledSelectedIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                   altIcon = b.getDisabledIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            } else if(model.isPressed() && model.isArmed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                altIcon = b.getPressedIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                if(altIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    // Use selected icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    altIcon = b.getSelectedIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            } else if(model.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                if(b.isRolloverEnabled() && model.isRollover()) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   153
                        altIcon = b.getRolloverSelectedIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                        if (altIcon == null) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   155
                                altIcon = b.getSelectedIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                } else {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   158
                        altIcon = b.getSelectedIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            } else if(b.isRolloverEnabled() && model.isRollover()) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   161
                altIcon = b.getRolloverIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            if(altIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                altIcon = b.getIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            altIcon.paintIcon(c, g, iconRect.x, iconRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            getDefaultIcon().paintIcon(c, g, iconRect.x, iconRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        // Draw the Text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if(text != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            View v = (View) c.getClientProperty(BasicHTML.propertyKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                v.paint(g, textRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                paintText(g, b, textRect, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            if(b.hasFocus() && b.isFocusPainted() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
               textRect.width > 0 && textRect.height > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                paintFocus(g, textRect, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    protected void paintFocus(Graphics g, Rectangle textRect, Dimension size){
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
    /* These Insets/Rectangles are allocated once for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * RadioButtonUI.getPreferredSize() calls.  Re-using rectangles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * rather than allocating them in each call substantially
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * reduced the time it took getPreferredSize() to run.  Obviously,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * this method can't be re-entered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    private static Rectangle prefViewRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private static Rectangle prefIconRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    private static Rectangle prefTextRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    private static Insets prefInsets = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * The preferred size of the radio button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if(c.getComponentCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        AbstractButton b = (AbstractButton) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        String text = b.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   217
        Icon buttonIcon = b.getIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if(buttonIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            buttonIcon = getDefaultIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        Font font = b.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        FontMetrics fm = b.getFontMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        prefViewRect.x = prefViewRect.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        prefViewRect.width = Short.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        prefViewRect.height = Short.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        prefIconRect.x = prefIconRect.y = prefIconRect.width = prefIconRect.height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        prefTextRect.x = prefTextRect.y = prefTextRect.width = prefTextRect.height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        SwingUtilities.layoutCompoundLabel(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            c, fm, text, buttonIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            b.getVerticalAlignment(), b.getHorizontalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            prefViewRect, prefIconRect, prefTextRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            text == null ? 0 : b.getIconTextGap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        // find the union of the icon and text rects (from Rectangle.java)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        int x1 = Math.min(prefIconRect.x, prefTextRect.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        int x2 = Math.max(prefIconRect.x + prefIconRect.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                          prefTextRect.x + prefTextRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        int y1 = Math.min(prefIconRect.y, prefTextRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        int y2 = Math.max(prefIconRect.y + prefIconRect.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                          prefTextRect.y + prefTextRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        int width = x2 - x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        int height = y2 - y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        prefInsets = b.getInsets(prefInsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        width += prefInsets.left + prefInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        height += prefInsets.top + prefInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
}