KickJava   Java API By Example, From Geeks To Geeks.

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


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

33 public class SVGOMAnimatedPoints
34     implements SVGAnimatedPoints,
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      * SVGPointList mapping the static 'points' attribute.
59      */

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

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

69     public SVGOMAnimatedPoints(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 SVGPointList mapping
82      * the static 'points' attribute
83      * of the element
84      *
85      * @return a point list.
86      */

87     public SVGPointList getPoints(){
88         if ( points == null ){
89             points = new SVGOMPointList();
90         }
91          return points;
92     }
93
94     /**
95      */

96     public SVGPointList getAnimatedPoints(){
97         throw new RuntimeException JavaDoc("TODO : getAnimatedPoints() !!");
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 && points != null) {
105             points.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 && points != null) {
114             points.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 && points != null) {
123             points.invalidate();
124         }
125     }
126     
127     /**
128      * SVGPointList implementation for the
129      * static 'points' attribute of the element.
130      */

131     public class SVGOMPointList extends AbstractSVGPointList {
132
133         /**
134          * Create a DOMException.
135          */

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

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

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

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