2
* Copyright (c) 2001-2009 JGoodies Karsten Lentzsch. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* o Redistributions of source code must retain the above copyright notice,
8
* this list of conditions and the following disclaimer.
10
* o Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
14
* o Neither the name of JGoodies Karsten Lentzsch nor the names of
15
* its contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
package com.jgoodies.looks.windows;
33
import java.awt.Component;
34
import java.awt.Graphics;
35
import java.io.Serializable;
38
import javax.swing.plaf.UIResource;
41
* Factory class that vends <code>Icon</code>s used in the JGoodies Windows look&feel.
43
* @author Karsten Lentzsch
44
* @version $Revision: 1.2 $
46
final class WindowsIconFactory {
48
private WindowsIconFactory() {
49
// Overrides default constructor; prevents instantiation.
52
// Accessing and Creating Icons *****************************************************
54
private static Icon checkBoxIcon;
55
private static Icon radioButtonIcon;
59
* Returns an <code>Icon</code> for a <code>JCheckBox</code>.
61
static Icon getCheckBoxIcon() {
62
if (checkBoxIcon == null) {
63
checkBoxIcon = new CheckBoxIcon();
70
* Returns an <code>Icon</code> for a <code>JCheckBox</code>.
72
static Icon getRadioButtonIcon() {
73
if (radioButtonIcon == null) {
74
radioButtonIcon = new RadioButtonIcon();
76
return radioButtonIcon;
80
// Helper Classes *******************************************************************
82
// Paints the icon for a check box.
83
private static class CheckBoxIcon implements Icon, Serializable {
85
private static final int SIZE = 13;
87
public void paintIcon(Component c, Graphics g, int x, int y) {
88
JCheckBox cb = (JCheckBox) c;
89
ButtonModel model = cb.getModel();
92
if (!cb.isBorderPaintedFlat()) {
94
g.setColor(UIManager.getColor("CheckBox.shadow"));
95
g.drawLine(x, y, x+11, y);
96
g.drawLine(x, y+1, x, y+11);
99
g.setColor(UIManager.getColor("CheckBox.highlight"));
100
g.drawLine(x+12, y, x+12, y+12);
101
g.drawLine(x, y+12, x+11, y+12);
104
g.setColor(UIManager.getColor("CheckBox.darkShadow"));
105
g.drawLine(x+1, y+1, x+10, y+1);
106
g.drawLine(x+1, y+2, x+1, y+10);
108
// Inner bottom/right
109
g.setColor(UIManager.getColor("CheckBox.light"));
110
g.drawLine(x+1, y+11, x+11, y+11);
111
g.drawLine(x+11, y+1, x+11, y+10);
113
g.setColor(UIManager.getColor("CheckBox.shadow"));
114
g.drawRect(x+1, y+1, SIZE-3, SIZE-3);
117
g.setColor(UIManager.getColor(
118
(model.isPressed() && model.isArmed()) || !model.isEnabled()
119
? "CheckBox.background"
120
: "CheckBox.interiorBackground"));
121
g.fillRect(x+2, y+2, SIZE-4, SIZE-4);
123
g.setColor(UIManager.getColor(model.isEnabled()
124
? "CheckBox.checkColor" // Modified by JGoodies
125
: "CheckBox.shadow"));
128
if (model.isSelected()) {
129
g.drawLine(x+9, y+3, x+9, y+3);
130
g.drawLine(x+8, y+4, x+9, y+4);
131
g.drawLine(x+7, y+5, x+9, y+5);
132
g.drawLine(x+6, y+6, x+8, y+6);
133
g.drawLine(x+3, y+7, x+7, y+7);
134
g.drawLine(x+4, y+8, x+6, y+8);
135
g.drawLine(x+5, y+9, x+5, y+9);
136
g.drawLine(x+3, y+5, x+3, y+5);
137
g.drawLine(x+3, y+6, x+4, y+6);
141
public int getIconWidth() { return SIZE; }
142
public int getIconHeight() { return SIZE; }
146
// Paints the icon for a radio button.
147
private static class RadioButtonIcon implements Icon, UIResource, Serializable {
149
private static final int SIZE = 13;
151
public void paintIcon(Component c, Graphics g, int x, int y) {
152
AbstractButton b = (AbstractButton) c;
153
ButtonModel model = b.getModel();
156
g.setColor(UIManager.getColor(
157
(model.isPressed() && model.isArmed()) || !model.isEnabled()
158
? "RadioButton.background"
159
: "RadioButton.interiorBackground"));
160
g.fillRect(x+2, y+2, 8, 8);
164
g.setColor(UIManager.getColor("RadioButton.shadow"));
165
g.drawLine(x+4, y+0, x+7, y+0);
166
g.drawLine(x+2, y+1, x+3, y+1);
167
g.drawLine(x+8, y+1, x+9, y+1);
168
g.drawLine(x+1, y+2, x+1, y+3);
169
g.drawLine(x+0, y+4, x+0, y+7);
170
g.drawLine(x+1, y+8, x+1, y+9);
173
g.setColor(UIManager.getColor("RadioButton.highlight"));
174
g.drawLine(x+2, y+10, x+3, y+10);
175
g.drawLine(x+4, y+11, x+7, y+11);
176
g.drawLine(x+8, y+10, x+9, y+10);
177
g.drawLine(x+10, y+9, x+10, y+8);
178
g.drawLine(x+11, y+7, x+11, y+4);
179
g.drawLine(x+10, y+3, x+10, y+2);
183
g.setColor(UIManager.getColor("RadioButton.darkShadow"));
184
g.drawLine(x+4, y+1, x+7, y+1);
185
g.drawLine(x+2, y+2, x+3, y+2);
186
g.drawLine(x+8, y+2, x+9, y+2);
187
g.drawLine(x+2, y+3, x+2, y+3);
188
g.drawLine(x+1, y+4, x+1, y+7);
189
g.drawLine(x+2, y+8, x+2, y+8);
193
g.setColor(UIManager.getColor("RadioButton.light"));
194
g.drawLine(x+2, y+9, x+3, y+9);
195
g.drawLine(x+4, y+10, x+7, y+10);
196
g.drawLine(x+8, y+9, x+9, y+9);
197
g.drawLine(x+9, y+8, x+9, y+8);
198
g.drawLine(x+10, y+7, x+10, y+4);
199
g.drawLine(x+9, y+3, x+9, y+3);
202
// indicate whether selected or not
203
if(model.isSelected()) {
204
g.setColor(UIManager.getColor("RadioButton.checkColor")); // Modified by JGoodies
205
g.fillRect(x+4, y+5, 4, 2);
206
g.fillRect(x+5, y+4, 2, 4);
210
public int getIconWidth() { return SIZE; }
211
public int getIconHeight() { return SIZE; }
b'\\ No newline at end of file'