jdk/src/share/classes/javax/swing/plaf/metal/MetalLabelUI.java
author yan
Mon, 30 Jun 2014 16:32:36 +0400
changeset 25178 dbab904451e9
parent 23010 6dadb192ad81
permissions -rw-r--r--
8046434: Fix doclint warnings from javax.swing.plaf.metal package Reviewed-by: alexsch Contributed-by: Andrei Eremeev <andrei.eremeev@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 20169
diff changeset
     2
 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4225
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4225
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4225
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4225
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4225
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.plaf.metal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.swing.SwingUtilities2;
4225
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    29
import sun.awt.AppContext;
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    30
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
    40
 * A Windows L&amp;F implementation of LabelUI.  This implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * is completely static, i.e. there's only one UIView implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * that's shared by all JLabel objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author Hans Muller
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public class MetalLabelUI extends BasicLabelUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    * The default <code>MetalLabelUI</code> instance. This field might
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    * not be used. To change the default instance use a subclass which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    * overrides the <code>createUI</code> method, and place that class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    * name in defaults table under the key "LabelUI".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    protected static MetalLabelUI metalLabelUI = new MetalLabelUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
4225
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    57
    private static final Object METAL_LABEL_UI_KEY = new Object();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
    59
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
    60
     * Returns an instance of {@code MetalLabelUI}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
    61
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
    62
     * @param c a component
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
    63
     * @return an instance of {@code MetalLabelUI}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
    64
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        if (System.getSecurityManager() != null) {
4225
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    67
            AppContext appContext = AppContext.getAppContext();
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    68
            MetalLabelUI safeMetalLabelUI =
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    69
                    (MetalLabelUI) appContext.get(METAL_LABEL_UI_KEY);
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    70
            if (safeMetalLabelUI == null) {
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    71
                safeMetalLabelUI = new MetalLabelUI();
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    72
                appContext.put(METAL_LABEL_UI_KEY, safeMetalLabelUI);
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    73
            }
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    74
            return safeMetalLabelUI;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
4225
57ec8171fcd5 6657138: Mutable statics in Windows PL&F (findbugs)
alexp
parents: 2
diff changeset
    76
        return metalLabelUI;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Just paint the text gray (Label.disabledForeground) rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * in the labels foreground color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @see #paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @see #paintEnabledText
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    protected void paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        int mnemIndex = l.getDisplayedMnemonicIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        g.setColor(UIManager.getColor("Label.disabledForeground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        SwingUtilities2.drawStringUnderlineCharAt(l, g, s, mnemIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                                   textX, textY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
}