KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > ext > awt > g2d > TransformType


1 /*
2
3    Copyright 1999-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
19 package org.apache.batik.ext.awt.g2d;
20
21 /**
22  * Enumeration for transformation types.
23  *
24  * @author <a HREF="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
25  * @version $Id: TransformType.java,v 1.4 2005/03/27 08:58:32 cam Exp $
26  */

27 public class TransformType{
28     /*
29      * Transform type constants
30      */

31     public static final int TRANSFORM_TRANSLATE = 0;
32     public static final int TRANSFORM_ROTATE = 1;
33     public static final int TRANSFORM_SCALE = 2;
34     public static final int TRANSFORM_SHEAR = 3;
35     public static final int TRANSFORM_GENERAL = 4;
36
37     /**
38      * Strings describing the elementary transforms
39      */

40     public static final String JavaDoc TRANSLATE_STRING = "translate";
41     public static final String JavaDoc ROTATE_STRING = "rotate";
42     public static final String JavaDoc SCALE_STRING = "scale";
43     public static final String JavaDoc SHEAR_STRING = "shear";
44     public static final String JavaDoc GENERAL_STRING = "general";
45
46     /**
47      * TransformType values
48      */

49     public static final TransformType TRANSLATE = new TransformType(TRANSFORM_TRANSLATE, TRANSLATE_STRING);
50     public static final TransformType ROTATE = new TransformType(TRANSFORM_ROTATE, ROTATE_STRING);
51     public static final TransformType SCALE = new TransformType(TRANSFORM_SCALE, SCALE_STRING);
52     public static final TransformType SHEAR = new TransformType(TRANSFORM_SHEAR, SHEAR_STRING);
53     public static final TransformType GENERAL = new TransformType(TRANSFORM_GENERAL, GENERAL_STRING);
54
55     /**
56      * All values
57      */

58     private static final TransformType[] enumValues = { TRANSLATE,
59                                                         ROTATE,
60                                                         SCALE,
61                                                         SHEAR,
62                                                         GENERAL };
63
64     private String JavaDoc desc;
65     private int val;
66
67     /**
68      * Constructor is private so that no instances other than
69      * the ones in the enumeration can be created.
70      * @see #readResolve
71      */

72     private TransformType(int val, String JavaDoc desc){
73         this.desc = desc;
74         this.val = val;
75     }
76
77     /**
78      * @return description
79      */

80     public String JavaDoc toString(){
81         return desc;
82     }
83
84     /**
85      * Convenience for enumeration switching.
86      * That is,
87      * <pre>
88      * switch(transformType.toInt()){
89      * case TransformType.TRANSFORM_TRANSLATE:
90      * ....
91      * case TransformType.TRANSFORM_ROTATE:
92      * </pre>
93      */

94     public int toInt(){
95         return val;
96     }
97
98     /**
99      * This is called by the serialization code before it returns an unserialized
100      * object. To provide for unicity of instances, the instance that was read
101      * is replaced by its static equivalent
102      */

103     public Object JavaDoc readResolve() {
104         switch(val){
105         case TRANSFORM_TRANSLATE:
106             return TransformType.TRANSLATE;
107         case TRANSFORM_ROTATE:
108             return TransformType.ROTATE;
109         case TRANSFORM_SCALE:
110             return TransformType.SCALE;
111         case TRANSFORM_SHEAR:
112             return TransformType.SHEAR;
113         case TRANSFORM_GENERAL:
114             return TransformType.GENERAL;
115         default:
116             throw new Error JavaDoc("Unknown TransformType value");
117         }
118     }
119 }
120
Popular Tags