001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.perseus.model;
028:
029: import com.sun.perseus.util.SVGConstants;
030:
031: import org.w3c.dom.DOMException;
032:
033: import java.util.Vector;
034:
035: /**
036: * <code>Animate</code> represents an SVG Tiny
037: * <code><animateTransform></code> element.
038: *
039: * @version $Id: AnimateTransform.java,v 1.5 2006/06/29 10:47:29 ln156897 Exp $
040: */
041: public final class AnimateTransform extends Animate {
042:
043: /**
044: * translate | scale | rotate | skewX | skewY
045: * Animation on the transform's translate components
046: */
047: public static final int TYPE_TRANSLATE = 2;
048:
049: /**
050: * Animation on the transform's scale components
051: */
052: public static final int TYPE_SCALE = 3;
053:
054: /**
055: * Animation on the transform's rotation.
056: */
057: public static final int TYPE_ROTATE = 4;
058:
059: /**
060: * Animation on the transform's skew x component
061: */
062: public static final int TYPE_SKEW_X = 5;
063:
064: /**
065: * Animation on the transform's skew y component.
066: */
067: public static final int TYPE_SKEW_Y = 6;
068:
069: /**
070: * Builds a new Animate element that belongs to the given
071: * document. This <code>Animate</code> will belong
072: * to the <code>DocumentNode</code>'s time container.
073: *
074: * @param ownerDocument the document this node belongs to.
075: * @throws IllegalArgumentException if the input ownerDocument is null
076: */
077: public AnimateTransform(final DocumentNode ownerDocument) {
078: super (ownerDocument, SVGConstants.SVG_ANIMATE_TRANSFORM_TAG);
079: type = TYPE_TRANSLATE;
080: }
081:
082: /**
083: * Used by <code>DocumentNode</code> to create a new instance from
084: * a prototype <code>TimedElementNode</code>.
085: *
086: * @param doc the <code>DocumentNode</code> for which a new node is
087: * should be created.
088: * @return a new <code>TimedElementNode</code> for the requested document.
089: */
090: public ElementNode newInstance(final DocumentNode doc) {
091: return new AnimateTransform(doc);
092: }
093:
094: /**
095: * Supported traits: to, attributeName
096: *
097: * @param traitName the name of the trait which the element may support.
098: * @return true if this element supports the given trait in one of the
099: * trait accessor methods.
100: */
101: boolean supportsTrait(final String traitName) {
102: if (SVGConstants.SVG_TYPE_ATTRIBUTE == traitName) {
103: return true;
104: } else {
105: return super .supportsTrait(traitName);
106: }
107: }
108:
109: /**
110: * AnimateTransform supports the type trait.
111: *
112: * Returns the trait value as String. In SVG Tiny only certain traits can be
113: * obtained as a String value. Syntax of the returned String matches the
114: * syntax of the corresponding attribute. This element is exactly equivalent
115: * to {@link org.w3c.dom.svg.SVGElement#getTraitNS getTraitNS} with
116: * namespaceURI set to null.
117: *
118: * The method is meant to be overridden by derived classes. The
119: * implementation pattern is that derived classes will override the method
120: * and call their super class' implementation. If the ElementNode
121: * implementation is called, it means that the trait is either not supported
122: * or that it cannot be seen as a String.
123: *
124: * @param name the requested trait name.
125: * @return the trait value.
126: *
127: * @throws DOMException with error code NOT_SUPPORTED_ERROR if the requested
128: * trait is not supported on this element or null.
129: * @throws DOMException with error code TYPE_MISMATCH_ERR if requested
130: * trait's computed value cannot be converted to a String (SVG Tiny only).
131: */
132: public String getTraitImpl(final String name) throws DOMException {
133: if (SVGConstants.SVG_TYPE_ATTRIBUTE == name) {
134: switch (type) {
135: case TYPE_TRANSLATE:
136: return SVGConstants.SVG_TRANSLATE_VALUE;
137: case TYPE_SCALE:
138: return SVGConstants.SVG_SCALE_VALUE;
139: case TYPE_ROTATE:
140: return SVGConstants.SVG_ROTATE_VALUE;
141: case TYPE_SKEW_X:
142: return SVGConstants.SVG_SKEW_X;
143: case TYPE_SKEW_Y:
144: default:
145: return SVGConstants.SVG_SKEW_Y;
146: }
147: } else {
148: return super .getTraitImpl(name);
149: }
150: }
151:
152: /**
153: * AnimateTransform supports the type trait.
154: *
155: * @param name the trait's name.
156: * @param value the trait's value.
157: *
158: * @throws DOMException with error code NOT_SUPPORTED_ERR if the requested
159: * trait is not supported on this element or null.
160: * @throws DOMException with error code TYPE_MISMATCH_ERR if the requested
161: * trait's value cannot be specified as a String
162: * @throws DOMException with error code INVALID_ACCESS_ERR if the input
163: * value is an invalid value for the given trait or null.
164: * @throws DOMException with error code NO_MODIFICATION_ALLOWED_ERR: if
165: * attempt is made to change readonly trait.
166: */
167: public void setTraitImpl(final String name, final String value)
168: throws DOMException {
169: if (SVGConstants.SVG_TYPE_ATTRIBUTE == name) {
170: checkWriteLoading(name);
171: if (SVGConstants.SVG_TRANSLATE_VALUE.equals(value)) {
172: type = TYPE_TRANSLATE;
173: } else if (SVGConstants.SVG_SCALE_VALUE.equals(value)) {
174: type = TYPE_SCALE;
175: } else if (SVGConstants.SVG_ROTATE_VALUE.equals(value)) {
176: type = TYPE_ROTATE;
177: } else if (SVGConstants.SVG_SKEW_X.equals(value)) {
178: type = TYPE_SKEW_X;
179: } else if (SVGConstants.SVG_SKEW_Y.equals(value)) {
180: type = TYPE_SKEW_Y;
181: } else {
182: throw illegalTraitValue(name, value);
183: }
184: } else {
185: super.setTraitImpl(name, value);
186: }
187: }
188:
189: }
|