KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > svggen > NegativeLengths


1 /*
2
3    Copyright 2001-2002 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.svggen;
19
20 import java.awt.*;
21 import java.awt.geom.*;
22
23 /**
24  * This test validates the convertion of Java 2D negative length values:<br />
25  * - On rectangles: a negative width or height makes the rectangle invisible.<br />
26  * - On rounded rectangles: a negative width or height makes the rectangle invisible.<br />
27  * - On ellipses: a negative width or height makes the ellipse invisible<br />
28  * - On 3D rect: a negative width *and* height makes the rectangle invisible. A
29  * negative width or height makes the rectangle display as a line.<br />
30  * The above behavior is that of the default Graphics2D implementations.
31  *
32  * @author <a HREF="mailto:vhardy@sun.com">Vincent Hardy</a>
33  * @version $Id: NegativeLengths.java,v 1.5 2004/08/18 07:16:45 vhardy Exp $
34  */

35 public class NegativeLengths implements Painter {
36     public void paint(Graphics2D g){
37         g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
38                            RenderingHints.VALUE_ANTIALIAS_ON);
39
40         g.setPaint(Color.black);
41
42         // Rectangle
43
g.drawString("Rectangle", 10, 20);
44
45         // w negative, h negative
46
Rectangle rect = new Rectangle(10, 30, -10, -8);
47         g.draw(rect);
48
49         // w negative, h zero
50
rect = new Rectangle(30, 30, -10, 0);
51         g.draw(rect);
52
53         // w negative, h positive
54
rect = new Rectangle(50, 30, -10, 8);
55         g.draw(rect);
56
57         // w zero, h negative
58
rect = new Rectangle(70, 30, 0, -8);
59         g.draw(rect);
60
61         // w zero, h zero
62
rect = new Rectangle(90, 30, 0, 0);
63         g.draw(rect);
64
65         // w zero, h positive
66
rect = new Rectangle(110, 30, 0, 8);
67         g.draw(rect);
68
69         // w positive, h negative
70
rect = new Rectangle(130, 30, 10, -8);
71         g.draw(rect);
72
73         // w positive, h zero
74
rect = new Rectangle(150, 30, 5, 0);
75         g.draw(rect);
76
77         // w positive, h positive
78
rect = new Rectangle(170, 30, 5, 8);
79         g.draw(rect);
80
81
82         g.translate(0, 35);
83         
84         //
85
// Round Rectangle
86
//
87
g.drawString("RoundRectangle2D", 10, 20);
88
89         // w negative, h negative
90
RoundRectangle2D rrect = new RoundRectangle2D.Double(10, 30, -10, -8, 2, 2);
91         g.draw(rrect);
92
93         // w negative, h zero
94
rrect = new RoundRectangle2D.Double(30, 30, -10, 0, 2, 2);
95         g.draw(rrect);
96
97         // w negative, h positive
98
rrect = new RoundRectangle2D.Double(50, 30, -10, 8, 2, 2);
99         g.draw(rrect);
100
101         // w zero, h negative
102
rrect = new RoundRectangle2D.Double(70, 30, 0, -8, 2, 2);
103         g.draw(rrect);
104
105         // w zero, h zero
106
rrect = new RoundRectangle2D.Double(90, 30, 0, 0, 2, 2);
107         g.draw(rrect);
108
109         // w zero, h positive
110
rrect = new RoundRectangle2D.Double(110, 30, 0, 8, 2, 2);
111         g.draw(rrect);
112
113         // w positive, h negative
114
rrect = new RoundRectangle2D.Double(130, 30, 5, -8, 2, 2);
115         g.draw(rrect);
116
117         // w positive, h zero
118
rrect = new RoundRectangle2D.Double(150, 30, 5, 0, 2, 2);
119         g.draw(rrect);
120
121         // w positive, h positive
122
rrect = new RoundRectangle2D.Double(170, 30, 5, 8, 2, 2);
123         g.draw(rrect);
124
125
126         g.translate(0, 35);
127
128         //
129
// Round Rectangle 2
130
//
131
g.drawString("RoundRectangle2D, negative radius", 10, 20);
132
133         // w negative, h negative
134
rrect = new RoundRectangle2D.Double(10, 30, -10, -8, -2, -2);
135         g.draw(rrect);
136
137         // w negative, h zero
138
rrect = new RoundRectangle2D.Double(30, 30, -10, 0, -2, -2);
139         g.draw(rrect);
140
141         // w negative, h positive
142
rrect = new RoundRectangle2D.Double(50, 30, -10, 8, -2, -2);
143         g.draw(rrect);
144
145         // w zero, h negative
146
rrect = new RoundRectangle2D.Double(70, 30, 0, -8, -2, -2);
147         g.draw(rrect);
148
149         // w zero, h zero
150
rrect = new RoundRectangle2D.Double(90, 30, 0, 0, -2, -2);
151         g.draw(rrect);
152
153         // w zero, h positive
154
rrect = new RoundRectangle2D.Double(110, 30, 0, 8, -2, -2);
155         g.draw(rrect);
156
157         // w positive, h negative
158
rrect = new RoundRectangle2D.Double(130, 30, 5, -8, -2, -2);
159         g.draw(rrect);
160
161         // w positive, h zero
162
rrect = new RoundRectangle2D.Double(150, 30, 5, 0, -2, -2);
163         g.draw(rrect);
164
165         // w positive, h positive
166
rrect = new RoundRectangle2D.Double(170, 30, 5, 8, -2, -2);
167         g.draw(rrect);
168         
169         g.translate(0, 35);
170
171         //
172
// Circle
173
//
174
g.drawString("Circle", 10, 20);
175
176         // w negative
177
Ellipse2D circle = new Ellipse2D.Double(10, 30, -10, -10);
178         g.draw(circle);
179
180         // w zero, h negative
181
circle = new Ellipse2D.Double(30, 30, 0, 0);
182         g.draw(circle);
183
184         // w positive, h negative
185
circle = new Ellipse2D.Double(50, 30, 5, 5);
186         g.draw(circle);
187
188         g.translate(0, 35);
189
190         //
191
// Ellipse
192
//
193
g.drawString("Ellipse", 10, 20);
194
195         // w negative, h negative
196
Ellipse2D ellipse = new Ellipse2D.Double(10, 30, -10, -8);
197         g.draw(ellipse);
198
199         // w negative, h zero
200
ellipse = new Ellipse2D.Double(30, 30, -10, 0);
201         g.draw(ellipse);
202
203         // w negative, h positive
204
ellipse = new Ellipse2D.Double(50, 30, -10, 8);
205         g.draw(ellipse);
206
207         // w zero, h negative
208
ellipse = new Ellipse2D.Double(70, 30, 0, -8);
209         g.draw(ellipse);
210
211         // w zero, h zero
212
ellipse = new Ellipse2D.Double(90, 30, 0, 0);
213         g.draw(ellipse);
214
215         // w zero, h positive
216
ellipse = new Ellipse2D.Double(110, 30, 0, 8);
217         g.draw(ellipse);
218
219         // w positive, h negative
220
ellipse = new Ellipse2D.Double(130, 30, 5, -8);
221         g.draw(ellipse);
222
223         // w positive, h zero
224
ellipse = new Ellipse2D.Double(150, 30, 5, 0);
225         g.draw(ellipse);
226
227         // w positive, h positive
228
ellipse = new Ellipse2D.Double(170, 30, 5, 8);
229         g.draw(ellipse);
230
231
232         g.translate(0, 35);
233
234         // 3D Rect
235
g.drawString("fill3Drect", 10, 20);
236
237         // w negative, h negative
238
g.setColor(new Color(192, 192, 192));
239         g.fill3DRect(10, 30, -10, -8, true);
240
241         // w negative, h zero
242
g.fill3DRect(30, 30, -10, 0, true);
243
244         // w negative, h positive
245
g.fill3DRect(50, 30, -10, 8, true);
246
247         // w zero, h negative
248
g.fill3DRect(70, 30, 0, -8, true);
249
250         // w zero, h zero
251
g.fill3DRect(90, 30, 0, 0, true);
252
253         // w zero, h positive
254
g.fill3DRect(110, 30, 0, 8, true);
255
256         // w positive, h negative
257
g.fill3DRect(130, 30, 5, -8, true);
258         
259         // w positive, h zero
260
g.fill3DRect(150, 30, 5, 0, true);
261         
262         // w positive, h positive
263
g.fill3DRect(170, 30, 5, 8, true);
264
265         g.translate(0, 40);
266
267         // Clip
268
rect = new Rectangle(10, 30, 10, -30);
269         g.setPaint(Color.gray);
270         g.fill(rect);
271         g.setPaint(Color.black);
272         g.clip(rect);
273         g.drawString("Hello There", 10, 25);
274     }
275 }
276
277
278
Popular Tags