KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2000-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.dom.svg;
19
20 import org.w3c.dom.Attr JavaDoc;
21 import org.w3c.dom.DOMException JavaDoc;
22 import org.w3c.dom.svg.SVGAnimatedTransformList;
23 import org.w3c.dom.svg.SVGException;
24 import org.w3c.dom.svg.SVGTransformList;
25
26 /**
27  * This class is the implementation of
28  * the SVGAnimatedTransformList interface.
29  *
30  * @author <a HREF="mailto:nicolas.socheleau@bitflash.com">Nicolas Socheleau</a>
31  * @version $Id: SVGOMAnimatedTransformList.java,v 1.10 2004/08/18 07:13:14 vhardy Exp $
32  */

33 public class SVGOMAnimatedTransformList
34     implements SVGAnimatedTransformList,
35                LiveAttributeValue {
36
37     /**
38      * The associated element.
39      */

40     protected AbstractElement element;
41
42     /**
43      * The attribute's namespace URI.
44      */

45     protected String JavaDoc namespaceURI;
46
47     /**
48      * The attribute's local name.
49      */

50     protected String JavaDoc localName;
51
52     /**
53      * Whether the list is changing.
54      */

55     protected boolean changing;
56
57     /**
58      * SVGTransformList mapping the static 'transform' attribute.
59      */

60     protected AbstractSVGTransformList transformList;
61
62     /**
63      * Default value for the 'transform' attribute.
64      */

65     protected String JavaDoc defaultValue;
66
67     /**
68      */

69     public SVGOMAnimatedTransformList(AbstractElement elt,
70                                       String JavaDoc ns,
71                                       String JavaDoc ln,
72                                       String JavaDoc defaultValue){
73
74         element = elt;
75         namespaceURI = ns;
76         localName = ln;
77         this.defaultValue = defaultValue;
78     }
79
80
81     /**
82      * return the SVGTransformList mapping
83      * the static 'transform' attribute
84      * of the element
85      *
86      * @return a transform list.
87      */

88     public SVGTransformList getBaseVal(){
89         if ( transformList == null ){
90             transformList = new SVGOMTransformList();
91         }
92          return transformList;
93     }
94
95     public SVGTransformList getAnimVal(){
96         throw new RuntimeException JavaDoc("TODO : getAnimVal() !!");
97     }
98
99     /**
100      * Called when an Attr node has been added.
101      */

102     public void attrAdded(Attr JavaDoc node, String JavaDoc newv) {
103         if (!changing && transformList != null) {
104             transformList.invalidate();
105         }
106     }
107
108     /**
109      * Called when an Attr node has been modified.
110      */

111     public void attrModified(Attr JavaDoc node, String JavaDoc oldv, String JavaDoc newv) {
112         if (!changing && transformList != null) {
113             transformList.invalidate();
114         }
115     }
116
117     /**
118      * Called when an Attr node has been removed.
119      */

120     public void attrRemoved(Attr JavaDoc node, String JavaDoc oldv) {
121         if (!changing && transformList != null) {
122             transformList.invalidate();
123         }
124     }
125     
126     /**
127      * SVGTransformList implementation for the
128      * static 'transform' attribute of the element.
129      */

130     public class SVGOMTransformList extends AbstractSVGTransformList {
131
132         /**
133          * Create a DOMException.
134          */

135         protected DOMException JavaDoc createDOMException(short type,
136                                                   String JavaDoc key,
137                                                   Object JavaDoc[] args){
138             return element.createDOMException(type,key,args);
139         }
140
141         /**
142          * Create a SVGException.
143          */

144         protected SVGException createSVGException(short type,
145                                                   String JavaDoc key,
146                                                   Object JavaDoc[] args){
147
148             return ((SVGOMElement)element).createSVGException(type,key,args);
149         }
150
151         /**
152          * Retrieve the value of the attribute 'points'.
153          */

154         protected String JavaDoc getValueAsString(){
155             Attr JavaDoc attr = element.getAttributeNodeNS(namespaceURI, localName);
156             if (attr == null) {
157                 return defaultValue;
158             }
159             return attr.getValue();
160         }
161
162         /**
163          * Set the value of the attribute 'points'
164          */

165         protected void setAttributeValue(String JavaDoc value){
166             try{
167                 changing = true;
168                 element.setAttributeNS(namespaceURI, localName, value);
169             }
170             finally{
171                 changing = false;
172             }
173         }
174     }
175 }
176
Popular Tags