38 |
|
|
39 |
package javax.swing.plaf.metal; |
package javax.swing.plaf.metal; |
40 |
|
|
41 |
|
import java.awt.Color; |
42 |
|
import java.awt.Graphics; |
43 |
|
|
44 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
45 |
|
import javax.swing.JLabel; |
46 |
|
import javax.swing.UIDefaults; |
47 |
|
import javax.swing.UIManager; |
48 |
import javax.swing.plaf.ComponentUI; |
import javax.swing.plaf.ComponentUI; |
49 |
|
import javax.swing.plaf.basic.BasicGraphicsUtils; |
50 |
import javax.swing.plaf.basic.BasicLabelUI; |
import javax.swing.plaf.basic.BasicLabelUI; |
51 |
|
|
52 |
|
/** |
53 |
|
* A UI delegate used for {@link JLabel}s in the {@link MetalLookAndFeel}. |
54 |
|
*/ |
55 |
public class MetalLabelUI |
public class MetalLabelUI |
56 |
extends BasicLabelUI |
extends BasicLabelUI |
57 |
{ |
{ |
58 |
|
|
|
// FIXME: maybe replace by a Map of instances when this becomes stateful |
|
59 |
/** The shared UI instance for JLabels. */ |
/** The shared UI instance for JLabels. */ |
60 |
private static MetalLabelUI instance = null; |
protected static MetalLabelUI metalLabelUI; |
61 |
|
|
62 |
/** |
/** |
63 |
* Constructs a new instance of MetalLabelUI. |
* Constructs a new instance of MetalLabelUI. |
76 |
*/ |
*/ |
77 |
public static ComponentUI createUI(JComponent component) |
public static ComponentUI createUI(JComponent component) |
78 |
{ |
{ |
79 |
if (instance == null) |
if (metalLabelUI == null) |
80 |
instance = new MetalLabelUI(); |
metalLabelUI = new MetalLabelUI(); |
81 |
return instance; |
return metalLabelUI; |
82 |
|
} |
83 |
|
|
84 |
|
/** |
85 |
|
* Draws the text for a disabled label, using the color defined in the |
86 |
|
* {@link UIDefaults} with the key <code>Label.disabledForeground</code>. |
87 |
|
* |
88 |
|
* @param l the label. |
89 |
|
* @param g the graphics device. |
90 |
|
* @param s the label text. |
91 |
|
* @param textX the x-coordinate for the label. |
92 |
|
* @param textY the y-coordinate for the label. |
93 |
|
* |
94 |
|
* @see UIManager#getLookAndFeelDefaults() |
95 |
|
*/ |
96 |
|
protected void paintDisabledText(JLabel l, Graphics g, String s, int textX, |
97 |
|
int textY) |
98 |
|
{ |
99 |
|
Color savedColor = g.getColor(); |
100 |
|
UIDefaults defaults = UIManager.getLookAndFeelDefaults(); |
101 |
|
g.setColor(defaults.getColor("Label.disabledForeground")); |
102 |
|
int mnemIndex = l.getDisplayedMnemonicIndex(); |
103 |
|
if (mnemIndex != -1) |
104 |
|
BasicGraphicsUtils.drawStringUnderlineCharAt(g, s, mnemIndex, textX, |
105 |
|
textY); |
106 |
|
else |
107 |
|
g.drawString(s, textX, textY); |
108 |
|
|
109 |
|
g.setColor(savedColor); |
110 |
} |
} |
111 |
} |
} |