KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * ToolBarSeparatorPainter.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 ToolBarSeparatorPainter 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 ToolBarSeparatorPainter 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 ToolBarSeparatorPainter would be created. For the moment at least,
36
//however, all are created for each instance.
37
private Color color1 = new Color(116, 120, 128, 255);
38
39
40     //Array of current component colors, updated in each paint call
41
private Object JavaDoc[] componentColors;
42
43     public ToolBarSeparatorPainter(PaintContext ctx, int state) {
44         super();
45         this.state = state;
46         this.ctx = ctx;
47     }
48
49     @Override JavaDoc
50     protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object JavaDoc[] extendedCacheKeys) {
51         //populate componentColors array with colors calculated in getExtendedCacheKeys call
52
componentColors = extendedCacheKeys;
53         //generate this entire method. Each state/bg/fg/border combo that has
54
//been painted gets its own KEY and paint method.
55
switch(state) {
56             case BACKGROUND_ENABLED: paintBackgroundEnabled(g); break;
57
58         }
59     }
60         
61
62
63     @Override JavaDoc
64     protected final PaintContext getPaintContext() {
65         return ctx;
66     }
67
68     private void paintBackgroundEnabled(Graphics2D g) {
69         rect = decodeRect1();
70         g.setPaint(color1);
71         g.fill(rect);
72         rect = decodeRect2();
73         g.setPaint(color1);
74         g.fill(rect);
75         rect = decodeRect3();
76         g.setPaint(color1);
77         g.fill(rect);
78         rect = decodeRect4();
79         g.setPaint(color1);
80         g.fill(rect);
81         rect = decodeRect5();
82         g.setPaint(color1);
83         g.fill(rect);
84         rect = decodeRect6();
85         g.setPaint(color1);
86         g.fill(rect);
87         rect = decodeRect7();
88         g.setPaint(color1);
89         g.fill(rect);
90         rect = decodeRect8();
91         g.setPaint(color1);
92         g.fill(rect);
93         rect = decodeRect9();
94         g.setPaint(color1);
95         g.fill(rect);
96         rect = decodeRect10();
97         g.setPaint(color1);
98         g.fill(rect);
99         rect = decodeRect11();
100         g.setPaint(color1);
101         g.fill(rect);
102         rect = decodeRect12();
103         g.setPaint(color1);
104         g.fill(rect);
105
106     }
107
108
109
110     private Rectangle2D decodeRect1() {
111             rect.setRect(decodeX(1.0526316f), //x
112
decodeY(1.4f), //y
113
decodeX(1.0789473f) - decodeX(1.0526316f), //width
114
decodeY(1.6f) - decodeY(1.4f)); //height
115
return rect;
116     }
117
118     private Rectangle2D decodeRect2() {
119             rect.setRect(decodeX(1.1315789f), //x
120
decodeY(1.4f), //y
121
decodeX(1.1578947f) - decodeX(1.1315789f), //width
122
decodeY(1.6f) - decodeY(1.4f)); //height
123
return rect;
124     }
125
126     private Rectangle2D decodeRect3() {
127             rect.setRect(decodeX(1.2105263f), //x
128
decodeY(1.4f), //y
129
decodeX(1.2368422f) - decodeX(1.2105263f), //width
130
decodeY(1.6f) - decodeY(1.4f)); //height
131
return rect;
132     }
133
134     private Rectangle2D decodeRect4() {
135             rect.setRect(decodeX(1.2894737f), //x
136
decodeY(1.4f), //y
137
decodeX(1.3157895f) - decodeX(1.2894737f), //width
138
decodeY(1.6f) - decodeY(1.4f)); //height
139
return rect;
140     }
141
142     private Rectangle2D decodeRect5() {
143             rect.setRect(decodeX(1.3684211f), //x
144
decodeY(1.4f), //y
145
decodeX(1.3947369f) - decodeX(1.3684211f), //width
146
decodeY(1.6f) - decodeY(1.4f)); //height
147
return rect;
148     }
149
150     private Rectangle2D decodeRect6() {
151             rect.setRect(decodeX(1.4473684f), //x
152
decodeY(1.4f), //y
153
decodeX(1.4736842f) - decodeX(1.4473684f), //width
154
decodeY(1.6f) - decodeY(1.4f)); //height
155
return rect;
156     }
157
158     private Rectangle2D decodeRect7() {
159             rect.setRect(decodeX(1.5263158f), //x
160
decodeY(1.4f), //y
161
decodeX(1.5526316f) - decodeX(1.5263158f), //width
162
decodeY(1.6f) - decodeY(1.4f)); //height
163
return rect;
164     }
165
166     private Rectangle2D decodeRect8() {
167             rect.setRect(decodeX(1.6052632f), //x
168
decodeY(1.4f), //y
169
decodeX(1.6315789f) - decodeX(1.6052632f), //width
170
decodeY(1.6f) - decodeY(1.4f)); //height
171
return rect;
172     }
173
174     private Rectangle2D decodeRect9() {
175             rect.setRect(decodeX(1.6842105f), //x
176
decodeY(1.4f), //y
177
decodeX(1.7105262f) - decodeX(1.6842105f), //width
178
decodeY(1.6f) - decodeY(1.4f)); //height
179
return rect;
180     }
181
182     private Rectangle2D decodeRect10() {
183             rect.setRect(decodeX(1.7631578f), //x
184
decodeY(1.4f), //y
185
decodeX(1.7894738f) - decodeX(1.7631578f), //width
186
decodeY(1.6f) - decodeY(1.4f)); //height
187
return rect;
188     }
189
190     private Rectangle2D decodeRect11() {
191             rect.setRect(decodeX(1.8421053f), //x
192
decodeY(1.4f), //y
193
decodeX(1.8684211f) - decodeX(1.8421053f), //width
194
decodeY(1.6f) - decodeY(1.4f)); //height
195
return rect;
196     }
197
198     private Rectangle2D decodeRect12() {
199             rect.setRect(decodeX(1.9210527f), //x
200
decodeY(1.4f), //y
201
decodeX(1.9473684f) - decodeX(1.9210527f), //width
202
decodeY(1.6f) - decodeY(1.4f)); //height
203
return rect;
204     }
205
206
207
208
209 }
210
Popular Tags