-
Notifications
You must be signed in to change notification settings - Fork 341
Expand file tree
/
Copy pathBasicAnimator.java
More file actions
129 lines (113 loc) · 3.31 KB
/
BasicAnimator.java
File metadata and controls
129 lines (113 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Copyright (C) 2012 United States Government as represented by the Administrator of the
* National Aeronautics and Space Administration.
* All Rights Reserved.
*/
package gov.nasa.worldwind.animation;
/**
* @author jym
* @version $Id: BasicAnimator.java 1171 2013-02-11 21:45:02Z dcollins $
*/
/**
* A base class for an interpolating <code>Animator</code>.
*/
public class BasicAnimator implements Animator
{
private boolean stopOnInvalidState = false;
private boolean lastStateValid = true;
private boolean hasNext = true;
/**
* Used to drive the animators next value based on the interpolant returned by the
* <code>Interpolator</code>'s next interpolant
*/
protected Interpolator interpolator;
/**
* Constructs a <code>BasicAnimator</code>. Sets the <code>Animator</code>'s <code>Interpolator</code> to
* <code>null</code>.
*/
public BasicAnimator()
{
interpolator = null;
}
/**
* Constructs a <code>BasicAnimator</code>. The <code>next</code> method will use the passed
* <code>Interpolator</code> to retrieve the <code>interpolant</code>
*
* @param interpolator The <code>Interpolator</code> to be used to get the interpolant for
* setting the next value.
*/
public BasicAnimator(Interpolator interpolator)
{
this.interpolator = interpolator;
}
/**
* Calls the <code>set</code> method with the next <code>interpolant</code> as determined
* by the <code>interpolator</code> member.
*/
public void next()
{
set(this.interpolator.nextInterpolant());
}
/**
* Calls the setImpl method with the interpolant value. Deriving classes are expected to
* implement the desired action of a set operation in thier <code>setImpl</code> method.
*
* @param interpolant A value between 0 and 1.
*/
public void set(double interpolant)
{
this.setImpl(interpolant);
if (isStopOnInvalidState() && !isLastStateValid())
{
this.stop();
}
}
/**
* Returns <code>true</code> if the <code>Animator</code> has more elements.
*
* @return <code>true</code> if the <code>Animator</code> has more elements
*/
public boolean hasNext()
{
return this.hasNext;
}
/**
* Starts the <code>Animator</code>, <code>hasNext</code> will now return <code>true</code>
*/
public void start()
{
this.hasNext = true;
}
/**
* Stops the <code>Animator</code>, <code>hasNext</code> will now return <code>false</code>
*/
public void stop()
{
this.hasNext = false;
}
/**
* No-op intended to be overrided by deriving classes. Deriving classes are expected to
* implement the desired action of a set operation in this method.
*
* @param interpolant A value between 0 and 1.
*/
protected void setImpl(double interpolant)
{
}
public void setStopOnInvalidState(boolean stop)
{
this.stopOnInvalidState = stop;
}
public boolean isStopOnInvalidState()
{
return this.stopOnInvalidState;
}
protected void flagLastStateInvalid()
{
this.lastStateValid = false;
}
protected boolean isLastStateValid()
{
return this.lastStateValid;
}
}