KickJava   Java API By Example, From Geeks To Geeks.

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


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.Element JavaDoc;
23 import org.w3c.dom.svg.SVGAnimatedNumberList;
24 import org.w3c.dom.svg.SVGException;
25 import org.w3c.dom.svg.SVGNumberList;
26
27 /**
28  * This class is the implementation of
29  * the SVGAnimatedNumberList interface.
30  *
31  * @author tonny@kiyut.com
32  */

33 public class SVGOMAnimatedNumberList
34     implements SVGAnimatedNumberList,
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      * SVGNumberList
59      */

60     protected AbstractSVGNumberList numbers;
61
62     /**
63      * Default value for the 'points' attribute.
64      */

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

69     public SVGOMAnimatedNumberList(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      * return the SVGNumberList mapping
82      * the static attribute
83      * of the element
84      *
85      * @return a number list.
86      */

87     public SVGNumberList getBaseVal(){
88         if ( numbers == null ){
89             numbers = new SVGOMNumberList();
90         }
91          return numbers;
92     }
93
94     /**
95      */

96     public SVGNumberList getAnimVal(){
97         throw new RuntimeException JavaDoc("TODO : getAnimVal() !!");
98     }
99     
100     /**
101      * Called when an Attr node has been added.
102      */

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

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

121     public void attrRemoved(Attr JavaDoc node, String JavaDoc oldv) {
122         if (!changing && numbers != null) {
123             numbers.invalidate();
124         }
125     }
126     
127     /**
128      * SVGNumberList implementation.
129      */

130     public class SVGOMNumberList extends AbstractSVGNumberList {
131
132         public SVGOMNumberList(){
133             super();
134         }
135
136         /**
137          * Create a DOMException.
138          */

139         protected DOMException JavaDoc createDOMException(short type,
140                                                   String JavaDoc key,
141                                                   Object JavaDoc[] args){
142             return element.createDOMException(type,key,args);
143         }
144
145         /**
146          * Create a SVGException.
147          */

148         protected SVGException createSVGException(short type,
149                                                   String JavaDoc key,
150                                                   Object JavaDoc[] args){
151
152             return ((SVGOMElement)element).createSVGException(type,key,args);
153         }
154
155         /**
156          */

157         protected Element JavaDoc getElement(){
158             return element;
159         }
160
161         /**
162          * Retrieve the value of the attribute 'points'.
163          */

164         protected String JavaDoc getValueAsString(){
165             Attr JavaDoc attr = element.getAttributeNodeNS(namespaceURI, localName);
166             if (attr == null) {
167                 return defaultValue;
168             }
169             return attr.getValue();
170         }
171
172         /**
173          * Set the value of the attribute 'points'
174          */

175         protected void setAttributeValue(String JavaDoc value){
176             try{
177                 changing = true;
178                 element.setAttributeNS(namespaceURI, localName, value);
179             }
180             finally{
181                 changing = false;
182             }
183         }
184     }
185 }
186
Popular Tags