KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > nimbus > InternalFramePainter


1 /*
2  * InternalFramePainter.java %E%
3  *
4  * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package com.sun.java.swing.plaf.nimbus;
8
9 import java.awt.*;
10 import java.awt.geom.*;
11 import java.awt.image.*;
12 import javax.swing.*;
13 import com.sun.java.swing.Painter;
14
15 /**
16  */

17 public final class InternalFramePainter extends AbstractRegionPainter {
18     //package private integers representing the available states that
19
//this painter will paint. These are used when creating a new instance
20
//of InternalFramePainter to determine which region/state is being painted
21
//by that instance.
22
static final int BACKGROUND_ENABLED = 1;
23     static final int BACKGROUND_ENABLED_WINDOWFOCUSED = 2;
24
25
26     private int state; //refers to one of the static final ints above
27
private PaintContext ctx;
28
29     //the following 4 variables are reused during the painting code of the layers
30
private Path2D path = new Path2D.Float();
31     private Rectangle2D rect = new Rectangle2D.Float(0, 0, 0, 0);
32     private RoundRectangle2D roundRect = new RoundRectangle2D.Float(0, 0, 0, 0, 0, 0);
33     private Ellipse2D ellipse = new Ellipse2D.Float(0, 0, 0, 0);
34
35     //All Colors used for painting are stored here. Ideally, only those colors being used
36
//by a particular instance of InternalFramePainter would be created. For the moment at least,
37
//however, all are created for each instance.
38
private Color color1 = decodeColor("nimbusBase", 0.032459438f, -0.53637654f, 0.043137252f, 0);
39     private Color color2 = decodeColor("nimbusBlueGrey", 0.004273474f, -0.039488062f, -0.027450979f, 0);
40     private Color color3 = decodeColor("nimbusBlueGrey", -0.00505054f, -0.056339122f, 0.05098039f, 0);
41     private Color color4 = decodeColor("nimbusBlueGrey", -0.01111114f, -0.06357796f, 0.09019607f, 0);
42     private Color color5 = decodeColor("nimbusBlueGrey", 0.0f, -0.023821115f, -0.06666666f, 0);
43     private Color color6 = decodeColor("control", 0.0f, 0.0f, 0.0f, 0);
44     private Color color7 = decodeColor("nimbusBlueGrey", -0.006944418f, -0.07399663f, 0.11372548f, 0);
45     private Color color8 = decodeColor("nimbusBase", 0.02551502f, -0.47885156f, -0.34901965f, 0);
46     private Color color9 = new Color(255, 200, 0, 255);
47     private Color color10 = decodeColor("nimbusBase", 0.004681647f, -0.6274498f, 0.39999998f, 0);
48     private Color color11 = decodeColor("nimbusBase", 0.032459438f, -0.5934608f, 0.2862745f, 0);
49     private Color color12 = new Color(204, 207, 213, 255);
50     private Color color13 = decodeColor("nimbusBase", 0.032459438f, -0.55506915f, 0.18039215f, 0);
51     private Color color14 = decodeColor("nimbusBase", 0.004681647f, -0.52792984f, 0.10588235f, 0);
52     private Color color15 = decodeColor("nimbusBase", 0.03801495f, -0.4794643f, -0.04705882f, 0);
53     private Color color16 = decodeColor("nimbusBase", 0.021348298f, -0.61416256f, 0.3607843f, 0);
54     private Color color17 = decodeColor("nimbusBase", 0.032459438f, -0.5546332f, 0.17647058f, 0);
55     private Color color18 = new Color(235, 236, 238, 255);
56
57
58     //Array of current component colors, updated in each paint call
59
private Object JavaDoc[] componentColors;
60
61     public InternalFramePainter(PaintContext ctx, int state) {
62         super();
63         this.state = state;
64         this.ctx = ctx;
65     }
66
67     @Override JavaDoc
68     protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object JavaDoc[] extendedCacheKeys) {
69         //populate componentColors array with colors calculated in getExtendedCacheKeys call
70
componentColors = extendedCacheKeys;
71         //generate this entire method. Each state/bg/fg/border combo that has
72
//been painted gets its own KEY and paint method.
73
switch(state) {
74             case BACKGROUND_ENABLED: paintBackgroundEnabled(g); break;
75             case BACKGROUND_ENABLED_WINDOWFOCUSED: paintBackgroundEnabledAndWindowFocused(g); break;
76
77         }
78     }
79         
80
81
82     @Override JavaDoc
83     protected final PaintContext getPaintContext() {
84         return ctx;
85     }
86
87     private void paintBackgroundEnabled(Graphics2D g) {
88         roundRect = decodeRoundRect1();
89         g.setPaint(color1);
90         g.fill(roundRect);
91         path = decodePath1();
92         g.setPaint(decodeGradient1(path));
93         g.fill(path);
94         path = decodePath2();
95         g.setPaint(color3);
96         g.fill(path);
97         path = decodePath3();
98         g.setPaint(color4);
99         g.fill(path);
100         path = decodePath4();
101         g.setPaint(color5);
102         g.fill(path);
103         rect = decodeRect1();
104         g.setPaint(color6);
105         g.fill(rect);
106         rect = decodeRect2();
107         g.setPaint(color7);
108         g.fill(rect);
109
110     }
111
112     private void paintBackgroundEnabledAndWindowFocused(Graphics2D g) {
113         roundRect = decodeRoundRect2();
114         g.setPaint(color8);
115         g.fill(roundRect);
116         path = decodePath5();
117         g.setPaint(color9);
118         g.fill(path);
119         path = decodePath1();
120         g.setPaint(decodeGradient2(path));
121         g.fill(path);
122         path = decodePath6();
123         g.setPaint(color12);
124         g.fill(path);
125         path = decodePath7();
126         g.setPaint(color13);
127         g.fill(path);
128         path = decodePath8();
129         g.setPaint(color14);
130         g.fill(path);
131         path = decodePath9();
132         g.setPaint(color15);
133         g.fill(path);
134         rect = decodeRect1();
135         g.setPaint(color6);
136         g.fill(rect);
137         rect = decodeRect3();
138         g.setPaint(color9);
139         g.fill(rect);
140         rect = decodeRect3();
141         g.setPaint(color9);
142         g.fill(rect);
143         rect = decodeRect3();
144         g.setPaint(color9);
145         g.fill(rect);
146         rect = decodeRect4();
147         g.setPaint(decodeGradient3(rect));
148         g.fill(rect);
149         rect = decodeRect2();
150         g.setPaint(color18);
151         g.fill(rect);
152
153     }
154
155
156
157     private RoundRectangle2D decodeRoundRect1() {
158         roundRect.setRoundRect(decodeX(0.0f), //x
159
decodeY(0.0f), //y
160
decodeX(3.0f) - decodeX(0.0f), //width
161
decodeY(3.0f) - decodeY(0.0f), //height
162
4.6666665f, 4.6666665f); //rounding
163
return roundRect;
164     }
165
166     private Path2D decodePath1() {
167         path.reset();
168         path.moveTo(decodeX(0.16666667f), decodeY(0.12f));
169         path.curveTo(decodeAnchorX(0.1666666716337204f, 0.0f), decodeAnchorY(0.11999999731779099f, -1.0f), decodeAnchorX(0.5f, -1.0f), decodeAnchorY(0.03999999910593033f, 0.0f), decodeX(0.5f), decodeY(0.04f));
170         path.curveTo(decodeAnchorX(0.5f, 1.0f), decodeAnchorY(0.03999999910593033f, 0.0f), decodeAnchorX(2.5f, -1.0f), decodeAnchorY(0.03999999910593033f, 0.0f), decodeX(2.5f), decodeY(0.04f));
171         path.curveTo(decodeAnchorX(2.5f, 1.0f), decodeAnchorY(0.03999999910593033f, 0.0f), decodeAnchorX(2.8333332538604736f, 0.0f), decodeAnchorY(0.11999999731779099f, -1.0f), decodeX(2.8333333f), decodeY(0.12f));
172         path.curveTo(decodeAnchorX(2.8333332538604736f, 0.0f), decodeAnchorY(0.11999999731779099f, 1.0f), decodeAnchorX(2.8333332538604736f, 0.0f), decodeAnchorY(0.9599999785423279f, 0.0f), decodeX(2.8333333f), decodeY(0.96f));
173         path.lineTo(decodeX(0.16666667f), decodeY(0.96f));
174         path.curveTo(decodeAnchorX(0.1666666716337204f, 0.0f), decodeAnchorY(0.9599999785423279f, 0.0f), decodeAnchorX(0.1666666716337204f, 0.0f), decodeAnchorY(0.11999999731779099f, 1.0f), decodeX(0.16666667f), decodeY(0.12f));
175         path.closePath();
176         return path;
177     }
178
179     private Path2D decodePath2() {
180         path.reset();
181         path.moveTo(decodeX(0.6666667f), decodeY(0.96f));
182         path.lineTo(decodeX(0.16666667f), decodeY(0.96f));
183         path.curveTo(decodeAnchorX(0.1666666716337204f, 0.0f), decodeAnchorY(0.9599999785423279f, 0.0f), decodeAnchorX(0.1666666716337204f, 0.0f), decodeAnchorY(2.5f, -1.0f), decodeX(0.16666667f), decodeY(2.5f));
184         path.curveTo(decodeAnchorX(0.1666666716337204f, 0.0f), decodeAnchorY(2.5f, 1.0f), decodeAnchorX(0.5f, -1.0f), decodeAnchorY(2.8333332538604736f, 0.0f), decodeX(0.5f), decodeY(2.8333333f));
185         path.curveTo(decodeAnchorX(0.5f, 1.0f), decodeAnchorY(2.8333332538604736f, 0.0f), decodeAnchorX(2.5f, -1.0f), decodeAnchorY(2.8333332538604736f, 0.0f), decodeX(2.5f), decodeY(2.8333333f));
186         path.curveTo(decodeAnchorX(2.5f, 1.0f), decodeAnchorY(2.8333332538604736f, 0.0f), decodeAnchorX(2.8333332538604736f, 0.0f), decodeAnchorY(2.5f, 1.0f), decodeX(2.8333333f), decodeY(2.5f));
187         path.curveTo(decodeAnchorX(2.8333332538604736f, 0.0f), decodeAnchorY(2.5f, -1.0f), decodeAnchorX(2.8333332538604736f, 0.0f), decodeAnchorY(0.9599999785423279f, 0.0f), decodeX(2.8333333f), decodeY(0.96f));
188         path.lineTo(decodeX(2.3333333f), decodeY(0.96f));
189         path.lineTo(decodeX(2.3333333f), decodeY(2.3333333f));
190         path.lineTo(decodeX(0.6666667f), decodeY(2.3333333f));
191         path.lineTo(decodeX(0.6666667f), decodeY(0.96f));
192         path.closePath();
193         return path;
194     }
195
196     private Path2D decodePath3() {
197         path.reset();
198         path.moveTo(decodeX(0.8333333f), decodeY(0.96f));
199         path.lineTo(decodeX(0.6666667f), decodeY(0.96f));
200         path.lineTo(decodeX(0.6666667f), decodeY(2.3333333f));
201         path.lineTo(decodeX(2.3333333f), decodeY(2.3333333f));
202         path.lineTo(decodeX(2.3333333f), decodeY(0.96f));
203         path.lineTo(decodeX(2.1666667f), decodeY(0.96f));
204         path.lineTo(decodeX(2.1666667f), decodeY(2.1666667f));
205         path.lineTo(decodeX(0.8333333f), decodeY(2.1666667f));
206         path.lineTo(decodeX(0.8333333f), decodeY(0.96f));
207         path.closePath();
208         return path;
209     }
210
211     private Path2D decodePath4() {
212         path.reset();
213         path.moveTo(decodeX(2.1666667f), decodeY(1.0f));
214         path.lineTo(decodeX(1.0f), decodeY(1.0f));
215         path.lineTo(decodeX(1.0f), decodeY(2.0f));
216         path.lineTo(decodeX(2.0f), decodeY(2.0f));
217         path.lineTo(decodeX(2.0f), decodeY(1.0f));
218         path.lineTo(decodeX(2.1666667f), decodeY(1.0f));
219         path.lineTo(decodeX(2.1666667f), decodeY(2.1666667f));
220         path.lineTo(decodeX(0.8333333f), decodeY(2.1666667f));
221         path.lineTo(decodeX(0.8333333f), decodeY(0.96f));
222         path.lineTo(decodeX(2.1666667f), decodeY(0.96f));
223         path.lineTo(decodeX(2.1666667f), decodeY(1.0f));
224         path.closePath();
225         return path;
226     }
227
228     private Rectangle2D decodeRect1() {
229             rect.setRect(decodeX(1.0f), //x
230
decodeY(1.0f), //y
231
decodeX(2.0f) - decodeX(1.0f), //width
232
decodeY(2.0f) - decodeY(1.0f)); //height
233
return rect;
234     }
235
236     private Rectangle2D decodeRect2() {
237             rect.setRect(decodeX(0.33333334f), //x
238
decodeY(2.6666667f), //y
239
decodeX(2.6666667f) - decodeX(0.33333334f), //width
240
decodeY(2.8333333f) - decodeY(2.6666667f)); //height
241
return rect;
242     }
243
244     private RoundRectangle2D decodeRoundRect2() {
245         roundRect.setRoundRect(decodeX(0.0f), //x
246
decodeY(0.0f), //y
247
decodeX(3.0f) - decodeX(0.0f), //width
248
decodeY(3.0f) - decodeY(0.0f), //height
249
4.8333335f, 4.8333335f); //rounding
250
return roundRect;
251     }
252
253     private Path2D decodePath5() {
254         path.reset();
255         path.moveTo(decodeX(0.16666667f), decodeY(0.08f));
256         path.curveTo(decodeAnchorX(0.1666666716337204f, 0.0f), decodeAnchorY(0.07999999821186066f, 1.0f), decodeAnchorX(0.1666666716337204f, 0.0f), decodeAnchorY(0.07999999821186066f, -1.0f), decodeX(0.16666667f), decodeY(0.08f));
257         path.closePath();
258         return path;
259     }
260
261     private Path2D decodePath6() {
262         path.reset();
263         path.moveTo(decodeX(0.5f), decodeY(0.96f));
264         path.lineTo(decodeX(0.16666667f), decodeY(0.96f));
265         path.curveTo(decodeAnchorX(0.1666666716337204f, 0.0f), decodeAnchorY(0.9599999785423279f, 0.0f), decodeAnchorX(0.1666666716337204f, 0.0f), decodeAnchorY(2.5f, -1.0f), decodeX(0.16666667f), decodeY(2.5f));
266         path.curveTo(decodeAnchorX(0.1666666716337204f, 0.0f), decodeAnchorY(2.5f, 1.0f), decodeAnchorX(0.5f, -1.0f), decodeAnchorY(2.8333332538604736f, 0.0f), decodeX(0.5f), decodeY(2.8333333f));
267         path.curveTo(decodeAnchorX(0.5f, 1.0f), decodeAnchorY(2.8333332538604736f, 0.0f), decodeAnchorX(2.5f, -1.0f), decodeAnchorY(2.8333332538604736f, 0.0f), decodeX(2.5f), decodeY(2.8333333f));
268         path.curveTo(decodeAnchorX(2.5f, 1.0f), decodeAnchorY(2.8333332538604736f, 0.0f), decodeAnchorX(2.8333332538604736f, 0.0f), decodeAnchorY(2.5f, 1.0f), decodeX(2.8333333f), decodeY(2.5f));
269         path.curveTo(decodeAnchorX(2.8333332538604736f, 0.0f), decodeAnchorY(2.5f, -1.0f), decodeAnchorX(2.8333332538604736f, 0.0f), decodeAnchorY(0.9599999785423279f, 0.0f), decodeX(2.8333333f), decodeY(0.96f));
270         path.lineTo(decodeX(2.5f), decodeY(0.96f));
271         path.lineTo(decodeX(2.5f), decodeY(2.5f));
272         path.lineTo(decodeX(0.5f), decodeY(2.5f));
273         path.lineTo(decodeX(0.5f), decodeY(0.96f));
274         path.closePath();
275         return path;
276     }
277
278     private Path2D decodePath7() {
279         path.reset();
280         path.moveTo(decodeX(0.6666667f), decodeY(0.96f));
281         path.lineTo(decodeX(0.33333334f), decodeY(0.96f));
282         path.curveTo(decodeAnchorX(0.3333333432674408f, 0.0f), decodeAnchorY(0.9599999785423279f, 0.0f), decodeAnchorX(0.3333333432674408f, 0.0f), decodeAnchorY(2.3333332538604736f, -1.0f), decodeX(0.33333334f), decodeY(2.3333333f));
283         path.curveTo(decodeAnchorX(0.3333333432674408f, 0.0f), decodeAnchorY(2.3333332538604736f, 1.0f), decodeAnchorX(0.6666666865348816f, -1.0f), decodeAnchorY(2.6666667461395264f, 0.0f), decodeX(0.6666667f), decodeY(2.6666667f));
284         path.curveTo(decodeAnchorX(0.6666666865348816f, 1.0f), decodeAnchorY(2.6666667461395264f, 0.0f), decodeAnchorX(2.3333332538604736f, -1.0f), decodeAnchorY(2.6666667461395264f, 0.0f), decodeX(2.3333333f), decodeY(2.6666667f));
285         path.curveTo(decodeAnchorX(2.3333332538604736f, 1.0f), decodeAnchorY(2.6666667461395264f, 0.0f), decodeAnchorX(2.6666667461395264f, 0.0f), decodeAnchorY(2.3333332538604736f, 1.0f), decodeX(2.6666667f), decodeY(2.3333333f));
286         path.curveTo(decodeAnchorX(2.6666667461395264f, 0.0f), decodeAnchorY(2.3333332538604736f, -1.0f), decodeAnchorX(2.6666667461395264f, 0.0f), decodeAnchorY(0.9599999785423279f, 0.0f), decodeX(2.6666667f), decodeY(0.96f));
287         path.lineTo(decodeX(2.3333333f), decodeY(0.96f));
288         path.lineTo(decodeX(2.3333333f), decodeY(2.3333333f));
289         path.lineTo(decodeX(0.6666667f), decodeY(2.3333333f));
290         path.lineTo(decodeX(0.6666667f), decodeY(0.96f));
291         path.closePath();
292         return path;
293     }
294
295     private Path2D decodePath8() {
296         path.reset();
297         path.moveTo(decodeX(2.3333333f), decodeY(0.96f));
298         path.lineTo(decodeX(2.1666667f), decodeY(0.96f));
299         path.lineTo(decodeX(2.1666667f), decodeY(2.1666667f));
300         path.lineTo(decodeX(0.8333333f), decodeY(2.1666667f));
301         path.lineTo(decodeX(0.8333333f), decodeY(0.96f));
302         path.lineTo(decodeX(0.6666667f), decodeY(0.96f));
303         path.lineTo(decodeX(0.6666667f), decodeY(2.3333333f));
304         path.lineTo(decodeX(2.3333333f), decodeY(2.3333333f));
305         path.lineTo(decodeX(2.3333333f), decodeY(0.96f));
306         path.closePath();
307         return path;
308     }
309
310     private Path2D decodePath9() {
311         path.reset();
312         path.moveTo(decodeX(0.8333333f), decodeY(1.0f));
313         path.lineTo(decodeX(0.8333333f), decodeY(2.1666667f));
314         path.lineTo(decodeX(2.1666667f), decodeY(2.1666667f));
315         path.lineTo(decodeX(2.1666667f), decodeY(0.96f));
316         path.lineTo(decodeX(0.8333333f), decodeY(0.96f));
317         path.lineTo(decodeX(0.8333333f), decodeY(1.0f));
318         path.lineTo(decodeX(2.0f), decodeY(1.0f));
319         path.lineTo(decodeX(2.0f), decodeY(2.0f));
320         path.lineTo(decodeX(1.0f), decodeY(2.0f));
321         path.lineTo(decodeX(1.0f), decodeY(1.0f));
322         path.lineTo(decodeX(0.8333333f), decodeY(1.0f));
323         path.closePath();
324         return path;
325     }
326
327     private Rectangle2D decodeRect3() {
328             rect.setRect(decodeX(0.0f), //x
329
decodeY(0.0f), //y
330
decodeX(0.0f) - decodeX(0.0f), //width
331
decodeY(0.0f) - decodeY(0.0f)); //height
332
return rect;
333     }
334
335     private Rectangle2D decodeRect4() {
336             rect.setRect(decodeX(0.33333334f), //x
337
decodeY(0.08f), //y
338
decodeX(2.6666667f) - decodeX(0.33333334f), //width
339
decodeY(0.96f) - decodeY(0.08f)); //height
340
return rect;
341     }
342
343
344
345     private Paint decodeGradient1(Shape s) {
346         Rectangle2D bounds = s.getBounds2D();
347         float x = (float)bounds.getX();
348         float y = (float)bounds.getY();
349         float w = (float)bounds.getWidth();
350         float h = (float)bounds.getHeight();
351         return decodeGradient((0.5f * w) + x, (0.0f * h) + y, (0.5f * w) + x, (1.0f * h) + y,
352                 new float[] { 0.0f,0.3203593f,1.0f },
353                 new Color[] { color2,
354                             decodeColor(color2,color3,0.5f),
355                             color3});
356     }
357
358     private Paint decodeGradient2(Shape s) {
359         Rectangle2D bounds = s.getBounds2D();
360         float x = (float)bounds.getX();
361         float y = (float)bounds.getY();
362         float w = (float)bounds.getWidth();
363         float h = (float)bounds.getHeight();
364         return decodeGradient((0.5f * w) + x, (0.0f * h) + y, (0.5f * w) + x, (1.0f * h) + y,
365                 new float[] { 0.0f,0.5f,1.0f },
366                 new Color[] { color10,
367                             decodeColor(color10,color11,0.5f),
368                             color11});
369     }
370
371     private Paint decodeGradient3(Shape s) {
372         Rectangle2D bounds = s.getBounds2D();
373         float x = (float)bounds.getX();
374         float y = (float)bounds.getY();
375         float w = (float)bounds.getWidth();
376         float h = (float)bounds.getHeight();
377         return decodeGradient((0.5f * w) + x, (0.0f * h) + y, (0.5f * w) + x, (1.0f * h) + y,
378                 new float[] { 0.0f,0.24251497f,1.0f },
379                 new Color[] { color16,
380                             decodeColor(color16,color17,0.5f),
381                             color17});
382     }
383
384
385 }
386
Popular Tags