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