org.apache.batik.anim.timing

Class TimedElement

public abstract class TimedElement extends Object implements SMILConstants

An abstract base class for elements that can have timing applied to them. The concrete versions of this class do not necessarily have to be the same as the DOM class, and in fact, this will mostly be impossible unless creating new DOM classes that inherit from these elements.
Field Summary
protected LinkedListbeginDependents
List of TimingSpecifiers on other elements that depend on this element's begin times.
protected ListbeginInstanceTimes
List of begin InstanceTimes.
protected TimingSpecifier[]beginTimes
Timing specifiers for the begin times of this element.
protected IntervalcurrentInterval
The current Interval.
protected intcurrentRepeatIteration
The current repeat iteration.
protected booleandurMedia
Whether the simple duration of this element should be equal to the implicit duration.
protected LinkedListendDependents
List of TimingSpecifiers on other elements that depend on this element's end times.
protected ListendInstanceTimes
List of end InstanceTimes.
protected TimingSpecifier[]endTimes
Timing specifiers for the end times of this element.
protected intfillMode
The fill mode for this element.
static intFILL_FREEZE
static intFILL_REMOVE
protected MaphandledEvents
Map of Event objects to HashSets of TimingSpecifiers that caught them.
protected booleanhasParsed
Whether this timed element has parsed its timing attributes yet.
protected booleanhasPropagated
Whether an instance time update message has already been propagated to this timed element.
protected booleanisActive
Whether the element is currently active.
protected booleanisFrozen
Whether the element is currently frozen.
protected booleanisSampling
Whether this timed element is currently being sampled.
static floatINDEFINITE
protected floatlastIntervalEnd
The end time of the previous interval, initially Float#NEGATIVE_INFINITY.
protected floatlastRepeatTime
The local active time of the last repeat.
protected floatlastSampleTime
The current time of this element in local active time.
protected static LocalizableSupportlocalizableSupport
The localizable support for the error messages.
protected floatmax
The maximum active duration of this element.
protected booleanmaxMedia
Whether the max value was specified as 'media'.
protected floatmin
The minimum active duration of this element.
protected booleanminMedia
Whether the min value was specified as 'media'.
protected TimeContainerparent
The parent time container.
protected IntervalpreviousInterval
The previous interval.
protected floatrepeatCount
The number of repeats.
protected floatrepeatDur
The duration of repeats.
protected floatrepeatDuration
The computed repeat duration of the element.
protected intrestartMode
The restart mode for this element.
protected TimedDocumentRootroot
The root time container.
protected static StringRESOURCES
The error messages bundle class name.
static intRESTART_ALWAYS
static intRESTART_NEVER
static intRESTART_WHEN_NOT_ACTIVE
protected booleanshouldUpdateCurrentInterval
Whether the list of instance times should be checked to update the current interval.
protected floatsimpleDur
Duration of this element, if durMedia = false.
static floatUNRESOLVED
Constructor Summary
TimedElement()
Creates a new TimedElement.
Method Summary
protected voidaddDependent(TimingSpecifier dependent, boolean forBegin)
Adds a dependent TimingSpecifier for this element.
protected floataddInstanceTime(InstanceTime time, boolean isBegin)
Called by a TimingSpecifier of this element when a new InstanceTime is created.
voidbeginElement()
Adds a time to the begin time instance list that will cause the element to begin immediately (if restart semantics allow it).
voidbeginElement(float offset)
Adds a time to the begin time instance list that will cause the element to begin at some offset to the current time (if restart semantics allow it).
booleancanBegin()
Returns whether this element can be begun or restarted currently.
booleancanEnd()
Returns whether this element can be ended currently.
protected IntervalcomputeInterval(boolean first, boolean fixedBegin, float beginAfter, boolean incl)
Computes an interval from the begin and end instance time lists.
AnimationExceptioncreateException(String code, Object[] params)
Creates and returns a new AnimationException.
voiddeinitialize()
Deinitializes this timed element.
voidendElement()
Adds a time to the end time instance list that will cause the element to end immediately (if restart semantics allow it).
voidendElement(float offset)
Adds a time to the end time instance list that will cause the element to end at some offset to the current time (if restart semantics allow it).
protected booleanendHasEventConditions()
Returns whether the end timing specifier list contains any eventbase, accesskey or repeat timing specifiers.
protected voidfireTimeEvent(String eventType, float time, int detail)
Fires a TimeEvent of the given type on this element.
protected abstract voidfireTimeEvent(String eventType, Calendar time, int detail)
Fires a TimeEvent of the given type on this element.
static StringformatMessage(String key, Object[] args)
Implements (String,Object[]).
floatgetActiveDur(float B, float end)
Returns the active duration time of this element.
floatgetActiveTime()
Returns the current active time of this element.
protected abstract EventTargetgetAnimationEventTarget()
Returns the target of this animation as an EventTarget.
floatgetCurrentBeginTime()
Returns the begin time of the current interval, in parent simple time, or Float.NaN if the element is not active.
abstract ElementgetElement()
Returns the DOM element that corresponds to this timed element, if such a DOM element exists.
protected abstract EventTargetgetEventTargetById(String id)
Returns the event target with the given ID.
floatgetHyperlinkBeginTime()
Returns the time that the document would seek to if this animation element were hyperlinked to, or NaN if there is no such begin time.
protected floatgetImplicitDur()
Returns the implicit duration of the element.
floatgetLastSampleTime()
Returns the last sample time of this element, in local active time.
static LocalegetLocale()
Implements getLocale.
TimedDocumentRootgetRoot()
Returns the root time container of this timed element.
protected abstract EventTargetgetRootEventTarget()
Returns the event target that should be listened to for access key events.
floatgetSimpleDur()
Returns the simple duration time of this element.
floatgetSimpleTime()
Returns the current simple time of this element.
protected abstract TimedElementgetTimedElementById(String id)
Returns the timed element with the given ID.
voidinitialize()
Initializes this timed element.
protected floatinstanceTimeChanged(InstanceTime time, boolean isBegin)
Called by a TimingSpecifier of this element when an InstanceTime has been updated.
abstract booleanisBefore(TimedElement other)
Returns whether this timed element comes before the given timed element in document order.
protected abstract booleanisConstantAnimation()
Returns whether this timed element is for a constant animation (i.e., a 'set' animation.
static booleanisUnresolved(float t)
Returns whether the given time value is equal to the UNRESOLVED value.
protected floatmaxTime(float t1, float t2)
Returns the maximum of two time values.
protected floatminTime(float t1, float t2)
Returns the minimum of two time values.
protected floatminusTime(float t1, float t2)
Subtracts one simple time from another.
protected floatmultiplyTime(float t, float n)
Multiplies one simple time by n.
protected floatnotifyNewInterval(Interval interval)
Notifies dependents of a new interval.
protected floatnotifyRemoveInterval(Interval interval)
Notifies dependents of a removed interval.
voidparseAttributes(String begin, String dur, String end, String min, String max, String repeatCount, String repeatDur, String fill, String restart)
Parses the animation attributes for this timed element.
protected voidparseBegin(String begin)
Parses a new 'begin' attribute.
protected floatparseClockValue(String s, boolean parseOffset)
Parses a clock value or offset and returns it as a float.
protected voidparseDur(String dur)
Parses a new 'dur' attribute.
protected voidparseEnd(String end)
Parses a new 'end' attribute.
protected voidparseFill(String fill)
Parses a new 'fill' attribute.
protected voidparseMax(String max)
Parses a new 'max' attribute.
protected voidparseMin(String min)
Parses a new 'min' attribute.
protected voidparseRepeatCount(String repeatCount)
Parses a new 'repeatCount' attribute.
protected voidparseRepeatDur(String repeatDur)
Parses a new 'repeatDur' attribute.
protected voidparseRestart(String restart)
Parses a new 'restart' attribute.
protected voidremoveDependent(TimingSpecifier dependent, boolean forBegin)
Removes a dependent TimingSpecifier for this element.
protected abstract voidremoveFill()
Invoked to indicate that this timed element has had its fill removed.
protected floatremoveInstanceTime(InstanceTime time, boolean isBegin)
Called by a TimingSpecifier of this element when an InstanceTime should be removed.
protected voidreset(boolean clearCurrentBegin)
Resets this element.
protected floatsampleAt(float parentSimpleTime, boolean hyperlinking)
Calculates the local simple time.
protected abstract voidsampledAt(float simpleTime, float simpleDur, int repeatIteration)
Invoked to indicate that this timed element has been sampled at the given time.
protected abstract voidsampledLastValue(int repeatIteration)
Invoked to indicate that this timed element has been sampled at the end of its active time, at an integer multiple of the simple duration.
protected floatselectNewInterval(float time, Interval interval)
Sets the current interval to the one specified.
static voidsetLocale(Locale l)
Implements setLocale.
protected abstract voidtoActive(float begin)
Invoked to indicate this timed element became active at the specified time.
protected abstract voidtoInactive(boolean stillActive, boolean isFrozen)
Invoked to indicate that this timed element became inactive.
static StringtoString(float time)
Returns a string representation of the given time value.

Field Detail

beginDependents

protected LinkedList beginDependents
List of TimingSpecifiers on other elements that depend on this element's begin times.

beginInstanceTimes

protected List beginInstanceTimes
List of begin InstanceTimes.

beginTimes

protected TimingSpecifier[] beginTimes
Timing specifiers for the begin times of this element.

currentInterval

protected Interval currentInterval
The current Interval.

currentRepeatIteration

protected int currentRepeatIteration
The current repeat iteration.

durMedia

protected boolean durMedia
Whether the simple duration of this element should be equal to the implicit duration.

endDependents

protected LinkedList endDependents
List of TimingSpecifiers on other elements that depend on this element's end times.

endInstanceTimes

protected List endInstanceTimes
List of end InstanceTimes.

endTimes

protected TimingSpecifier[] endTimes
Timing specifiers for the end times of this element.

fillMode

protected int fillMode
The fill mode for this element. Uses the FILL_* constants defined in this class.

FILL_FREEZE

public static final int FILL_FREEZE

FILL_REMOVE

public static final int FILL_REMOVE

handledEvents

protected Map handledEvents
Map of Event objects to HashSets of TimingSpecifiers that caught them.

hasParsed

protected boolean hasParsed
Whether this timed element has parsed its timing attributes yet.

hasPropagated

protected boolean hasPropagated
Whether an instance time update message has already been propagated to this timed element.

isActive

protected boolean isActive
Whether the element is currently active.

isFrozen

protected boolean isFrozen
Whether the element is currently frozen.

isSampling

protected boolean isSampling
Whether this timed element is currently being sampled.

INDEFINITE

public static final float INDEFINITE

lastIntervalEnd

protected float lastIntervalEnd
The end time of the previous interval, initially Float#NEGATIVE_INFINITY.

lastRepeatTime

protected float lastRepeatTime
The local active time of the last repeat.

lastSampleTime

protected float lastSampleTime
The current time of this element in local active time.

localizableSupport

protected static LocalizableSupport localizableSupport
The localizable support for the error messages.

max

protected float max
The maximum active duration of this element. If maxMedia = true, it will be INDEFINITE.

maxMedia

protected boolean maxMedia
Whether the max value was specified as 'media'.

min

protected float min
The minimum active duration of this element. If minMedia = true, it will be 0f.

minMedia

protected boolean minMedia
Whether the min value was specified as 'media'.

parent

protected TimeContainer parent
The parent time container.

previousInterval

protected Interval previousInterval
The previous interval.

repeatCount

protected float repeatCount
The number of repeats. If unspecified, it will be UNRESOLVED.

repeatDur

protected float repeatDur
The duration of repeats. If unspecified, it will be UNRESOLVED.

repeatDuration

protected float repeatDuration
The computed repeat duration of the element.

restartMode

protected int restartMode
The restart mode for this element. Uses the RESTART_* constants defined in this class.

root

protected TimedDocumentRoot root
The root time container.

RESOURCES

protected static final String RESOURCES
The error messages bundle class name.

RESTART_ALWAYS

public static final int RESTART_ALWAYS

RESTART_NEVER

public static final int RESTART_NEVER

RESTART_WHEN_NOT_ACTIVE

public static final int RESTART_WHEN_NOT_ACTIVE

shouldUpdateCurrentInterval

protected boolean shouldUpdateCurrentInterval
Whether the list of instance times should be checked to update the current interval.

simpleDur

protected float simpleDur
Duration of this element, if durMedia = false. If unspecified, it will be UNRESOLVED.

UNRESOLVED

public static final float UNRESOLVED

Constructor Detail

TimedElement

public TimedElement()
Creates a new TimedElement.

Method Detail

addDependent

protected void addDependent(TimingSpecifier dependent, boolean forBegin)
Adds a dependent TimingSpecifier for this element.

addInstanceTime

protected float addInstanceTime(InstanceTime time, boolean isBegin)
Called by a TimingSpecifier of this element when a new InstanceTime is created. This will be in response to an event firing, a DOM method being called or a new Instance being created by a syncbase element.

beginElement

public void beginElement()
Adds a time to the begin time instance list that will cause the element to begin immediately (if restart semantics allow it).

beginElement

public void beginElement(float offset)
Adds a time to the begin time instance list that will cause the element to begin at some offset to the current time (if restart semantics allow it).

canBegin

public boolean canBegin()
Returns whether this element can be begun or restarted currently.

canEnd

public boolean canEnd()
Returns whether this element can be ended currently.

computeInterval

protected Interval computeInterval(boolean first, boolean fixedBegin, float beginAfter, boolean incl)
Computes an interval from the begin and end instance time lists.

Parameters: first indicates whether this is the first interval to compute fixedBegin if true, specifies that the value given for beginAfter is taken to be the actual begin time for the interval; only the end value is computed. beginAfter the earliest possible begin time for the computed interval. incl if true (and !fixedBegin), specifies that the new interval's begin time must be greater than beginAfter; otherwise, the begin time must be greater than or equal to beginAfter.

createException

public AnimationException createException(String code, Object[] params)
Creates and returns a new AnimationException.

deinitialize

public void deinitialize()
Deinitializes this timed element.

endElement

public void endElement()
Adds a time to the end time instance list that will cause the element to end immediately (if restart semantics allow it).

endElement

public void endElement(float offset)
Adds a time to the end time instance list that will cause the element to end at some offset to the current time (if restart semantics allow it).

endHasEventConditions

protected boolean endHasEventConditions()
Returns whether the end timing specifier list contains any eventbase, accesskey or repeat timing specifiers.

fireTimeEvent

protected void fireTimeEvent(String eventType, float time, int detail)
Fires a TimeEvent of the given type on this element.

Parameters: eventType the type of TimeEvent ("beginEvent", "endEvent" or "repeatEvent"). time the timestamp of the event object detail the repeat iteration, if this event is a repeat event

fireTimeEvent

protected abstract void fireTimeEvent(String eventType, Calendar time, int detail)
Fires a TimeEvent of the given type on this element.

Parameters: eventType the type of TimeEvent ("beginEvent", "endEvent" or "repeatEvent"). time the timestamp of the event object

formatMessage

public static String formatMessage(String key, Object[] args)
Implements (String,Object[]).

getActiveDur

public float getActiveDur(float B, float end)
Returns the active duration time of this element.

getActiveTime

public float getActiveTime()
Returns the current active time of this element.

getAnimationEventTarget

protected abstract EventTarget getAnimationEventTarget()
Returns the target of this animation as an EventTarget. Used for eventbase timing specifiers where the element ID is omitted.

getCurrentBeginTime

public float getCurrentBeginTime()
Returns the begin time of the current interval, in parent simple time, or Float.NaN if the element is not active.

getElement

public abstract Element getElement()
Returns the DOM element that corresponds to this timed element, if such a DOM element exists.

getEventTargetById

protected abstract EventTarget getEventTargetById(String id)
Returns the event target with the given ID.

getHyperlinkBeginTime

public float getHyperlinkBeginTime()
Returns the time that the document would seek to if this animation element were hyperlinked to, or NaN if there is no such begin time.

getImplicitDur

protected float getImplicitDur()
Returns the implicit duration of the element. Currently, nested time containers are not supported by SVG so this just returns UNRESOLVED by default. This should be overriden in derived classes that play media, since they will have an implicit duration.

getLastSampleTime

public float getLastSampleTime()
Returns the last sample time of this element, in local active time.

getLocale

public static Locale getLocale()
Implements getLocale.

getRoot

public TimedDocumentRoot getRoot()
Returns the root time container of this timed element.

getRootEventTarget

protected abstract EventTarget getRootEventTarget()
Returns the event target that should be listened to for access key events.

getSimpleDur

public float getSimpleDur()
Returns the simple duration time of this element.

getSimpleTime

public float getSimpleTime()
Returns the current simple time of this element.

getTimedElementById

protected abstract TimedElement getTimedElementById(String id)
Returns the timed element with the given ID.

initialize

public void initialize()
Initializes this timed element.

instanceTimeChanged

protected float instanceTimeChanged(InstanceTime time, boolean isBegin)
Called by a TimingSpecifier of this element when an InstanceTime has been updated. This will be in response to a dependent syncbase change.

isBefore

public abstract boolean isBefore(TimedElement other)
Returns whether this timed element comes before the given timed element in document order.

isConstantAnimation

protected abstract boolean isConstantAnimation()
Returns whether this timed element is for a constant animation (i.e., a 'set' animation.

isUnresolved

public static boolean isUnresolved(float t)
Returns whether the given time value is equal to the UNRESOLVED value.

maxTime

protected float maxTime(float t1, float t2)
Returns the maximum of two time values.

minTime

protected float minTime(float t1, float t2)
Returns the minimum of two time values.

minusTime

protected float minusTime(float t1, float t2)
Subtracts one simple time from another.

multiplyTime

protected float multiplyTime(float t, float n)
Multiplies one simple time by n.

notifyNewInterval

protected float notifyNewInterval(Interval interval)
Notifies dependents of a new interval.

notifyRemoveInterval

protected float notifyRemoveInterval(Interval interval)
Notifies dependents of a removed interval.

parseAttributes

public void parseAttributes(String begin, String dur, String end, String min, String max, String repeatCount, String repeatDur, String fill, String restart)
Parses the animation attributes for this timed element.

parseBegin

protected void parseBegin(String begin)
Parses a new 'begin' attribute.

parseClockValue

protected float parseClockValue(String s, boolean parseOffset)
Parses a clock value or offset and returns it as a float.

parseDur

protected void parseDur(String dur)
Parses a new 'dur' attribute.

parseEnd

protected void parseEnd(String end)
Parses a new 'end' attribute.

parseFill

protected void parseFill(String fill)
Parses a new 'fill' attribute.

parseMax

protected void parseMax(String max)
Parses a new 'max' attribute.

parseMin

protected void parseMin(String min)
Parses a new 'min' attribute.

parseRepeatCount

protected void parseRepeatCount(String repeatCount)
Parses a new 'repeatCount' attribute.

parseRepeatDur

protected void parseRepeatDur(String repeatDur)
Parses a new 'repeatDur' attribute.

parseRestart

protected void parseRestart(String restart)
Parses a new 'restart' attribute.

removeDependent

protected void removeDependent(TimingSpecifier dependent, boolean forBegin)
Removes a dependent TimingSpecifier for this element.

removeFill

protected abstract void removeFill()
Invoked to indicate that this timed element has had its fill removed.

removeInstanceTime

protected float removeInstanceTime(InstanceTime time, boolean isBegin)
Called by a TimingSpecifier of this element when an InstanceTime should be removed. This will be in response to the pruning of an Interval.

reset

protected void reset(boolean clearCurrentBegin)
Resets this element.

sampleAt

protected float sampleAt(float parentSimpleTime, boolean hyperlinking)
Calculates the local simple time. Currently the hyperlinking parameter is ignored, so DOM timing events are fired during hyperlinking seeks. If we were following SMIL 2.1 rather than SMIL Animation, then these events would have to be suppressed.

Returns: the number of seconds until this element becomes active again if it currently is not, Float#POSITIVE_INFINITY if this element will become active at some undetermined point in the future (because of unresolved begin times, for example) or will never become active again, or 0f if the element is currently active.

sampledAt

protected abstract void sampledAt(float simpleTime, float simpleDur, int repeatIteration)
Invoked to indicate that this timed element has been sampled at the given time.

Parameters: simpleTime the sample time in local simple time simpleDur the simple duration of the element repeatIteration the repeat iteration during which the element was sampled

sampledLastValue

protected abstract void sampledLastValue(int repeatIteration)
Invoked to indicate that this timed element has been sampled at the end of its active time, at an integer multiple of the simple duration. This is the "last" value that will be used for filling, which cannot be sampled normally.

selectNewInterval

protected float selectNewInterval(float time, Interval interval)
Sets the current interval to the one specified. This will notify dependents and fire the 'begin' and any necessary 'repeat' events.

Parameters: time the current sampling time interval the Interval object to select to be current

Returns: the minimum time the animation engine can safely wait, as determined by dependents of the interval

setLocale

public static void setLocale(Locale l)
Implements setLocale.

toActive

protected abstract void toActive(float begin)
Invoked to indicate this timed element became active at the specified time.

Parameters: begin the time the element became active, in document simple time

toInactive

protected abstract void toInactive(boolean stillActive, boolean isFrozen)
Invoked to indicate that this timed element became inactive.

Parameters: stillActive if true, indicates that the element is still actually active, but between the end of the computed repeat duration and the end of the interval isFrozen whether the element is frozen or not

toString

public static String toString(float time)
Returns a string representation of the given time value.
Copyright B) 2008 Apache Software Foundation. All Rights Reserved.