jdk/src/share/classes/javax/swing/plaf/basic/BasicLabelUI.java
author xdono
Mon, 15 Dec 2008 16:55:25 -0800
changeset 1639 a97859015238
parent 1289 43d45f4159b6
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: 1289
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 sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.swing.DefaultLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.swing.UIAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.*;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.event.ActionEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.event.ActionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.event.KeyEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.FontMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * A Windows L&F implementation of LabelUI.  This implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * is completely static, i.e. there's only one UIView implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * that's shared by all JLabel objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @author Hans Muller
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
public class BasicLabelUI extends LabelUI implements  PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    * The default <code>BasicLabelUI</code> instance. This field might
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    * not be used. To change the default instance use a subclass which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    * overrides the <code>createUI</code> method, and place that class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    * name in defaults table under the key "LabelUI".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    protected static BasicLabelUI labelUI = new BasicLabelUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private final static BasicLabelUI SAFE_BASIC_LABEL_UI = new BasicLabelUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
1289
43d45f4159b6 6727829: BasicLabelUI rendering fails if multiple AppContexts exist in same java JVM
mlapshin
parents: 2
diff changeset
    68
    private Rectangle paintIconR = new Rectangle();
43d45f4159b6 6727829: BasicLabelUI rendering fails if multiple AppContexts exist in same java JVM
mlapshin
parents: 2
diff changeset
    69
    private Rectangle paintTextR = new Rectangle();
43d45f4159b6 6727829: BasicLabelUI rendering fails if multiple AppContexts exist in same java JVM
mlapshin
parents: 2
diff changeset
    70
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    static void loadActionMap(LazyActionMap map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        map.put(new Actions(Actions.PRESS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        map.put(new Actions(Actions.RELEASE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Forwards the call to SwingUtilities.layoutCompoundLabel().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * This method is here so that a subclass could do Label specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * layout and to shorten the method name a little.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @see SwingUtilities#layoutCompoundLabel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected String layoutCL(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        JLabel label,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        FontMetrics fontMetrics,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        String text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        Icon icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        Rectangle viewR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        Rectangle iconR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        Rectangle textR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return SwingUtilities.layoutCompoundLabel(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            (JComponent) label,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            fontMetrics,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            label.getVerticalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            label.getHorizontalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            label.getVerticalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            label.getHorizontalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            viewR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            iconR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            textR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            label.getIconTextGap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Paint clippedText at textX, textY with the labels foreground color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @see #paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @see #paintDisabledText
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    protected void paintEnabledText(JLabel l, Graphics g, String s, int textX, int textY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        int mnemIndex = l.getDisplayedMnemonicIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        g.setColor(l.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        SwingUtilities2.drawStringUnderlineCharAt(l, g, s, mnemIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                                     textX, textY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * Paint clippedText at textX, textY with background.lighter() and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * shifted down and to the right by one pixel with background.darker().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @see #paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @see #paintEnabledText
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    protected void paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        int accChar = l.getDisplayedMnemonicIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        Color background = l.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        g.setColor(background.brighter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        SwingUtilities2.drawStringUnderlineCharAt(l, g, s, accChar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                                                   textX + 1, textY + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        g.setColor(background.darker());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        SwingUtilities2.drawStringUnderlineCharAt(l, g, s, accChar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                                                   textX, textY);
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
     * Paint the label text in the foreground color, if the label
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * is opaque then paint the entire background with the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * color.  The Label text is drawn by paintEnabledText() or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * paintDisabledText().  The locations of the label parts are computed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * by layoutCL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @see #paintEnabledText
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @see #paintDisabledText
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @see #layoutCL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public void paint(Graphics g, JComponent c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        JLabel label = (JLabel)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        String text = label.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if ((icon == null) && (text == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        FontMetrics fm = SwingUtilities2.getFontMetrics(label, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        String clippedText = layout(label, fm, c.getWidth(), c.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            icon.paintIcon(c, g, paintIconR.x, paintIconR.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (text != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            View v = (View) c.getClientProperty(BasicHTML.propertyKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                v.paint(g, paintTextR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                int textX = paintTextR.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                int textY = paintTextR.y + fm.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                if (label.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    paintEnabledText(label, g, clippedText, textX, textY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    paintDisabledText(label, g, clippedText, textX, textY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    private String layout(JLabel label, FontMetrics fm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                          int width, int height) {
1289
43d45f4159b6 6727829: BasicLabelUI rendering fails if multiple AppContexts exist in same java JVM
mlapshin
parents: 2
diff changeset
   189
        Insets insets = label.getInsets(null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        String text = label.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        Icon icon = (label.isEnabled()) ? label.getIcon() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                                          label.getDisabledIcon();
1289
43d45f4159b6 6727829: BasicLabelUI rendering fails if multiple AppContexts exist in same java JVM
mlapshin
parents: 2
diff changeset
   193
        Rectangle paintViewR = new Rectangle();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        paintViewR.x = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        paintViewR.y = insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        paintViewR.width = width - (insets.left + insets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        paintViewR.height = height - (insets.top + insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return layoutCL(label, fm, text, icon, paintViewR, paintIconR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                        paintTextR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public Dimension getPreferredSize(JComponent c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        JLabel label = (JLabel)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        String text = label.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        Icon icon = (label.isEnabled()) ? label.getIcon() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                          label.getDisabledIcon();
1289
43d45f4159b6 6727829: BasicLabelUI rendering fails if multiple AppContexts exist in same java JVM
mlapshin
parents: 2
diff changeset
   210
        Insets insets = label.getInsets(null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        Font font = label.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        int dx = insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        int dy = insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if ((icon == null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            ((text == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
             ((text != null) && (font == null)))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            return new Dimension(dx, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        else if ((text == null) || ((icon != null) && (font == null))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            return new Dimension(icon.getIconWidth() + dx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                 icon.getIconHeight() + dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            FontMetrics fm = label.getFontMetrics(font);
1289
43d45f4159b6 6727829: BasicLabelUI rendering fails if multiple AppContexts exist in same java JVM
mlapshin
parents: 2
diff changeset
   227
            Rectangle iconR = new Rectangle();
43d45f4159b6 6727829: BasicLabelUI rendering fails if multiple AppContexts exist in same java JVM
mlapshin
parents: 2
diff changeset
   228
            Rectangle textR = new Rectangle();
43d45f4159b6 6727829: BasicLabelUI rendering fails if multiple AppContexts exist in same java JVM
mlapshin
parents: 2
diff changeset
   229
            Rectangle viewR = new Rectangle();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            iconR.x = iconR.y = iconR.width = iconR.height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            textR.x = textR.y = textR.width = textR.height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            viewR.x = dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            viewR.y = dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            viewR.width = viewR.height = Short.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            layoutCL(label, fm, text, icon, viewR, iconR, textR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            int x1 = Math.min(iconR.x, textR.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            int x2 = Math.max(iconR.x + iconR.width, textR.x + textR.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            int y1 = Math.min(iconR.y, textR.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            int y2 = Math.max(iconR.y + iconR.height, textR.y + textR.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            Dimension rv = new Dimension(x2 - x1, y2 - y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            rv.width += dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            rv.height += dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @return getPreferredSize(c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public Dimension getMinimumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        Dimension d = getPreferredSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            d.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @return getPreferredSize(c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public Dimension getMaximumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        Dimension d = getPreferredSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            d.width += v.getMaximumSpan(View.X_AXIS) - v.getPreferredSpan(View.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Returns the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @throws IllegalArgumentException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public int getBaseline(JComponent c, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        super.getBaseline(c, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        JLabel label = (JLabel)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        String text = label.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (text == null || "".equals(text) || label.getFont() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        FontMetrics fm = label.getFontMetrics(label.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        layout(label, fm, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        return BasicHTML.getBaseline(label, paintTextR.y, fm.getAscent(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                                     paintTextR.width, paintTextR.height);
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
     * Returns an enum indicating how the baseline of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * changes as the size changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public Component.BaselineResizeBehavior getBaselineResizeBehavior(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        super.getBaselineResizeBehavior(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        if (c.getClientProperty(BasicHTML.propertyKey) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            return Component.BaselineResizeBehavior.OTHER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        switch(((JLabel)c).getVerticalAlignment()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        case JLabel.TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        case JLabel.BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            return Component.BaselineResizeBehavior.CONSTANT_DESCENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        case JLabel.CENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            return Component.BaselineResizeBehavior.CENTER_OFFSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        return Component.BaselineResizeBehavior.OTHER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        installDefaults((JLabel)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        installComponents((JLabel)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        installListeners((JLabel)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        installKeyboardActions((JLabel)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        uninstallDefaults((JLabel)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        uninstallComponents((JLabel)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        uninstallListeners((JLabel)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        uninstallKeyboardActions((JLabel)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     protected void installDefaults(JLabel c){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
         LookAndFeel.installColorsAndFont(c, "Label.background", "Label.foreground", "Label.font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
         LookAndFeel.installProperty(c, "opaque", Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    protected void installListeners(JLabel c){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        c.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    protected void installComponents(JLabel c){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        BasicHTML.updateRenderer(c, c.getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        c.setInheritsPopupMenu(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    protected void installKeyboardActions(JLabel l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        int dka = l.getDisplayedMnemonic();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        Component lf = l.getLabelFor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        if ((dka != 0) && (lf != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            LazyActionMap.installLazyActionMap(l, BasicLabelUI.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                                               "Label.actionMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            InputMap inputMap = SwingUtilities.getUIInputMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                            (l, JComponent.WHEN_IN_FOCUSED_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            if (inputMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                inputMap = new ComponentInputMapUIResource(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                SwingUtilities.replaceUIInputMap(l,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                                JComponent.WHEN_IN_FOCUSED_WINDOW, inputMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            inputMap.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            inputMap.put(KeyStroke.getKeyStroke(dka, ActionEvent.ALT_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                                              false), "press");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            InputMap inputMap = SwingUtilities.getUIInputMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                            (l, JComponent.WHEN_IN_FOCUSED_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            if (inputMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                inputMap.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    protected void uninstallDefaults(JLabel c){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    protected void uninstallListeners(JLabel c){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        c.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    protected void uninstallComponents(JLabel c){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        BasicHTML.updateRenderer(c, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    protected void uninstallKeyboardActions(JLabel c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        SwingUtilities.replaceUIInputMap(c, JComponent.WHEN_FOCUSED, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        SwingUtilities.replaceUIInputMap(c, JComponent.WHEN_IN_FOCUSED_WINDOW,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                                       null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        SwingUtilities.replaceUIActionMap(c, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        if (System.getSecurityManager() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            return SAFE_BASIC_LABEL_UI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            return labelUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        String name = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        if (name == "text" || "font" == name || "foreground" == name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            // remove the old html view client property if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            // existed, and install a new one if the text installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            // into the JLabel is html source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            JLabel lbl = ((JLabel) e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            String text = lbl.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            BasicHTML.updateRenderer(lbl, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        else if (name == "labelFor" || name == "displayedMnemonic") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            installKeyboardActions((JLabel) e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    // When the accelerator is pressed, temporarily make the JLabel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    // focusTraversable by registering a WHEN_FOCUSED action for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    // release of the accelerator.  Then give it focus so it can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    // prevent unwanted keyTyped events from getting to other components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    private static class Actions extends UIAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        private static final String PRESS = "press";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        private static final String RELEASE = "release";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        Actions(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            super(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            JLabel label = (JLabel)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            String key = getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            if (key == PRESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                doPress(label);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            else if (key == RELEASE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                doRelease(label);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        private void doPress(JLabel label) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            Component labelFor = label.getLabelFor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            if (labelFor != null && labelFor.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                InputMap inputMap = SwingUtilities.getUIInputMap(label, JComponent.WHEN_FOCUSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                if (inputMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    inputMap = new InputMapUIResource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    SwingUtilities.replaceUIInputMap(label, JComponent.WHEN_FOCUSED, inputMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                int dka = label.getDisplayedMnemonic();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                inputMap.put(KeyStroke.getKeyStroke(dka, ActionEvent.ALT_MASK, true), RELEASE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                // Need this if ALT is released before the accelerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ALT, 0, true), RELEASE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                label.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        private void doRelease(JLabel label) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            Component labelFor = label.getLabelFor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            if (labelFor != null && labelFor.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                InputMap inputMap = SwingUtilities.getUIInputMap(label, JComponent.WHEN_FOCUSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                if (inputMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    // inputMap should never be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    inputMap.remove(KeyStroke.getKeyStroke(label.getDisplayedMnemonic(), ActionEvent.ALT_MASK, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                    inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ALT, 0, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                if (labelFor instanceof Container &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                        ((Container) labelFor).isFocusCycleRoot()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    labelFor.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                    SwingUtilities2.compositeRequestFocus(labelFor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
}