~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/looks-2.2.2/src/core/com/jgoodies/looks/windows/WindowsIconFactory.java

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2001-2009 JGoodies Karsten Lentzsch. All Rights Reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions are met:
 
6
 *
 
7
 *  o Redistributions of source code must retain the above copyright notice,
 
8
 *    this list of conditions and the following disclaimer.
 
9
 *
 
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.
 
13
 *
 
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.
 
17
 *
 
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.
 
29
 */
 
30
 
 
31
package com.jgoodies.looks.windows;
 
32
 
 
33
import java.awt.Component;
 
34
import java.awt.Graphics;
 
35
import java.io.Serializable;
 
36
 
 
37
import javax.swing.*;
 
38
import javax.swing.plaf.UIResource;
 
39
 
 
40
/**
 
41
 * Factory class that vends <code>Icon</code>s used in the JGoodies Windows look&amp;feel.
 
42
 *
 
43
 * @author  Karsten Lentzsch
 
44
 * @version $Revision: 1.2 $
 
45
 */
 
46
final class WindowsIconFactory {
 
47
 
 
48
    private WindowsIconFactory() {
 
49
        // Overrides default constructor; prevents instantiation.
 
50
    }
 
51
 
 
52
        // Accessing and Creating Icons *****************************************************
 
53
 
 
54
    private static Icon checkBoxIcon;
 
55
    private static Icon radioButtonIcon;
 
56
 
 
57
 
 
58
    /**
 
59
     * Returns an <code>Icon</code> for a <code>JCheckBox</code>.
 
60
     */
 
61
    static Icon getCheckBoxIcon() {
 
62
                if (checkBoxIcon == null) {
 
63
                checkBoxIcon = new CheckBoxIcon();
 
64
                }
 
65
                return checkBoxIcon;
 
66
    }
 
67
 
 
68
 
 
69
    /**
 
70
     * Returns an <code>Icon</code> for a <code>JCheckBox</code>.
 
71
     */
 
72
    static Icon getRadioButtonIcon() {
 
73
                if (radioButtonIcon == null) {
 
74
                radioButtonIcon = new RadioButtonIcon();
 
75
                }
 
76
                return radioButtonIcon;
 
77
    }
 
78
 
 
79
 
 
80
        // Helper Classes *******************************************************************
 
81
 
 
82
        // Paints the icon for a check box.
 
83
    private static class CheckBoxIcon implements Icon, Serializable {
 
84
 
 
85
                private static final int SIZE  = 13;
 
86
 
 
87
                public void paintIcon(Component c, Graphics g, int x, int y) {
 
88
                    JCheckBox cb = (JCheckBox) c;
 
89
                    ButtonModel model = cb.getModel();
 
90
 
 
91
                    // outer bevel
 
92
                    if (!cb.isBorderPaintedFlat()) {
 
93
                // Outer top/left
 
94
                g.setColor(UIManager.getColor("CheckBox.shadow"));
 
95
                g.drawLine(x, y, x+11, y);
 
96
                g.drawLine(x, y+1, x, y+11);
 
97
 
 
98
                // Outer bottom/right
 
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);
 
102
 
 
103
                // Inner top.left
 
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);
 
107
 
 
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);
 
112
                    } else {
 
113
                                g.setColor(UIManager.getColor("CheckBox.shadow"));
 
114
                                g.drawRect(x+1, y+1, SIZE-3, SIZE-3);
 
115
                    }
 
116
                        // inside box
 
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);
 
122
 
 
123
                    g.setColor(UIManager.getColor(model.isEnabled()
 
124
                                                        ? "CheckBox.checkColor"  // Modified by JGoodies
 
125
                                                        : "CheckBox.shadow"));
 
126
 
 
127
                    // paint check
 
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);
 
138
                    }
 
139
                }
 
140
 
 
141
                public int getIconWidth()  { return SIZE; }
 
142
                public int getIconHeight() { return SIZE; }
 
143
    }
 
144
 
 
145
 
 
146
        // Paints the icon for a radio button.
 
147
        private static class RadioButtonIcon implements Icon, UIResource, Serializable {
 
148
 
 
149
                private static final int SIZE  = 13;
 
150
 
 
151
                public void paintIcon(Component c, Graphics g, int x, int y) {
 
152
                    AbstractButton b = (AbstractButton) c;
 
153
                    ButtonModel model = b.getModel();
 
154
 
 
155
                    // fill interior
 
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);
 
161
 
 
162
 
 
163
                        // outter left arc
 
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);
 
171
 
 
172
                    // outter right arc
 
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);
 
180
 
 
181
 
 
182
                    // inner left arc
 
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);
 
190
 
 
191
 
 
192
                    // inner right arc
 
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);
 
200
 
 
201
 
 
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);
 
207
                    }
 
208
                }
 
209
 
 
210
                public int getIconWidth()  { return SIZE; }
 
211
                public int getIconHeight() { return SIZE; }
 
212
 
 
213
    }
 
214
 
 
215
}
 
 
b'\\ No newline at end of file'