KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2001,2003 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.Polygon JavaDoc;
21 import java.awt.Shape JavaDoc;
22 import java.awt.geom.Arc2D JavaDoc;
23 import java.awt.geom.Ellipse2D JavaDoc;
24 import java.awt.geom.Line2D JavaDoc;
25 import java.awt.geom.Rectangle2D JavaDoc;
26 import java.awt.geom.RoundRectangle2D JavaDoc;
27
28 import org.w3c.dom.Element JavaDoc;
29
30 /**
31  * Utility class that converts a Shape object into the corresponding
32  * SVG element. Note that this class analyzes the input Shape class
33  * to generate the most appropriate corresponding SVG element:
34  * + Polygon is mapped to polygon
35  * + Rectangle2D and RoundRectangle2D are mapped to rect
36  * + Ellipse2D is mapped to circle or ellipse
37  * + Line2D is mapped to line
38  * + Arc2D, CubicCurve2D, Area, GeneralPath and QuadCurve2D are mapped to
39  * path.
40  * + Any custom Shape implementation is mapped to path as well.
41  *
42  * @author <a HREF="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
43  * @version $Id: SVGShape.java,v 1.9 2004/10/30 16:54:53 deweese Exp $
44  */

45 public class SVGShape extends SVGGraphicObjectConverter {
46     /*
47      * Subconverts, for each type of Shape class
48      */

49     private SVGArc svgArc;
50     private SVGEllipse svgEllipse;
51     private SVGLine svgLine;
52     private SVGPath svgPath;
53     private SVGPolygon svgPolygon;
54     private SVGRectangle svgRectangle;
55
56     /**
57      * @param generatorContext used to build Elements
58      */

59     public SVGShape(SVGGeneratorContext generatorContext) {
60         super(generatorContext);
61         svgArc = new SVGArc(generatorContext);
62         svgEllipse = new SVGEllipse(generatorContext);
63         svgLine = new SVGLine(generatorContext);
64         svgPath = new SVGPath(generatorContext);
65         svgPolygon = new SVGPolygon(generatorContext);
66         svgRectangle = new SVGRectangle(generatorContext);
67     }
68
69     /**
70      * @param shape Shape object to be converted
71      */

72     public Element JavaDoc toSVG(Shape JavaDoc shape){
73         if(shape instanceof Polygon JavaDoc)
74             return svgPolygon.toSVG((Polygon JavaDoc)shape);
75         else if(shape instanceof Rectangle2D JavaDoc)
76             return svgRectangle.toSVG((Rectangle2D JavaDoc)shape);
77         else if(shape instanceof RoundRectangle2D JavaDoc)
78             return svgRectangle.toSVG((RoundRectangle2D JavaDoc)shape);
79         else if(shape instanceof Ellipse2D JavaDoc)
80             return svgEllipse.toSVG((Ellipse2D JavaDoc)shape);
81         else if(shape instanceof Line2D JavaDoc)
82             return svgLine.toSVG((Line2D JavaDoc)shape);
83         else if(shape instanceof Arc2D JavaDoc)
84             return svgArc.toSVG((Arc2D JavaDoc)shape);
85         else
86             return svgPath.toSVG(shape);
87     }
88 }
89
Popular Tags