KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2000-2001 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.SVGAnimatedBoolean;
23
24 /**
25  * This class implements the {@link SVGAnimatedBoolean} interface.
26  *
27  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
28  * @version $Id: SVGOMAnimatedBoolean.java,v 1.5 2004/08/18 07:13:14 vhardy Exp $
29  */

30 public class SVGOMAnimatedBoolean
31     implements SVGAnimatedBoolean,
32                LiveAttributeValue {
33
34     /**
35      * The associated element.
36      */

37     protected AbstractElement element;
38
39     /**
40      * The attribute's namespace URI.
41      */

42     protected String JavaDoc namespaceURI;
43
44     /**
45      * The attribute's local name.
46      */

47     protected String JavaDoc localName;
48
49     /**
50      * The actual boolean value.
51      */

52     protected boolean baseVal;
53
54     /**
55      * The default's attribute value.
56      */

57     protected String JavaDoc defaultValue;
58
59     /**
60      * Whether the mutation comes from this object.
61      */

62     protected boolean mutate;
63
64     /**
65      * Creates a new SVGOMAnimatedBoolean.
66      * @param elt The associated element.
67      * @param ns The attribute's namespace URI.
68      * @param ln The attribute's local name.
69      * @param attr The attribute node, if any.
70      * @param val The default attribute value, if missing.
71      */

72     public SVGOMAnimatedBoolean(AbstractElement elt,
73                                 String JavaDoc ns,
74                                 String JavaDoc ln,
75                                 Attr JavaDoc attr,
76                                 String JavaDoc val) {
77         element = elt;
78         namespaceURI = ns;
79         localName = ln;
80         if (attr != null) {
81             String JavaDoc s = attr.getValue();
82             baseVal = "true".equals(s);
83         }
84         defaultValue = val;
85     }
86
87     /**
88      * <b>DOM</b>: Implements {@link SVGAnimatedBoolean#getBaseVal()}.
89      */

90     public boolean getBaseVal() {
91         return baseVal;
92     }
93
94     /**
95      * <b>DOM</b>: Implements {@link SVGAnimatedBoolean#setBaseVal(boolean)}.
96      */

97     public void setBaseVal(boolean baseVal) throws DOMException JavaDoc {
98         if (this.baseVal != baseVal) {
99             mutate = true;
100             this.baseVal = baseVal;
101             element.setAttributeNS(namespaceURI, localName,
102                                    (baseVal) ? "true" : "false");
103             mutate = false;
104         }
105     }
106
107     /**
108      * <b>DOM</b>: Implements {@link SVGAnimatedBoolean#getAnimVal()}.
109      */

110     public boolean getAnimVal() {
111         throw new RuntimeException JavaDoc("!!! TODO: getAnimVal()");
112     }
113
114     /**
115      * Called when an Attr node has been added.
116      */

117     public void attrAdded(Attr JavaDoc node, String JavaDoc newv) {
118         if (!mutate) {
119             baseVal = "true".equals(newv);
120         }
121     }
122
123     /**
124      * Called when an Attr node has been modified.
125      */

126     public void attrModified(Attr JavaDoc node, String JavaDoc oldv, String JavaDoc newv) {
127         if (!mutate) {
128             baseVal = "true".equals(newv);
129         }
130     }
131
132     /**
133      * Called when an Attr node has been removed.
134      */

135     public void attrRemoved(Attr JavaDoc node, String JavaDoc oldv) {
136         if (!mutate) {
137             baseVal = "true".equals(defaultValue);
138         }
139     }
140 }
141
Popular Tags