001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.anim.timing;
020:
021: import java.util.Iterator;
022: import java.util.LinkedList;
023:
024: /**
025: * A class that represents an interval for a timed element.
026: *
027: * @author <a href="mailto:cam%40mcc%2eid%2eau">Cameron McCormack</a>
028: * @version $Id: Interval.java 492528 2007-01-04 11:45:47Z cam $
029: */
030: public class Interval {
031:
032: /**
033: * The begin time for the interval.
034: */
035: protected float begin;
036:
037: /**
038: * The end time for the interval.
039: */
040: protected float end;
041:
042: /**
043: * The InstanceTime that defined the begin time of the current interval.
044: */
045: protected InstanceTime beginInstanceTime;
046:
047: /**
048: * The InstanceTime that defined the end time of the current interval.
049: */
050: protected InstanceTime endInstanceTime;
051:
052: /**
053: * The list of {@link InstanceTime} objects that are dependent
054: * on the begin time of this Interval.
055: */
056: protected LinkedList beginDependents = new LinkedList();
057:
058: /**
059: * The list of {@link InstanceTime} objects that are dependent
060: * on the end time of this Interval.
061: */
062: protected LinkedList endDependents = new LinkedList();
063:
064: /**
065: * Creates a new Interval.
066: * @param begin the begin time of the Interval
067: * @param end the end time of the Interval
068: * @param beginInstanceTime the {@link InstanceTime} object that defined
069: * the begin time of the Interval
070: * @param endInstanceTime the {@link InstanceTime} object that defined
071: * the end time of the Interval
072: */
073: public Interval(float begin, float end,
074: InstanceTime beginInstanceTime, InstanceTime endInstanceTime) {
075: // Trace.enter(this, null, new Object[] { new Float(begin), new Float(end), beginInstanceTime, endInstanceTime } ); try {
076: this .begin = begin;
077: this .end = end;
078: this .beginInstanceTime = beginInstanceTime;
079: this .endInstanceTime = endInstanceTime;
080: // } finally { Trace.exit(); }
081: }
082:
083: /**
084: * Returns a string representation of this Interval.
085: */
086: public String toString() {
087: return TimedElement.toString(begin) + ".."
088: + TimedElement.toString(end);
089: }
090:
091: /**
092: * Returns the begin time of this interval.
093: */
094: public float getBegin() {
095: return begin;
096: }
097:
098: /**
099: * Returns the end time of this interval.
100: */
101: public float getEnd() {
102: return end;
103: }
104:
105: /**
106: * Returns the {@link InstanceTime} that defined the begin time of this
107: * interval.
108: */
109: public InstanceTime getBeginInstanceTime() {
110: return beginInstanceTime;
111: }
112:
113: /**
114: * Returns the {@link InstanceTime} that defined the end time of this
115: * interval.
116: */
117: public InstanceTime getEndInstanceTime() {
118: return endInstanceTime;
119: }
120:
121: /**
122: * Adds a dependent InstanceTime for this Interval.
123: */
124: void addDependent(InstanceTime dependent, boolean forBegin) {
125: // Trace.enter(this, "addDependent", new Object[] { dependent, new Boolean(forBegin) } ); try {
126: if (forBegin) {
127: beginDependents.add(dependent);
128: } else {
129: endDependents.add(dependent);
130: }
131: // } finally { Trace.exit(); }
132: }
133:
134: /**
135: * Removes a dependent InstanceTime for this Interval.
136: */
137: void removeDependent(InstanceTime dependent, boolean forBegin) {
138: // Trace.enter(this, "removeDependent", new Object[] { dependent, new Boolean(forBegin) } ); try {
139: if (forBegin) {
140: beginDependents.remove(dependent);
141: } else {
142: endDependents.remove(dependent);
143: }
144: // } finally { Trace.exit(); }
145: }
146:
147: /**
148: * Updates the begin time for this interval.
149: */
150: float setBegin(float begin) {
151: // Trace.enter(this, "setBegin", new Object[] { new Float(begin) } ); try {
152: float minTime = Float.POSITIVE_INFINITY;
153: this .begin = begin;
154: Iterator i = beginDependents.iterator();
155: while (i.hasNext()) {
156: InstanceTime it = (InstanceTime) i.next();
157: float t = it.dependentUpdate(begin);
158: if (t < minTime) {
159: minTime = t;
160: }
161: }
162: return minTime;
163: // } finally { Trace.exit(); }
164: }
165:
166: /**
167: * Updates the end time for this interval.
168: */
169: float setEnd(float end, InstanceTime endInstanceTime) {
170: // Trace.enter(this, "setEnd", new Object[] { new Float(end) } ); try {
171: float minTime = Float.POSITIVE_INFINITY;
172: this .end = end;
173: this .endInstanceTime = endInstanceTime;
174: Iterator i = endDependents.iterator();
175: while (i.hasNext()) {
176: InstanceTime it = (InstanceTime) i.next();
177: float t = it.dependentUpdate(end);
178: if (t < minTime) {
179: minTime = t;
180: }
181: }
182: return minTime;
183: // } finally { Trace.exit(); }
184: }
185: }
|