TraitAnimpublic abstract class TraitAnim extends Object implements BaseValueThe TraitAnim class is the link between animation targets
(i.e., traits on elements) and animation elements.
When an animation becomes active on a target (i.e., on a trait or pseudo
trait for an element), it invokes getAnimTrait(traitName) on the
corresponding element to get the trait's TraitAnim. One is created if the
trait is not currently animated. Then, the animation adds itself to the
TraitAnim through a call to addAnimation(). As an animation adds itself, it
becomes the TraitAnim's rootAnim. If there was no animation, the new
animation's baseVal becomes the TraitAnim itself. If there was already an
animation, the new Animation's baseVal becomes the previous rootAnim.
When an animation becomes inactive, it removes itself from the TraitAnim
by calling the removeAnimation method. When the last active animation removes
itself from the TraitAnim, the TraitAnim removes itself from the
ElementNode's TraitAnim list and it restores the trait's original base value
(stored as baseValue).
This achieves the sandwich model behavior described in the SMIL Animation
specification (section 3.5). In particular, because the tree is sampled in
document order in Perseus, the animation that appears first in document order
will have lower priority (i.e., it will be added first to the TraitAnim). If
an animation is a time dependent of another one, then it will become active
after its time sync and will have higher priority than its time sync. |
Fields Summary |
---|
String | traitTypeThe TraitAnim underlying type. One of ElementNode.TRAIT_TYPE
constants. | Animation | rootAnimThis animation's root. | ElementNode | targetElementThe target element. | String | traitNameThe target trait name. | String | traitNamespaceThe target trait namespace. | String | specifiedTraitValueThe trait's specified value, as a String. | boolean | activeTrue when the TraitAnim has at least one active animation. |
Constructors Summary |
---|
TraitAnim(ElementNode targetElement, String traitNamespace, String traitName, String traitType)Constructs a new TraitAnim for a given ElementNode trait
in the given namespace.
if (targetElement == null
||
traitName == null
||
traitNamespace == null
||
traitType == null) {
throw new NullPointerException();
}
this.targetElement = targetElement;
this.traitNamespace = traitNamespace;
this.traitName = traitName;
this.traitType = traitType;
|
Methods Summary |
---|
void | addAnimation(Animation newAnim)Adds a new animation to this TraitAnim. The new animation
becomes the highest priority animation. If this is the
first animation added to the TraitAnim, the new animation's
base value becomes the TraitAnim itself and the TraitAnim
registers with the DocumentNode. If there is already
one or more animation in the TraitAnim, the baseValue for the
new animation becomes the previous animation root. In all
cases, the new animation becomes the rootAnim.
// Reject null values
if (newAnim == null) {
throw new NullPointerException();
}
if (rootAnim == null) {
// This is the first animation.
// Set the animation as the root animation and set its
// baseValue.
rootAnim = newAnim;
newAnim.baseVal = this;
targetElement.ownerDocument.activeTraitAnims.addElement(this);
// We need to recompute the specifiedTraitAnim at this point
// Otherwise, the specifiedTrait value may be off (i.e., different
// from what it was set to originally, when the TraitAnim was
// created.
this.specifiedTraitValue = targetElement.getSpecifiedTraitNSImpl(
traitNamespace, traitName);
} else {
// This is a new animation in the sandwich.
// The new animation becomes the highest priority animation and
// its baseValue is the previous rootAnim.
newAnim.baseVal = rootAnim;
rootAnim = newAnim;
}
active = true;
| abstract void | apply()Applies the animation effect. The implementation makes sure it
implements the sandwich model by 'pulling' values from the
root animation (i.e., the animation with the highest priority).
| public java.lang.String | getSpecifiedTraitNS()
if (specifiedTraitValue == null) {
specifiedTraitValue = targetElement.getSpecifiedTraitNSImpl(
traitNamespace, traitName);
}
return specifiedTraitValue;
| final java.lang.String | getTrait(java.lang.String traitType)
if (ElementNode.TRAIT_TYPE_STRING.equals(traitType)
||
this.traitType.equals(traitType)) {
return getTraitImpl();
} else {
throw targetElement.unsupportedTraitTypeNS(traitName,
traitNamespace,
traitType);
}
| protected abstract java.lang.String | getTraitImpl()
| abstract java.lang.Object[] | multiply(java.lang.Object[] value, int iter)Used to multiply an animated trait value by a number of iterations.
| void | removeAnimation(Animation removedAnim)Removes the input animation from this TraitAnim. If the removed
animation's baseValue is the TraitAnim itself, it means this is
the last active animation on the trait and the TraitAnim will
mark itself as inactive. If this is not the last animation,
then this animation's baseValue becomes the rootAnim.
If removedAnim is not part of this TraitAnim, this method
does nothing.
// Reject null values.
if (removedAnim == null) {
throw new NullPointerException();
}
if (removedAnim == rootAnim) {
// Removing the root animatoin
if (removedAnim.baseVal == this) {
// This is the last animation in the TraitAnim.
// Unregister from the Document.
targetElement.ownerDocument.activeTraitAnims.removeElement(
this);
rootAnim = null;
// Mark the animation as inactive.
active = false;
restore();
} else {
rootAnim = (Animation) removedAnim.baseVal;
}
} else {
if (rootAnim != null) {
// Removing an animation other than the root.
// Find the preceding animation.
Animation prevAnim = null;
Animation curAnim = rootAnim;
while (curAnim.baseVal != this) {
if (curAnim.baseVal == removedAnim) {
prevAnim = curAnim;
break;
}
curAnim = (Animation) curAnim.baseVal;
}
// If removedAnimat was indeed part of the sandwich.
if (prevAnim != null) {
prevAnim.baseVal = removedAnim.baseVal;
}
}
}
| final void | restore()Restores the base value. This is invoked when there are not more
animations and the original base value needs to be restored.
// Now, restore the specified trait value
if (traitNamespace == ElementNode.NULL_NS) {
targetElement.setTraitImpl(traitName, specifiedTraitValue);
} else {
targetElement.setTraitNSImpl(traitNamespace, traitName,
specifiedTraitValue);
}
| final void | setTrait(java.lang.String value, java.lang.String traitType)Sets the trait's base value, as a String.
if (ElementNode.TRAIT_TYPE_STRING.equals(traitType)
||
this.traitType.equals(traitType)) {
setTraitImpl(value);
} else {
throw targetElement.unsupportedTraitTypeNS(traitName,
traitNamespace,
traitType);
}
| abstract void | setTraitImpl(java.lang.String value)Sets the trait's base value, as a String.
| abstract java.lang.Object[] | sum(java.lang.Object[] valueA, java.lang.Object[] valueB)Used to sum two animated trait values.
| boolean | supportsInterpolation()
return false;
| abstract RefValues | toRefValues(Animation anim, java.lang.String[] values, java.lang.String reqTraitNamespace, java.lang.String reqTraitName)Converts the input values set to a RefValues object.
|
|