KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > dom > svg > AbstractSVGTransform


1 /*
2
3    Copyright 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.dom.svg;
19
20 import java.awt.geom.AffineTransform JavaDoc;
21
22 import org.w3c.dom.svg.SVGMatrix;
23 import org.w3c.dom.svg.SVGTransform;
24
25 /**
26  * Abstract implementation for SVGTransform.
27  *
28  * This is the base implementation for SVGTransform
29  *
30  * @author nicolas.socheleau@bitflash.com
31  * @version $Id :$
32  */

33 public abstract class AbstractSVGTransform implements SVGTransform {
34
35     /**
36      * Type of the transformation.
37      *
38      * By default, the type is unknown
39      */

40     protected short type = SVG_TRANSFORM_UNKNOWN;
41
42     /**
43      * AffineTranform associated to the SVGTransform
44      *
45      * Java2D representation of the SVGTransform.
46      */

47     protected AffineTransform JavaDoc affineTransform;
48
49     /**
50      * Angle associated to the transform.
51      * This value is not necessary since the AffineTransform
52      * will contain it but it is easier to have it than
53      * extracting it from the AffineTransform.
54      */

55     protected float angle;
56
57     protected float x;
58
59     protected float y;
60
61     /**
62      * Create a SVGMatrix associated to the transform.
63      *
64      * @return SVGMatrix representing the transformation
65      */

66     protected abstract SVGMatrix createMatrix();
67
68     /**
69      * Default constructor.
70      */

71     protected AbstractSVGTransform(){
72     }
73
74     /**
75      */

76     protected void setType(short type){
77         this.type = type;
78     }
79
80     protected float getX(){
81         return x;
82     }
83
84     protected float getY(){
85         return y;
86     }
87
88     /**
89      */

90     public short getType( ){
91         return type;
92     }
93
94     /**
95      */

96     public SVGMatrix getMatrix( ){
97         return createMatrix();
98     }
99     /**
100      */

101     public float getAngle( ){
102         return angle;
103     }
104     /**
105      */

106     public void setMatrix ( SVGMatrix matrix ){
107         type = SVG_TRANSFORM_MATRIX;
108         affineTransform = new AffineTransform JavaDoc(matrix.getA(),matrix.getB(),matrix.getC(),
109                                               matrix.getD(),matrix.getE(),matrix.getF());
110     }
111     /**
112      */

113     public void setTranslate ( float tx, float ty ){
114         type = SVG_TRANSFORM_TRANSLATE;
115         affineTransform = AffineTransform.getTranslateInstance(tx,ty);
116     }
117     /**
118      */

119     public void setScale ( float sx, float sy ){
120         type = SVG_TRANSFORM_SCALE;
121         affineTransform = AffineTransform.getScaleInstance(sx,sy);
122     }
123     /**
124      */

125     public void setRotate ( float angle, float cx, float cy ){
126         type = SVG_TRANSFORM_ROTATE;
127         affineTransform = AffineTransform.getRotateInstance(Math.toRadians(angle),cx,cy);
128         this.angle = angle;
129         this.x = cx;
130         this.y = cy;
131     }
132     /**
133      */

134     public void setSkewX ( float angle ){
135         type = SVG_TRANSFORM_SKEWX;
136         affineTransform = new AffineTransform JavaDoc(1.0,Math.tan(Math.toRadians(angle)),0.0,
137                                               1.0,0.0,0.0);
138         this.angle = angle;
139     }
140     /**
141      */

142     public void setSkewY ( float angle ){
143         type = SVG_TRANSFORM_SKEWY;
144         this.angle = angle;
145         affineTransform = new AffineTransform JavaDoc(1.0,0.0,Math.tan(Math.toRadians(angle)),
146                                               1.0,0.0,0.0);
147     }
148
149 }
150
151
Popular Tags