001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026: package com.sun.perseus.model;
027:
028: /**
029: *
030: * @version $Id: TimeContainerRootSupport.java,v 1.2 2006/04/21 06:37:20 st125089 Exp $
031: */
032: public class TimeContainerRootSupport extends TimeContainerSupport {
033: /**
034: * The time at which the document started. This is
035: * initially set when animation is started and then
036: * modified when the document's timeline is seeked
037: * to a particular time.
038: */
039: protected long beginWallClockTime = -1;
040:
041: /**
042: * The last sample time.
043: */
044: protected Time lastSampleTime = Time.UNRESOLVED;
045:
046: /**
047: * Flags that the seek is backwards
048: */
049: protected boolean seekingBack;
050:
051: /**
052: * There is no parent container for this root. The parent is this
053: * node itself.
054: * Also, the root time container has a default 0-offset begin condition
055: * added to it so that the first interval is created and is
056: * [0, INDEFINITE[.
057: */
058: TimeContainerRootSupport() {
059: timeContainer = this ;
060:
061: // Add a new 0-offset begin condition.
062: new OffsetCondition(this , true, 0);
063: }
064:
065: /**
066: * Always throws an exception because a root container should not have
067: * a parent container.
068: *
069: * @param timeContainer time container
070: * @throws IllegalArgumentException always thrown for a root time
071: * container which should not have a parent container.
072: */
073: protected void setTimeContainer(
074: final TimeContainerSupport timeContainer) {
075: throw new IllegalArgumentException();
076: }
077:
078: /**
079: * Helper method.
080: *
081: * @return this timed element's root container.
082: */
083: TimeContainerRootSupport getRootContainer() {
084: return this ;
085: }
086:
087: /**
088: * Converts the input 'local' time to an absolute wallclock time.
089: *
090: * @param localTime the time to convert to wallclock time
091: * @return the time, converted to wall clock time.
092: */
093: long toWallClockTime(final long localTime) {
094: return beginWallClockTime + localTime;
095: }
096:
097: /**
098: * Dispatches beginEvent. See the <code>TimedElementSupport</code> class
099: * method implementation. This class also uses the opportunity to record
100: * what the wallclock time is for the begin time so that localTimes can
101: * be converted later.
102: *
103: * @param beginTime the interval begin time
104: */
105: void dispatchBeginEvent(final Time beginTime) {
106: super .dispatchBeginEvent(beginTime);
107:
108: beginWallClockTime = System.currentTimeMillis();
109:
110: // With the following, beginTime will map to beginWallClockTime,
111: // as expected.
112: beginWallClockTime -= beginTime.value;
113: }
114:
115: /**
116: * For the root container, there is no container simple duration, so we
117: * retun INDEFINITE, no matter what the state is.
118: *
119: * @return the container's simple duration.
120: */
121: Time getContainerSimpleDuration() {
122: return Time.INDEFINITE;
123: }
124:
125: /**
126: * Converts the input simple time (i.e., a time in the parent container's
127: * simple duration) to a root container simple time (i.e., a time
128: * in the root time container's simple time interval).
129: *
130: * @param simpleTime the time in the parent container's simple duration
131: * @return a time in the root time container's simple duration (i.e., in
132: * the root container's simple time interval).
133: */
134: Time toRootContainerSimpleTime(final Time simpleTime) {
135: return simpleTime;
136: }
137:
138: /**
139: * Converts the input simple time (i.e., a time in the parent container's
140: * simple duration) to a root container simple time (i.e., a time
141: * in the root time container's simple time interval).
142: *
143: * @param simpleTime the time in the parent container's simple duration
144: * @return a time in the root time container's simple duration (i.e., in
145: * the root container's simple time interval).
146: */
147: Time toRootContainerSimpleTimeClamp(final Time simpleTime) {
148: // Note that no clamping is necessary here because the clamping is
149: // done in a timed element, relative to its container's simple time.
150: // By the time this is called on the root, the child timed element has
151: // already applied the root's constraints.
152: return simpleTime;
153: }
154:
155: /**
156: * Converts the input root container simple time (i.e., a time in the root
157: * container's simple time interval) to a time in this element's time
158: * container simple duration.
159: *
160: * @param rootSimpleTime the time in the root container's simple duration.
161: * @return a simple time in the parent container's simple duration The
162: * return value is in the [0, container simple duration] interval.
163: *
164: */
165: Time toContainerSimpleTime(final Time rootSimpleTime) {
166: return rootSimpleTime;
167: }
168:
169: /**
170: * Seek to the requested time. The time is assumed to be in
171: * document simple time.
172: *
173: * @param seekToTime the time to seek to
174: */
175: void seekTo(final Time seekToTime) {
176: if (!seekToTime.isResolved()) {
177: throw new IllegalStateException();
178: }
179:
180: seeking = true;
181: seekingBack = !seekToTime.greaterThan(lastSampleTime);
182: try {
183: sample(seekToTime);
184: } finally {
185: seeking = false;
186: }
187: }
188:
189: /**
190: * Overrides the default sample time to capture the last sample time.
191: *
192: * @param currentTime the time at which this element should be
193: * sampled.
194: */
195: void sample(final Time currentTime) {
196: super.sample(currentTime);
197: lastSampleTime = currentTime;
198: }
199: }
|