KickJava   Java API By Example, From Geeks To Geeks.

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


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

31 public class SVGOMAnimatedEnumeration
32     implements SVGAnimatedEnumeration,
33                LiveAttributeValue {
34     
35     /**
36      * The associated element.
37      */

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

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

48     protected String JavaDoc localName;
49
50     /**
51      * The values in this enumeration.
52      */

53     protected String JavaDoc[] values;
54
55     /**
56      * The default value, if the attribute is not specified.
57      */

58     protected short defaultValue;
59
60     /**
61      * Creates a new SVGOMAnimatedEnumeration.
62      * @param elt The associated element.
63      * @param ns The attribute's namespace URI.
64      * @param ln The attribute's local name.
65      * @param val The values in this enumeration.
66      * @param def The default value to use.
67      */

68     public SVGOMAnimatedEnumeration(AbstractElement elt,
69                                     String JavaDoc ns,
70                                     String JavaDoc ln,
71                                     String JavaDoc[] val,
72                                     short def) {
73         element = elt;
74         namespaceURI = ns;
75         localName = ln;
76         values = val;
77         defaultValue = def;
78     }
79
80     /**
81      * <b>DOM</b>: Implements {@link SVGAnimatedEnumeration#getBaseVal()}.
82      */

83     public short getBaseVal() {
84         String JavaDoc val = element.getAttributeNS(namespaceURI, localName);
85         if (val.length() == 0) {
86             return defaultValue;
87         }
88         for (short i = 0; i < values.length; i++) {
89             if (val.equals(values[i])) {
90                 return i;
91             }
92         }
93         return 0;
94     }
95
96     /**
97      * <b>DOM</b>: Implements {@link
98      * SVGAnimatedEnumeration#setBaseVal(short)}.
99      */

100     public void setBaseVal(short baseVal) throws DOMException JavaDoc {
101         if (baseVal >= 0 && baseVal < values.length) {
102             element.setAttributeNS(namespaceURI, localName, values[baseVal]);
103         }
104     }
105
106     /**
107      * <b>DOM</b>: Implements {@link SVGAnimatedEnumeration#getAnimVal()}.
108      */

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

116     public void attrAdded(Attr JavaDoc node, String JavaDoc newv) {
117     }
118
119     /**
120      * Called when an Attr node has been modified.
121      */

122     public void attrModified(Attr JavaDoc node, String JavaDoc oldv, String JavaDoc newv) {
123     }
124
125     /**
126      * Called when an Attr node has been removed.
127      */

128     public void attrRemoved(Attr JavaDoc node, String JavaDoc oldv) {
129     }
130 }
131
Popular Tags