001: /*
002: * Copyright (c) 2001-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.looks.windows;
032:
033: import java.awt.Component;
034: import java.awt.Graphics;
035: import java.io.Serializable;
036:
037: import javax.swing.AbstractButton;
038: import javax.swing.ButtonModel;
039: import javax.swing.Icon;
040: import javax.swing.JCheckBox;
041: import javax.swing.UIManager;
042: import javax.swing.plaf.UIResource;
043:
044: /**
045: * Factory class that vends <code>Icon</code>s used in the JGoodies Windows look&feel.
046: *
047: * @author Karsten Lentzsch
048: * @version $Revision: 1.3 $
049: */
050: final class WindowsIconFactory {
051:
052: private WindowsIconFactory() {
053: // Overrides default constructor; prevents instantiation.
054: }
055:
056: // Accessing and Creating Icons *****************************************************
057:
058: private static Icon checkBoxIcon;
059: private static Icon radioButtonIcon;
060:
061: /**
062: * Returns an <code>Icon</code> for a <code>JCheckBox</code>.
063: */
064: static Icon getCheckBoxIcon() {
065: if (checkBoxIcon == null) {
066: checkBoxIcon = new CheckBoxIcon();
067: }
068: return checkBoxIcon;
069: }
070:
071: /**
072: * Returns an <code>Icon</code> for a <code>JCheckBox</code>.
073: */
074: static Icon getRadioButtonIcon() {
075: if (radioButtonIcon == null) {
076: radioButtonIcon = new RadioButtonIcon();
077: }
078: return radioButtonIcon;
079: }
080:
081: // Helper Classes *******************************************************************
082:
083: // Paints the icon for a check box.
084: private static class CheckBoxIcon implements Icon, Serializable {
085:
086: private static final int SIZE = 13;
087:
088: public void paintIcon(Component c, Graphics g, int x, int y) {
089: JCheckBox cb = (JCheckBox) c;
090: ButtonModel model = cb.getModel();
091:
092: // outer bevel
093: if (!cb.isBorderPaintedFlat()) {
094: // Outer top/left
095: g.setColor(UIManager.getColor("CheckBox.shadow"));
096: g.drawLine(x, y, x + 11, y);
097: g.drawLine(x, y + 1, x, y + 11);
098:
099: // Outer bottom/right
100: g.setColor(UIManager.getColor("CheckBox.highlight"));
101: g.drawLine(x + 12, y, x + 12, y + 12);
102: g.drawLine(x, y + 12, x + 11, y + 12);
103:
104: // Inner top.left
105: g.setColor(UIManager.getColor("CheckBox.darkShadow"));
106: g.drawLine(x + 1, y + 1, x + 10, y + 1);
107: g.drawLine(x + 1, y + 2, x + 1, y + 10);
108:
109: // Inner bottom/right
110: g.setColor(UIManager.getColor("CheckBox.light"));
111: g.drawLine(x + 1, y + 11, x + 11, y + 11);
112: g.drawLine(x + 11, y + 1, x + 11, y + 10);
113: } else {
114: g.setColor(UIManager.getColor("CheckBox.shadow"));
115: g.drawRect(x + 1, y + 1, SIZE - 3, SIZE - 3);
116: }
117: // inside box
118: g.setColor(UIManager.getColor((model.isPressed() && model
119: .isArmed())
120: || !model.isEnabled() ? "CheckBox.background"
121: : "CheckBox.interiorBackground"));
122: g.fillRect(x + 2, y + 2, SIZE - 4, SIZE - 4);
123:
124: g.setColor(UIManager
125: .getColor(model.isEnabled() ? "CheckBox.checkColor" // Modified by JGoodies
126: : "CheckBox.shadow"));
127:
128: // paint check
129: if (model.isSelected()) {
130: g.drawLine(x + 9, y + 3, x + 9, y + 3);
131: g.drawLine(x + 8, y + 4, x + 9, y + 4);
132: g.drawLine(x + 7, y + 5, x + 9, y + 5);
133: g.drawLine(x + 6, y + 6, x + 8, y + 6);
134: g.drawLine(x + 3, y + 7, x + 7, y + 7);
135: g.drawLine(x + 4, y + 8, x + 6, y + 8);
136: g.drawLine(x + 5, y + 9, x + 5, y + 9);
137: g.drawLine(x + 3, y + 5, x + 3, y + 5);
138: g.drawLine(x + 3, y + 6, x + 4, y + 6);
139: }
140: }
141:
142: public int getIconWidth() {
143: return SIZE;
144: }
145:
146: public int getIconHeight() {
147: return SIZE;
148: }
149: }
150:
151: // Paints the icon for a radio button.
152: private static class RadioButtonIcon implements Icon, UIResource,
153: Serializable {
154:
155: private static final int SIZE = 13;
156:
157: public void paintIcon(Component c, Graphics g, int x, int y) {
158: AbstractButton b = (AbstractButton) c;
159: ButtonModel model = b.getModel();
160:
161: // fill interior
162: g.setColor(UIManager.getColor((model.isPressed() && model
163: .isArmed())
164: || !model.isEnabled() ? "RadioButton.background"
165: : "RadioButton.interiorBackground"));
166: g.fillRect(x + 2, y + 2, 8, 8);
167:
168: // outter left arc
169: g.setColor(UIManager.getColor("RadioButton.shadow"));
170: g.drawLine(x + 4, y + 0, x + 7, y + 0);
171: g.drawLine(x + 2, y + 1, x + 3, y + 1);
172: g.drawLine(x + 8, y + 1, x + 9, y + 1);
173: g.drawLine(x + 1, y + 2, x + 1, y + 3);
174: g.drawLine(x + 0, y + 4, x + 0, y + 7);
175: g.drawLine(x + 1, y + 8, x + 1, y + 9);
176:
177: // outter right arc
178: g.setColor(UIManager.getColor("RadioButton.highlight"));
179: g.drawLine(x + 2, y + 10, x + 3, y + 10);
180: g.drawLine(x + 4, y + 11, x + 7, y + 11);
181: g.drawLine(x + 8, y + 10, x + 9, y + 10);
182: g.drawLine(x + 10, y + 9, x + 10, y + 8);
183: g.drawLine(x + 11, y + 7, x + 11, y + 4);
184: g.drawLine(x + 10, y + 3, x + 10, y + 2);
185:
186: // inner left arc
187: g.setColor(UIManager.getColor("RadioButton.darkShadow"));
188: g.drawLine(x + 4, y + 1, x + 7, y + 1);
189: g.drawLine(x + 2, y + 2, x + 3, y + 2);
190: g.drawLine(x + 8, y + 2, x + 9, y + 2);
191: g.drawLine(x + 2, y + 3, x + 2, y + 3);
192: g.drawLine(x + 1, y + 4, x + 1, y + 7);
193: g.drawLine(x + 2, y + 8, x + 2, y + 8);
194:
195: // inner right arc
196: g.setColor(UIManager.getColor("RadioButton.light"));
197: g.drawLine(x + 2, y + 9, x + 3, y + 9);
198: g.drawLine(x + 4, y + 10, x + 7, y + 10);
199: g.drawLine(x + 8, y + 9, x + 9, y + 9);
200: g.drawLine(x + 9, y + 8, x + 9, y + 8);
201: g.drawLine(x + 10, y + 7, x + 10, y + 4);
202: g.drawLine(x + 9, y + 3, x + 9, y + 3);
203:
204: // indicate whether selected or not
205: if (model.isSelected()) {
206: g
207: .setColor(UIManager
208: .getColor("RadioButton.checkColor")); // Modified by JGoodies
209: g.fillRect(x + 4, y + 5, 4, 2);
210: g.fillRect(x + 5, y + 4, 2, 4);
211: }
212: }
213:
214: public int getIconWidth() {
215: return SIZE;
216: }
217:
218: public int getIconHeight() {
219: return SIZE;
220: }
221:
222: }
223:
224: }
|