38 |
|
|
39 |
package javax.swing.plaf.metal; |
package javax.swing.plaf.metal; |
40 |
|
|
41 |
|
import java.awt.Color; |
42 |
|
import java.awt.Dimension; |
43 |
|
import java.awt.Graphics; |
44 |
|
import java.awt.Rectangle; |
45 |
|
|
46 |
|
import javax.swing.AbstractButton; |
47 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
48 |
|
import javax.swing.JRadioButton; |
49 |
|
import javax.swing.UIDefaults; |
50 |
|
import javax.swing.UIManager; |
51 |
import javax.swing.plaf.ComponentUI; |
import javax.swing.plaf.ComponentUI; |
52 |
import javax.swing.plaf.basic.BasicRadioButtonUI; |
import javax.swing.plaf.basic.BasicRadioButtonUI; |
53 |
|
|
54 |
|
|
55 |
|
/** |
56 |
|
* A UI delegate for the {@link JRadioButton} component under the |
57 |
|
* {@link MetalLookAndFeel}. |
58 |
|
*/ |
59 |
public class MetalRadioButtonUI |
public class MetalRadioButtonUI |
60 |
extends BasicRadioButtonUI |
extends BasicRadioButtonUI |
61 |
{ |
{ |
62 |
|
|
63 |
// FIXME: maybe replace by a Map of instances when this becomes stateful |
/** Used to draw the focus rectangle. */ |
64 |
/** The shared UI instance for JRadioButtons. */ |
protected Color focusColor; |
65 |
private static MetalRadioButtonUI instance = null; |
|
66 |
|
/** Used to fill the icon when the button is pressed. */ |
67 |
|
protected Color selectColor; |
68 |
|
|
69 |
|
/** Used to draw disabled text. */ |
70 |
|
protected Color disabledTextColor; |
71 |
|
|
72 |
/** |
/** |
73 |
* Constructs a new instance of MetalRadioButtonUI. |
* Constructs a new instance of MetalRadioButtonUI. |
74 |
*/ |
*/ |
86 |
*/ |
*/ |
87 |
public static ComponentUI createUI(JComponent component) |
public static ComponentUI createUI(JComponent component) |
88 |
{ |
{ |
89 |
if (instance == null) |
return new MetalRadioButtonUI(); |
90 |
instance = new MetalRadioButtonUI(); |
} |
91 |
return instance; |
|
92 |
|
/** |
93 |
|
* Sets the default values for the specified button. |
94 |
|
* |
95 |
|
* @param b the button. |
96 |
|
*/ |
97 |
|
public void installDefaults(AbstractButton b) |
98 |
|
{ |
99 |
|
super.installDefaults(b); |
100 |
|
UIDefaults defaults = UIManager.getLookAndFeelDefaults(); |
101 |
|
disabledTextColor = defaults.getColor("RadioButton.disabledText"); |
102 |
|
focusColor = defaults.getColor("RadioButton.focus"); |
103 |
|
selectColor = defaults.getColor("RadioButton.select"); |
104 |
|
} |
105 |
|
|
106 |
|
/** |
107 |
|
* Clears any defaults set in the installDefaults() method. |
108 |
|
* |
109 |
|
* @param b the {@link JRadioButton}. |
110 |
|
*/ |
111 |
|
protected void uninstallDefaults(AbstractButton b) |
112 |
|
{ |
113 |
|
super.uninstallDefaults(b); |
114 |
|
disabledTextColor = null; |
115 |
|
focusColor = null; |
116 |
|
selectColor = null; |
117 |
|
} |
118 |
|
|
119 |
|
/** |
120 |
|
* Returns the color used to fill the {@link JRadioButton}'s icon when the |
121 |
|
* button is pressed. The default color is obtained from the |
122 |
|
* {@link UIDefaults} via an entry with the key |
123 |
|
* <code>RadioButton.select</code>. |
124 |
|
* |
125 |
|
* @return The select color. |
126 |
|
*/ |
127 |
|
protected Color getSelectColor() |
128 |
|
{ |
129 |
|
return selectColor; |
130 |
|
} |
131 |
|
|
132 |
|
/** |
133 |
|
* Returns the color for the {@link JRadioButton}'s text when the button is |
134 |
|
* disabled. The default color is obtained from the {@link UIDefaults} via |
135 |
|
* an entry with the key <code>RadioButton.disabledText</code>. |
136 |
|
* |
137 |
|
* @return The disabled text color. |
138 |
|
*/ |
139 |
|
protected Color getDisabledTextColor() |
140 |
|
{ |
141 |
|
return disabledTextColor; |
142 |
|
} |
143 |
|
|
144 |
|
/** |
145 |
|
* Returns the color used to draw the focus rectangle when the |
146 |
|
* {@link JRadioButton} has the focus. The default color is obtained from |
147 |
|
* the {@link UIDefaults} via an entry with the key |
148 |
|
* <code>RadioButton.focus</code>. |
149 |
|
* |
150 |
|
* @return The color used to draw the focus rectangle. |
151 |
|
* |
152 |
|
* @see #paintFocus(Graphics, Rectangle, Dimension) |
153 |
|
*/ |
154 |
|
protected Color getFocusColor() |
155 |
|
{ |
156 |
|
return focusColor; |
157 |
|
} |
158 |
|
|
159 |
|
/** |
160 |
|
* Paints the {@link JRadioButton}. |
161 |
|
* |
162 |
|
* @param g the graphics device. |
163 |
|
* @param c the component (an instance of {@link JRadioButton}). |
164 |
|
*/ |
165 |
|
public void paint(Graphics g, JComponent c) |
166 |
|
{ |
167 |
|
super.paint(g, c); |
168 |
|
// FIXME: disabled text isn't being drawn correctly, it's possible that |
169 |
|
// it could be done here... |
170 |
|
} |
171 |
|
|
172 |
|
/** |
173 |
|
* Paints the focus rectangle for the {@link JRadioButton}. |
174 |
|
* |
175 |
|
* @param g the graphics device. |
176 |
|
* @param t the bounding rectangle for the text. |
177 |
|
* @param d ??? |
178 |
|
*/ |
179 |
|
protected void paintFocus(Graphics g, Rectangle t, Dimension d) |
180 |
|
{ |
181 |
|
g.setColor(focusColor); |
182 |
|
g.drawRect(t.x, t.y, t.width, t.height); |
183 |
|
// FIXME: we seem to be drawing too tight a rectangle here, perhaps there |
184 |
|
// is some padding to do somewhere??? |
185 |
} |
} |
186 |
|
|
187 |
} |
} |