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.Graphics;
034:
035: import javax.swing.UIManager;
036:
037: /**
038: * Drawing utils.
039: *
040: * @author Karsten Lentzsch
041: * @version $Revision: 1.4 $
042: */
043:
044: final class WindowsUtils {
045:
046: private WindowsUtils() {
047: // Override default constructor; prevents instantiation.
048: }
049:
050: /*
051: static class CheckBoxIcon implements Icon, Serializable, UIResource {
052: final static int csize = 13;
053:
054: private final Color background;
055: private final Color highlight;
056: private final Color shadow;
057: private final Color darkShadow;
058:
059: CheckBoxIcon(Color background, Color highlight, Color shadow, Color darkShadow) {
060: this.background = background;
061: this.highlight = highlight;
062: this.shadow = shadow;
063: this.darkShadow = darkShadow;
064: }
065:
066: public void paintIcon(Component c, Graphics g, int x, int y) {
067: AbstractButton b = (AbstractButton) c;
068: ButtonModel model = b.getModel();
069:
070: // outer bevel
071: g.setColor(background);
072: g.fill3DRect(x, y, csize, csize, false);
073:
074: // inner bevel
075: g.setColor(shadow);
076: g.fill3DRect(x + 1, y + 1, csize - 2, csize - 2, false);
077:
078: // inside box
079: if ((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
080: g.setColor(background);
081: } else {
082: g.setColor(highlight);
083: }
084: g.fillRect(x + 2, y + 2, csize - 4, csize - 4);
085:
086: if (model.isEnabled()) {
087: g.setColor(darkShadow);
088: } else {
089: g.setColor(shadow);
090: }
091:
092: // paint check
093: if (model.isSelected()) {
094: g.drawLine(x + 9, y + 3, x + 9, y + 3);
095: g.drawLine(x + 8, y + 4, x + 9, y + 4);
096: g.drawLine(x + 7, y + 5, x + 9, y + 5);
097: g.drawLine(x + 6, y + 6, x + 8, y + 6);
098: g.drawLine(x + 3, y + 7, x + 7, y + 7);
099: g.drawLine(x + 4, y + 8, x + 6, y + 8);
100: g.drawLine(x + 5, y + 9, x + 5, y + 9);
101: g.drawLine(x + 3, y + 5, x + 3, y + 5);
102: g.drawLine(x + 3, y + 6, x + 4, y + 6);
103: }
104: }
105:
106: public int getIconWidth() {
107: return csize;
108: }
109:
110: public int getIconHeight() {
111: return csize;
112: }
113: }
114:
115: static class RadioButtonIcon implements Icon, Serializable, UIResource {
116: private final Color background;
117: private final Color highlight;
118: private final Color shadow;
119: private final Color darkShadow;
120:
121: RadioButtonIcon(Color background, Color highlight, Color shadow, Color darkShadow) {
122: this.background = background;
123: this.highlight = highlight;
124: this.shadow = shadow;
125: this.darkShadow = darkShadow;
126: }
127:
128: public void paintIcon(Component c, Graphics g, int x, int y) {
129: AbstractButton b = (AbstractButton) c;
130: ButtonModel model = b.getModel();
131:
132: // fill interior
133: if ((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
134: g.setColor(background);
135: } else {
136: g.setColor(highlight);
137: }
138: g.fillRect(x + 2, y + 2, 8, 8);
139:
140: // outter left arc
141: g.setColor(shadow);
142: g.drawLine(x + 4, y + 0, x + 7, y + 0);
143: g.drawLine(x + 2, y + 1, x + 3, y + 1);
144: g.drawLine(x + 8, y + 1, x + 9, y + 1);
145: g.drawLine(x + 1, y + 2, x + 1, y + 3);
146: g.drawLine(x + 0, y + 4, x + 0, y + 7);
147: g.drawLine(x + 1, y + 8, x + 1, y + 9);
148:
149: // outter right arc
150: g.setColor(highlight);
151: g.drawLine(x + 2, y + 10, x + 3, y + 10);
152: g.drawLine(x + 4, y + 11, x + 7, y + 11);
153: g.drawLine(x + 8, y + 10, x + 9, y + 10);
154: g.drawLine(x + 10, y + 9, x + 10, y + 8);
155: g.drawLine(x + 11, y + 7, x + 11, y + 4);
156: g.drawLine(x + 10, y + 3, x + 10, y + 2);
157:
158: // inner left arc
159: g.setColor(darkShadow);
160: g.drawLine(x + 4, y + 1, x + 7, y + 1);
161: g.drawLine(x + 2, y + 2, x + 3, y + 2);
162: g.drawLine(x + 8, y + 2, x + 9, y + 2);
163: g.drawLine(x + 2, y + 3, x + 2, y + 3);
164: g.drawLine(x + 1, y + 4, x + 1, y + 7);
165: g.drawLine(x + 2, y + 8, x + 2, y + 8);
166:
167: // inner right arc
168: g.setColor(background);
169: g.drawLine(x + 2, y + 9, x + 3, y + 9);
170: g.drawLine(x + 4, y + 10, x + 7, y + 10);
171: g.drawLine(x + 8, y + 9, x + 9, y + 9);
172: g.drawLine(x + 9, y + 8, x + 9, y + 8);
173: g.drawLine(x + 10, y + 7, x + 10, y + 4);
174: g.drawLine(x + 9, y + 3, x + 9, y + 3);
175:
176: // indicate whether selected or not
177: if (model.isSelected()) {
178: g.setColor(darkShadow);
179: g.fillRect(x + 4, y + 5, 4, 2);
180: g.fillRect(x + 5, y + 4, 2, 4);
181: }
182: }
183:
184: public int getIconWidth() {
185: return 13;
186: }
187:
188: public int getIconHeight() {
189: return 13;
190: }
191: }
192: */
193:
194: public static void drawRoundedDashedRect(Graphics g, int x, int y,
195: int width, int height) {
196: for (int vx = x + 1; vx < (x + width); vx += 2) {
197: g.fillRect(vx, y, 1, 1);
198: g.fillRect(vx, y + height - 1, 1, 1);
199: }
200: int offset = (width + 1) % 2;
201: for (int vy = y + 1; vy < (y + height - offset); vy += 2) {
202: g.fillRect(x, vy, 1, 1);
203: g.fillRect(x + width - 1, vy + offset, 1, 1);
204: }
205: }
206:
207: static void drawFlush3DBorder(Graphics g, int x, int y, int w, int h) {
208: g.translate(x, y);
209: g.setColor(UIManager.getColor("controlLtHighlight"));
210: g.drawLine(0, 0, w - 2, 0);
211: g.drawLine(0, 0, 0, h - 2);
212: g.setColor(UIManager.getColor("controlShadow"));
213: g.drawLine(w - 1, 0, w - 1, h - 1);
214: g.drawLine(0, h - 1, w - 1, h - 1);
215: g.translate(-x, -y);
216: }
217:
218: static void drawPressed3DBorder(Graphics g, int x, int y, int w,
219: int h) {
220: g.translate(x, y);
221: g.setColor(UIManager.getColor("controlShadow"));
222: g.drawLine(0, 0, w - 2, 0);
223: g.drawLine(0, 0, 0, h - 2);
224: g.setColor(UIManager.getColor("controlLtHighlight"));
225: g.drawLine(w - 1, 0, w - 1, h - 1);
226: g.drawLine(0, h - 1, w - 1, h - 1);
227: g.translate(-x, -y);
228: }
229: }
|