blob: 5abbf512de2a68b1ab17c0f89eaa1559746a6bdd [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1997-2005 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package com.sun.java.swing.plaf.windows;
27
28import sun.swing.SwingUtilities2;
29import java.awt.Color;
30import java.awt.Graphics;
31
32import javax.swing.JComponent;
33import javax.swing.JLabel;
34import javax.swing.UIManager;
35
36import javax.swing.plaf.ComponentUI;
37
38import javax.swing.plaf.basic.BasicLabelUI;
39
40
41
42/**
43 * Windows rendition of the component.
44 * <p>
45 * <strong>Warning:</strong>
46 * Serialized objects of this class will not be compatible with
47 * future Swing releases. The current serialization support is appropriate
48 * for short term storage or RMI between applications running the same
49 * version of Swing. A future release of Swing will provide support for
50 * long term persistence.
51 */
52public class WindowsLabelUI extends BasicLabelUI {
53
54 private final static WindowsLabelUI windowsLabelUI = new WindowsLabelUI();
55
56 // ********************************
57 // Create PLAF
58 // ********************************
59 public static ComponentUI createUI(JComponent c){
60 return windowsLabelUI;
61 }
62
63 protected void paintEnabledText(JLabel l, Graphics g, String s,
64 int textX, int textY) {
65 int mnemonicIndex = l.getDisplayedMnemonicIndex();
66 // W2K Feature: Check to see if the Underscore should be rendered.
67 if (WindowsLookAndFeel.isMnemonicHidden() == true) {
68 mnemonicIndex = -1;
69 }
70
71 g.setColor(l.getForeground());
72 SwingUtilities2.drawStringUnderlineCharAt(l, g, s, mnemonicIndex,
73 textX, textY);
74 }
75
76 protected void paintDisabledText(JLabel l, Graphics g, String s,
77 int textX, int textY) {
78 int mnemonicIndex = l.getDisplayedMnemonicIndex();
79 // W2K Feature: Check to see if the Underscore should be rendered.
80 if (WindowsLookAndFeel.isMnemonicHidden() == true) {
81 mnemonicIndex = -1;
82 }
83 if ( UIManager.getColor("Label.disabledForeground") instanceof Color &&
84 UIManager.getColor("Label.disabledShadow") instanceof Color) {
85 g.setColor( UIManager.getColor("Label.disabledShadow") );
86 SwingUtilities2.drawStringUnderlineCharAt(l, g, s,
87 mnemonicIndex,
88 textX + 1, textY + 1);
89 g.setColor( UIManager.getColor("Label.disabledForeground") );
90 SwingUtilities2.drawStringUnderlineCharAt(l, g, s,
91 mnemonicIndex,
92 textX, textY);
93 } else {
94 Color background = l.getBackground();
95 g.setColor(background.brighter());
96 SwingUtilities2.drawStringUnderlineCharAt(l,g, s, mnemonicIndex,
97 textX + 1, textY + 1);
98 g.setColor(background.darker());
99 SwingUtilities2.drawStringUnderlineCharAt(l,g, s, mnemonicIndex,
100 textX, textY);
101 }
102 }
103}