KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMenuButtonPainter.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 InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMenuButtonPainter 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 InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMenuButtonPainter to determine which region/state is being painted
21
//by that instance.
22
static final int ICON_ENABLED = 1;
23     static final int ICON_DISABLED = 2;
24     static final int ICON_MOUSEOVER = 3;
25     static final int ICON_PRESSED = 4;
26     static final int ICON_ENABLED_WINDOWNOTFOCUSED = 5;
27     static final int ICON_MOUSEOVER_WINDOWNOTFOCUSED = 6;
28     static final int ICON_PRESSED_WINDOWNOTFOCUSED = 7;
29
30
31     private int state; //refers to one of the static final ints above
32
private PaintContext ctx;
33
34     //the following 4 variables are reused during the painting code of the layers
35
private Path2D path = new Path2D.Float();
36     private Rectangle2D rect = new Rectangle2D.Float(0, 0, 0, 0);
37     private RoundRectangle2D roundRect = new RoundRectangle2D.Float(0, 0, 0, 0, 0, 0);
38     private Ellipse2D ellipse = new Ellipse2D.Float(0, 0, 0, 0);
39
40     //All Colors used for painting are stored here. Ideally, only those colors being used
41
//by a particular instance of InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMenuButtonPainter would be created. For the moment at least,
42
//however, all are created for each instance.
43
private Color color1 = decodeColor("nimbusBlueGrey", 0.0055555105f, -0.0029994324f, -0.38039216f, -185);
44     private Color color2 = decodeColor("nimbusBase", 0.08801502f, 0.3642857f, -0.5019608f, 0);
45     private Color color3 = decodeColor("nimbusBase", 0.030543745f, -0.3835404f, -0.09803924f, 0);
46     private Color color4 = decodeColor("nimbusBase", 0.029191494f, -0.53801316f, 0.13333333f, 0);
47     private Color color5 = decodeColor("nimbusBase", 0.030543745f, -0.3857143f, -0.09411767f, 0);
48     private Color color6 = decodeColor("nimbusBase", 0.030543745f, -0.43148893f, 0.007843137f, 0);
49     private Color color7 = decodeColor("nimbusBase", 0.029191494f, -0.24935067f, -0.20392159f, -132);
50     private Color color8 = decodeColor("nimbusBase", 0.029191494f, -0.24935067f, -0.20392159f, 0);
51     private Color color9 = decodeColor("nimbusBase", 0.029191494f, -0.24935067f, -0.20392159f, -123);
52     private Color color10 = decodeColor("nimbusBase", 0.0f, -0.6357143f, 0.45098037f, 0);
53     private Color color11 = decodeColor("nimbusBlueGrey", 0.0055555105f, -0.0029994324f, -0.38039216f, -208);
54     private Color color12 = decodeColor("nimbusBase", 0.02551502f, -0.5942635f, 0.20784312f, 0);
55     private Color color13 = decodeColor("nimbusBase", 0.032459438f, -0.5490091f, 0.12941176f, 0);
56     private Color color14 = decodeColor("nimbusBase", 0.032459438f, -0.5469569f, 0.11372548f, 0);
57     private Color color15 = decodeColor("nimbusBase", 0.032459438f, -0.5760128f, 0.23921567f, 0);
58     private Color color16 = decodeColor("nimbusBase", 0.08801502f, 0.3642857f, -0.4901961f, 0);
59     private Color color17 = decodeColor("nimbusBase", 0.032459438f, -0.1857143f, -0.23529413f, 0);
60     private Color color18 = decodeColor("nimbusBase", 0.029191494f, -0.5438224f, 0.17647058f, 0);
61     private Color color19 = decodeColor("nimbusBase", 0.030543745f, -0.41929638f, -0.02352941f, 0);
62     private Color color20 = decodeColor("nimbusBase", 0.030543745f, -0.45559007f, 0.082352936f, 0);
63     private Color color21 = decodeColor("nimbusBase", 0.03409344f, -0.329408f, -0.11372551f, -132);
64     private Color color22 = decodeColor("nimbusBase", 0.03409344f, -0.329408f, -0.11372551f, 0);
65     private Color color23 = decodeColor("nimbusBase", 0.03409344f, -0.329408f, -0.11372551f, -123);
66     private Color color24 = decodeColor("nimbusBase", -0.57865167f, -0.6357143f, -0.54901963f, 0);
67     private Color color25 = decodeColor("nimbusBase", 0.031104386f, 0.12354499f, -0.33725494f, 0);
68     private Color color26 = decodeColor("nimbusBase", 0.032459438f, -0.4592437f, -0.015686274f, 0);
69     private Color color27 = decodeColor("nimbusBase", 0.029191494f, -0.2579365f, -0.19607845f, 0);
70     private Color color28 = decodeColor("nimbusBase", 0.03409344f, -0.3149596f, -0.13333336f, 0);
71     private Color color29 = decodeColor("nimbusBase", 0.029681683f, 0.07857144f, -0.3294118f, -132);
72     private Color color30 = decodeColor("nimbusBase", 0.029681683f, 0.07857144f, -0.3294118f, 0);
73     private Color color31 = decodeColor("nimbusBase", 0.029681683f, 0.07857144f, -0.3294118f, -123);
74     private Color color32 = decodeColor("nimbusBase", 0.032459438f, -0.53637654f, 0.043137252f, 0);
75     private Color color33 = decodeColor("nimbusBase", 0.032459438f, -0.49935067f, -0.11764708f, 0);
76     private Color color34 = decodeColor("nimbusBase", 0.021348298f, -0.6133929f, 0.32941175f, 0);
77     private Color color35 = decodeColor("nimbusBase", 0.042560518f, -0.5804379f, 0.23137254f, 0);
78     private Color color36 = decodeColor("nimbusBase", 0.032459438f, -0.57417583f, 0.21568626f, 0);
79     private Color color37 = decodeColor("nimbusBase", 0.027408898f, -0.5784226f, 0.20392156f, -132);
80     private Color color38 = decodeColor("nimbusBase", 0.042560518f, -0.5665319f, 0.0745098f, 0);
81     private Color color39 = decodeColor("nimbusBase", 0.036732912f, -0.5642857f, 0.16470587f, -123);
82     private Color color40 = decodeColor("nimbusBase", 0.021348298f, -0.54480517f, -0.11764708f, 0);
83
84
85     //Array of current component colors, updated in each paint call
86
private Object JavaDoc[] componentColors;
87
88     public InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMenuButtonPainter(PaintContext ctx, int state) {
89         super();
90         this.state = state;
91         this.ctx = ctx;
92     }
93
94     @Override JavaDoc
95     protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object JavaDoc[] extendedCacheKeys) {
96         //populate componentColors array with colors calculated in getExtendedCacheKeys call
97
componentColors = extendedCacheKeys;
98         //generate this entire method. Each state/bg/fg/border combo that has
99
//been painted gets its own KEY and paint method.
100
switch(state) {
101             case ICON_ENABLED: painticonEnabled(g); break;
102             case ICON_DISABLED: painticonDisabled(g); break;
103             case ICON_MOUSEOVER: painticonMouseOver(g); break;
104             case ICON_PRESSED: painticonPressed(g); break;
105             case ICON_ENABLED_WINDOWNOTFOCUSED: painticonEnabledAndWindowNotFocused(g); break;
106             case ICON_MOUSEOVER_WINDOWNOTFOCUSED: painticonMouseOverAndWindowNotFocused(g); break;
107             case ICON_PRESSED_WINDOWNOTFOCUSED: painticonPressedAndWindowNotFocused(g); break;
108
109         }
110     }
111         
112
113
114     @Override JavaDoc
115     protected final PaintContext getPaintContext() {
116         return ctx;
117     }
118
119     private void painticonEnabled(Graphics2D g) {
120         roundRect = decodeRoundRect1();
121         g.setPaint(color1);
122         g.fill(roundRect);
123         roundRect = decodeRoundRect2();
124         g.setPaint(decodeGradient1(roundRect));
125         g.fill(roundRect);
126         roundRect = decodeRoundRect3();
127         g.setPaint(decodeGradient2(roundRect));
128         g.fill(roundRect);
129         path = decodePath1();
130         g.setPaint(decodeGradient3(path));
131         g.fill(path);
132         path = decodePath2();
133         g.setPaint(color10);
134         g.fill(path);
135
136     }
137
138     private void painticonDisabled(Graphics2D g) {
139         roundRect = decodeRoundRect1();
140         g.setPaint(color11);
141         g.fill(roundRect);
142         roundRect = decodeRoundRect2();
143         g.setPaint(decodeGradient4(roundRect));
144         g.fill(roundRect);
145         path = decodePath2();
146         g.setPaint(color15);
147         g.fill(path);
148
149     }
150
151     private void painticonMouseOver(Graphics2D g) {
152         roundRect = decodeRoundRect1();
153         g.setPaint(color1);
154         g.fill(roundRect);
155         roundRect = decodeRoundRect2();
156         g.setPaint(decodeGradient5(roundRect));
157         g.fill(roundRect);
158         roundRect = decodeRoundRect3();
159         g.setPaint(decodeGradient6(roundRect));
160         g.fill(roundRect);
161         path = decodePath1();
162         g.setPaint(decodeGradient7(path));
163         g.fill(path);
164         path = decodePath2();
165         g.setPaint(color10);
166         g.fill(path);
167
168     }
169
170     private void painticonPressed(Graphics2D g) {
171         roundRect = decodeRoundRect1();
172         g.setPaint(color1);
173         g.fill(roundRect);
174         roundRect = decodeRoundRect2();
175         g.setPaint(decodeGradient8(roundRect));
176         g.fill(roundRect);
177         roundRect = decodeRoundRect3();
178         g.setPaint(decodeGradient9(roundRect));
179         g.fill(roundRect);
180         path = decodePath1();
181         g.setPaint(decodeGradient10(path));
182         g.fill(path);
183         path = decodePath2();
184         g.setPaint(color10);
185         g.fill(path);
186
187     }
188
189     private void painticonEnabledAndWindowNotFocused(Graphics2D g) {
190         roundRect = decodeRoundRect2();
191         g.setPaint(decodeGradient11(roundRect));
192         g.fill(roundRect);
193         roundRect = decodeRoundRect3();
194         g.setPaint(decodeGradient12(roundRect));
195         g.fill(roundRect);
196         path = decodePath3();
197         g.setPaint(decodeGradient13(path));
198         g.fill(path);
199         path = decodePath2();
200         g.setPaint(color40);
201         g.fill(path);
202
203     }
204
205     private void painticonMouseOverAndWindowNotFocused(Graphics2D g) {
206         roundRect = decodeRoundRect1();
207         g.setPaint(color1);
208         g.fill(roundRect);
209         roundRect = decodeRoundRect2();
210         g.setPaint(decodeGradient5(roundRect));
211         g.fill(roundRect);
212         roundRect = decodeRoundRect3();
213         g.setPaint(decodeGradient6(roundRect));
214         g.fill(roundRect);
215         path = decodePath1();
216         g.setPaint(decodeGradient7(path));
217         g.fill(path);
218         path = decodePath2();
219         g.setPaint(color10);
220         g.fill(path);
221
222     }
223
224     private void painticonPressedAndWindowNotFocused(Graphics2D g) {
225         roundRect = decodeRoundRect1();
226         g.setPaint(color1);
227         g.fill(roundRect);
228         roundRect = decodeRoundRect2();
229         g.setPaint(decodeGradient8(roundRect));
230         g.fill(roundRect);
231         roundRect = decodeRoundRect3();
232         g.setPaint(decodeGradient9(roundRect));
233         g.fill(roundRect);
234         path = decodePath1();
235         g.setPaint(decodeGradient10(path));
236         g.fill(path);
237         path = decodePath2();
238         g.setPaint(color10);
239         g.fill(path);
240
241     }
242
243
244
245     private RoundRectangle2D decodeRoundRect1() {
246         roundRect.setRoundRect(decodeX(1.0f), //x
247
decodeY(1.6111112f), //y
248
decodeX(2.0f) - decodeX(1.0f), //width
249
decodeY(2.0f) - decodeY(1.6111112f), //height
250
6.0f, 6.0f); //rounding
251
return roundRect;
252     }
253
254     private RoundRectangle2D decodeRoundRect2() {
255         roundRect.setRoundRect(decodeX(1.0f), //x
256
decodeY(1.0f), //y
257
decodeX(2.0f) - decodeX(1.0f), //width
258
decodeY(1.9444444f) - decodeY(1.0f), //height
259
8.6f, 8.6f); //rounding
260
return roundRect;
261     }
262
263     private RoundRectangle2D decodeRoundRect3() {
264         roundRect.setRoundRect(decodeX(1.0526316f), //x
265
decodeY(1.0555556f), //y
266
decodeX(1.9473684f) - decodeX(1.0526316f), //width
267
decodeY(1.8888888f) - decodeY(1.0555556f), //height
268
6.75f, 6.75f); //rounding
269
return roundRect;
270     }
271
272     private Path2D decodePath1() {
273         path.reset();
274         path.moveTo(decodeX(1.3157895f), decodeY(1.4444444f));
275         path.lineTo(decodeX(1.6842105f), decodeY(1.4444444f));
276         path.lineTo(decodeX(1.5013158f), decodeY(1.7208333f));
277         path.lineTo(decodeX(1.3157895f), decodeY(1.4444444f));
278         path.closePath();
279         return path;
280     }
281
282     private Path2D decodePath2() {
283         path.reset();
284         path.moveTo(decodeX(1.3157895f), decodeY(1.3333334f));
285         path.lineTo(decodeX(1.6842105f), decodeY(1.3333334f));
286         path.lineTo(decodeX(1.5f), decodeY(1.6083333f));
287         path.lineTo(decodeX(1.3157895f), decodeY(1.3333334f));
288         path.closePath();
289         return path;
290     }
291
292     private Path2D decodePath3() {
293         path.reset();
294         path.moveTo(decodeX(1.3157895f), decodeY(1.3888888f));
295         path.lineTo(decodeX(1.6842105f), decodeY(1.3888888f));
296         path.lineTo(decodeX(1.4952153f), decodeY(1.655303f));
297         path.lineTo(decodeX(1.3157895f), decodeY(1.3888888f));
298         path.closePath();
299         return path;
300     }
301
302
303
304     private Paint decodeGradient1(Shape s) {
305         Rectangle2D bounds = s.getBounds2D();
306         float x = (float)bounds.getX();
307         float y = (float)bounds.getY();
308         float w = (float)bounds.getWidth();
309         float h = (float)bounds.getHeight();
310         return decodeGradient((0.24868421f * w) + x, (0.0014705883f * h) + y, (0.24868421f * w) + x, (1.0f * h) + y,
311                 new float[] { 0.0f,0.5f,1.0f },
312                 new Color[] { color2,
313                             decodeColor(color2,color3,0.5f),
314                             color3});
315     }
316
317     private Paint decodeGradient2(Shape s) {
318         Rectangle2D bounds = s.getBounds2D();
319         float x = (float)bounds.getX();
320         float y = (float)bounds.getY();
321         float w = (float)bounds.getWidth();
322         float h = (float)bounds.getHeight();
323         return decodeGradient((0.25f * w) + x, (0.0f * h) + y, (0.25441176f * w) + x, (1.0016667f * h) + y,
324                 new float[] { 0.0f,0.26988637f,0.53977275f,0.5951705f,0.6505682f,0.8252841f,1.0f },
325                 new Color[] { color4,
326                             decodeColor(color4,color5,0.5f),
327                             color5,
328                             decodeColor(color5,color3,0.5f),
329                             color3,
330                             decodeColor(color3,color6,0.5f),
331                             color6});
332     }
333
334     private Paint decodeGradient3(Shape s) {
335         Rectangle2D bounds = s.getBounds2D();
336         float x = (float)bounds.getX();
337         float y = (float)bounds.getY();
338         float w = (float)bounds.getWidth();
339         float h = (float)bounds.getHeight();
340         return decodeGradient((0.50714284f * w) + x, (0.095f * h) + y, (0.49285713f * w) + x, (0.91f * h) + y,
341                 new float[] { 0.0f,0.24289773f,0.48579547f,0.74289775f,1.0f },
342                 new Color[] { color7,
343                             decodeColor(color7,color8,0.5f),
344                             color8,
345                             decodeColor(color8,color9,0.5f),
346                             color9});
347     }
348
349     private Paint decodeGradient4(Shape s) {
350         Rectangle2D bounds = s.getBounds2D();
351         float x = (float)bounds.getX();
352         float y = (float)bounds.getY();
353         float w = (float)bounds.getWidth();
354         float h = (float)bounds.getHeight();
355         return decodeGradient((0.24868421f * w) + x, (0.0014705883f * h) + y, (0.24868421f * w) + x, (1.0f * h) + y,
356                 new float[] { 0.0f,0.31107953f,0.62215906f,0.8110795f,1.0f },
357                 new Color[] { color12,
358                             decodeColor(color12,color13,0.5f),
359                             color13,
360                             decodeColor(color13,color14,0.5f),
361                             color14});
362     }
363
364     private Paint decodeGradient5(Shape s) {
365         Rectangle2D bounds = s.getBounds2D();
366         float x = (float)bounds.getX();
367         float y = (float)bounds.getY();
368         float w = (float)bounds.getWidth();
369         float h = (float)bounds.getHeight();
370         return decodeGradient((0.24868421f * w) + x, (0.0014705883f * h) + y, (0.24868421f * w) + x, (1.0f * h) + y,
371                 new float[] { 0.0f,0.5f,1.0f },
372                 new Color[] { color16,
373                             decodeColor(color16,color17,0.5f),
374                             color17});
375     }
376
377     private Paint decodeGradient6(Shape s) {
378         Rectangle2D bounds = s.getBounds2D();
379         float x = (float)bounds.getX();
380         float y = (float)bounds.getY();
381         float w = (float)bounds.getWidth();
382         float h = (float)bounds.getHeight();
383         return decodeGradient((0.25f * w) + x, (0.0f * h) + y, (0.25441176f * w) + x, (1.0016667f * h) + y,
384                 new float[] { 0.0f,0.26988637f,0.53977275f,0.5951705f,0.6505682f,0.8252841f,1.0f },
385                 new Color[] { color18,
386                             decodeColor(color18,color19,0.5f),
387                             color19,
388                             decodeColor(color19,color19,0.5f),
389                             color19,
390                             decodeColor(color19,color20,0.5f),
391                             color20});
392     }
393
394     private Paint decodeGradient7(Shape s) {
395         Rectangle2D bounds = s.getBounds2D();
396         float x = (float)bounds.getX();
397         float y = (float)bounds.getY();
398         float w = (float)bounds.getWidth();
399         float h = (float)bounds.getHeight();
400         return decodeGradient((0.50714284f * w) + x, (0.095f * h) + y, (0.49285713f * w) + x, (0.91f * h) + y,
401                 new float[] { 0.0f,0.24289773f,0.48579547f,0.74289775f,1.0f },
402                 new Color[] { color21,
403                             decodeColor(color21,color22,0.5f),
404                             color22,
405                             decodeColor(color22,color23,0.5f),
406                             color23});
407     }
408
409     private Paint decodeGradient8(Shape s) {
410         Rectangle2D bounds = s.getBounds2D();
411         float x = (float)bounds.getX();
412         float y = (float)bounds.getY();
413         float w = (float)bounds.getWidth();
414         float h = (float)bounds.getHeight();
415         return decodeGradient((0.24868421f * w) + x, (0.0014705883f * h) + y, (0.24868421f * w) + x, (1.0f * h) + y,
416                 new float[] { 0.0f,0.5f,1.0f },
417                 new Color[] { color24,
418                             decodeColor(color24,color25,0.5f),
419                             color25});
420     }
421
422     private Paint decodeGradient9(Shape s) {
423         Rectangle2D bounds = s.getBounds2D();
424         float x = (float)bounds.getX();
425         float y = (float)bounds.getY();
426         float w = (float)bounds.getWidth();
427         float h = (float)bounds.getHeight();
428         return decodeGradient((0.25f * w) + x, (0.0f * h) + y, (0.25441176f * w) + x, (1.0016667f * h) + y,
429                 new float[] { 0.0f,0.26988637f,0.53977275f,0.5951705f,0.6505682f,0.8252841f,1.0f },
430                 new Color[] { color26,
431                             decodeColor(color26,color27,0.5f),
432                             color27,
433                             decodeColor(color27,color27,0.5f),
434                             color27,
435                             decodeColor(color27,color28,0.5f),
436                             color28});
437     }
438
439     private Paint decodeGradient10(Shape s) {
440         Rectangle2D bounds = s.getBounds2D();
441         float x = (float)bounds.getX();
442         float y = (float)bounds.getY();
443         float w = (float)bounds.getWidth();
444         float h = (float)bounds.getHeight();
445         return decodeGradient((0.50714284f * w) + x, (0.095f * h) + y, (0.49285713f * w) + x, (0.91f * h) + y,
446                 new float[] { 0.0f,0.24289773f,0.48579547f,0.74289775f,1.0f },
447                 new Color[] { color29,
448                             decodeColor(color29,color30,0.5f),
449                             color30,
450                             decodeColor(color30,color31,0.5f),
451                             color31});
452     }
453
454     private Paint decodeGradient11(Shape s) {
455         Rectangle2D bounds = s.getBounds2D();
456         float x = (float)bounds.getX();
457         float y = (float)bounds.getY();
458         float w = (float)bounds.getWidth();
459         float h = (float)bounds.getHeight();
460         return decodeGradient((0.24868421f * w) + x, (0.0014705883f * h) + y, (0.24868421f * w) + x, (1.0f * h) + y,
461                 new float[] { 0.0f,0.5f,1.0f },
462                 new Color[] { color32,
463                             decodeColor(color32,color33,0.5f),
464                             color33});
465     }
466
467     private Paint decodeGradient12(Shape s) {
468         Rectangle2D bounds = s.getBounds2D();
469         float x = (float)bounds.getX();
470         float y = (float)bounds.getY();
471         float w = (float)bounds.getWidth();
472         float h = (float)bounds.getHeight();
473         return decodeGradient((0.25f * w) + x, (0.0f * h) + y, (0.25441176f * w) + x, (1.0016667f * h) + y,
474                 new float[] { 0.0f,0.26988637f,0.53977275f,0.5951705f,0.6505682f,0.8252841f,1.0f },
475                 new Color[] { color34,
476                             decodeColor(color34,color35,0.5f),
477                             color35,
478                             decodeColor(color35,color36,0.5f),
479                             color36,
480                             decodeColor(color36,color15,0.5f),
481                             color15});
482     }
483
484     private Paint decodeGradient13(Shape s) {
485         Rectangle2D bounds = s.getBounds2D();
486         float x = (float)bounds.getX();
487         float y = (float)bounds.getY();
488         float w = (float)bounds.getWidth();
489         float h = (float)bounds.getHeight();
490         return decodeGradient((0.50714284f * w) + x, (0.095f * h) + y, (0.49285713f * w) + x, (0.91f * h) + y,
491                 new float[] { 0.0f,0.24289773f,0.48579547f,0.74289775f,1.0f },
492                 new Color[] { color37,
493                             decodeColor(color37,color38,0.5f),
494                             color38,
495                             decodeColor(color38,color39,0.5f),
496                             color39});
497     }
498
499
500 }
501
Popular Tags