author | darcy |
Wed, 02 Jul 2014 23:03:27 -0700 | |
changeset 25565 | ce603b34c98d |
parent 22574 | 7f8ce0c8c20a |
child 25761 | c408b10ef757 |
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 |
||
64 |
public static Icon getMenuItemCheckIcon() { |
|
65 |
if (menuItemCheckIcon == null) { |
|
66 |
menuItemCheckIcon = new MenuItemCheckIcon(); |
|
67 |
} |
|
68 |
return menuItemCheckIcon; |
|
69 |
} |
|
70 |
||
71 |
public static Icon getMenuItemArrowIcon() { |
|
72 |
if (menuItemArrowIcon == null) { |
|
73 |
menuItemArrowIcon = new MenuItemArrowIcon(); |
|
74 |
} |
|
75 |
return menuItemArrowIcon; |
|
76 |
} |
|
77 |
||
78 |
public static Icon getMenuArrowIcon() { |
|
79 |
if (menuArrowIcon == null) { |
|
80 |
menuArrowIcon = new MenuArrowIcon(); |
|
81 |
} |
|
82 |
return menuArrowIcon; |
|
83 |
} |
|
84 |
||
85 |
public static Icon getCheckBoxIcon() { |
|
86 |
if (checkBoxIcon == null) { |
|
87 |
checkBoxIcon = new CheckBoxIcon(); |
|
88 |
} |
|
89 |
return checkBoxIcon; |
|
90 |
} |
|
91 |
||
92 |
public static Icon getRadioButtonIcon() { |
|
93 |
if (radioButtonIcon == null) { |
|
94 |
radioButtonIcon = new RadioButtonIcon(); |
|
95 |
} |
|
96 |
return radioButtonIcon; |
|
97 |
} |
|
98 |
||
99 |
public static Icon getCheckBoxMenuItemIcon() { |
|
100 |
if (checkBoxMenuItemIcon == null) { |
|
101 |
checkBoxMenuItemIcon = new CheckBoxMenuItemIcon(); |
|
102 |
} |
|
103 |
return checkBoxMenuItemIcon; |
|
104 |
} |
|
105 |
||
106 |
public static Icon getRadioButtonMenuItemIcon() { |
|
107 |
if (radioButtonMenuItemIcon == null) { |
|
108 |
radioButtonMenuItemIcon = new RadioButtonMenuItemIcon(); |
|
109 |
} |
|
110 |
return radioButtonMenuItemIcon; |
|
111 |
} |
|
112 |
||
113 |
public static Icon createEmptyFrameIcon() { |
|
114 |
if(frame_icon == null) |
|
115 |
frame_icon = new EmptyFrameIcon(); |
|
116 |
return frame_icon; |
|
117 |
} |
|
118 |
||
119 |
private static class EmptyFrameIcon implements Icon, Serializable { |
|
120 |
int height = 16; |
|
121 |
int width = 14; |
|
122 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
123 |
} |
|
124 |
public int getIconWidth() { return width; } |
|
125 |
public int getIconHeight() { return height; } |
|
126 |
}; |
|
127 |
||
128 |
private static class CheckBoxIcon implements Icon, Serializable |
|
129 |
{ |
|
130 |
final static int csize = 13; |
|
131 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
132 |
} |
|
133 |
||
134 |
public int getIconWidth() { |
|
135 |
return csize; |
|
136 |
} |
|
137 |
||
138 |
public int getIconHeight() { |
|
139 |
return csize; |
|
140 |
} |
|
141 |
} |
|
142 |
||
143 |
private static class RadioButtonIcon implements Icon, UIResource, Serializable |
|
144 |
{ |
|
145 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
146 |
} |
|
147 |
||
148 |
public int getIconWidth() { |
|
149 |
return 13; |
|
150 |
} |
|
151 |
||
152 |
public int getIconHeight() { |
|
153 |
return 13; |
|
154 |
} |
|
155 |
} // end class RadioButtonIcon |
|
156 |
||
157 |
||
158 |
private static class CheckBoxMenuItemIcon implements Icon, UIResource, Serializable |
|
159 |
{ |
|
160 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
161 |
AbstractButton b = (AbstractButton) c; |
|
162 |
ButtonModel model = b.getModel(); |
|
163 |
boolean isSelected = model.isSelected(); |
|
164 |
if (isSelected) { |
|
165 |
g.drawLine(x+7, y+1, x+7, y+3); |
|
166 |
g.drawLine(x+6, y+2, x+6, y+4); |
|
167 |
g.drawLine(x+5, y+3, x+5, y+5); |
|
168 |
g.drawLine(x+4, y+4, x+4, y+6); |
|
169 |
g.drawLine(x+3, y+5, x+3, y+7); |
|
170 |
g.drawLine(x+2, y+4, x+2, y+6); |
|
171 |
g.drawLine(x+1, y+3, x+1, y+5); |
|
172 |
} |
|
173 |
} |
|
174 |
public int getIconWidth() { return 9; } |
|
175 |
public int getIconHeight() { return 9; } |
|
176 |
||
177 |
} // End class CheckBoxMenuItemIcon |
|
178 |
||
179 |
||
180 |
private static class RadioButtonMenuItemIcon implements Icon, UIResource, Serializable |
|
181 |
{ |
|
182 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
183 |
AbstractButton b = (AbstractButton) c; |
|
184 |
ButtonModel model = b.getModel(); |
|
185 |
if (b.isSelected() == true) { |
|
186 |
g.fillOval(x+1, y+1, getIconWidth(), getIconHeight()); |
|
187 |
} |
|
188 |
} |
|
189 |
public int getIconWidth() { return 6; } |
|
190 |
public int getIconHeight() { return 6; } |
|
191 |
||
192 |
} // End class RadioButtonMenuItemIcon |
|
193 |
||
194 |
||
195 |
private static class MenuItemCheckIcon implements Icon, UIResource, Serializable{ |
|
196 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
197 |
} |
|
198 |
public int getIconWidth() { return 9; } |
|
199 |
public int getIconHeight() { return 9; } |
|
200 |
||
201 |
} // End class MenuItemCheckIcon |
|
202 |
||
203 |
private static class MenuItemArrowIcon implements Icon, UIResource, Serializable { |
|
204 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
205 |
} |
|
206 |
public int getIconWidth() { return 4; } |
|
207 |
public int getIconHeight() { return 8; } |
|
208 |
||
209 |
} // End class MenuItemArrowIcon |
|
210 |
||
211 |
private static class MenuArrowIcon implements Icon, UIResource, Serializable { |
|
212 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
213 |
Polygon p = new Polygon(); |
|
214 |
p.addPoint(x, y); |
|
215 |
p.addPoint(x+getIconWidth(), y+getIconHeight()/2); |
|
216 |
p.addPoint(x, y+getIconHeight()); |
|
217 |
g.fillPolygon(p); |
|
218 |
||
219 |
} |
|
220 |
public int getIconWidth() { return 4; } |
|
221 |
public int getIconHeight() { return 8; } |
|
222 |
} // End class MenuArrowIcon |
|
223 |
} |