KickJava   Java API By Example, From Geeks To Geeks.

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


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:vhardy@eng.sun.com">Vincent Hardy</a>
28  * @version $Id: BasicShapes.java,v 1.3 2004/08/18 07:16:43 vhardy Exp $
29  */

30 public class BasicShapes implements Painter {
31     public void paint(Graphics2D g){
32         g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
33                            RenderingHints.VALUE_ANTIALIAS_ON);
34
35         g.setPaint(Color.black);
36
37     // Rectangle
38
g.drawString("Rectangle", 10, 20);
39         Rectangle rect = new Rectangle(10, 30, 50, 40);
40         g.draw(rect);
41     
42         g.translate(0, 90);
43
44     // Round Rectangle
45
g.drawString("RoundRectangle", 10, 20);
46         RoundRectangle2D roundRect = new RoundRectangle2D.Double(10, 30, 50, 40, 10, 10);
47         g.draw(roundRect);
48
49         g.translate(0, 90);
50
51     // Circle
52
g.drawString("Circle", 10, 20);
53         Ellipse2D circle = new Ellipse2D.Float(10, 30, 50, 50);
54         g.draw(circle);
55
56         g.translate(0, 90);
57
58     // CubicCurve2D
59
g.drawString("CubicCurve2D", 10, 20);
60         CubicCurve2D curve = new CubicCurve2D.Float(10, 55, 22.5f, 00, 38.5f, 110, 60, 55);
61         g.draw(curve);
62
63         g.translate(150, -270);
64
65     // Polygon
66
g.drawString("Polygon", 10, 20);
67         Polygon polygon = new Polygon(new int[] { 30, 50, 10 },
68                                       new int[] { 30, 60, 60 },
69                                       3);
70         g.draw(polygon);
71
72         g.translate(0, 90);
73
74         // General Path
75
g.drawString("GeneralPath", 10, 20);
76         GeneralPath path = new GeneralPath();
77         path.moveTo(30, 30);
78         path.quadTo(30, 50, 50, 60);
79         path.quadTo(30, 50, 10, 60);
80         path.quadTo(30, 50, 30, 30);
81         path.closePath();
82         g.draw(path);
83
84         g.translate(0, 90);
85     
86         // Area
87
g.drawString("Area", 10, 20);
88         Area area = new Area(new Rectangle(10, 30, 50, 50));
89         area.subtract(new Area(new Ellipse2D.Double(12, 32, 46, 46)));
90         g.fill(area);
91
92         g.translate(0, 90);
93     
94         // QuadCurve 2D
95
g.drawString("QuadCurve2D", 10, 20);
96         QuadCurve2D quad = new QuadCurve2D.Float(10, 55, 35, 105, 60, 55);
97         g.draw(quad);
98
99         g.translate(-75, 70);
100   
101     // Line
102
g.drawString("Line2D", 10, 20);
103         g.draw(new Line2D.Float(10, 30, 60, 30));
104     }
105 }
106
Popular Tags