KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * DesktopPanePainter.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 DesktopPanePainter 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 DesktopPanePainter to determine which region/state is being painted
21
//by that instance.
22
static final int BACKGROUND_ENABLED = 1;
23
24
25     private int state; //refers to one of the static final ints above
26
private PaintContext ctx;
27
28     //the following 4 variables are reused during the painting code of the layers
29
private Path2D path = new Path2D.Float();
30     private Rectangle2D rect = new Rectangle2D.Float(0, 0, 0, 0);
31     private RoundRectangle2D roundRect = new RoundRectangle2D.Float(0, 0, 0, 0, 0, 0);
32     private Ellipse2D ellipse = new Ellipse2D.Float(0, 0, 0, 0);
33
34     //All Colors used for painting are stored here. Ideally, only those colors being used
35
//by a particular instance of DesktopPanePainter would be created. For the moment at least,
36
//however, all are created for each instance.
37
private Color color1 = decodeColor("nimbusBase", -0.004577577f, -0.12867206f, 0.007843137f, 0);
38     private Color color2 = decodeColor("nimbusBase", -0.0063245893f, -0.08363098f, -0.17254904f, 0);
39     private Color color3 = decodeColor("nimbusBase", -3.6883354E-4f, -0.056766927f, -0.10196081f, 0);
40     private Color color4 = decodeColor("nimbusBase", -0.008954704f, -0.12645501f, -0.12549022f, 0);
41     private Color color5 = new Color(255, 200, 0, 6);
42     private Color color6 = decodeColor("nimbusBase", -8.028746E-5f, -0.084533215f, -0.05098042f, 0);
43     private Color color7 = decodeColor("nimbusBase", -0.0052053332f, -0.12267083f, -0.09803924f, 0);
44     private Color color8 = decodeColor("nimbusBase", -0.012559712f, -0.13136649f, -0.09803924f, 0);
45     private Color color9 = decodeColor("nimbusBase", -0.009207249f, -0.13984653f, -0.07450983f, 0);
46     private Color color10 = decodeColor("nimbusBase", -0.010750473f, -0.13571429f, -0.12549022f, 0);
47     private Color color11 = decodeColor("nimbusBase", -0.008476257f, -0.1267857f, -0.109803945f, 0);
48     private Color color12 = decodeColor("nimbusBase", -0.0034883022f, -0.042691052f, -0.21176472f, 0);
49     private Color color13 = decodeColor("nimbusBase", -0.012613952f, -0.11610645f, -0.14901963f, 0);
50     private Color color14 = decodeColor("nimbusBase", -0.0038217902f, -0.05238098f, -0.21960786f, 0);
51
52
53     //Array of current component colors, updated in each paint call
54
private Object JavaDoc[] componentColors;
55
56     public DesktopPanePainter(PaintContext ctx, int state) {
57         super();
58         this.state = state;
59         this.ctx = ctx;
60     }
61
62     @Override JavaDoc
63     protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object JavaDoc[] extendedCacheKeys) {
64         //populate componentColors array with colors calculated in getExtendedCacheKeys call
65
componentColors = extendedCacheKeys;
66         //generate this entire method. Each state/bg/fg/border combo that has
67
//been painted gets its own KEY and paint method.
68
switch(state) {
69             case BACKGROUND_ENABLED: paintBackgroundEnabled(g); break;
70
71         }
72     }
73         
74
75
76     @Override JavaDoc
77     protected final PaintContext getPaintContext() {
78         return ctx;
79     }
80
81     private void paintBackgroundEnabled(Graphics2D g) {
82         path = decodePath1();
83         g.setPaint(decodeGradient1(path));
84         g.fill(path);
85         path = decodePath2();
86         g.setPaint(decodeGradient2(path));
87         g.fill(path);
88         path = decodePath3();
89         g.setPaint(color5);
90         g.fill(path);
91         path = decodePath4();
92         g.setPaint(decodeGradient3(path));
93         g.fill(path);
94         path = decodePath5();
95         g.setPaint(decodeGradient4(path));
96         g.fill(path);
97         path = decodePath6();
98         g.setPaint(decodeGradient5(path));
99         g.fill(path);
100         path = decodePath7();
101         g.setPaint(decodeGradient6(path));
102         g.fill(path);
103         path = decodePath8();
104         g.setPaint(decodeGradient7(path));
105         g.fill(path);
106         path = decodePath9();
107         g.setPaint(decodeGradient8(path));
108         g.fill(path);
109
110     }
111
112
113
114     private Path2D decodePath1() {
115         path.reset();
116         path.moveTo(decodeX(1.2716666f), decodeY(2.0f));
117         path.curveTo(decodeAnchorX(1.2716666460037231f, 0.0f), decodeAnchorY(2.0f, 0.5f), decodeAnchorX(1.128333330154419f, 0.0f), decodeAnchorY(1.0f, 0.0f), decodeX(1.1283333f), decodeY(1.0f));
118         path.lineTo(decodeX(1.3516667f), decodeY(1.0f));
119         path.lineTo(decodeX(1.5866666f), decodeY(1.5754311f));
120         path.lineTo(decodeX(1.5416667f), decodeY(2.0f));
121         path.curveTo(decodeAnchorX(1.5416667461395264f, 0.0f), decodeAnchorY(2.0f, 0.0f), decodeAnchorX(1.2716666460037231f, 0.0f), decodeAnchorY(2.0f, -0.5f), decodeX(1.2716666f), decodeY(2.0f));
122         path.closePath();
123         return path;
124     }
125
126     private Path2D decodePath2() {
127         path.reset();
128         path.moveTo(decodeX(1.7883334f), decodeY(2.0f));
129         path.curveTo(decodeAnchorX(1.7883334159851074f, 0.0f), decodeAnchorY(2.0f, 0.5f), decodeAnchorX(1.653333306312561f, 0.0f), decodeAnchorY(1.7737069129943848f, 0.0f), decodeX(1.6533333f), decodeY(1.7737069f));
130         path.lineTo(decodeX(2.0f), decodeY(1.1465517f));
131         path.curveTo(decodeAnchorX(2.0f, 0.0f), decodeAnchorY(1.1465517282485962f, 0.0f), decodeAnchorX(2.0f, -0.5f), decodeAnchorY(2.0f, -0.5f), decodeX(2.0f), decodeY(2.0f));
132         path.curveTo(decodeAnchorX(2.0f, 0.5f), decodeAnchorY(2.0f, 0.5f), decodeAnchorX(1.7883334159851074f, 0.0f), decodeAnchorY(2.0f, -0.5f), decodeX(1.7883334f), decodeY(2.0f));
133         path.closePath();
134         return path;
135     }
136
137     private Path2D decodePath3() {
138         path.reset();
139         path.moveTo(decodeX(1.5666666f), decodeY(1.0f));
140         path.lineTo(decodeX(1.5666666f), decodeY(1.5689654f));
141         path.lineTo(decodeX(1.675f), decodeY(1.7715517f));
142         path.curveTo(decodeAnchorX(1.6749999523162842f, 0.0f), decodeAnchorY(1.7715517282485962f, 0.0f), decodeAnchorX(1.81166672706604f, -23.5f), decodeAnchorY(1.4978448152542114f, 33.5f), decodeX(1.8116667f), decodeY(1.4978448f));
143         path.curveTo(decodeAnchorX(1.81166672706604f, 23.5f), decodeAnchorY(1.4978448152542114f, -33.5f), decodeAnchorX(2.0f, 0.0f), decodeAnchorY(1.200430989265442f, 0.0f), decodeX(2.0f), decodeY(1.200431f));
144         path.lineTo(decodeX(2.0f), decodeY(1.0f));
145         path.lineTo(decodeX(1.5666666f), decodeY(1.0f));
146         path.closePath();
147         return path;
148     }
149
150     private Path2D decodePath4() {
151         path.reset();
152         path.moveTo(decodeX(1.3383334f), decodeY(1.0f));
153         path.curveTo(decodeAnchorX(1.3383333683013916f, 0.0f), decodeAnchorY(1.0f, 0.0f), decodeAnchorX(1.441666603088379f, -21.0f), decodeAnchorY(1.3103448152542114f, -37.5f), decodeX(1.4416666f), decodeY(1.3103448f));
154         path.curveTo(decodeAnchorX(1.441666603088379f, 21.0f), decodeAnchorY(1.3103448152542114f, 37.5f), decodeAnchorX(1.5733332633972168f, 0.0f), decodeAnchorY(1.5840517282485962f, 0.0f), decodeX(1.5733333f), decodeY(1.5840517f));
155         path.curveTo(decodeAnchorX(1.5733332633972168f, 0.0f), decodeAnchorY(1.5840517282485962f, 0.0f), decodeAnchorX(1.6066666841506958f, 1.5f), decodeAnchorY(1.2413792610168457f, 29.5f), decodeX(1.6066667f), decodeY(1.2413793f));
156         path.curveTo(decodeAnchorX(1.6066666841506958f, -1.5f), decodeAnchorY(1.2413792610168457f, -29.5f), decodeAnchorX(1.6050000190734863f, 0.0f), decodeAnchorY(1.0f, 0.0f), decodeX(1.605f), decodeY(1.0f));
157         path.lineTo(decodeX(1.3383334f), decodeY(1.0f));
158         path.closePath();
159         return path;
160     }
161
162     private Path2D decodePath5() {
163         path.reset();
164         path.moveTo(decodeX(1.5683334f), decodeY(1.5797414f));
165         path.curveTo(decodeAnchorX(1.568333387374878f, 0.0f), decodeAnchorY(1.579741358757019f, 0.0f), decodeAnchorX(1.5750000476837158f, 0.0f), decodeAnchorY(1.2392241954803467f, 33.0f), decodeX(1.575f), decodeY(1.2392242f));
166         path.curveTo(decodeAnchorX(1.5750000476837158f, 0.0f), decodeAnchorY(1.2392241954803467f, -33.0f), decodeAnchorX(1.56166672706604f, 0.0f), decodeAnchorY(1.0f, 0.0f), decodeX(1.5616667f), decodeY(1.0f));
167         path.lineTo(decodeX(1.9983333f), decodeY(1.0f));
168         path.lineTo(decodeX(2.0f), decodeY(1.1982758f));
169         path.curveTo(decodeAnchorX(2.0f, 0.0f), decodeAnchorY(1.1982758045196533f, 0.0f), decodeAnchorX(1.806666612625122f, 27.5f), decodeAnchorY(1.5043103694915771f, -38.5f), decodeX(1.8066666f), decodeY(1.5043104f));
170         path.curveTo(decodeAnchorX(1.806666612625122f, -27.5f), decodeAnchorY(1.5043103694915771f, 38.5f), decodeAnchorX(1.6766667366027832f, 0.0f), decodeAnchorY(1.778017282485962f, 0.0f), decodeX(1.6766667f), decodeY(1.7780173f));
171         path.lineTo(decodeX(1.5683334f), decodeY(1.5797414f));
172         path.closePath();
173         return path;
174     }
175
176     private Path2D decodePath6() {
177         path.reset();
178         path.moveTo(decodeX(1.5216666f), decodeY(2.0f));
179         path.curveTo(decodeAnchorX(1.5216666460037231f, 0.0f), decodeAnchorY(2.0f, 0.0f), decodeAnchorX(1.5550000667572021f, -2.0f), decodeAnchorY(1.778017282485962f, 22.5f), decodeX(1.5550001f), decodeY(1.7780173f));
180         path.curveTo(decodeAnchorX(1.5550000667572021f, 2.0f), decodeAnchorY(1.778017282485962f, -22.5f), decodeAnchorX(1.568333387374878f, 0.0f), decodeAnchorY(1.576508641242981f, 0.0f), decodeX(1.5683334f), decodeY(1.5765086f));
181         path.lineTo(decodeX(1.6775f), decodeY(1.7747846f));
182         path.curveTo(decodeAnchorX(1.6775000095367432f, 0.0f), decodeAnchorY(1.7747845649719238f, 0.0f), decodeAnchorX(1.6508333683013916f, 6.0f), decodeAnchorY(1.892241358757019f, -14.0f), decodeX(1.6508334f), decodeY(1.8922414f));
183         path.curveTo(decodeAnchorX(1.6508333683013916f, -6.0f), decodeAnchorY(1.892241358757019f, 14.0f), decodeAnchorX(1.6083333492279053f, 0.0f), decodeAnchorY(2.0f, 0.0f), decodeX(1.6083333f), decodeY(2.0f));
184         path.lineTo(decodeX(1.5216666f), decodeY(2.0f));
185         path.closePath();
186         return path;
187     }
188
189     private Path2D decodePath7() {
190         path.reset();
191         path.moveTo(decodeX(1.6066667f), decodeY(2.0f));
192         path.curveTo(decodeAnchorX(1.6066666841506958f, 0.0f), decodeAnchorY(2.0f, 0.0f), decodeAnchorX(1.6399999856948853f, -7.0f), decodeAnchorY(1.8814654350280762f, 17.0f), decodeX(1.64f), decodeY(1.8814654f));
193         path.curveTo(decodeAnchorX(1.6399999856948853f, 7.0f), decodeAnchorY(1.8814654350280762f, -17.0f), decodeAnchorX(1.6775000095367432f, 0.0f), decodeAnchorY(1.7747845649719238f, 0.0f), decodeX(1.6775f), decodeY(1.7747846f));
194         path.curveTo(decodeAnchorX(1.6775000095367432f, 0.0f), decodeAnchorY(1.7747845649719238f, 0.0f), decodeAnchorX(1.7416666746139526f, -11.0f), decodeAnchorY(1.8836207389831543f, -15.0f), decodeX(1.7416667f), decodeY(1.8836207f));
195         path.curveTo(decodeAnchorX(1.7416666746139526f, 11.0f), decodeAnchorY(1.8836207389831543f, 15.0f), decodeAnchorX(1.81333327293396f, 0.0f), decodeAnchorY(2.0f, -0.5f), decodeX(1.8133333f), decodeY(2.0f));
196         path.curveTo(decodeAnchorX(1.81333327293396f, 0.0f), decodeAnchorY(2.0f, 0.5f), decodeAnchorX(1.6066666841506958f, 0.0f), decodeAnchorY(2.0f, 0.0f), decodeX(1.6066667f), decodeY(2.0f));
197         path.closePath();
198         return path;
199     }
200
201     private Path2D decodePath8() {
202         path.reset();
203         path.moveTo(decodeX(1.2733333f), decodeY(2.0f));
204         path.curveTo(decodeAnchorX(1.2733333110809326f, 0.0f), decodeAnchorY(2.0f, 0.0f), decodeAnchorX(1.2633333206176758f, 5.0f), decodeAnchorY(1.659482717514038f, 37.0f), decodeX(1.2633333f), decodeY(1.6594827f));
205         path.curveTo(decodeAnchorX(1.2633333206176758f, -5.0f), decodeAnchorY(1.659482717514038f, -37.0f), decodeAnchorX(1.193333387374878f, 9.0f), decodeAnchorY(1.2241379022598267f, 33.5f), decodeX(1.1933334f), decodeY(1.2241379f));
206         path.curveTo(decodeAnchorX(1.193333387374878f, -9.0f), decodeAnchorY(1.2241379022598267f, -33.5f), decodeAnchorX(1.1333333253860474f, 0.0f), decodeAnchorY(1.0f, 0.0f), decodeX(1.1333333f), decodeY(1.0f));
207         path.lineTo(decodeX(1.0f), decodeY(1.0f));
208         path.lineTo(decodeX(1.0f), decodeY(1.6120689f));
209         path.curveTo(decodeAnchorX(1.0f, 0.0f), decodeAnchorY(1.6120688915252686f, 0.0f), decodeAnchorX(1.149999976158142f, 0.0f), decodeAnchorY(2.0f, -0.5f), decodeX(1.15f), decodeY(2.0f));
210         path.curveTo(decodeAnchorX(1.149999976158142f, 0.0f), decodeAnchorY(2.0f, 0.5f), decodeAnchorX(1.2733333110809326f, 0.0f), decodeAnchorY(2.0f, 0.0f), decodeX(1.2733333f), decodeY(2.0f));
211         path.closePath();
212         return path;
213     }
214
215     private Path2D decodePath9() {
216         path.reset();
217         path.moveTo(decodeX(1.0f), decodeY(2.0f));
218         path.lineTo(decodeX(1.0f), decodeY(1.5969827f));
219         path.curveTo(decodeAnchorX(1.0f, 0.0f), decodeAnchorY(1.596982717514038f, 0.0f), decodeAnchorX(1.0733333826065063f, -10.0f), decodeAnchorY(1.7974138259887695f, -19.5f), decodeX(1.0733334f), decodeY(1.7974138f));
220         path.curveTo(decodeAnchorX(1.0733333826065063f, 10.0f), decodeAnchorY(1.7974138259887695f, 19.5f), decodeAnchorX(1.1666666269302368f, 0.0f), decodeAnchorY(2.0f, -0.5f), decodeX(1.1666666f), decodeY(2.0f));
221         path.curveTo(decodeAnchorX(1.1666666269302368f, 0.0f), decodeAnchorY(2.0f, 0.5f), decodeAnchorX(1.0f, 0.0f), decodeAnchorY(2.0f, 0.0f), decodeX(1.0f), decodeY(2.0f));
222         path.closePath();
223         return path;
224     }
225
226
227
228     private Paint decodeGradient1(Shape s) {
229         Rectangle2D bounds = s.getBounds2D();
230         float x = (float)bounds.getX();
231         float y = (float)bounds.getY();
232         float w = (float)bounds.getWidth();
233         float h = (float)bounds.getHeight();
234         return decodeGradient((0.25f * w) + x, (0.0f * h) + y, (0.75f * w) + x, (1.0f * h) + y,
235                 new float[] { 0.0f,0.5f,1.0f },
236                 new Color[] { color1,
237                             decodeColor(color1,color2,0.5f),
238                             color2});
239     }
240
241     private Paint decodeGradient2(Shape s) {
242         Rectangle2D bounds = s.getBounds2D();
243         float x = (float)bounds.getX();
244         float y = (float)bounds.getY();
245         float w = (float)bounds.getWidth();
246         float h = (float)bounds.getHeight();
247         return decodeGradient((0.9567308f * w) + x, (0.06835443f * h) + y, (0.75f * w) + x, (1.0f * h) + y,
248                 new float[] { 0.0f,0.5f,1.0f },
249                 new Color[] { color3,
250                             decodeColor(color3,color4,0.5f),
251                             color4});
252     }
253
254     private Paint decodeGradient3(Shape s) {
255         Rectangle2D bounds = s.getBounds2D();
256         float x = (float)bounds.getX();
257         float y = (float)bounds.getY();
258         float w = (float)bounds.getWidth();
259         float h = (float)bounds.getHeight();
260         return decodeGradient((0.25f * w) + x, (0.0f * h) + y, (0.83536583f * w) + x, (0.9522059f * h) + y,
261                 new float[] { 0.0f,0.5f,1.0f },
262                 new Color[] { color6,
263                             decodeColor(color6,color7,0.5f),
264                             color7});
265     }
266
267     private Paint decodeGradient4(Shape s) {
268         Rectangle2D bounds = s.getBounds2D();
269         float x = (float)bounds.getX();
270         float y = (float)bounds.getY();
271         float w = (float)bounds.getWidth();
272         float h = (float)bounds.getHeight();
273         return decodeGradient((0.8659696f * w) + x, (0.011049724f * h) + y, (0.24809887f * w) + x, (0.95027626f * h) + y,
274                 new float[] { 0.0f,0.5f,1.0f },
275                 new Color[] { color6,
276                             decodeColor(color6,color8,0.5f),
277                             color8});
278     }
279
280     private Paint decodeGradient5(Shape s) {
281         Rectangle2D bounds = s.getBounds2D();
282         float x = (float)bounds.getX();
283         float y = (float)bounds.getY();
284         float w = (float)bounds.getWidth();
285         float h = (float)bounds.getHeight();
286         return decodeGradient((0.3511236f * w) + x, (0.09326425f * h) + y, (0.33426967f * w) + x, (0.9846154f * h) + y,
287                 new float[] { 0.0f,0.5f,1.0f },
288                 new Color[] { color9,
289                             decodeColor(color9,color10,0.5f),
290                             color10});
291     }
292
293     private Paint decodeGradient6(Shape s) {
294         Rectangle2D bounds = s.getBounds2D();
295         float x = (float)bounds.getX();
296         float y = (float)bounds.getY();
297         float w = (float)bounds.getWidth();
298         float h = (float)bounds.getHeight();
299         return decodeGradient((0.3548387f * w) + x, (0.114285715f * h) + y, (0.48387095f * w) + x, (0.9809524f * h) + y,
300                 new float[] { 0.0f,0.5f,1.0f },
301                 new Color[] { color11,
302                             decodeColor(color11,color4,0.5f),
303                             color4});
304     }
305
306     private Paint decodeGradient7(Shape s) {
307         Rectangle2D bounds = s.getBounds2D();
308         float x = (float)bounds.getX();
309         float y = (float)bounds.getY();
310         float w = (float)bounds.getWidth();
311         float h = (float)bounds.getHeight();
312         return decodeGradient((0.25f * w) + x, (0.0f * h) + y, (0.75f * w) + x, (1.0f * h) + y,
313                 new float[] { 0.0f,0.5f,1.0f },
314                 new Color[] { color1,
315                             decodeColor(color1,color12,0.5f),
316                             color12});
317     }
318
319     private Paint decodeGradient8(Shape s) {
320         Rectangle2D bounds = s.getBounds2D();
321         float x = (float)bounds.getX();
322         float y = (float)bounds.getY();
323         float w = (float)bounds.getWidth();
324         float h = (float)bounds.getHeight();
325         return decodeGradient((0.25f * w) + x, (0.0f * h) + y, (0.75f * w) + x, (1.0f * h) + y,
326                 new float[] { 0.0f,0.5f,1.0f },
327                 new Color[] { color13,
328                             decodeColor(color13,color14,0.5f),
329                             color14});
330     }
331
332
333 }
334
Popular Tags