/** * Sets the current document time. */ public float setCurrentTime(float t) { boolean p = pauseTime != 0; unpause(); Calendar begin = timedDocumentRoot.getDocumentBeginTime(); float now = timedDocumentRoot.convertEpochTime(System.currentTimeMillis()); begin.add(Calendar.MILLISECOND, (int) ((now - t) * 1000)); if (p) { pause(); } return tick(t, true); }
/** * Creates a new AnimationEngine for the given document. */ public AnimationEngine(Document doc) { this.document = doc; timedDocumentRoot = createDocumentRoot(); }
/** * Disposes this animation engine. */ public void dispose() { synchronized (this) { pause(); super.dispose(); } }
/** * Moves the given animation to the top of the sandwich. */ protected void moveToTop(AbstractAnimation anim) { AnimationInfo animInfo = getAnimationInfo(anim); Sandwich sandwich = getSandwich(animInfo.target, animInfo.type, animInfo.attributeNamespaceURI, animInfo.attributeLocalName); sandwich.shouldUpdate = true; if (anim.higherAnimation == null) { return; } if (anim.lowerAnimation == null) { sandwich.lowestAnimation = anim.higherAnimation; } else { anim.lowerAnimation.higherAnimation = anim.higherAnimation; } anim.higherAnimation.lowerAnimation = anim.lowerAnimation; if (sandwich.animation != null) { sandwich.animation.higherAnimation = anim; } anim.lowerAnimation = sandwich.animation; anim.higherAnimation = null; sandwich.animation = anim; }
/** * Invoked to indicate an animation became active at the specified time. * * @param anim the animation * @param begin the time the element became active, in document simple time */ public void toActive(AbstractAnimation anim, float begin) { moveToTop(anim); anim.isActive = true; anim.beginTime = begin; anim.isFrozen = false; // Move the animation down, in case it began at the same time as another // animation in the sandwich and it's earlier in document order. pushDown(anim); anim.markDirty(); }
/** * Removes an animation from the document. */ public void removeAnimation(AbstractAnimation anim) { // org.apache.batik.anim.timing.Trace.enter(this, "removeAnimation", new Object[] { anim } ); try { timedDocumentRoot.removeChild(anim.getTimedElement()); AbstractAnimation nextHigher = anim.higherAnimation; if (nextHigher != null) { nextHigher.markDirty(); } moveToBottom(anim); if (anim.higherAnimation != null) { anim.higherAnimation.lowerAnimation = null; } AnimationInfo animInfo = getAnimationInfo(anim); Sandwich sandwich = getSandwich(animInfo.target, animInfo.type, animInfo.attributeNamespaceURI, animInfo.attributeLocalName); if (sandwich.animation == anim) { sandwich.animation = null; sandwich.lowestAnimation = null; sandwich.shouldUpdate = true; } // } finally { org.apache.batik.anim.timing.Trace.exit(); } }
/** * Pauses the animations. */ public void unpause() { super.unpause(); UpdateManager um = ctx.getUpdateManager(); if (um != null) { um.getUpdateRunnableQueue().setIdleRunnable(animationTickRunnable); } }
/** * Pauses the animations. */ public void pause() { super.pause(); UpdateManager um = ctx.getUpdateManager(); if (um != null) { um.getUpdateRunnableQueue().setIdleRunnable(null); } }
/** * Invoked to indicate that this timed element has had its fill removed. */ public void removeFill(AbstractAnimation anim) { anim.isActive = false; anim.isFrozen = false; anim.value = null; anim.markDirty(); moveToBottom(anim); }
/** * Invoked to indicate that base value of the specified attribute * or property has changed. */ public void baseValueChanged(AnimationTarget t, String ns, String ln, boolean isCSS) { short type = isCSS ? ANIM_TYPE_CSS : ANIM_TYPE_XML; Sandwich sandwich = getSandwich(t, type, ns, ln); sandwich.shouldUpdate = true; AbstractAnimation anim = sandwich.animation; while (anim.lowerAnimation != null) { anim = anim.lowerAnimation; } anim.markDirty(); } }
/** * Returns the Sandwich for the given animation type/attribute. */ protected Sandwich getSandwich(AnimationTarget target, short type, String ns, String an) { TargetInfo info = getTargetInfo(target); Sandwich sandwich; if (type == ANIM_TYPE_XML) { sandwich = (Sandwich) info.xmlAnimations.get(ns, an); if (sandwich == null) { sandwich = new Sandwich(); info.xmlAnimations.put(ns, an, sandwich); } } else if (type == ANIM_TYPE_CSS) { sandwich = (Sandwich) info.cssAnimations.get(an); if (sandwich == null) { sandwich = new Sandwich(); info.cssAnimations.put(an, sandwich); } } else { sandwich = (Sandwich) info.otherAnimations.get(an); if (sandwich == null) { sandwich = new Sandwich(); info.otherAnimations.put(an, sandwich); } } return sandwich; }
/** * Moves the given animation to the top of the sandwich. */ protected void moveToTop(AbstractAnimation anim) { AnimationInfo animInfo = getAnimationInfo(anim); Sandwich sandwich = getSandwich(animInfo.target, animInfo.type, animInfo.attributeNamespaceURI, animInfo.attributeLocalName); sandwich.shouldUpdate = true; if (anim.higherAnimation == null) { return; } if (anim.lowerAnimation == null) { sandwich.lowestAnimation = anim.higherAnimation; } else { anim.lowerAnimation.higherAnimation = anim.higherAnimation; } anim.higherAnimation.lowerAnimation = anim.lowerAnimation; if (sandwich.animation != null) { sandwich.animation.higherAnimation = anim; } anim.lowerAnimation = sandwich.animation; anim.higherAnimation = null; sandwich.animation = anim; }
/** * Removes an animation from the document. */ public void removeAnimation(AbstractAnimation anim) { // org.apache.batik.anim.timing.Trace.enter(this, "removeAnimation", new Object[] { anim } ); try { timedDocumentRoot.removeChild(anim.getTimedElement()); AbstractAnimation nextHigher = anim.higherAnimation; if (nextHigher != null) { nextHigher.markDirty(); } moveToBottom(anim); if (anim.higherAnimation != null) { anim.higherAnimation.lowerAnimation = null; } AnimationInfo animInfo = getAnimationInfo(anim); Sandwich sandwich = getSandwich(animInfo.target, animInfo.type, animInfo.attributeNamespaceURI, animInfo.attributeLocalName); if (sandwich.animation == anim) { sandwich.animation = null; sandwich.lowestAnimation = null; sandwich.shouldUpdate = true; } // } finally { org.apache.batik.anim.timing.Trace.exit(); } }
/** * Invoked to indicate an animation became active at the specified time. * * @param anim the animation * @param begin the time the element became active, in document simple time */ public void toActive(AbstractAnimation anim, float begin) { moveToTop(anim); anim.isActive = true; anim.beginTime = begin; anim.isFrozen = false; // Move the animation down, in case it began at the same time as another // animation in the sandwich and it's earlier in document order. pushDown(anim); anim.markDirty(); }
/** * Pauses the animations. */ public void unpause() { super.unpause(); UpdateManager um = ctx.getUpdateManager(); if (um != null) { um.getUpdateRunnableQueue().setIdleRunnable(animationTickRunnable); } }
/** * Pauses the animations. */ public void pause() { super.pause(); UpdateManager um = ctx.getUpdateManager(); if (um != null) { um.getUpdateRunnableQueue().setIdleRunnable(null); } }
/** * Invoked to indicate that this timed element has had its fill removed. */ public void removeFill(AbstractAnimation anim) { anim.isActive = false; anim.isFrozen = false; anim.value = null; anim.markDirty(); moveToBottom(anim); }
/** * Invoked to indicate that base value of the specified attribute * or property has changed. */ public void baseValueChanged(AnimationTarget t, String ns, String ln, boolean isCSS) { short type = isCSS ? ANIM_TYPE_CSS : ANIM_TYPE_XML; Sandwich sandwich = getSandwich(t, type, ns, ln); sandwich.shouldUpdate = true; AbstractAnimation anim = sandwich.animation; while (anim.lowerAnimation != null) { anim = anim.lowerAnimation; } anim.markDirty(); } }
/** * Returns the Sandwich for the given animation type/attribute. */ protected Sandwich getSandwich(AnimationTarget target, short type, String ns, String an) { TargetInfo info = getTargetInfo(target); Sandwich sandwich; if (type == ANIM_TYPE_XML) { sandwich = (Sandwich) info.xmlAnimations.get(ns, an); if (sandwich == null) { sandwich = new Sandwich(); info.xmlAnimations.put(ns, an, sandwich); } } else if (type == ANIM_TYPE_CSS) { sandwich = (Sandwich) info.cssAnimations.get(an); if (sandwich == null) { sandwich = new Sandwich(); info.cssAnimations.put(an, sandwich); } } else { sandwich = (Sandwich) info.otherAnimations.get(an); if (sandwich == null) { sandwich = new Sandwich(); info.otherAnimations.put(an, sandwich); } } return sandwich; }
/** * Sets the current document time. */ public float setCurrentTime(float t) { boolean p = pauseTime != 0; unpause(); Calendar begin = timedDocumentRoot.getDocumentBeginTime(); float now = timedDocumentRoot.convertEpochTime(System.currentTimeMillis()); begin.add(Calendar.MILLISECOND, (int) ((now - t) * 1000)); if (p) { pause(); } return tick(t, true); }