FileDocCategorySizeDatePackage
Animation.javaAPI DocphoneME MR2 API (J2ME)12116Wed May 02 18:00:36 BST 2007com.sun.perseus.model

Animation

public abstract class Animation extends TimedElementNode implements BaseValue, IDRef
The Animation class is the base class for all the SVG animation elements. Note that this is not the base class for media elements such as <audio> or <video>. The Animation class is the abstraction manipulated by TraitAnim to compose the chain of currently active animations in priority order.
version
$Id: Animation.java,v 1.5 2006/06/29 10:47:29 ln156897 Exp $

Fields Summary
public static final int
TYPE_GENERIC
Constant used by default to identify the type of animation values. Derived classes, such as AnimateTransform, may use other values.
boolean
hasNoEffect
Controls whether the animation has an effect on its target or not. There are situations where the animation may have no effect, for example when none of the values/to/from/by attributes are specified on an or .
TraitAnim
traitAnim
The associated TraitAnim
BaseValue
baseVal
This animation's base value, if it needs a base value. The base value is needed in some scenarios, for example in the case of 'to-animations'.
ElementNode
targetElement
This animation's target element.
String
traitName
This animation's target trait name.
String
traitNamespace
This animation's target trait namespace.
String
idRef
The identifier of the target animation element.
int
type
The type of animation.
Constructors Summary
public Animation(DocumentNode ownerDocument, String localName)
Builds a new animation element that belongs to the given document. This Animation will belong to the DocumentNode's time container.

param
ownerDocument the document this node belongs to.
param
localName the element's local name
throws
IllegalArgumentException if the input ownerDocument is null


                                                    
       
                        
        super(ownerDocument, localName);
        
        // If the document is _not_ loaded (i.e., we are at parse time),
        // add this animation to the document's animations vector for
        // validation at the end of the loading phase.
        if (!ownerDocument.loaded) {
            ownerDocument.animations.addElement(this);
        }
    
Methods Summary
public voidactivate()
Should be called when the animation is the target of an hyperlink.

        timedElementSupport.activate();
    
final java.lang.Object[]compute()
Computes the animation value for the current animation's simple time.

return
the current animation value.

        return f(timedElementSupport.lastSampleTime);
    
public voiddispatchEvent(ModelEvent evt)
Event dispatching override, to capture begin and end events. When a begin event occurs, the animation adds itself to the target element and trait's TraitAnim. When an end event occurs, the animation removes itself from the target element and trait's TraitAnim if the animation is not in the frozen state.

param
evt the event that occured

        super.dispatchEvent(evt);

        if (targetElement != null) {
            if (TimedElementSupport.BEGIN_EVENT_TYPE.equals(evt.getType())
                ||
                TimedElementSupport.SEEK_BEGIN_EVENT_TYPE.equals(
                        evt.getType())) {
                // Remove the animation, just in case the animation was 
                // previously frozen.
                if (traitAnim != null && !hasNoEffect) {
                    traitAnim.removeAnimation(this);
                    
                    // Now, add the animation.
                    traitAnim.addAnimation(this);
                }
            } else if (TimedElementSupport.LAST_DUR_END_EVENT_TYPE.equals(
                            evt.getType())) {
                // Only remove the animation if it is _not_ frozen.
                if ((timedElementSupport.fillBehavior 
                     != 
                     TimedElementSupport.FILL_BEHAVIOR_FREEZE)
                    &&
                    traitAnim != null && !hasNoEffect) {
                    traitAnim.removeAnimation(this);
                }
            } else if (TimedElementSupport.SEEK_END_EVENT_TYPE.equals(
                            evt.getType())
                       &&
                       traitAnim != null && !hasNoEffect) {
                // Remove the animation no matter what
                traitAnim.removeAnimation(this);
            }
        }
    
abstract java.lang.Object[]f(long t)
This is the animation function, the heart of the animation engine. There are multiple implementations of that function, and no good default one, so this method is abstract.

param
t the animation's simple time.

public java.lang.Object[]getBaseValue()
Returns the BaseValue as an array of objects.

return
the base value as an object array. The dimensions of the returned array depend on the trait.
see
com.sun.perseus.model.BaseValue

        return compute();
    
public java.lang.StringgetIdRef()

return
the Use element's idRef.

        return idRef;
    
public java.lang.StringgetTraitNSImpl(java.lang.String namespaceURI, java.lang.String name)
Set handles the xlink href attribute

param
namespaceURI the requested trait's namespace URI.
param
name the requested trait's local name (i.e., un-prefixed, as "href")
return
the requested trait's string value.
throws
DOMException with error code NOT_SUPPORTED_ERROR if the requested trait is not supported on this element or null.
throws
DOMException with error code TYPE_MISMATCH_ERR if requested trait's computed value cannot be converted to a String (SVG Tiny only).
throws
SecurityException if the application does not have the necessary privilege rights to access this (SVG) content.

        if (SVGConstants.XLINK_NAMESPACE_URI.equals(namespaceURI)
            &&
            SVGConstants.SVG_HREF_ATTRIBUTE.equals(name)) {
            if (idRef == null) {
                return "";
            } 
            return "#" + idRef;
        } else {
            return super.getTraitNSImpl(namespaceURI, name);
        }
    
final voidnodeHookedInDocumentTree()
When an Animation is hooked into the document tree, it needs to validate (only if the Document is loaded).

        super.nodeHookedInDocumentTree();

        if (ownerDocument.loaded) {
            validate();
        }
    
final voidnodeUnhookedFromDocumentTree()
When an Animation is removed from the document tree, it needs to remove itself from its associated traitAnim.

        super.nodeUnhookedFromDocumentTree();

        if (traitAnim != null) {
            traitAnim.removeAnimation(this);
        }
    
public voidresolveTo(ElementNode ref)
IDRef implementation.

param
ref the resolved reference (mapped from the id passed to the setIdRef method).

        targetElement = ref;
    
public voidsetIdRef(java.lang.String idRef)
Sets this Animation targetElement's idRef

param
idRef the identifier of the animation's target element. Should not be null

        this.idRef = idRef;
        ownerDocument.resolveIDRef(this, idRef);
    
public voidsetTraitNSImpl(java.lang.String namespaceURI, java.lang.String name, java.lang.String value)
Set supports the xlink:href trait.

param
namespaceURI the trait's namespace.
param
name the trait's local name (un-prefixed, e.g., "href");
param
value the new trait value (e.g., "http://www.sun.com/mypng.png")
throws
DOMException with error code NOT_SUPPORTED_ERROR if the requested trait is not supported on this element or null.
throws
DOMException with error code TYPE_MISMATCH_ERR if the requested trait's value cannot be specified as a String
throws
DOMException with error code INVALID_ACCESS_ERR if the input value is an invalid value for the given trait or null.
throws
DOMException with error code NO_MODIFICATION_ALLOWED_ERR: if attempt is made to change readonly trait.
throws
SecurityException if the application does not have the necessary privilege rights to access this (SVG) content.

        if (SVGConstants.XLINK_NAMESPACE_URI.equals(namespaceURI)
            &&
            SVGConstants.SVG_HREF_ATTRIBUTE.equals(name)) {
            if (value == null || !value.startsWith("#")) {
                throw illegalTraitValue(name, value);
            }
            setIdRef(value.substring(1));
        } else {
            super.setTraitNSImpl(namespaceURI, name, value);
        }
    
booleansupportsTraitNS(java.lang.String namespaceURI, java.lang.String traitName)
Supported NS traits: xlink:href

param
namespaceURI the trait's namespace.
param
traitName the name of the trait which the element may support.
return
true if this element supports the given trait in one of the trait accessor methods.

        if (SVGConstants.XLINK_NAMESPACE_URI.equals(namespaceURI)
            &&
            SVGConstants.SVG_HREF_ATTRIBUTE.equals(traitName)) {
            return true;
        } else {
            return super.supportsTraitNS(namespaceURI, traitName);
        }
    
abstract voidvalidate()
This method can be overridden by specific implementations to validate that the various values attributes (values, to, from, by or any subset of these) are valid i.e., compatible with the target element and target trait. There are two situations when this method is called: - parse time. When the document has been fully loaded, it validates all animations. - run time. When a new animation is created, it validates itself when it is hooked into the tree (i.e., when its parent node is set).