T
- the type of the values.@Immutable public class KeyFrames<T> extends java.lang.Object implements java.lang.Iterable<KeyFrames.Frame<T>>
Client code should never mutate values that have been passed into a key frames instance. The behavior of this implementation is undefined if values are mutate by client code.
Modifier and Type | Class and Description |
---|---|
static class |
KeyFrames.Builder<T>
This class is used to construct
KeyFrames instances. |
static class |
KeyFrames.Frame<T>
Represents a single key frame.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Class<?> |
getClassOfValue()
This method returns the
Class object for the value of a frame. |
KeyFrames.Frame<T> |
getFrame(int index)
Returns the key frame at the specified position in this list.
|
int |
getFrameIndexAt(double fraction)
Returns interval of time, 0 to
size() - 2, that contains
the passed time fraction based upon the list of key frames managed by this
instance. |
T |
getInterpolatedValueAt(double fraction)
Gets the interpolated value at the passed time fraction based upon the list
of key frames managed by this instance.
|
java.util.Iterator<KeyFrames.Frame<T>> |
iterator() |
int |
size()
Gets the number of key frames contained in this list.
|
@Borrowed(value="this") @RegionEffects(value="reads this:Instance") public int size()
@NonNull public KeyFrames.Frame<T> getFrame(int index)
index
- index of the key frame to return.java.lang.IndexOutOfBoundsException
- if the index is out of range (
index < 0 || index >= size())@NonNull public java.lang.Class<?> getClassOfValue()
Class
object for the value of a frame. It
produces the same result as invoking
kf.getFrame(0).getClassOfValue()on a
KeyFrames
kf.Class
object for the value of this frame.@Borrowed(value="this") @RegionEffects(value="reads this:Instance") @Unique(value="return") public java.util.Iterator<KeyFrames.Frame<T>> iterator()
iterator
in interface java.lang.Iterable<KeyFrames.Frame<T>>
@RegionEffects(value="reads any(org.jdesktop.core.animation.timing.KeyFrames.Frame):Instance, this:Instance") public int getFrameIndexAt(double fraction)
size()
- 2, that contains
the passed time fraction based upon the list of key frames managed by this
instance. The return value is the index of the key frame closest to, but
not after, the passed time fraction. More precisely, the returned interval
is i if fraction is within the range ( getFrame(
i).getTimeFraction(), getFrame( i
+1).getTimeFraction()] unless i=0 in which case
fraction is within the range [0, getFrame(i
+1).getTimeFraction()] (i.e., zero inclusive).
For example, consider the following instance (ignoring the integer key frame values):
KeyFrames.Builder<Integer> builder = new KeyFrames.Builder<Integer>(1); builder.addFrame(2, 0.1); // addFrame(value, atTimeFraction) builder.addFrame(3, 0.2); builder.addFrame(4, 0.5); builder.addFrame(5, 1); KeyFrames<Integer> k = builder.build();The table below shows the results obtained from calls on this instance.
f | i=k.getFrameIndexAt(f) | k.getFrame(i).getTimeFraction() | k.getFrame(i+1).getTimeFraction() |
---|---|---|---|
-1† | 0 | 0.0 | 0.1 |
0 | 0 | 0.0 | 0.1 |
0.1 | 0 | 0.0 | 0.1 |
0.11 | 1 | 0.1 | 0.2 |
0.2 | 1 | 0.1 | 0.2 |
0.34 | 2 | 0.2 | 0.5 |
0.5 | 2 | 0.2 | 0.5 |
0.6 | 3 | 0.5 | 1.0 |
1 | 3 | 0.5 | 1.0 |
2† | 3 | 0.5 | 1.0 |
fraction
- a time fraction in the range [0,1].public T getInterpolatedValueAt(double fraction)
Evaluator
using the two key frames
fraction lies between and the Interpolator
set for that
interval of time.fraction
- a time fraction in the range [0,1].