author | weijun |
Thu, 11 Dec 2014 15:19:12 +0800 | |
changeset 28228 | be83f404724d |
parent 25859 | 3317bb8137f4 |
child 32865 | f9cb6e427f9e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22574
7f8ce0c8c20a
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents:
20458
diff
changeset
|
2 |
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.swing.plaf.basic; |
|
27 |
||
28 |
import javax.swing.*; |
|
29 |
import javax.swing.plaf.UIResource; |
|
30 |
||
31 |
import java.awt.Graphics; |
|
32 |
import java.awt.Color; |
|
33 |
import java.awt.Component; |
|
34 |
import java.awt.Polygon; |
|
35 |
import java.io.Serializable; |
|
36 |
||
37 |
/** |
|
20169 | 38 |
* Factory object that can vend Icons appropriate for the basic L & F. |
2 | 39 |
* <p> |
40 |
* <strong>Warning:</strong> |
|
41 |
* Serialized objects of this class will not be compatible with |
|
42 |
* future Swing releases. The current serialization support is |
|
43 |
* appropriate for short term storage or RMI between applications running |
|
44 |
* the same version of Swing. As of 1.4, support for long term storage |
|
20458 | 45 |
* of all JavaBeans™ |
2 | 46 |
* has been added to the <code>java.beans</code> package. |
47 |
* Please see {@link java.beans.XMLEncoder}. |
|
48 |
* |
|
49 |
* @author David Kloba |
|
50 |
* @author Georges Saab |
|
51 |
*/ |
|
22574
7f8ce0c8c20a
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents:
20458
diff
changeset
|
52 |
@SuppressWarnings("serial") // Same-version serialization only |
2 | 53 |
public class BasicIconFactory implements Serializable |
54 |
{ |
|
55 |
private static Icon frame_icon; |
|
56 |
private static Icon checkBoxIcon; |
|
57 |
private static Icon radioButtonIcon; |
|
58 |
private static Icon checkBoxMenuItemIcon; |
|
59 |
private static Icon radioButtonMenuItemIcon; |
|
60 |
private static Icon menuItemCheckIcon; |
|
61 |
private static Icon menuItemArrowIcon; |
|
62 |
private static Icon menuArrowIcon; |
|
63 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
64 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
65 |
* Returns a menu item check icon. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
66 |
* |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
67 |
* @return a menu item check icon |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
68 |
*/ |
2 | 69 |
public static Icon getMenuItemCheckIcon() { |
70 |
if (menuItemCheckIcon == null) { |
|
71 |
menuItemCheckIcon = new MenuItemCheckIcon(); |
|
72 |
} |
|
73 |
return menuItemCheckIcon; |
|
74 |
} |
|
75 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
76 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
77 |
* Returns a menu item arrow icon. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
78 |
* |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
79 |
* @return a menu item arrow icon |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
80 |
*/ |
2 | 81 |
public static Icon getMenuItemArrowIcon() { |
82 |
if (menuItemArrowIcon == null) { |
|
83 |
menuItemArrowIcon = new MenuItemArrowIcon(); |
|
84 |
} |
|
85 |
return menuItemArrowIcon; |
|
86 |
} |
|
87 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
88 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
89 |
* Returns a menu arrow icon. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
90 |
* |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
91 |
* @return a menu arrow icon |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
92 |
*/ |
2 | 93 |
public static Icon getMenuArrowIcon() { |
94 |
if (menuArrowIcon == null) { |
|
95 |
menuArrowIcon = new MenuArrowIcon(); |
|
96 |
} |
|
97 |
return menuArrowIcon; |
|
98 |
} |
|
99 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
100 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
101 |
* Returns a check box icon. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
102 |
* |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
103 |
* @return a check box icon |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
104 |
*/ |
2 | 105 |
public static Icon getCheckBoxIcon() { |
106 |
if (checkBoxIcon == null) { |
|
107 |
checkBoxIcon = new CheckBoxIcon(); |
|
108 |
} |
|
109 |
return checkBoxIcon; |
|
110 |
} |
|
111 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
112 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
113 |
* Returns a radio button icon. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
114 |
* |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
115 |
* @return a radio button icon |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
116 |
*/ |
2 | 117 |
public static Icon getRadioButtonIcon() { |
118 |
if (radioButtonIcon == null) { |
|
119 |
radioButtonIcon = new RadioButtonIcon(); |
|
120 |
} |
|
121 |
return radioButtonIcon; |
|
122 |
} |
|
123 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
124 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
125 |
* Returns a check box menu item icon. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
126 |
* |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
127 |
* @return a check box menu item icon |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
128 |
*/ |
2 | 129 |
public static Icon getCheckBoxMenuItemIcon() { |
130 |
if (checkBoxMenuItemIcon == null) { |
|
131 |
checkBoxMenuItemIcon = new CheckBoxMenuItemIcon(); |
|
132 |
} |
|
133 |
return checkBoxMenuItemIcon; |
|
134 |
} |
|
135 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
136 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
137 |
* Returns a radio button menu item icon. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
138 |
* |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
139 |
* @return a radio button menu item icon |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
140 |
*/ |
2 | 141 |
public static Icon getRadioButtonMenuItemIcon() { |
142 |
if (radioButtonMenuItemIcon == null) { |
|
143 |
radioButtonMenuItemIcon = new RadioButtonMenuItemIcon(); |
|
144 |
} |
|
145 |
return radioButtonMenuItemIcon; |
|
146 |
} |
|
147 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
148 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
149 |
* Returns an empty frame icon. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
150 |
* |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
151 |
* @return an empty frame icon |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
22574
diff
changeset
|
152 |
*/ |
2 | 153 |
public static Icon createEmptyFrameIcon() { |
154 |
if(frame_icon == null) |
|
155 |
frame_icon = new EmptyFrameIcon(); |
|
156 |
return frame_icon; |
|
157 |
} |
|
158 |
||
159 |
private static class EmptyFrameIcon implements Icon, Serializable { |
|
160 |
int height = 16; |
|
161 |
int width = 14; |
|
162 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
163 |
} |
|
164 |
public int getIconWidth() { return width; } |
|
165 |
public int getIconHeight() { return height; } |
|
166 |
}; |
|
167 |
||
168 |
private static class CheckBoxIcon implements Icon, Serializable |
|
169 |
{ |
|
170 |
final static int csize = 13; |
|
171 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
172 |
} |
|
173 |
||
174 |
public int getIconWidth() { |
|
175 |
return csize; |
|
176 |
} |
|
177 |
||
178 |
public int getIconHeight() { |
|
179 |
return csize; |
|
180 |
} |
|
181 |
} |
|
182 |
||
183 |
private static class RadioButtonIcon implements Icon, UIResource, Serializable |
|
184 |
{ |
|
185 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
186 |
} |
|
187 |
||
188 |
public int getIconWidth() { |
|
189 |
return 13; |
|
190 |
} |
|
191 |
||
192 |
public int getIconHeight() { |
|
193 |
return 13; |
|
194 |
} |
|
195 |
} // end class RadioButtonIcon |
|
196 |
||
197 |
||
198 |
private static class CheckBoxMenuItemIcon implements Icon, UIResource, Serializable |
|
199 |
{ |
|
200 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
201 |
AbstractButton b = (AbstractButton) c; |
|
202 |
ButtonModel model = b.getModel(); |
|
203 |
boolean isSelected = model.isSelected(); |
|
204 |
if (isSelected) { |
|
205 |
g.drawLine(x+7, y+1, x+7, y+3); |
|
206 |
g.drawLine(x+6, y+2, x+6, y+4); |
|
207 |
g.drawLine(x+5, y+3, x+5, y+5); |
|
208 |
g.drawLine(x+4, y+4, x+4, y+6); |
|
209 |
g.drawLine(x+3, y+5, x+3, y+7); |
|
210 |
g.drawLine(x+2, y+4, x+2, y+6); |
|
211 |
g.drawLine(x+1, y+3, x+1, y+5); |
|
212 |
} |
|
213 |
} |
|
214 |
public int getIconWidth() { return 9; } |
|
215 |
public int getIconHeight() { return 9; } |
|
216 |
||
217 |
} // End class CheckBoxMenuItemIcon |
|
218 |
||
219 |
||
220 |
private static class RadioButtonMenuItemIcon implements Icon, UIResource, Serializable |
|
221 |
{ |
|
222 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
223 |
AbstractButton b = (AbstractButton) c; |
|
224 |
ButtonModel model = b.getModel(); |
|
225 |
if (b.isSelected() == true) { |
|
226 |
g.fillOval(x+1, y+1, getIconWidth(), getIconHeight()); |
|
227 |
} |
|
228 |
} |
|
229 |
public int getIconWidth() { return 6; } |
|
230 |
public int getIconHeight() { return 6; } |
|
231 |
||
232 |
} // End class RadioButtonMenuItemIcon |
|
233 |
||
234 |
||
235 |
private static class MenuItemCheckIcon implements Icon, UIResource, Serializable{ |
|
236 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
237 |
} |
|
238 |
public int getIconWidth() { return 9; } |
|
239 |
public int getIconHeight() { return 9; } |
|
240 |
||
241 |
} // End class MenuItemCheckIcon |
|
242 |
||
243 |
private static class MenuItemArrowIcon implements Icon, UIResource, Serializable { |
|
244 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
245 |
} |
|
246 |
public int getIconWidth() { return 4; } |
|
247 |
public int getIconHeight() { return 8; } |
|
248 |
||
249 |
} // End class MenuItemArrowIcon |
|
250 |
||
251 |
private static class MenuArrowIcon implements Icon, UIResource, Serializable { |
|
252 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
253 |
Polygon p = new Polygon(); |
|
254 |
p.addPoint(x, y); |
|
255 |
p.addPoint(x+getIconWidth(), y+getIconHeight()/2); |
|
256 |
p.addPoint(x, y+getIconHeight()); |
|
257 |
g.fillPolygon(p); |
|
258 |
||
259 |
} |
|
260 |
public int getIconWidth() { return 4; } |
|
261 |
public int getIconHeight() { return 8; } |
|
262 |
} // End class MenuArrowIcon |
|
263 |
} |