KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2001 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 shapes into SVG
25  * Shapes.
26  *
27  * @author <a HREF="mailto:cjolif@ilog.fr">Christophe Jolif</a>
28  * @author <a HREF="mailto:vhardy@eng.sun.com">Vincent Hardy</a>
29  * @version $Id: BasicShapes2.java,v 1.3 2004/08/18 07:16:43 vhardy Exp $
30  */

31 public class BasicShapes2 implements Painter {
32     public void paint(Graphics2D g) {
33         g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
34                            RenderingHints.VALUE_ANTIALIAS_ON);
35
36         g.setPaint(Color.black);
37
38         // Arc2D
39
g.drawString("Arc2D", 10, 20);
40         Arc2D arc = new Arc2D.Float(10, 30, 50, 40, 0, 270, Arc2D.PIE);
41         g.draw(arc);
42
43         g.translate(0, 90);
44
45         // Ellipse
46
g.drawString("Ellipse", 10, 20);
47         Ellipse2D ellipse = new Ellipse2D.Double(10, 30, 100, 40);
48         g.draw(ellipse);
49
50         g.translate(150, -90);
51
52         // GeneralPath lineTo
53
g.drawString("GeneralPath, lineTo", 10, 20);
54         GeneralPath lineToPath = new GeneralPath();
55         lineToPath.moveTo(10, 30);
56         lineToPath.lineTo(60, 30);
57         lineToPath.lineTo(60, 70);
58         lineToPath.lineTo(10, 30);
59         lineToPath.closePath();
60         g.draw(lineToPath);
61
62         g.translate(0, 90);
63
64         // GeneralPath curveTo
65
g.drawString("GeneralPath, curveTo", 10, 20);
66         GeneralPath curveToPath = new GeneralPath();
67         curveToPath.moveTo(10, 30);
68         curveToPath.curveTo(35, 10, 35, 50, 60, 30);
69         curveToPath.curveTo(80, 55, 40, 55, 60, 80);
70         curveToPath.curveTo(35, 60, 35, 100, 10, 80);
71         curveToPath.curveTo(-10, 55, 30, 55, 10, 30);
72         curveToPath.closePath();
73         g.draw(curveToPath);
74     }
75 }
76
Popular Tags