1 /* BasicIconFactory.java --
2 Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax
.swing
.plaf
.basic
;
41 import java
.awt
.Color
;
42 import java
.awt
.Component
;
43 import java
.awt
.Graphics
;
44 import java
.io
.Serializable
;
46 import javax
.swing
.Icon
;
47 import javax
.swing
.JCheckBoxMenuItem
;
50 * Creates icons for the {@link BasicLookAndFeel}.
52 public class BasicIconFactory
implements Serializable
54 static final long serialVersionUID
= 5605588811185324383L;
56 private static class DummyIcon
59 public int getIconHeight() { return 10; }
60 public int getIconWidth() { return 10; }
61 public void paintIcon(Component c
, Graphics g
, int x
, int y
)
63 Color save
= g
.getColor();
64 g
.setColor(c
.getForeground());
65 g
.drawRect(x
, y
, 10, 10);
71 * The icon used for CheckBoxes in the BasicLookAndFeel. This is an empty
72 * icon with a size of 13x13 pixels.
74 static class CheckBoxIcon
78 * Returns the height of the icon. The BasicLookAndFeel CheckBox icon
79 * has a height of 13 pixels.
81 * @return the height of the icon
83 public int getIconHeight()
89 * Returns the width of the icon. The BasicLookAndFeel CheckBox icon
90 * has a width of 13 pixels.
92 * @return the height of the icon
94 public int getIconWidth()
100 * Paints the icon. The BasicLookAndFeel CheckBox icon is empty and does
101 * not need to be painted.
103 * @param c the component to be painted
104 * @param g the Graphics context to be painted with
105 * @param x the x position of the icon
106 * @param y the y position of the icon
108 public void paintIcon(Component c
, Graphics g
, int x
, int y
)
110 // The icon is empty and needs no painting.
115 * The icon used for {@link JCheckBoxMenuItem}s in the
116 * {@link BasicLookAndFeel}. This icon has a size of 9x9 pixels.
118 static class CheckBoxMenuItemIcon
122 * Returns the height of the icon in pixels.
124 * @return the height of the icon
126 public int getIconHeight()
132 * Returns the width of the icon in pixels.
134 * @return the height of the icon
136 public int getIconWidth()
144 * @param c the component to be painted
145 * @param g the Graphics context to be painted with
146 * @param x the x position of the icon
147 * @param y the y position of the icon
149 public void paintIcon(Component c
, Graphics g
, int x
, int y
)
151 JCheckBoxMenuItem item
= (JCheckBoxMenuItem
) c
;
152 if (item
.isSelected())
154 // paint the check...
155 g
.setColor(Color
.black
);
156 g
.drawLine(x
+ 1, y
+ 3, x
+ 1, y
+ 4);
157 g
.drawLine(x
+ 2, y
+ 4, x
+ 2, y
+ 5);
158 for (int i
= 0; i
< 5; i
++)
159 g
.drawLine(x
+ 3 + i
, y
+ 5 - i
, x
+ 3 + i
, y
+ 6 - i
);
165 * The icon used for RadioButtons in the BasicLookAndFeel. This is an empty
166 * icon with a size of 13x13 pixels.
168 static class RadioButtonIcon
172 * Returns the height of the icon. The BasicLookAndFeel RadioButton icon
173 * has a height of 13 pixels.
175 * @return the height of the icon
177 public int getIconHeight()
183 * Returns the width of the icon. The BasicLookAndFeel RadioButton icon
184 * has a width of 13 pixels.
186 * @return the height of the icon
188 public int getIconWidth()
194 * Paints the icon. The BasicLookAndFeel RadioButton icon is empty and does
195 * not need to be painted.
197 * @param c the component to be painted
198 * @param g the Graphics context to be painted with
199 * @param x the x position of the icon
200 * @param y the y position of the icon
202 public void paintIcon(Component c
, Graphics g
, int x
, int y
)
204 // The icon is empty and needs no painting.
207 /** The cached CheckBoxIcon instance. */
208 private static CheckBoxIcon checkBoxIcon
;
210 /** The cached RadioButtonIcon instance. */
211 private static RadioButtonIcon radioButtonIcon
;
213 public static Icon
getMenuItemCheckIcon()
217 public int getIconHeight()
222 public int getIconWidth()
227 public void paintIcon(Component c
, Graphics g
, int x
, int y
)
229 Color saved
= g
.getColor();
230 g
.setColor(Color
.BLACK
);
231 g
.drawLine(3 + x
, 5 + y
, 3 + x
, 9 + y
);
232 g
.drawLine(4 + x
, 5 + y
, 4 + x
, 9 + y
);
233 g
.drawLine(5 + x
, 7 + y
, 9 + x
, 3 + y
);
234 g
.drawLine(5 + x
, 8 + y
, 9 + x
, 4 + y
);
239 public static Icon
getMenuItemArrowIcon()
241 return new DummyIcon();
245 * Returns a new instance of a 4 x 8 icon showing a small black triangle that
246 * points to the right. This is displayed in menu items that have a
251 public static Icon
getMenuArrowIcon()
255 public int getIconHeight()
259 public int getIconWidth()
263 public void paintIcon(Component c
, Graphics g
, int x
, int y
)
265 Color saved
= g
.getColor();
266 g
.setColor(Color
.BLACK
);
267 for (int i
= 0; i
< 4; i
++)
268 g
.drawLine(x
+ i
, y
+ i
, x
+ i
, y
+ 7 - i
);
275 * Returns an icon for CheckBoxes in the BasicLookAndFeel. CheckBox icons
276 * in the Basic L&F are empty and have a size of 13x13 pixels.
277 * This method returns a shared single instance of this icon.
279 * @return an icon for CheckBoxes in the BasicLookAndFeel
281 public static Icon
getCheckBoxIcon()
283 if (checkBoxIcon
== null)
284 checkBoxIcon
= new CheckBoxIcon();
289 * Returns an icon for RadioButtons in the BasicLookAndFeel. RadioButton
290 * icons in the Basic L&F are empty and have a size of 13x13 pixels.
291 * This method returns a shared single instance of this icon.
293 * @return an icon for RadioButtons in the BasicLookAndFeel
295 public static Icon
getRadioButtonIcon()
297 if (radioButtonIcon
== null)
298 radioButtonIcon
= new RadioButtonIcon();
299 return radioButtonIcon
;
303 * Creates and returns an icon used when rendering {@link JCheckBoxMenuItem}
308 public static Icon
getCheckBoxMenuItemIcon()
310 return new CheckBoxMenuItemIcon();
313 public static Icon
getRadioButtonMenuItemIcon()
315 return getRadioButtonIcon();
318 public static Icon
createEmptyFrameIcon()
320 return new DummyIcon();
322 } // class BasicIconFactory