001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.dom.svg;
020:
021: import java.awt.geom.AffineTransform;
022:
023: import org.apache.batik.anim.values.AnimatableMotionPointValue;
024: import org.apache.batik.anim.values.AnimatableValue;
025: import org.apache.batik.dom.AbstractDocument;
026: import org.apache.batik.dom.util.DoublyIndexedTable;
027: import org.apache.batik.dom.util.XMLSupport;
028: import org.apache.batik.util.SVGTypes;
029:
030: import org.w3c.dom.svg.SVGAnimatedBoolean;
031: import org.w3c.dom.svg.SVGAnimatedTransformList;
032: import org.w3c.dom.svg.SVGElement;
033: import org.w3c.dom.svg.SVGException;
034: import org.w3c.dom.svg.SVGMatrix;
035: import org.w3c.dom.svg.SVGRect;
036: import org.w3c.dom.svg.SVGStringList;
037:
038: /**
039: * This class provides a common superclass for all graphics elements.
040: *
041: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
042: * @version $Id: SVGGraphicsElement.java 491229 2006-12-30 14:37:28Z dvholten $
043: */
044: public abstract class SVGGraphicsElement extends SVGStylableElement
045: implements SVGMotionAnimatableElement {
046:
047: /**
048: * Table mapping XML attribute names to TraitInformation objects.
049: */
050: protected static DoublyIndexedTable xmlTraitInformation;
051: static {
052: DoublyIndexedTable t = new DoublyIndexedTable(
053: SVGStylableElement.xmlTraitInformation);
054: t.put(null, SVG_TRANSFORM_ATTRIBUTE, new TraitInformation(true,
055: SVGTypes.TYPE_TRANSFORM_LIST));
056: t.put(null, SVG_EXTERNAL_RESOURCES_REQUIRED_ATTRIBUTE,
057: new TraitInformation(true, SVGTypes.TYPE_BOOLEAN));
058: // t.put(null, SVG_REQUIRED_EXTENSIONS_ATTRIBUTE,
059: // new TraitInformation(false, SVGTypes.TYPE_URI_LIST));
060: // t.put(null, SVG_REQUIRED_FEATURES_ATTRIBUTE,
061: // new TraitInformation(false, SVGTypes.TYPE_URI_LIST));
062: // t.put(null, SVG_SYSTEM_LANGUAGE_ATTRIBUTE,
063: // new TraitInformation(false, SVGTypes.TYPE_LANG_LIST));
064: xmlTraitInformation = t;
065:
066: }
067:
068: /**
069: * The 'transform' attribute value.
070: */
071: protected SVGOMAnimatedTransformList transform;
072:
073: /**
074: * The 'externalResourcesRequired' attribute value.
075: */
076: protected SVGOMAnimatedBoolean externalResourcesRequired;
077:
078: /**
079: * Supplemental transformation due to motion animation.
080: */
081: protected AffineTransform motionTransform;
082:
083: /**
084: * Creates a new SVGGraphicsElement.
085: */
086: protected SVGGraphicsElement() {
087: }
088:
089: /**
090: * Creates a new SVGGraphicsElement object.
091: * @param prefix The namespace prefix.
092: * @param owner The owner document.
093: */
094: protected SVGGraphicsElement(String prefix, AbstractDocument owner) {
095: super (prefix, owner);
096: initializeLiveAttributes();
097: }
098:
099: /**
100: * Initializes all live attributes for this element.
101: */
102: protected void initializeAllLiveAttributes() {
103: super .initializeAllLiveAttributes();
104: initializeLiveAttributes();
105: }
106:
107: /**
108: * Initializes the live attribute values of this element.
109: */
110: private void initializeLiveAttributes() {
111: transform = createLiveAnimatedTransformList(null,
112: SVG_TRANSFORM_ATTRIBUTE, "");
113: externalResourcesRequired = createLiveAnimatedBoolean(null,
114: SVG_EXTERNAL_RESOURCES_REQUIRED_ATTRIBUTE, false);
115: }
116:
117: /**
118: * Returns the table of TraitInformation objects for this element.
119: */
120: protected DoublyIndexedTable getTraitInformationTable() {
121: return xmlTraitInformation;
122: }
123:
124: // SVGLocatable support /////////////////////////////////////////////
125:
126: /**
127: * <b>DOM</b>: Implements {@link
128: * org.w3c.dom.svg.SVGLocatable#getNearestViewportElement()}.
129: */
130: public SVGElement getNearestViewportElement() {
131: return SVGLocatableSupport.getNearestViewportElement(this );
132: }
133:
134: /**
135: * <b>DOM</b>: Implements {@link
136: * org.w3c.dom.svg.SVGLocatable#getFarthestViewportElement()}.
137: */
138: public SVGElement getFarthestViewportElement() {
139: return SVGLocatableSupport.getFarthestViewportElement(this );
140: }
141:
142: /**
143: * <b>DOM</b>: Implements {@link
144: * org.w3c.dom.svg.SVGLocatable#getBBox()}.
145: */
146: public SVGRect getBBox() {
147: return SVGLocatableSupport.getBBox(this );
148: }
149:
150: /**
151: * <b>DOM</b>: Implements {@link
152: * org.w3c.dom.svg.SVGLocatable#getCTM()}.
153: */
154: public SVGMatrix getCTM() {
155: return SVGLocatableSupport.getCTM(this );
156: }
157:
158: /**
159: * <b>DOM</b>: Implements {@link
160: * org.w3c.dom.svg.SVGLocatable#getScreenCTM()}.
161: */
162: public SVGMatrix getScreenCTM() {
163: return SVGLocatableSupport.getScreenCTM(this );
164: }
165:
166: /**
167: * <b>DOM</b>: Implements {@link
168: * org.w3c.dom.svg.SVGLocatable#getTransformToElement(SVGElement)}.
169: */
170: public SVGMatrix getTransformToElement(SVGElement element)
171: throws SVGException {
172: return SVGLocatableSupport.getTransformToElement(this , element);
173: }
174:
175: // SVGTransformable support //////////////////////////////////////////////
176:
177: /**
178: * <b>DOM</b>: Implements {@link
179: * org.w3c.dom.svg.SVGTransformable#getTransform()}.
180: */
181: public SVGAnimatedTransformList getTransform() {
182: return transform;
183: }
184:
185: // SVGExternalResourcesRequired support /////////////////////////////
186:
187: /**
188: * <b>DOM</b>: Implements {@link
189: * org.w3c.dom.svg.SVGExternalResourcesRequired#getExternalResourcesRequired()}.
190: */
191: public SVGAnimatedBoolean getExternalResourcesRequired() {
192: return externalResourcesRequired;
193: }
194:
195: // SVGLangSpace support //////////////////////////////////////////////////
196:
197: /**
198: * <b>DOM</b>: Returns the xml:lang attribute value.
199: */
200: public String getXMLlang() {
201: return XMLSupport.getXMLLang(this );
202: }
203:
204: /**
205: * <b>DOM</b>: Sets the xml:lang attribute value.
206: */
207: public void setXMLlang(String lang) {
208: setAttributeNS(XML_NAMESPACE_URI, XML_LANG_QNAME, lang);
209: }
210:
211: /**
212: * <b>DOM</b>: Returns the xml:space attribute value.
213: */
214: public String getXMLspace() {
215: return XMLSupport.getXMLSpace(this );
216: }
217:
218: /**
219: * <b>DOM</b>: Sets the xml:space attribute value.
220: */
221: public void setXMLspace(String space) {
222: setAttributeNS(XML_NAMESPACE_URI, XML_SPACE_QNAME, space);
223: }
224:
225: // SVGTests support ///////////////////////////////////////////////////
226:
227: /**
228: * <b>DOM</b>: Implements {@link
229: * org.w3c.dom.svg.SVGTests#getRequiredFeatures()}.
230: */
231: public SVGStringList getRequiredFeatures() {
232: return SVGTestsSupport.getRequiredFeatures(this );
233: }
234:
235: /**
236: * <b>DOM</b>: Implements {@link
237: * org.w3c.dom.svg.SVGTests#getRequiredExtensions()}.
238: */
239: public SVGStringList getRequiredExtensions() {
240: return SVGTestsSupport.getRequiredExtensions(this );
241: }
242:
243: /**
244: * <b>DOM</b>: Implements {@link
245: * org.w3c.dom.svg.SVGTests#getSystemLanguage()}.
246: */
247: public SVGStringList getSystemLanguage() {
248: return SVGTestsSupport.getSystemLanguage(this );
249: }
250:
251: /**
252: * <b>DOM</b>: Implements {@link
253: * org.w3c.dom.svg.SVGTests#hasExtension(String)}.
254: */
255: public boolean hasExtension(String extension) {
256: return SVGTestsSupport.hasExtension(this , extension);
257: }
258:
259: // SVGMotionAnimatableElement ////////////////////////////////////////////
260:
261: /**
262: * Returns the {@link AffineTransform} representing the current motion
263: * animation for this element.
264: */
265: public AffineTransform getMotionTransform() {
266: return motionTransform;
267: }
268:
269: // AnimationTarget ///////////////////////////////////////////////////////
270:
271: /**
272: * Updates a 'other' animation value in this target.
273: */
274: public void updateOtherValue(String type, AnimatableValue val) {
275: if (type.equals("motion")) {
276: if (motionTransform == null) {
277: motionTransform = new AffineTransform();
278: }
279: if (val == null) {
280: motionTransform.setToIdentity();
281: } else {
282: AnimatableMotionPointValue p = (AnimatableMotionPointValue) val;
283: motionTransform.setToTranslation(p.getX(), p.getY());
284: motionTransform.rotate(p.getAngle());
285: }
286: SVGOMDocument d = (SVGOMDocument) ownerDocument;
287: d.getAnimatedAttributeListener().otherAnimationChanged(
288: this, type);
289: } else {
290: super.updateOtherValue(type, val);
291: }
292: }
293: }
|