KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > windows > WindowsLabelUI


1 /*
2  * @(#)WindowsLabelUI.java 1.18 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.java.swing.plaf.windows;
9
10 import com.sun.java.swing.SwingUtilities2;
11 import java.awt.Color JavaDoc;
12 import java.awt.Graphics JavaDoc;
13
14 import javax.swing.JComponent JavaDoc;
15 import javax.swing.JLabel JavaDoc;
16 import javax.swing.UIManager JavaDoc;
17
18 import javax.swing.plaf.ComponentUI JavaDoc;
19
20 import javax.swing.plaf.basic.BasicLabelUI JavaDoc;
21
22
23
24 /**
25  * Windows rendition of the component.
26  * <p>
27  * <strong>Warning:</strong>
28  * Serialized objects of this class will not be compatible with
29  * future Swing releases. The current serialization support is appropriate
30  * for short term storage or RMI between applications running the same
31  * version of Swing. A future release of Swing will provide support for
32  * long term persistence.
33  */

34 public class WindowsLabelUI extends BasicLabelUI JavaDoc {
35
36     private final static WindowsLabelUI windowsLabelUI = new WindowsLabelUI();
37
38     // ********************************
39
// Create PLAF
40
// ********************************
41
public static ComponentUI JavaDoc createUI(JComponent JavaDoc c){
42     return windowsLabelUI;
43     }
44
45     protected void paintEnabledText(JLabel JavaDoc l, Graphics JavaDoc g, String JavaDoc s,
46                     int textX, int textY) {
47     int mnemonicIndex = l.getDisplayedMnemonicIndex();
48     // W2K Feature: Check to see if the Underscore should be rendered.
49
if (WindowsLookAndFeel.isMnemonicHidden() == true) {
50         mnemonicIndex = -1;
51     }
52
53         g.setColor(l.getForeground());
54         SwingUtilities2.drawStringUnderlineCharAt(l, g, s, mnemonicIndex,
55                                                      textX, textY);
56     }
57
58     protected void paintDisabledText(JLabel JavaDoc l, Graphics JavaDoc g, String JavaDoc s,
59                      int textX, int textY) {
60     int mnemonicIndex = l.getDisplayedMnemonicIndex();
61     // W2K Feature: Check to see if the Underscore should be rendered.
62
if (WindowsLookAndFeel.isMnemonicHidden() == true) {
63         mnemonicIndex = -1;
64     }
65     if ( UIManager.getColor("Label.disabledForeground") instanceof Color JavaDoc &&
66          UIManager.getColor("Label.disabledShadow") instanceof Color JavaDoc) {
67         g.setColor( UIManager.getColor("Label.disabledShadow") );
68         SwingUtilities2.drawStringUnderlineCharAt(l, g, s,
69                              mnemonicIndex,
70                              textX + 1, textY + 1);
71         g.setColor( UIManager.getColor("Label.disabledForeground") );
72         SwingUtilities2.drawStringUnderlineCharAt(l, g, s,
73                              mnemonicIndex,
74                              textX, textY);
75     } else {
76         Color JavaDoc background = l.getBackground();
77         g.setColor(background.brighter());
78         SwingUtilities2.drawStringUnderlineCharAt(l,g, s, mnemonicIndex,
79                              textX + 1, textY + 1);
80         g.setColor(background.darker());
81             SwingUtilities2.drawStringUnderlineCharAt(l,g, s, mnemonicIndex,
82                              textX, textY);
83     }
84     }
85 }
86
87
Popular Tags