1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46:
47: import ;
48: import ;
49: import ;
50: import ;
51:
52:
55: public class BasicIconFactory implements Serializable
56: {
57: static final long serialVersionUID = 5605588811185324383L;
58:
59: private static class DummyIcon
60: implements Icon
61: {
62: public int getIconHeight() { return 10; }
63: public int getIconWidth() { return 10; }
64: public void paintIcon(Component c, Graphics g, int x, int y)
65: {
66: Color save = g.getColor();
67: g.setColor(c.getForeground());
68: g.drawRect(x, y, 10, 10);
69: g.setColor(save);
70: }
71: }
72:
73:
74: public BasicIconFactory()
75: {
76: }
77: public static Icon getMenuItemCheckIcon()
78: {
79: return new DummyIcon();
80: }
81: public static Icon getMenuItemArrowIcon()
82: {
83: return new DummyIcon();
84: }
85: public static Icon getMenuArrowIcon()
86: {
87: return new Icon()
88: {
89: public int getIconHeight()
90: {
91: return 12;
92: }
93:
94: public int getIconWidth()
95: {
96: return 12;
97: }
98:
99: public void paintIcon(Component c, Graphics g, int x, int y)
100: {
101: g.translate(x, y);
102:
103: Color saved = g.getColor();
104:
105: g.setColor(Color.BLACK);
106:
107: g.fillPolygon(new Polygon(new int[] { 3, 9, 3 },
108: new int[] { 2, 6, 10 },
109: 3));
110:
111: g.setColor(saved);
112: g.translate(-x, -y);
113: }
114: };
115: }
116:
117: public static Icon getCheckBoxIcon()
118: {
119: return new Icon()
120: {
121: public int getIconHeight()
122: {
123: return 10;
124: }
125: public int getIconWidth()
126: {
127: return 10;
128: }
129: public void paintIcon(Component c, Graphics g, int x, int y)
130: {
131: if (c instanceof AbstractButton)
132: {
133: UIDefaults defaults;
134: defaults = UIManager.getLookAndFeelDefaults();
135: Color hi = defaults.getColor("CheckBox.highlight");
136: Color low = defaults.getColor("CheckBox.darkShadow");
137: Color sel = defaults.getColor("CheckBox.foreground");
138: Color dim = defaults.getColor("CheckBox.shadow");
139: Polygon check = new Polygon(new int[] {x+3, x+3, x+8},
140: new int[] {y+5, y+9, y+3}, 3);
141: AbstractButton b = (AbstractButton) c;
142: Color saved = g.getColor();
143: if (b.isEnabled())
144: {
145: g.setColor(low);
146: g.drawRect(x, y, 10, 10);
147: g.setColor(hi);
148: g.drawRect(x+1, y+1, 10, 10);
149: if (b.isSelected())
150: {
151: g.setColor(sel);
152: if (b.isSelected())
153: {
154: g.drawLine(x+3, y+5, x+3, y+8);
155: g.drawLine(x+4, y+5, x+4, y+8);
156: g.drawLine(x+3, y+8, x+8, y+3);
157: g.drawLine(x+4, y+8, x+8, y+3);
158: }
159: }
160: }
161: else
162: {
163: g.setColor(hi);
164: g.drawRect(x, y, 10, 10);
165: if (b.isSelected())
166: {
167: g.drawLine(x+3, y+5, x+3, y+9);
168: g.drawLine(x+3, y+9, x+8, y+3);
169: }
170: }
171: g.setColor(saved);
172: }
173: }
174: };
175: }
176:
177: public static Icon getRadioButtonIcon()
178: {
179: return new Icon()
180: {
181: public int getIconHeight()
182: {
183: return 12;
184: }
185: public int getIconWidth()
186: {
187: return 12;
188: }
189: public void paintIcon(Component c, Graphics g, int x, int y)
190: {
191: UIDefaults defaults;
192: defaults = UIManager.getLookAndFeelDefaults();
193: Color hi = defaults.getColor("RadioButton.highlight");
194: Color low = defaults.getColor("RadioButton.darkShadow");
195: Color sel = defaults.getColor("RadioButton.foreground");
196: Color dim = defaults.getColor("RadioButton.shadow");
197:
198: if (c instanceof AbstractButton)
199: {
200: AbstractButton b = (AbstractButton) c;
201: Color saved = g.getColor();
202: if (b.isEnabled())
203: {
204: g.setColor(low);
205: g.drawOval(x, y, 12, 12);
206: g.setColor(hi);
207: g.drawOval(x+1, y+1, 12, 12);
208: if (b.isSelected())
209: {
210: g.setColor(sel);
211: g.fillOval(x+4, y+4, 6, 6);
212: }
213: }
214: else
215: {
216: g.setColor(hi);
217: g.drawOval(x, y, 12, 12);
218: if (b.isSelected())
219: g.fillOval(x+4, y+4, 6, 6);
220: }
221: g.setColor(saved);
222: }
223: }
224: };
225: }
226: public static Icon getCheckBoxMenuItemIcon()
227: {
228: return getCheckBoxIcon();
229: }
230: public static Icon getRadioButtonMenuItemIcon()
231: {
232: return getRadioButtonIcon();
233: }
234: public static Icon createEmptyFrameIcon()
235: {
236: return new DummyIcon();
237: }
238: }