FileDocCategorySizeDatePackage
EventBaseCondition.javaAPI DocphoneME MR2 API (J2ME)10260Wed May 02 18:00:36 BST 2007com.sun.perseus.model

EventBaseCondition

public class EventBaseCondition extends TimeCondition implements EventListener, IDRef
An 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.

version
$Id: EventBaseCondition.java,v 1.3 2006/06/29 10:47:31 ln156897 Exp $

Fields Summary
long
offset
Offset from the event base
Time
lastEventTime
Keeps a reference to the last occurence of the event.
ModelNode
eventBase
The event base, i.e., the element which generates events this listeners listens to.
String
eventBaseId
The id of the event base. If null, the event base is the timed element of this condition.
String
eventType
The type of event this listener listens to.
Constructors Summary
public EventBaseCondition(TimedElementSupport timedElement, boolean isBegin, String eventBaseId, String eventType, long offset)

param
timedElement the associated TimedElementSupport. Should not be null.
param
isBegin defines whether this condition is for a begin list.
param
eventBaseId the id of the element which generates events this listener listens to. If null, this means the events are generated by the timedElement itself.
param
eventType the type of event this listener listens to. Should not be null.
param
offset offset from the sync base. This means that time instances synchronized on the syncBase begin or end time are offset by this amount.
throws
IllegalArgumentException if eventType is null or if the ModelNode associated with the timedElement is null.


                                                                                                                                                                             
       
                                
                                
                                
                                 
        this(timedElement, 
             isBegin, 
             eventBaseId, 
             timedElement.animationElement, 
             eventType, 
             offset);
    
protected EventBaseCondition(TimedElementSupport timedElement, boolean isBegin, String eventBaseId, ModelNode eventBase, String eventType, long offset)

param
timedElement the associated TimedElementSupport. Should not be null.
param
isBegin defines whether this condition is for a begin list.
param
eventBaseId the id of the element which generates events this listener listens to. If null, this means the events are generated by the timedElement itself.
param
eventBase in case eventBaseId is null, this should be used as the source for generating events. If eventBaseId is null, this should not be null.
param
eventType the type of event this listener listens to. Should not be null.
param
offset offset from the sync base. This means that time instances synchronized on the syncBase begin or end time are offset by this amount.
throws
IllegalArgumentException if eventType is null or if eventBase and eventBaseId are null.

        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 voidhandleEvent(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').

param
evt the event that occured

        // =====================================================================
        // 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 voidresolveTo(ElementNode ref)
IDRef implementation.

param
ref the resolved reference (from eventBaseId).

        setEventBase(ref);
    
private voidsetEventBase(ModelNode eventBase)
Implementation helper.

param
eventBase this node's event base.

        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.StringtoStringTrait()
Converts this EventBaseCondition to a String trait.

return
a string describing this TimeCondition

        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();