Animationpublic abstract class Animation extends TimedElementNode implements BaseValue, IDRefThe 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. |
Fields Summary |
---|
public static final int | TYPE_GENERICConstant used by default to identify the type of animation values.
Derived classes, such as AnimateTransform, may use other values. | boolean | hasNoEffectControls 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 | traitAnimThe associated TraitAnim | BaseValue | baseValThis 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 | targetElementThis animation's target element. | String | traitNameThis animation's target trait name. | String | traitNamespaceThis animation's target trait namespace. | String | idRefThe identifier of the target animation element. | int | typeThe 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.
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 void | activate()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 f(timedElementSupport.lastSampleTime);
| public void | dispatchEvent(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.
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.
| public java.lang.Object[] | getBaseValue()Returns the BaseValue as an array of objects.
return compute();
| public java.lang.String | getIdRef()
return idRef;
| public java.lang.String | getTraitNSImpl(java.lang.String namespaceURI, java.lang.String name)Set handles the xlink href attribute
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 void | nodeHookedInDocumentTree()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 void | nodeUnhookedFromDocumentTree()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 void | resolveTo(ElementNode ref)IDRef implementation.
targetElement = ref;
| public void | setIdRef(java.lang.String idRef)Sets this Animation targetElement's idRef
this.idRef = idRef;
ownerDocument.resolveIDRef(this, idRef);
| public void | setTraitNSImpl(java.lang.String namespaceURI, java.lang.String name, java.lang.String value)Set supports the xlink:href trait.
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);
}
| boolean | supportsTraitNS(java.lang.String namespaceURI, java.lang.String traitName)Supported NS traits: xlink:href
if (SVGConstants.XLINK_NAMESPACE_URI.equals(namespaceURI)
&&
SVGConstants.SVG_HREF_ATTRIBUTE.equals(traitName)) {
return true;
} else {
return super.supportsTraitNS(namespaceURI, traitName);
}
| abstract void | validate()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).
|
|