KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2004 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.apache.batik.util.SVGConstants;
21
22 import org.w3c.dom.Attr JavaDoc;
23 import org.w3c.dom.DOMException JavaDoc;
24 import org.w3c.dom.svg.SVGAnimatedPreserveAspectRatio;
25 import org.w3c.dom.svg.SVGPreserveAspectRatio;
26 import org.w3c.dom.svg.SVGException;
27
28 /**
29  * This class implements the {@link SVGAnimatedPreserveAspectRatio} interface.
30  *
31  * @author Tonny Kohar
32  * @version $Id: SVGOMAnimatedPreserveAspectRatio.java,v 1.3 2005/03/27 08:58:32 cam Exp $
33  */

34 public class SVGOMAnimatedPreserveAspectRatio
35     implements SVGAnimatedPreserveAspectRatio, LiveAttributeValue {
36     /**
37      * The associated element.
38      */

39     protected AbstractElement element;
40     
41     /**
42      * Whether the value is changing.
43      */

44     protected boolean changing = false;
45     
46     /**
47      * SVGPreserveAspectRatio mapping the static 'preserveAspectRatio'
48      * attribute.
49      */

50     protected AbstractSVGPreserveAspectRatio preserveAspectRatio;
51     
52     
53     /** Creates a new instance of SVGOMAnimatePreserveAspectRatio */
54     public SVGOMAnimatedPreserveAspectRatio(AbstractElement elt) {
55         element = elt;
56         preserveAspectRatio = new SVGOMPreserveAspectRatio();
57         String JavaDoc attrValue = elt.getAttributeNS
58             (null,SVGConstants.SVG_PRESERVE_ASPECT_RATIO_ATTRIBUTE);
59         if (attrValue != null) {
60             preserveAspectRatio.setValueAsString(attrValue);
61         }
62     }
63     
64     public void attrAdded(Attr JavaDoc node, String JavaDoc newv) {
65         if (!changing) {
66             preserveAspectRatio.setValueAsString(newv);
67             // System.out.println("attr added: " + newv);
68
}
69     }
70     
71     public void attrModified(Attr JavaDoc node, String JavaDoc oldv, String JavaDoc newv) {
72         if (!changing) {
73             preserveAspectRatio.setValueAsString(newv);
74         }
75     }
76     
77     public void attrRemoved(Attr JavaDoc node, String JavaDoc oldv) {
78         if (!changing) {
79             preserveAspectRatio.reset();
80         }
81     }
82     
83     public SVGPreserveAspectRatio getAnimVal() {
84         throw new RuntimeException JavaDoc("!!! TODO: getAnimVal()");
85         
86     }
87     
88     public SVGPreserveAspectRatio getBaseVal() {
89         return preserveAspectRatio;
90     }
91     
92     /** The implementation of SVGPreserveAspectRatio
93      */

94     public class SVGOMPreserveAspectRatio
95         extends AbstractSVGPreserveAspectRatio {
96         
97         /**
98          * Create a DOMException.
99          */

100         protected DOMException JavaDoc createDOMException(short type,
101                                                   String JavaDoc key,
102                                                   Object JavaDoc[] args){
103             return element.createDOMException(type,key,args);
104         }
105         
106         protected void setAttributeValue(String JavaDoc value) throws DOMException JavaDoc {
107             try {
108                 changing = true;
109                 element.setAttributeNS
110                     (null,SVGConstants.SVG_PRESERVE_ASPECT_RATIO_ATTRIBUTE,
111                      value);
112             } finally {
113                 changing = false;
114             }
115         }
116     }
117 }
118
Popular Tags