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

TimedElementNode

public class TimedElementNode extends ElementNode implements org.w3c.dom.svg.SVGAnimationElement
TimedElementNode models ModelNodes
version
$Id: TimedElementNode.java,v 1.6 2006/07/13 00:55:58 st125089 Exp $

Fields Summary
protected TimedElementSupport
timedElementSupport
The timing support is added by compositing rather than inheritance because Java only allows single inheritance.
protected String
localName
The timed element's local name.
Constructors Summary
public TimedElementNode(DocumentNode ownerDocument, String localName)
Builds a new timed element that belongs to the given document. This TimedElementNode will belong to the DocumentNode's time container.

param
ownerDocument the document this node belongs to.
param
localName the element's local name
throws
IllegalArgumentException if the input ownerDocument is null

        this(ownerDocument, new TimedElementSupport(), localName);
    
public TimedElementNode(DocumentNode ownerDocument)
Builds a new timed element that belongs to the given document. This TimedElementNode will belong to the DocumentNode's time container.

param
ownerDocument the document this node belongs to.
throws
IllegalArgumentException if the input ownerDocument is null

        this(ownerDocument, new TimedElementSupport());
    
protected TimedElementNode(DocumentNode ownerDocument, TimedElementSupport timedElementSupport)
Constructor used by derived classes.

param
ownerDocument the document this node belongs to.
param
timedElementSupport the associated TimedElementSupport.
throws
IllegalArgumentException if the input ownerDocument is null.

        this(ownerDocument, 
             timedElementSupport,
             // <!> IMPL NOTE : DO THIS WHILE THE REST OF THE ANIMATION
             // IMPLEMENTATION IS PENDING.
             SVGConstants.SVG_SET_TAG);
    
protected TimedElementNode(DocumentNode ownerDocument, TimedElementSupport timedElementSupport, String localName)
Constructor used by derived classes.

param
ownerDocument the document this node belongs to.
param
timedElementSupport the associated TimedElementSupport.
param
localName the element's local name. Should not be null.
throws
IllegalArgumentException if the input ownerDocument is null or if the input timedElementSupport is null.

        super(ownerDocument);

        if (timedElementSupport == null) {
            throw new IllegalArgumentException();
        }

        if (localName == null) {
            throw new IllegalArgumentException();
        }

        this.timedElementSupport = timedElementSupport;

        this.localName = localName;

        timedElementSupport.animationElement = this;
    
Methods Summary
public voidbeginElement()
Creates a begin instance time for the current time.

        timedElementSupport.beginAt(0);
    
public voidbeginElementAt(float offset)

        timedElementSupport.beginAt((long) (offset * 1000));
    
public voidendElement()
Creates an end instance time for the current time.

        timedElementSupport.endAt(0);
    
public voidendElementAt(float offset)

        timedElementSupport.endAt((long) (offset * 1000));
    
public java.lang.String[][]getDefaultTraits()
The default value for the begin attribute is '0s'.

return
an array of trait default values, used if this element requires that the default trait value be explicitly set through a setTrait call. This happens, for example, with the begin trait value on animation elements.

        return new String[][] { {SVGConstants.SVG_BEGIN_ATTRIBUTE, "0s"} };
    
public booleangetElementPaused()

return
true if the element is currently paused, false otherwise. See the SMIL 2 specification for a description of pausing elements.

        throw new Error("NOT IMPLEMENTED");
    
public java.lang.StringgetLocalName()

return
the animation tag name passed at construction time.

        return localName;
    
public TimedElementSupportgetTimedElementSupport()

return
this node's TimedElementSupport

        return timedElementSupport;
    
public java.lang.StringgetTraitImpl(java.lang.String name)

        if (SVGConstants.SVG_BEGIN_ATTRIBUTE == name) {
            if (timedElementSupport.beginConditions.size() == 0) {
                return "0s";
            }
            return TimeCondition.toStringTrait(
                    timedElementSupport.beginConditions);
        } else if (SVGConstants.SVG_END_ATTRIBUTE == name) {
            if (timedElementSupport.endConditions.size() == 0) {
                return SVGConstants.SVG_INDEFINITE_VALUE;
            }
            return TimeCondition.toStringTrait(
                    timedElementSupport.endConditions);
        } else if (SVGConstants.SVG_DUR_ATTRIBUTE == name) {
            return Time.toStringTrait(timedElementSupport.dur);
        } else if (SVGConstants.SVG_MIN_ATTRIBUTE == name) {
            return Time.toStringTrait(timedElementSupport.min);
        } else if (SVGConstants.SVG_MAX_ATTRIBUTE == name) {
            return Time.toStringTrait(timedElementSupport.max);
        } else if (SVGConstants.SVG_RESTART_ATTRIBUTE == name) {
            switch (timedElementSupport.restart) {
            case TimedElementSupport.RESTART_ALWAYS:
                return SVGConstants.SVG_ALWAYS_VALUE;
            case TimedElementSupport.RESTART_WHEN_NOT_ACTIVE:
                return SVGConstants.SVG_WHEN_NOT_ACTIVE_VALUE;
            case TimedElementSupport.RESTART_NEVER:
                return SVGConstants.SVG_NEVER_VALUE;
            default:
                throw new IllegalStateException();
            }
        } else if (SVGConstants.SVG_REPEAT_COUNT_ATTRIBUTE == name) {
            if (Float.isNaN(timedElementSupport.repeatCount)) {
                return null; // Unspecified
            } else if (timedElementSupport.repeatCount == Float.MAX_VALUE) {
                return SVGConstants.SVG_INDEFINITE_VALUE;
            }
            return Float.toString(timedElementSupport.repeatCount);
        } else if (SVGConstants.SVG_REPEAT_DUR_ATTRIBUTE == name) {
            return Time.toStringTrait(timedElementSupport.repeatDur);
        } else if (SVGConstants.SVG_FILL_ATTRIBUTE == name) {
            switch (timedElementSupport.fillBehavior) {
            case TimedElementSupport.FILL_BEHAVIOR_REMOVE:
                return SVGConstants.SVG_REMOVE_VALUE;
            case TimedElementSupport.FILL_BEHAVIOR_FREEZE:
                return SVGConstants.SVG_FREEZE_VALUE;
            default:
                throw new IllegalStateException();
            }
        } else {
            return super.getTraitImpl(name);
        }
    
public ElementNodenewInstance(DocumentNode doc)
Used by DocumentNode to create a new instance from a prototype TimedElementNode.

param
doc the DocumentNode for which a new node is should be created.
return
a new TimedElementNode for the requested document.

        return new TimedElementNode(doc, new TimedElementSupport(), localName);
    
voidnodeHookedInDocumentTree()
When a TimedElementNode is hooked into the document tree, it needs to register with the closest ancestor TimeContainerNode it can find. If none, it must register with the root time container.

        super.nodeHookedInDocumentTree();

        ModelNode p = parent;
        while (p != ownerDocument && p != null) {
            if (p instanceof TimeContainerNode) {
                timedElementSupport.setTimeContainer
                    (((TimeContainerNode) p).timeContainerSupport);
                break;
            }
            p = p.parent;
        }

        if (p == ownerDocument) {
            timedElementSupport.setTimeContainer
                (ownerDocument.timeContainerRootSupport);
        }
    
voidnodeUnhookedFromDocumentTree()
When a TimedElementNode is unhooked from the document tree, it needs to unregister from its TimeContainer node. Extentions, such as Animation, may have to perform additional operations, such as removing themselves from TraitAnim.

        timedElementSupport.setTimeContainer(null);
        timedElementSupport.reset();
    
protected voidparseTimeConditionsTrait(java.lang.String traitName, java.lang.String value, boolean isBegin)
Parses the input value an creates TimeCondition instances for the current instance.

param
traitName the name of the time condition trait.
param
value the trait value.
param
isBegin true if this should be parsed as a begin value, i.e., with a 0s default.
throws
DOMException if the input value is invalid.

        try {
            ownerDocument.timeConditionParser.parseBeginEndAttribute(value,
                                                                     this,
                                                                     isBegin);
        } catch (IllegalArgumentException iae) {
            iae.printStackTrace();
            throw illegalTraitValue(traitName, value);
        }                                                           
    
public voidpauseElement()
Pauses the element. If the element is already paused, this method has no effect. See the SMIL 2 specification for a description of pausing elements.

        throw new Error("NOT IMPLEMENTED");
    
public voidsetTraitImpl(java.lang.String name, java.lang.String value)

        if (SVGConstants.SVG_BEGIN_ATTRIBUTE == name) {
            checkWriteLoading(name);
            timedElementSupport.beginConditions.removeAllElements();
            parseTimeConditionsTrait(name, value, true);
        } else if (SVGConstants.SVG_END_ATTRIBUTE == name) {
            checkWriteLoading(name);
            timedElementSupport.endConditions.removeAllElements();
            parseTimeConditionsTrait(name, value, false);
        } else if (SVGConstants.SVG_DUR_ATTRIBUTE == name) {
            checkWriteLoading(name);
            // Ignore 'media'
            if (SVGConstants.SVG_MEDIA_VALUE.equals(value)) {
                return;
            }
            timedElementSupport.setDur(parseClockTrait(name, value));
        } else if (SVGConstants.SVG_MIN_ATTRIBUTE == name) {
            checkWriteLoading(name);

            // Ignore 'media'
            if (SVGConstants.SVG_MEDIA_VALUE.equals(value)) {
                return;
            }
            timedElementSupport.setMin(parseMinMaxClock(name, value, true));
        } else if (SVGConstants.SVG_MAX_ATTRIBUTE == name) {
            checkWriteLoading(name);

            // Ignore 'media'
            if (SVGConstants.SVG_MEDIA_VALUE.equals(value)) {
                return;
            }
            timedElementSupport.setMax(parseMinMaxClock(name, value, false));
        } else if (SVGConstants.SVG_RESTART_ATTRIBUTE == name) {
            checkWriteLoading(name);

            if (SVGConstants.SVG_ALWAYS_VALUE.equals(value)) {
                timedElementSupport.restart = 
                    TimedElementSupport.RESTART_ALWAYS;
            } else if (SVGConstants.SVG_WHEN_NOT_ACTIVE_VALUE.equals(value)) {
                timedElementSupport.restart =
                    TimedElementSupport.RESTART_WHEN_NOT_ACTIVE;
            } else if (SVGConstants.SVG_NEVER_VALUE.equals(value)) {
                timedElementSupport.restart =
                    TimedElementSupport.RESTART_NEVER;
            } else {
                throw illegalTraitValue(name, value);
            }
        } else if (SVGConstants.SVG_REPEAT_COUNT_ATTRIBUTE == name) {
            checkWriteLoading(name);

            if (SVGConstants.SVG_INDEFINITE_VALUE.equals(value)) {
                timedElementSupport.repeatCount = Float.MAX_VALUE;
            } else {
                timedElementSupport.repeatCount =
                    parseFloatTrait(name, value);
            }
        } else if (SVGConstants.SVG_REPEAT_DUR_ATTRIBUTE == name) {
            checkWriteLoading(name);
            if (SVGConstants.SVG_INDEFINITE_VALUE.equals(value)) {
                timedElementSupport.repeatDur = Time.INDEFINITE;
            } else {
                timedElementSupport.setRepeatDur(parseClockTrait(name, value));
            }
        } else if (SVGConstants.SVG_FILL_ATTRIBUTE == name) {
            checkWriteLoading(name);
            if (SVGConstants.SVG_REMOVE_VALUE.equals(value)) {
                timedElementSupport.fillBehavior 
                    = TimedElementSupport.FILL_BEHAVIOR_REMOVE;
            } else if (SVGConstants.SVG_FREEZE_VALUE.equals(value)) {
                timedElementSupport.fillBehavior
                    = TimedElementSupport.FILL_BEHAVIOR_FREEZE;
            } else {
                throw illegalTraitValue(name, value);
            }
        } else {
            super.setTraitImpl(name, value);
        }
    
booleansupportsTrait(java.lang.String traitName)
TimedElementNode supports the begin, end, dur, min, max, restart, repeatCount, repeatDur and fill attributes.

param
traitName the name of the trait which the element may support.
return
true if this element supports the given trait in one of the trait accessor methods (such as getTrait or setFloatTrait.

        if (SVGConstants.SVG_BEGIN_ATTRIBUTE == traitName
            || 
            SVGConstants.SVG_END_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_DUR_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_MIN_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_MAX_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_RESTART_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_REPEAT_COUNT_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_REPEAT_DUR_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_FILL_ATTRIBUTE == traitName) {
            return true;
        }

        return super.supportsTrait(traitName);
    
public voidunpauseElement()
Unpauses the element if it was paused. If the element was not paused, this method has no effect. See the SMIL 2 specification for a description of pausing elements.

        throw new Error("NOT IMPLEMENTED");