KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jgoodies > looks > windows > WindowsUtils


1 /*
2  * Copyright (c) 2001-2005 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.Graphics JavaDoc;
34
35 import javax.swing.UIManager JavaDoc;
36
37 /**
38  * Drawing utils.
39  *
40  * @author Karsten Lentzsch
41  * @version $Revision: 1.2 $
42  */

43
44 final class WindowsUtils {
45     
46     private WindowsUtils() {
47         // Override default constructor; prevents instantiation.
48
}
49     
50     /*
51     static class CheckBoxIcon implements Icon, Serializable, UIResource {
52         final static int csize = 13;
53
54         private final Color background;
55         private final Color highlight;
56         private final Color shadow;
57         private final Color darkShadow;
58
59         CheckBoxIcon(Color background, Color highlight, Color shadow, Color darkShadow) {
60             this.background = background;
61             this.highlight = highlight;
62             this.shadow = shadow;
63             this.darkShadow = darkShadow;
64         }
65
66         public void paintIcon(Component c, Graphics g, int x, int y) {
67             AbstractButton b = (AbstractButton) c;
68             ButtonModel model = b.getModel();
69
70             // outer bevel
71             g.setColor(background);
72             g.fill3DRect(x, y, csize, csize, false);
73
74             // inner bevel
75             g.setColor(shadow);
76             g.fill3DRect(x + 1, y + 1, csize - 2, csize - 2, false);
77
78             // inside box
79             if ((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
80                 g.setColor(background);
81             } else {
82                 g.setColor(highlight);
83             }
84             g.fillRect(x + 2, y + 2, csize - 4, csize - 4);
85
86             if (model.isEnabled()) {
87                 g.setColor(darkShadow);
88             } else {
89                 g.setColor(shadow);
90             }
91
92             // paint check
93             if (model.isSelected()) {
94                 g.drawLine(x + 9, y + 3, x + 9, y + 3);
95                 g.drawLine(x + 8, y + 4, x + 9, y + 4);
96                 g.drawLine(x + 7, y + 5, x + 9, y + 5);
97                 g.drawLine(x + 6, y + 6, x + 8, y + 6);
98                 g.drawLine(x + 3, y + 7, x + 7, y + 7);
99                 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 drawDashedRect(Graphics JavaDoc g, int x, int y, int width, int height) {
195         int vx, vy;
196     
197         // draw upper and lower horizontal dashes
198
for (vx = x; vx < (x + width); vx += 2) {
199             g.fillRect(vx, y, 1, 1);
200             g.fillRect(vx, y + height - 1, 1, 1);
201         }
202     
203         // draw left and right vertical dashes
204
for (vy = y; vy < (y + height); vy += 2) {
205             g.fillRect(x, vy, 1, 1);
206             g.fillRect(x + width - 1, vy, 1, 1);
207         }
208     }
209     
210     
211     static void drawFlush3DBorder(Graphics JavaDoc g, int x, int y, int w, int h) {
212         g.translate(x, y);
213         g.setColor(UIManager.getColor("controlLtHighlight"));
214         g.drawLine(0, 0, w - 2, 0);
215         g.drawLine(0, 0, 0, h - 2);
216         g.setColor(UIManager.getColor("controlShadow"));
217         g.drawLine(w - 1, 0, w - 1, h - 1);
218         g.drawLine(0, h - 1, w - 1, h - 1);
219         g.translate(-x, -y);
220     }
221     
222     
223     static void drawPressed3DBorder(Graphics JavaDoc g, int x, int y, int w, int h) {
224         g.translate(x, y);
225         g.setColor(UIManager.getColor("controlShadow"));
226         g.drawLine(0, 0, w - 2, 0);
227         g.drawLine(0, 0, 0, h - 2);
228         g.setColor(UIManager.getColor("controlLtHighlight"));
229         g.drawLine(w - 1, 0, w - 1, h - 1);
230         g.drawLine(0, h - 1, w - 1, h - 1);
231         g.translate(-x, -y);
232     }
233 }
234
Popular Tags