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 org.apache.batik.anim.values.AnimatableValue;
022: import org.apache.batik.dom.AbstractDocument;
023: import org.apache.batik.dom.util.DoublyIndexedTable;
024: import org.apache.batik.util.SVGTypes;
025:
026: import org.w3c.dom.Attr;
027: import org.w3c.dom.Node;
028: import org.w3c.dom.svg.SVGAnimatedLength;
029: import org.w3c.dom.svg.SVGRectElement;
030:
031: /**
032: * This class implements {@link SVGRectElement}.
033: *
034: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
035: * @version $Id: SVGOMRectElement.java 489964 2006-12-24 01:30:23Z cam $
036: */
037: public class SVGOMRectElement extends SVGGraphicsElement implements
038: SVGRectElement {
039:
040: /**
041: * Table mapping XML attribute names to TraitInformation objects.
042: */
043: protected static DoublyIndexedTable xmlTraitInformation;
044: static {
045: DoublyIndexedTable t = new DoublyIndexedTable(
046: SVGGraphicsElement.xmlTraitInformation);
047: t.put(null, SVG_X_ATTRIBUTE, new TraitInformation(true,
048: SVGTypes.TYPE_LENGTH, PERCENTAGE_VIEWPORT_WIDTH));
049: t.put(null, SVG_Y_ATTRIBUTE, new TraitInformation(true,
050: SVGTypes.TYPE_LENGTH, PERCENTAGE_VIEWPORT_HEIGHT));
051: t.put(null, SVG_RX_ATTRIBUTE, new TraitInformation(true,
052: SVGTypes.TYPE_LENGTH, PERCENTAGE_VIEWPORT_WIDTH));
053: t.put(null, SVG_RY_ATTRIBUTE, new TraitInformation(true,
054: SVGTypes.TYPE_LENGTH, PERCENTAGE_VIEWPORT_HEIGHT));
055: t.put(null, SVG_WIDTH_ATTRIBUTE, new TraitInformation(true,
056: SVGTypes.TYPE_LENGTH, PERCENTAGE_VIEWPORT_WIDTH));
057: t.put(null, SVG_HEIGHT_ATTRIBUTE, new TraitInformation(true,
058: SVGTypes.TYPE_LENGTH, PERCENTAGE_VIEWPORT_HEIGHT));
059: xmlTraitInformation = t;
060: }
061:
062: /**
063: * The 'x' attribute value.
064: */
065: protected SVGOMAnimatedLength x;
066:
067: /**
068: * The 'y' attribute value.
069: */
070: protected SVGOMAnimatedLength y;
071:
072: /**
073: * The 'rx' attribute value.
074: */
075: protected AbstractSVGAnimatedLength rx;
076:
077: /**
078: * The 'ry' attribute value.
079: */
080: protected AbstractSVGAnimatedLength ry;
081:
082: /**
083: * The 'width' attribute value.
084: */
085: protected SVGOMAnimatedLength width;
086:
087: /**
088: * The 'height' attribute value.
089: */
090: protected SVGOMAnimatedLength height;
091:
092: /**
093: * Creates a new SVGOMRectElement object.
094: */
095: protected SVGOMRectElement() {
096: }
097:
098: /**
099: * Creates a new SVGOMRectElement object.
100: * @param prefix The namespace prefix.
101: * @param owner The owner document.
102: */
103: public SVGOMRectElement(String prefix, AbstractDocument owner) {
104: super (prefix, owner);
105: initializeLiveAttributes();
106: }
107:
108: /**
109: * Initializes all live attributes for this element.
110: */
111: protected void initializeAllLiveAttributes() {
112: super .initializeAllLiveAttributes();
113: initializeLiveAttributes();
114: }
115:
116: /**
117: * Initializes the live attribute values of this element.
118: */
119: private void initializeLiveAttributes() {
120: x = createLiveAnimatedLength(null, SVG_X_ATTRIBUTE,
121: SVG_RECT_X_DEFAULT_VALUE,
122: SVGOMAnimatedLength.HORIZONTAL_LENGTH, false);
123: y = createLiveAnimatedLength(null, SVG_Y_ATTRIBUTE,
124: SVG_RECT_Y_DEFAULT_VALUE,
125: SVGOMAnimatedLength.VERTICAL_LENGTH, false);
126: width = createLiveAnimatedLength(null, SVG_WIDTH_ATTRIBUTE,
127: null, SVGOMAnimatedLength.HORIZONTAL_LENGTH, true);
128: height = createLiveAnimatedLength(null, SVG_HEIGHT_ATTRIBUTE,
129: null, SVGOMAnimatedLength.VERTICAL_LENGTH, true);
130: rx = new AbstractSVGAnimatedLength(this , null,
131: SVG_RX_ATTRIBUTE,
132: SVGOMAnimatedLength.HORIZONTAL_LENGTH, true) {
133: protected String getDefaultValue() {
134: Attr attr = getAttributeNodeNS(null, SVG_RY_ATTRIBUTE);
135: if (attr == null) {
136: return "0";
137: }
138: return attr.getValue();
139: }
140:
141: protected void attrChanged() {
142: super .attrChanged();
143: AbstractSVGAnimatedLength ry = (AbstractSVGAnimatedLength) getRy();
144: if (isSpecified() && !ry.isSpecified()) {
145: ry.attrChanged();
146: }
147: }
148: };
149: ry = new AbstractSVGAnimatedLength(this , null,
150: SVG_RY_ATTRIBUTE, SVGOMAnimatedLength.VERTICAL_LENGTH,
151: true) {
152: protected String getDefaultValue() {
153: Attr attr = getAttributeNodeNS(null, SVG_RX_ATTRIBUTE);
154: if (attr == null) {
155: return "0";
156: }
157: return attr.getValue();
158: }
159:
160: protected void attrChanged() {
161: super .attrChanged();
162: AbstractSVGAnimatedLength rx = (AbstractSVGAnimatedLength) getRx();
163: if (isSpecified() && !rx.isSpecified()) {
164: rx.attrChanged();
165: }
166: }
167: };
168:
169: liveAttributeValues.put(null, SVG_RX_ATTRIBUTE, rx);
170: liveAttributeValues.put(null, SVG_RY_ATTRIBUTE, ry);
171: AnimatedAttributeListener l = ((SVGOMDocument) ownerDocument)
172: .getAnimatedAttributeListener();
173: rx.addAnimatedAttributeListener(l);
174: ry.addAnimatedAttributeListener(l);
175: }
176:
177: /**
178: * <b>DOM</b>: Implements {@link Node#getLocalName()}.
179: */
180: public String getLocalName() {
181: return SVG_RECT_TAG;
182: }
183:
184: /**
185: * <b>DOM</b>: Implements {@link SVGRectElement#getX()}.
186: */
187: public SVGAnimatedLength getX() {
188: return x;
189: }
190:
191: /**
192: * <b>DOM</b>: Implements {@link SVGRectElement#getY()}.
193: */
194: public SVGAnimatedLength getY() {
195: return y;
196: }
197:
198: /**
199: * <b>DOM</b>: Implements {@link SVGRectElement#getWidth()}.
200: */
201: public SVGAnimatedLength getWidth() {
202: return width;
203: }
204:
205: /**
206: * <b>DOM</b>: Implements {@link SVGRectElement#getHeight()}.
207: */
208: public SVGAnimatedLength getHeight() {
209: return height;
210: }
211:
212: /**
213: * <b>DOM</b>: Implements {@link SVGRectElement#getRx()}.
214: */
215: public SVGAnimatedLength getRx() {
216: return rx;
217: }
218:
219: /**
220: * <b>DOM</b>: Implements {@link SVGRectElement#getRy()}.
221: */
222: public SVGAnimatedLength getRy() {
223: return ry;
224: }
225:
226: /**
227: * Returns a new uninitialized instance of this object's class.
228: */
229: protected Node newNode() {
230: return new SVGOMRectElement();
231: }
232:
233: /**
234: * Returns the table of TraitInformation objects for this element.
235: */
236: protected DoublyIndexedTable getTraitInformationTable() {
237: return xmlTraitInformation;
238: }
239:
240: // AnimationTarget ///////////////////////////////////////////////////////
241:
242: /**
243: * Updates an attribute value in this target.
244: */
245: public void updateAttributeValue(String ns, String ln,
246: AnimatableValue val) {
247: if (ns == null) {
248: if (ln.equals(SVG_RX_ATTRIBUTE)) {
249: super .updateAttributeValue(ns, ln, val);
250: AbstractSVGAnimatedLength ry = (AbstractSVGAnimatedLength) getRy();
251: if (!ry.isSpecified()) {
252: super .updateAttributeValue(ns, SVG_RY_ATTRIBUTE,
253: val);
254: }
255: return;
256: } else if (ln.equals(SVG_RY_ATTRIBUTE)) {
257: super .updateAttributeValue(ns, ln, val);
258: AbstractSVGAnimatedLength rx = (AbstractSVGAnimatedLength) getRx();
259: if (!rx.isSpecified()) {
260: super.updateAttributeValue(ns, SVG_RX_ATTRIBUTE,
261: val);
262: }
263: return;
264: }
265: }
266: super.updateAttributeValue(ns, ln, val);
267: }
268: }
|