| 1 |
769 |
jeremybenn |
/* GNULookAndFeel.java -- An example of using the javax.swing UI.
|
| 2 |
|
|
Copyright (C) 2005 Free Software Foundation, Inc.
|
| 3 |
|
|
|
| 4 |
|
|
This file is part of GNU Classpath examples.
|
| 5 |
|
|
|
| 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.
|
| 10 |
|
|
|
| 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.
|
| 15 |
|
|
|
| 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.
|
| 20 |
|
|
*/
|
| 21 |
|
|
|
| 22 |
|
|
package gnu.javax.swing.plaf.gnu;
|
| 23 |
|
|
|
| 24 |
|
|
import java.awt.Color;
|
| 25 |
|
|
import java.awt.Component;
|
| 26 |
|
|
import java.awt.Graphics;
|
| 27 |
|
|
|
| 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;
|
| 36 |
|
|
|
| 37 |
|
|
public class GNULookAndFeel extends BasicLookAndFeel
|
| 38 |
|
|
{
|
| 39 |
|
|
|
| 40 |
|
|
static Color blueGray = new Color(0xdc, 0xda, 0xd5);
|
| 41 |
|
|
|
| 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"; }
|
| 47 |
|
|
|
| 48 |
|
|
static UIDefaults LAF_defaults;
|
| 49 |
|
|
|
| 50 |
|
|
private final static String iconspath = "/gnu/javax/swing/plaf/gtk/icons/";
|
| 51 |
|
|
|
| 52 |
|
|
public UIDefaults getDefaults()
|
| 53 |
|
|
{
|
| 54 |
|
|
if (LAF_defaults == null)
|
| 55 |
|
|
{
|
| 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(),
|
| 74 |
|
|
"Tree.hash", new ColorUIResource(Color.black),
|
| 75 |
|
|
|
| 76 |
|
|
"Tree.closedIcon",
|
| 77 |
|
|
new IconUIResource(new ImageIcon
|
| 78 |
|
|
(getClass().getResource
|
| 79 |
|
|
(iconspath + "TreeClosed.png"))),
|
| 80 |
|
|
"Tree.leafIcon",
|
| 81 |
|
|
new IconUIResource(new ImageIcon
|
| 82 |
|
|
(getClass().getResource
|
| 83 |
|
|
(iconspath + "TreeLeaf.png"))),
|
| 84 |
|
|
"Tree.openIcon",
|
| 85 |
|
|
new IconUIResource(new ImageIcon
|
| 86 |
|
|
(getClass().getResource
|
| 87 |
|
|
(iconspath + "TreeOpen.png"))),
|
| 88 |
|
|
};
|
| 89 |
|
|
LAF_defaults.putDefaults(myDefaults);
|
| 90 |
|
|
}
|
| 91 |
|
|
return LAF_defaults;
|
| 92 |
|
|
}
|
| 93 |
|
|
|
| 94 |
|
|
/**
|
| 95 |
|
|
* The icon used for CheckBoxes in the BasicLookAndFeel. This is an empty
|
| 96 |
|
|
* icon with a size of 13x13 pixels.
|
| 97 |
|
|
*/
|
| 98 |
|
|
static class CheckBoxIcon
|
| 99 |
|
|
implements Icon
|
| 100 |
|
|
{
|
| 101 |
|
|
/**
|
| 102 |
|
|
* Returns the height of the icon. The BasicLookAndFeel CheckBox icon
|
| 103 |
|
|
* has a height of 13 pixels.
|
| 104 |
|
|
*
|
| 105 |
|
|
* @return the height of the icon
|
| 106 |
|
|
*/
|
| 107 |
|
|
public int getIconHeight()
|
| 108 |
|
|
{
|
| 109 |
|
|
return 13;
|
| 110 |
|
|
}
|
| 111 |
|
|
|
| 112 |
|
|
/**
|
| 113 |
|
|
* Returns the width of the icon. The BasicLookAndFeel CheckBox icon
|
| 114 |
|
|
* has a width of 13 pixels.
|
| 115 |
|
|
*
|
| 116 |
|
|
* @return the height of the icon
|
| 117 |
|
|
*/
|
| 118 |
|
|
public int getIconWidth()
|
| 119 |
|
|
{
|
| 120 |
|
|
return 13;
|
| 121 |
|
|
}
|
| 122 |
|
|
|
| 123 |
|
|
/**
|
| 124 |
|
|
* Paints the icon. The BasicLookAndFeel CheckBox icon is empty and does
|
| 125 |
|
|
* not need to be painted.
|
| 126 |
|
|
*
|
| 127 |
|
|
* @param c the component to be painted
|
| 128 |
|
|
* @param g the Graphics context to be painted with
|
| 129 |
|
|
* @param x the x position of the icon
|
| 130 |
|
|
* @param y the y position of the icon
|
| 131 |
|
|
*/
|
| 132 |
|
|
public void paintIcon(Component c, Graphics g, int x, int y)
|
| 133 |
|
|
{
|
| 134 |
|
|
Color save = g.getColor();
|
| 135 |
|
|
g.setColor(c.getForeground());
|
| 136 |
|
|
g.drawRect(x, y, getIconWidth(), getIconHeight());
|
| 137 |
|
|
|
| 138 |
|
|
JCheckBox item = (JCheckBox) c;
|
| 139 |
|
|
if (item.isSelected())
|
| 140 |
|
|
{
|
| 141 |
|
|
g.drawLine(3 + x, 5 + y, 3 + x, 9 + y);
|
| 142 |
|
|
g.drawLine(4 + x, 5 + y, 4 + x, 9 + y);
|
| 143 |
|
|
g.drawLine(5 + x, 7 + y, 9 + x, 3 + y);
|
| 144 |
|
|
g.drawLine(5 + x, 8 + y, 9 + x, 4 + y);
|
| 145 |
|
|
}
|
| 146 |
|
|
|
| 147 |
|
|
g.setColor(save);
|
| 148 |
|
|
}
|
| 149 |
|
|
}
|
| 150 |
|
|
|
| 151 |
|
|
/**
|
| 152 |
|
|
* The icon used for RadioButtons in the GNULookAndFeel. This is an empty
|
| 153 |
|
|
* icon with a size of 13x13 pixels.
|
| 154 |
|
|
*/
|
| 155 |
|
|
static class RadioButtonIcon
|
| 156 |
|
|
implements Icon
|
| 157 |
|
|
{
|
| 158 |
|
|
/**
|
| 159 |
|
|
* Returns the height of the icon. The GNULookAndFeel RadioButton icon
|
| 160 |
|
|
* has a height of 13 pixels.
|
| 161 |
|
|
*
|
| 162 |
|
|
* @return the height of the icon
|
| 163 |
|
|
*/
|
| 164 |
|
|
public int getIconHeight()
|
| 165 |
|
|
{
|
| 166 |
|
|
return 13;
|
| 167 |
|
|
}
|
| 168 |
|
|
|
| 169 |
|
|
/**
|
| 170 |
|
|
* Returns the width of the icon. The GNULookAndFeel RadioButton icon
|
| 171 |
|
|
* has a width of 13 pixels.
|
| 172 |
|
|
*
|
| 173 |
|
|
* @return the height of the icon
|
| 174 |
|
|
*/
|
| 175 |
|
|
public int getIconWidth()
|
| 176 |
|
|
{
|
| 177 |
|
|
return 13;
|
| 178 |
|
|
}
|
| 179 |
|
|
|
| 180 |
|
|
/**
|
| 181 |
|
|
* Paints the icon. The GNULookAndFeel RadioButton icon is empty and does
|
| 182 |
|
|
* not need to be painted.
|
| 183 |
|
|
*
|
| 184 |
|
|
* @param c the component to be painted
|
| 185 |
|
|
* @param g the Graphics context to be painted with
|
| 186 |
|
|
* @param x the x position of the icon
|
| 187 |
|
|
* @param y the y position of the icon
|
| 188 |
|
|
*/
|
| 189 |
|
|
public void paintIcon(Component c, Graphics g, int x, int y)
|
| 190 |
|
|
{
|
| 191 |
|
|
Color savedColor = g.getColor();
|
| 192 |
|
|
JRadioButton b = (JRadioButton) c;
|
| 193 |
|
|
|
| 194 |
|
|
// draw outer circle
|
| 195 |
|
|
if (b.isEnabled())
|
| 196 |
|
|
g.setColor(Color.GRAY);
|
| 197 |
|
|
else
|
| 198 |
|
|
g.setColor(Color.GRAY);
|
| 199 |
|
|
g.drawLine(x + 2, y + 1, x + 3, y + 1);
|
| 200 |
|
|
g.drawLine(x + 4, y, x + 7, y);
|
| 201 |
|
|
g.drawLine(x + 8, y + 1, x + 9, y + 1);
|
| 202 |
|
|
g.drawLine(x + 10, y + 2, x + 10, y + 3);
|
| 203 |
|
|
g.drawLine(x + 11, y + 4, x + 11, y + 7);
|
| 204 |
|
|
g.drawLine(x + 10, y + 8, x + 10, y + 9);
|
| 205 |
|
|
g.drawLine(x + 8, y + 10, x + 9, y + 10);
|
| 206 |
|
|
g.drawLine(x + 4, y + 11, x + 7, y + 11);
|
| 207 |
|
|
g.drawLine(x + 2, y + 10, x + 3, y + 10);
|
| 208 |
|
|
g.drawLine(x + 1, y + 9, x + 1, y + 8);
|
| 209 |
|
|
g.drawLine(x, y + 7, x, y + 4);
|
| 210 |
|
|
g.drawLine(x + 1, y + 2, x + 1, y + 3);
|
| 211 |
|
|
|
| 212 |
|
|
if (b.getModel().isArmed())
|
| 213 |
|
|
{
|
| 214 |
|
|
g.setColor(Color.GRAY);
|
| 215 |
|
|
g.drawLine(x + 4, y + 1, x + 7, y + 1);
|
| 216 |
|
|
g.drawLine(x + 4, y + 10, x + 7, y + 10);
|
| 217 |
|
|
g.drawLine(x + 1, y + 4, x + 1, y + 7);
|
| 218 |
|
|
g.drawLine(x + 10, y + 4, x + 10, y + 7);
|
| 219 |
|
|
g.fillRect(x + 2, y + 2, 8, 8);
|
| 220 |
|
|
}
|
| 221 |
|
|
else
|
| 222 |
|
|
{
|
| 223 |
|
|
// only draw inner highlight if not filled
|
| 224 |
|
|
if (b.isEnabled())
|
| 225 |
|
|
{
|
| 226 |
|
|
g.setColor(Color.WHITE);
|
| 227 |
|
|
|
| 228 |
|
|
g.drawLine(x + 2, y + 8, x + 2, y + 9);
|
| 229 |
|
|
g.drawLine(x + 1, y + 4, x + 1, y + 7);
|
| 230 |
|
|
g.drawLine(x + 2, y + 2, x + 2, y + 3);
|
| 231 |
|
|
g.drawLine(x + 3, y + 2, x + 3, y + 2);
|
| 232 |
|
|
g.drawLine(x + 4, y + 1, x + 7, y + 1);
|
| 233 |
|
|
g.drawLine(x + 8, y + 2, x + 9, y + 2);
|
| 234 |
|
|
}
|
| 235 |
|
|
}
|
| 236 |
|
|
|
| 237 |
|
|
// draw outer highlight
|
| 238 |
|
|
if (b.isEnabled())
|
| 239 |
|
|
{
|
| 240 |
|
|
g.setColor(Color.WHITE);
|
| 241 |
|
|
|
| 242 |
|
|
// outer
|
| 243 |
|
|
g.drawLine(x + 10, y + 1, x + 10, y + 1);
|
| 244 |
|
|
g.drawLine(x + 11, y + 2, x + 11, y + 3);
|
| 245 |
|
|
g.drawLine(x + 12, y + 4, x + 12, y + 7);
|
| 246 |
|
|
g.drawLine(x + 11, y + 8, x + 11, y + 9);
|
| 247 |
|
|
g.drawLine(x + 10, y + 10, x + 10, y + 10);
|
| 248 |
|
|
g.drawLine(x + 8, y + 11, x + 9, y + 11);
|
| 249 |
|
|
g.drawLine(x + 4, y + 12, x + 7, y + 12);
|
| 250 |
|
|
g.drawLine(x + 2, y + 11, x + 3, y + 11);
|
| 251 |
|
|
}
|
| 252 |
|
|
|
| 253 |
|
|
if (b.isSelected())
|
| 254 |
|
|
{
|
| 255 |
|
|
if (b.isEnabled())
|
| 256 |
|
|
g.setColor(Color.BLACK);
|
| 257 |
|
|
else
|
| 258 |
|
|
g.setColor(Color.GRAY);
|
| 259 |
|
|
g.drawLine(x + 4, y + 3, x + 7, y + 3);
|
| 260 |
|
|
g.fillRect(x + 3, y + 4, 6, 4);
|
| 261 |
|
|
g.drawLine(x + 4, y + 8, x + 7, y + 8);
|
| 262 |
|
|
}
|
| 263 |
|
|
g.setColor(savedColor);
|
| 264 |
|
|
}
|
| 265 |
|
|
}
|
| 266 |
|
|
}
|