PR target/27599
[official-gcc.git] / libjava / classpath / examples / gnu / classpath / examples / swing / GNULookAndFeel.java
blobc8fd09d744c7da4f3a7fbf0e60dc64ca98edd921
1 /* GNULookAndFeel.java -- An example of using the javax.swing UI.
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath examples.
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)
9 any later version.
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
19 02110-1301 USA.
22 package gnu.classpath.examples.swing;
24 import java.awt.Color;
25 import java.awt.Component;
26 import java.awt.Graphics;
28 import javax.swing.Icon;
29 import javax.swing.ImageIcon;
30 import javax.swing.JCheckBox;
31 import javax.swing.JRadioButton;
32 import javax.swing.UIDefaults;
33 import javax.swing.plaf.ColorUIResource;
34 import javax.swing.plaf.IconUIResource;
35 import javax.swing.plaf.basic.BasicLookAndFeel;
37 public class GNULookAndFeel extends BasicLookAndFeel
40 static Color blueGray = new Color(0xdc, 0xda, 0xd5);
42 public boolean isNativeLookAndFeel() { return true; }
43 public boolean isSupportedLookAndFeel() { return true; }
44 public String getDescription() { return "GNU Look and Feel"; }
45 public String getID() { return "GNULookAndFeel"; }
46 public String getName() { return "GNU"; }
48 static UIDefaults LAF_defaults;
50 private final static String iconspath = "/gnu/javax/swing/plaf/gtk/icons/";
52 public UIDefaults getDefaults()
54 if (LAF_defaults == null)
56 LAF_defaults = super.getDefaults();
57 Object[] myDefaults = new Object[] {
58 "Button.background", new ColorUIResource(blueGray),
59 "CheckBox.background", new ColorUIResource(blueGray),
60 "CheckBoxMenuItem.background", new ColorUIResource(blueGray),
61 "ToolBar.background", new ColorUIResource(blueGray),
62 "Panel.background", new ColorUIResource(blueGray),
63 "Slider.background", new ColorUIResource(blueGray),
64 "OptionPane.background", new ColorUIResource(blueGray),
65 "ProgressBar.background", new ColorUIResource(blueGray),
66 "TabbedPane.background", new ColorUIResource(blueGray),
67 "Label.background", new ColorUIResource(blueGray),
68 "Menu.background", new ColorUIResource(blueGray),
69 "MenuBar.background", new ColorUIResource(blueGray),
70 "MenuItem.background", new ColorUIResource(blueGray),
71 "ScrollBar.background", new ColorUIResource(blueGray),
72 "CheckBox.icon", new CheckBoxIcon(),
73 "RadioButton.icon", new RadioButtonIcon(),
75 "Tree.closedIcon",
76 new IconUIResource(new ImageIcon
77 (getClass().getResource
78 (iconspath + "TreeClosed.png"))),
79 "Tree.leafIcon",
80 new IconUIResource(new ImageIcon
81 (getClass().getResource
82 (iconspath + "TreeLeaf.png"))),
83 "Tree.openIcon",
84 new IconUIResource(new ImageIcon
85 (getClass().getResource
86 (iconspath + "TreeOpen.png"))),
88 LAF_defaults.putDefaults(myDefaults);
90 return LAF_defaults;
93 /**
94 * The icon used for CheckBoxes in the BasicLookAndFeel. This is an empty
95 * icon with a size of 13x13 pixels.
97 static class CheckBoxIcon
98 implements Icon
101 * Returns the height of the icon. The BasicLookAndFeel CheckBox icon
102 * has a height of 13 pixels.
104 * @return the height of the icon
106 public int getIconHeight()
108 return 13;
112 * Returns the width of the icon. The BasicLookAndFeel CheckBox icon
113 * has a width of 13 pixels.
115 * @return the height of the icon
117 public int getIconWidth()
119 return 13;
123 * Paints the icon. The BasicLookAndFeel CheckBox icon is empty and does
124 * not need to be painted.
126 * @param c the component to be painted
127 * @param g the Graphics context to be painted with
128 * @param x the x position of the icon
129 * @param y the y position of the icon
131 public void paintIcon(Component c, Graphics g, int x, int y)
133 Color save = g.getColor();
134 g.setColor(c.getForeground());
135 g.drawRect(x, y, getIconWidth(), getIconHeight());
137 JCheckBox item = (JCheckBox) c;
138 if (item.isSelected())
140 g.drawLine(3 + x, 5 + y, 3 + x, 9 + y);
141 g.drawLine(4 + x, 5 + y, 4 + x, 9 + y);
142 g.drawLine(5 + x, 7 + y, 9 + x, 3 + y);
143 g.drawLine(5 + x, 8 + y, 9 + x, 4 + y);
146 g.setColor(save);
151 * The icon used for RadioButtons in the GNULookAndFeel. This is an empty
152 * icon with a size of 13x13 pixels.
154 static class RadioButtonIcon
155 implements Icon
158 * Returns the height of the icon. The GNULookAndFeel RadioButton icon
159 * has a height of 13 pixels.
161 * @return the height of the icon
163 public int getIconHeight()
165 return 13;
169 * Returns the width of the icon. The GNULookAndFeel RadioButton icon
170 * has a width of 13 pixels.
172 * @return the height of the icon
174 public int getIconWidth()
176 return 13;
180 * Paints the icon. The GNULookAndFeel RadioButton icon is empty and does
181 * not need to be painted.
183 * @param c the component to be painted
184 * @param g the Graphics context to be painted with
185 * @param x the x position of the icon
186 * @param y the y position of the icon
188 public void paintIcon(Component c, Graphics g, int x, int y)
190 Color savedColor = g.getColor();
191 JRadioButton b = (JRadioButton) c;
193 // draw outer circle
194 if (b.isEnabled())
195 g.setColor(Color.GRAY);
196 else
197 g.setColor(Color.GRAY);
198 g.drawLine(x + 2, y + 1, x + 3, y + 1);
199 g.drawLine(x + 4, y, x + 7, y);
200 g.drawLine(x + 8, y + 1, x + 9, y + 1);
201 g.drawLine(x + 10, y + 2, x + 10, y + 3);
202 g.drawLine(x + 11, y + 4, x + 11, y + 7);
203 g.drawLine(x + 10, y + 8, x + 10, y + 9);
204 g.drawLine(x + 8, y + 10, x + 9, y + 10);
205 g.drawLine(x + 4, y + 11, x + 7, y + 11);
206 g.drawLine(x + 2, y + 10, x + 3, y + 10);
207 g.drawLine(x + 1, y + 9, x + 1, y + 8);
208 g.drawLine(x, y + 7, x, y + 4);
209 g.drawLine(x + 1, y + 2, x + 1, y + 3);
211 if (b.getModel().isArmed())
213 g.setColor(Color.GRAY);
214 g.drawLine(x + 4, y + 1, x + 7, y + 1);
215 g.drawLine(x + 4, y + 10, x + 7, y + 10);
216 g.drawLine(x + 1, y + 4, x + 1, y + 7);
217 g.drawLine(x + 10, y + 4, x + 10, y + 7);
218 g.fillRect(x + 2, y + 2, 8, 8);
220 else
222 // only draw inner highlight if not filled
223 if (b.isEnabled())
225 g.setColor(Color.WHITE);
227 g.drawLine(x + 2, y + 8, x + 2, y + 9);
228 g.drawLine(x + 1, y + 4, x + 1, y + 7);
229 g.drawLine(x + 2, y + 2, x + 2, y + 3);
230 g.drawLine(x + 3, y + 2, x + 3, y + 2);
231 g.drawLine(x + 4, y + 1, x + 7, y + 1);
232 g.drawLine(x + 8, y + 2, x + 9, y + 2);
236 // draw outer highlight
237 if (b.isEnabled())
239 g.setColor(Color.WHITE);
241 // outer
242 g.drawLine(x + 10, y + 1, x + 10, y + 1);
243 g.drawLine(x + 11, y + 2, x + 11, y + 3);
244 g.drawLine(x + 12, y + 4, x + 12, y + 7);
245 g.drawLine(x + 11, y + 8, x + 11, y + 9);
246 g.drawLine(x + 10, y + 10, x + 10, y + 10);
247 g.drawLine(x + 8, y + 11, x + 9, y + 11);
248 g.drawLine(x + 4, y + 12, x + 7, y + 12);
249 g.drawLine(x + 2, y + 11, x + 3, y + 11);
252 if (b.isSelected())
254 if (b.isEnabled())
255 g.setColor(Color.BLACK);
256 else
257 g.setColor(Color.GRAY);
258 g.drawLine(x + 4, y + 3, x + 7, y + 3);
259 g.fillRect(x + 3, y + 4, 6, 4);
260 g.drawLine(x + 4, y + 8, x + 7, y + 8);
262 g.setColor(savedColor);