src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsLabelUI.java
changeset 48271 95f173494fe9
parent 48270 f27aad5782da
child 48272 128de6a38f8e
equal deleted inserted replaced
48270:f27aad5782da 48271:95f173494fe9
     1 /*
       
     2  * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package com.sun.java.swing.plaf.windows;
       
    27 
       
    28 import sun.swing.SwingUtilities2;
       
    29 import sun.awt.AppContext;
       
    30 
       
    31 import java.awt.Color;
       
    32 import java.awt.Graphics;
       
    33 
       
    34 import javax.swing.JComponent;
       
    35 import javax.swing.JLabel;
       
    36 import javax.swing.UIManager;
       
    37 
       
    38 import javax.swing.plaf.ComponentUI;
       
    39 
       
    40 import javax.swing.plaf.basic.BasicLabelUI;
       
    41 
       
    42 
       
    43 
       
    44 /**
       
    45  * Windows rendition of the component.
       
    46  * <p>
       
    47  * <strong>Warning:</strong>
       
    48  * Serialized objects of this class will not be compatible with
       
    49  * future Swing releases.  The current serialization support is appropriate
       
    50  * for short term storage or RMI between applications running the same
       
    51  * version of Swing.  A future release of Swing will provide support for
       
    52  * long term persistence.
       
    53  */
       
    54 public class WindowsLabelUI extends BasicLabelUI {
       
    55 
       
    56     private static final Object WINDOWS_LABEL_UI_KEY = new Object();
       
    57 
       
    58     // ********************************
       
    59     //          Create PLAF
       
    60     // ********************************
       
    61     public static ComponentUI createUI(JComponent c) {
       
    62         AppContext appContext = AppContext.getAppContext();
       
    63         WindowsLabelUI windowsLabelUI =
       
    64                 (WindowsLabelUI) appContext.get(WINDOWS_LABEL_UI_KEY);
       
    65         if (windowsLabelUI == null) {
       
    66             windowsLabelUI = new WindowsLabelUI();
       
    67             appContext.put(WINDOWS_LABEL_UI_KEY, windowsLabelUI);
       
    68         }
       
    69         return windowsLabelUI;
       
    70     }
       
    71 
       
    72     protected void paintEnabledText(JLabel l, Graphics g, String s,
       
    73                                     int textX, int textY) {
       
    74         int mnemonicIndex = l.getDisplayedMnemonicIndex();
       
    75         // W2K Feature: Check to see if the Underscore should be rendered.
       
    76         if (WindowsLookAndFeel.isMnemonicHidden() == true) {
       
    77             mnemonicIndex = -1;
       
    78         }
       
    79 
       
    80         g.setColor(l.getForeground());
       
    81         SwingUtilities2.drawStringUnderlineCharAt(l, g, s, mnemonicIndex,
       
    82                                                      textX, textY);
       
    83     }
       
    84 
       
    85     protected void paintDisabledText(JLabel l, Graphics g, String s,
       
    86                                      int textX, int textY) {
       
    87         int mnemonicIndex = l.getDisplayedMnemonicIndex();
       
    88         // W2K Feature: Check to see if the Underscore should be rendered.
       
    89         if (WindowsLookAndFeel.isMnemonicHidden() == true) {
       
    90             mnemonicIndex = -1;
       
    91         }
       
    92         if ( UIManager.getColor("Label.disabledForeground") instanceof Color &&
       
    93              UIManager.getColor("Label.disabledShadow") instanceof Color) {
       
    94             g.setColor( UIManager.getColor("Label.disabledShadow") );
       
    95             SwingUtilities2.drawStringUnderlineCharAt(l, g, s,
       
    96                                                          mnemonicIndex,
       
    97                                                          textX + 1, textY + 1);
       
    98             g.setColor( UIManager.getColor("Label.disabledForeground") );
       
    99             SwingUtilities2.drawStringUnderlineCharAt(l, g, s,
       
   100                                                          mnemonicIndex,
       
   101                                                          textX, textY);
       
   102         } else {
       
   103             Color background = l.getBackground();
       
   104             g.setColor(background.brighter());
       
   105             SwingUtilities2.drawStringUnderlineCharAt(l,g, s, mnemonicIndex,
       
   106                                                          textX + 1, textY + 1);
       
   107             g.setColor(background.darker());
       
   108             SwingUtilities2.drawStringUnderlineCharAt(l,g, s, mnemonicIndex,
       
   109                                                          textX, textY);
       
   110         }
       
   111     }
       
   112 }