2
* Copyright (c) 2005-2006, Sun Microsystems, Inc
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
9
* * Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above
12
* copyright notice, this list of conditions and the following
13
* disclaimer in the documentation and/or other materials provided
14
* with the distribution.
15
* * Neither the name of the TimingFramework project nor the names of its
16
* contributors may be used to endorse or promote products derived
17
* from this software without specific prior written permission.
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
package org.pushingpixels.trident.interpolator;
34
import java.util.ArrayList;
37
* Stores a list of times from 0 to 1 (the elapsed fraction of an animation
38
* cycle) that are used in calculating interpolated
39
* values for PropertySetter given a matching set of KeyValues and
40
* Interpolators for those time intervals. In the simplest case, a
41
* KeyFrame will consist of just two times in KeyTimes: 0 and 1.
45
public class KeyTimes {
47
private ArrayList<Float> times = new ArrayList<Float>();
50
* Creates a new instance of KeyTimes. Times should be in increasing
51
* order and should all be in the range [0,1], with the first value
52
* being zero and the last being 1
53
* @throws IllegalArgumentException Time values must be ordered in
54
* increasing value, the first value must be 0 and the last value
57
public KeyTimes(float... times) {
59
throw new IllegalArgumentException("First time value must" +
62
if (times[times.length - 1] != 1.0f) {
63
throw new IllegalArgumentException("Last time value must" +
67
for (float time : times) {
68
if (time < prevTime) {
69
throw new IllegalArgumentException("Time values must be" +
70
" in increasing order");
77
ArrayList getTimes() {
86
* Returns time interval that contains this time fraction
88
int getInterval(float fraction) {
90
for (int i = 1; i < times.size(); ++i) {
91
float time = times.get(i);
92
if (time >= fraction) {
93
// inclusive of start time at next interval. So fraction==1
94
// will return the final interval (times.size() - 1)
102
float getTime(int index) {
103
return times.get(index);
b'\\ No newline at end of file'