EventBaseConditionpublic class EventBaseCondition extends TimeCondition implements EventListener, IDRefAn EventBaseCondition generates a TimeInstance
everytime the associated event happens.
It is the responsibility of this class to register as an
EventListener . The TimeInstance created
by an EventBaseCondition are cleared on reset, i.e, when
the associated TimedElementSupport restarts. |
Fields Summary |
---|
long | offsetOffset from the event base | Time | lastEventTimeKeeps a reference to the last occurence of the event. | ModelNode | eventBaseThe event base, i.e., the element which generates events this
listeners listens to. | String | eventBaseIdThe id of the event base. If null, the event base is the timed
element of this condition. | String | eventTypeThe type of event this listener listens to. |
Constructors Summary |
---|
public EventBaseCondition(TimedElementSupport timedElement, boolean isBegin, String eventBaseId, String eventType, long offset)
this(timedElement,
isBegin,
eventBaseId,
timedElement.animationElement,
eventType,
offset);
| protected EventBaseCondition(TimedElementSupport timedElement, boolean isBegin, String eventBaseId, ModelNode eventBase, String eventType, long offset)
super(timedElement, isBegin);
if (eventType == null
||
(eventBaseId == null && eventBase == null)) {
throw new IllegalArgumentException();
}
this.eventBaseId = eventBaseId;
this.eventType = eventType;
this.offset = offset;
ModelNode elt = timedElement.animationElement;
if (eventBaseId == null) {
setEventBase(eventBase);
} else {
elt.ownerDocument.resolveIDRef(this, eventBaseId);
}
|
Methods Summary |
---|
public void | handleEvent(org.w3c.dom.events.Event evt)Implementation of the EventListener interface.
When an event is received from the event base, this condition
should generate a new TimeInstance that will be added
to the associdated TimedElementSupport begin or end instance
list (depending on the isBegin setting). The condition
should also record the time of the new event as its
lastEventTime .
Note that a condition is sensitive to events according to the
SMIL Animation specification, section 3.6.4 specifying 'Event
Sensitivity' (or SMIL 2 Timing and Synchronization Module,
'Event Sensitivity').
// =====================================================================
// If the container is not active, there is no event sensitivity
// If the event time is unresolved, there is no event sensitivy either,
// as there is no way to compute the time instance that should be
// added to the timed element.
if (timedElement.timeContainer.state
!=
TimedElementSupport.STATE_PLAYING
||
!((ModelEvent) evt).eventTime.isResolved()) {
return;
}
// =====================================================================
// When the container is active, begin condition are sensitive when:
// - there is no current interval yet, i.e., the timedElement is not
// active.
// - there is a current interval, and the restart behavior is 'always'
//
// When the container is active (i.e., there is a resolved currentTime),
// end condition are sensitive when the element is active and the
// restart behavior is never or when active and the restart behavior
// is 'always' but there is no begin condition for the event.
Time eventTime = new Time(((ModelEvent) evt).eventTime.value);
eventTime = timedElement.toContainerSimpleTime(eventTime);
if (timedElement.state != TimedElementSupport.STATE_PLAYING) {
if (isBegin) {
new TimeInstance(timedElement,
new Time(eventTime.value + offset),
true,
isBegin);
lastEventTime = eventTime;
}
} else {
// The element is active
if (timedElement.restart == TimedElementSupport.RESTART_ALWAYS) {
// Only add an instance if this is a begin condition
// of if there is not begin event condition
if (isBegin || !timedElement.hasBeginCondition(this)) {
new TimeInstance(timedElement,
new Time(eventTime.value + offset),
true,
isBegin);
lastEventTime = eventTime;
}
} else {
if (!isBegin) {
new TimeInstance(timedElement,
new Time(eventTime.value + offset),
true,
isBegin);
lastEventTime = eventTime;
}
}
}
| public void | resolveTo(ElementNode ref)IDRef implementation.
setEventBase(ref);
| private void | setEventBase(ModelNode eventBase)Implementation helper.
if (this.eventBase != null) {
throw new IllegalStateException();
}
this.eventBase = eventBase;
// Register the listener for the bubble phase.
eventBase.ownerDocument.getEventSupport().addEventListener
(eventBase, eventType, EventSupport.BUBBLE_PHASE, this);
| protected java.lang.String | toStringTrait()Converts this EventBaseCondition to a String trait.
StringBuffer sb = new StringBuffer();
sb.append(eventBaseId);
sb.append('.");
sb.append(eventType);
if (offset != 0) {
if (offset > 0) {
sb.append('+");
}
sb.append(offset / 1000f);
sb.append('s");
}
return sb.toString();
|
|