KickJava   Java API By Example, From Geeks To Geeks.

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


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

34 public class SVGOMAnimatedLengthList
35     implements SVGAnimatedLengthList,
36                LiveAttributeValue {
37
38     /**
39      * The associated element.
40      */

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

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

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

56     protected boolean changing;
57
58     /**
59      * SVGPLengthList
60      */

61     protected AbstractSVGLengthList lengths;
62
63     /**
64      * Default value for the 'points' attribute.
65      */

66     protected String JavaDoc defaultValue;
67
68     /**
69      * This length list's direction.
70      */

71     protected short direction;
72
73     /**
74      */

75     public SVGOMAnimatedLengthList(AbstractElement elt,
76                                    String JavaDoc ns,
77                                    String JavaDoc ln,
78                                    String JavaDoc defaultValue,
79                                    short direction){
80         
81         element = elt;
82         namespaceURI = ns;
83         localName = ln;
84         this.defaultValue = defaultValue;
85         this.direction = direction;
86     }
87
88     /**
89      * return the SVGLengthList mapping
90      * the static attribute
91      * of the element
92      *
93      * @return a length list.
94      */

95     public SVGLengthList getBaseVal(){
96         if ( lengths == null ){
97             lengths = new SVGOMLengthList(direction);
98         }
99          return lengths;
100     }
101
102     /**
103      */

104     public SVGLengthList getAnimVal(){
105         throw new RuntimeException JavaDoc("TODO : getAnimVal() !!");
106     }
107
108     /**
109      * Called when an Attr node has been added.
110      */

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

120     public void attrModified(Attr JavaDoc node, String JavaDoc oldv, String JavaDoc newv) {
121         if (!changing && lengths != null) {
122             lengths.invalidate();
123         }
124     }
125
126     /**
127      * Called when an Attr node has been removed.
128      */

129     public void attrRemoved(Attr JavaDoc node, String JavaDoc oldv) {
130         if (!changing && lengths != null) {
131             lengths.invalidate();
132         }
133     }
134     
135     /**
136      * SVGLengthList implementation.
137      */

138     public class SVGOMLengthList extends AbstractSVGLengthList {
139
140         public SVGOMLengthList(short direction){
141             super(direction);
142         }
143
144         /**
145          * Create a DOMException.
146          */

147         protected DOMException JavaDoc createDOMException(short type,
148                                                   String JavaDoc key,
149                                                   Object JavaDoc[] args){
150             return element.createDOMException(type,key,args);
151         }
152
153         /**
154          * Create a SVGException.
155          */

156         protected SVGException createSVGException(short type,
157                                                   String JavaDoc key,
158                                                   Object JavaDoc[] args){
159
160             return ((SVGOMElement)element).createSVGException(type,key,args);
161         }
162
163         /**
164          */

165         protected Element JavaDoc getElement(){
166             return element;
167         }
168
169         /**
170          * Retrieve the value of the attribute 'points'.
171          */

172         protected String JavaDoc getValueAsString(){
173             Attr JavaDoc attr = element.getAttributeNodeNS(namespaceURI, localName);
174             if (attr == null) {
175                 return defaultValue;
176             }
177             return attr.getValue();
178         }
179
180         /**
181          * Set the value of the attribute 'points'
182          */

183         protected void setAttributeValue(String JavaDoc value){
184             try{
185                 changing = true;
186                 element.setAttributeNS(namespaceURI, localName, value);
187             }
188             finally{
189                 changing = false;
190             }
191         }
192     }
193 }
194
Popular Tags