22 |
package gnu.classpath.examples.swing; |
package gnu.classpath.examples.swing; |
23 |
|
|
24 |
import java.awt.Color; |
import java.awt.Color; |
25 |
|
import java.awt.Component; |
26 |
|
import java.awt.Graphics; |
27 |
|
|
28 |
|
import javax.swing.Icon; |
29 |
import javax.swing.ImageIcon; |
import javax.swing.ImageIcon; |
30 |
|
import javax.swing.JCheckBox; |
31 |
|
import javax.swing.JRadioButton; |
32 |
import javax.swing.UIDefaults; |
import javax.swing.UIDefaults; |
33 |
import javax.swing.plaf.ColorUIResource; |
import javax.swing.plaf.ColorUIResource; |
34 |
import javax.swing.plaf.IconUIResource; |
import javax.swing.plaf.IconUIResource; |
69 |
"MenuBar.background", new ColorUIResource(blueGray), |
"MenuBar.background", new ColorUIResource(blueGray), |
70 |
"MenuItem.background", new ColorUIResource(blueGray), |
"MenuItem.background", new ColorUIResource(blueGray), |
71 |
"ScrollBar.background", new ColorUIResource(blueGray), |
"ScrollBar.background", new ColorUIResource(blueGray), |
72 |
|
"CheckBox.icon", new CheckBoxIcon(), |
73 |
"Tree.closedIcon", |
"RadioButton.icon", new RadioButtonIcon(), |
74 |
|
|
75 |
|
"Tree.closedIcon", |
76 |
new IconUIResource(new ImageIcon |
new IconUIResource(new ImageIcon |
77 |
(getClass().getResource |
(getClass().getResource |
78 |
(iconspath + "TreeClosed.png"))), |
(iconspath + "TreeClosed.png"))), |
89 |
} |
} |
90 |
return LAF_defaults; |
return LAF_defaults; |
91 |
} |
} |
92 |
|
|
93 |
|
/** |
94 |
|
* The icon used for CheckBoxes in the BasicLookAndFeel. This is an empty |
95 |
|
* icon with a size of 13x13 pixels. |
96 |
|
*/ |
97 |
|
static class CheckBoxIcon |
98 |
|
implements Icon |
99 |
|
{ |
100 |
|
/** |
101 |
|
* Returns the height of the icon. The BasicLookAndFeel CheckBox icon |
102 |
|
* has a height of 13 pixels. |
103 |
|
* |
104 |
|
* @return the height of the icon |
105 |
|
*/ |
106 |
|
public int getIconHeight() |
107 |
|
{ |
108 |
|
return 13; |
109 |
|
} |
110 |
|
|
111 |
|
/** |
112 |
|
* Returns the width of the icon. The BasicLookAndFeel CheckBox icon |
113 |
|
* has a width of 13 pixels. |
114 |
|
* |
115 |
|
* @return the height of the icon |
116 |
|
*/ |
117 |
|
public int getIconWidth() |
118 |
|
{ |
119 |
|
return 13; |
120 |
|
} |
121 |
|
|
122 |
|
/** |
123 |
|
* Paints the icon. The BasicLookAndFeel CheckBox icon is empty and does |
124 |
|
* not need to be painted. |
125 |
|
* |
126 |
|
* @param c the component to be painted |
127 |
|
* @param g the Graphics context to be painted with |
128 |
|
* @param x the x position of the icon |
129 |
|
* @param y the y position of the icon |
130 |
|
*/ |
131 |
|
public void paintIcon(Component c, Graphics g, int x, int y) |
132 |
|
{ |
133 |
|
Color save = g.getColor(); |
134 |
|
g.setColor(c.getForeground()); |
135 |
|
g.drawRect(x, y, getIconWidth(), getIconHeight()); |
136 |
|
|
137 |
|
JCheckBox item = (JCheckBox) c; |
138 |
|
if (item.isSelected()) |
139 |
|
{ |
140 |
|
g.drawLine(3 + x, 5 + y, 3 + x, 9 + y); |
141 |
|
g.drawLine(4 + x, 5 + y, 4 + x, 9 + y); |
142 |
|
g.drawLine(5 + x, 7 + y, 9 + x, 3 + y); |
143 |
|
g.drawLine(5 + x, 8 + y, 9 + x, 4 + y); |
144 |
|
} |
145 |
|
|
146 |
|
g.setColor(save); |
147 |
|
} |
148 |
|
} |
149 |
|
|
150 |
|
/** |
151 |
|
* The icon used for RadioButtons in the GNULookAndFeel. This is an empty |
152 |
|
* icon with a size of 13x13 pixels. |
153 |
|
*/ |
154 |
|
static class RadioButtonIcon |
155 |
|
implements Icon |
156 |
|
{ |
157 |
|
/** |
158 |
|
* Returns the height of the icon. The GNULookAndFeel RadioButton icon |
159 |
|
* has a height of 13 pixels. |
160 |
|
* |
161 |
|
* @return the height of the icon |
162 |
|
*/ |
163 |
|
public int getIconHeight() |
164 |
|
{ |
165 |
|
return 13; |
166 |
|
} |
167 |
|
|
168 |
|
/** |
169 |
|
* Returns the width of the icon. The GNULookAndFeel RadioButton icon |
170 |
|
* has a width of 13 pixels. |
171 |
|
* |
172 |
|
* @return the height of the icon |
173 |
|
*/ |
174 |
|
public int getIconWidth() |
175 |
|
{ |
176 |
|
return 13; |
177 |
|
} |
178 |
|
|
179 |
|
/** |
180 |
|
* Paints the icon. The GNULookAndFeel RadioButton icon is empty and does |
181 |
|
* not need to be painted. |
182 |
|
* |
183 |
|
* @param c the component to be painted |
184 |
|
* @param g the Graphics context to be painted with |
185 |
|
* @param x the x position of the icon |
186 |
|
* @param y the y position of the icon |
187 |
|
*/ |
188 |
|
public void paintIcon(Component c, Graphics g, int x, int y) |
189 |
|
{ |
190 |
|
Color savedColor = g.getColor(); |
191 |
|
JRadioButton b = (JRadioButton) c; |
192 |
|
|
193 |
|
// draw outer circle |
194 |
|
if (b.isEnabled()) |
195 |
|
g.setColor(Color.GRAY); |
196 |
|
else |
197 |
|
g.setColor(Color.GRAY); |
198 |
|
g.drawLine(x + 2, y + 1, x + 3, y + 1); |
199 |
|
g.drawLine(x + 4, y, x + 7, y); |
200 |
|
g.drawLine(x + 8, y + 1, x + 9, y + 1); |
201 |
|
g.drawLine(x + 10, y + 2, x + 10, y + 3); |
202 |
|
g.drawLine(x + 11, y + 4, x + 11, y + 7); |
203 |
|
g.drawLine(x + 10, y + 8, x + 10, y + 9); |
204 |
|
g.drawLine(x + 8, y + 10, x + 9, y + 10); |
205 |
|
g.drawLine(x + 4, y + 11, x + 7, y + 11); |
206 |
|
g.drawLine(x + 2, y + 10, x + 3, y + 10); |
207 |
|
g.drawLine(x + 1, y + 9, x + 1, y + 8); |
208 |
|
g.drawLine(x, y + 7, x, y + 4); |
209 |
|
g.drawLine(x + 1, y + 2, x + 1, y + 3); |
210 |
|
|
211 |
|
if (b.getModel().isArmed()) |
212 |
|
{ |
213 |
|
g.setColor(Color.GRAY); |
214 |
|
g.drawLine(x + 4, y + 1, x + 7, y + 1); |
215 |
|
g.drawLine(x + 4, y + 10, x + 7, y + 10); |
216 |
|
g.drawLine(x + 1, y + 4, x + 1, y + 7); |
217 |
|
g.drawLine(x + 10, y + 4, x + 10, y + 7); |
218 |
|
g.fillRect(x + 2, y + 2, 8, 8); |
219 |
|
} |
220 |
|
else |
221 |
|
{ |
222 |
|
// only draw inner highlight if not filled |
223 |
|
if (b.isEnabled()) |
224 |
|
{ |
225 |
|
g.setColor(Color.WHITE); |
226 |
|
|
227 |
|
g.drawLine(x + 2, y + 8, x + 2, y + 9); |
228 |
|
g.drawLine(x + 1, y + 4, x + 1, y + 7); |
229 |
|
g.drawLine(x + 2, y + 2, x + 2, y + 3); |
230 |
|
g.drawLine(x + 3, y + 2, x + 3, y + 2); |
231 |
|
g.drawLine(x + 4, y + 1, x + 7, y + 1); |
232 |
|
g.drawLine(x + 8, y + 2, x + 9, y + 2); |
233 |
|
} |
234 |
|
} |
235 |
|
|
236 |
|
// draw outer highlight |
237 |
|
if (b.isEnabled()) |
238 |
|
{ |
239 |
|
g.setColor(Color.WHITE); |
240 |
|
|
241 |
|
// outer |
242 |
|
g.drawLine(x + 10, y + 1, x + 10, y + 1); |
243 |
|
g.drawLine(x + 11, y + 2, x + 11, y + 3); |
244 |
|
g.drawLine(x + 12, y + 4, x + 12, y + 7); |
245 |
|
g.drawLine(x + 11, y + 8, x + 11, y + 9); |
246 |
|
g.drawLine(x + 10, y + 10, x + 10, y + 10); |
247 |
|
g.drawLine(x + 8, y + 11, x + 9, y + 11); |
248 |
|
g.drawLine(x + 4, y + 12, x + 7, y + 12); |
249 |
|
g.drawLine(x + 2, y + 11, x + 3, y + 11); |
250 |
|
} |
251 |
|
|
252 |
|
if (b.isSelected()) |
253 |
|
{ |
254 |
|
if (b.isEnabled()) |
255 |
|
g.setColor(Color.BLACK); |
256 |
|
else |
257 |
|
g.setColor(Color.GRAY); |
258 |
|
g.drawLine(x + 4, y + 3, x + 7, y + 3); |
259 |
|
g.fillRect(x + 3, y + 4, 6, 4); |
260 |
|
g.drawLine(x + 4, y + 8, x + 7, y + 8); |
261 |
|
} |
262 |
|
g.setColor(savedColor); |
263 |
|
} |
264 |
|
} |
265 |
} |
} |