Package edu.umd.cs.piccolo.activities
Class PActivity
java.lang.Object
edu.umd.cs.piccolo.activities.PActivity
- Direct Known Subclasses:
PInterpolatingActivity
PActivity controls some time dependent aspect of Piccolo, such as
animation. Once created activities must be scheduled with the
PActivityScheduler managed by the PRoot to run. They are automatically
removed from the scheduler when the animation has finished.
See the PNode.animate*() methods for an example of how to set up and run different activities.
- Version:
- 1.0
- Author:
- Jesse Grosjean
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacePActivityDelegate is used by classes to learn about and act on the different states that a PActivity goes through, such as when the activity starts and stops stepping. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intParameter for terminate that signifies that activity should bail out immediately, but flag activity as finished.static final intParameter for terminate that signifies that activity should bail out immediately, if currently active.static final intParameter for terminate that signifies that activity should bail out immediately without flagging activity as finished. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidThis method is called after an activity is has finished running and the activity has been removed from the PActivityScheduler queue.protected voidThis method is called right before an activity is scheduled to start running.protected voidactivityStep(long elapsedTime) This is the method that most activities override to perform their behavior.Returns the activity scheduler associated with this activity.Get the delegate for this activity.longReturn the amount of time that this activity should take to complete, after the startStepping method is called.longGets the next step time desired for this activity.longReturn the time that this activity should start running in PRoot global time.longReturn the amount of time that this activity should delay between steps.longReturn the time when this activity should finish running.protected booleanReturn true if this activity is performing an animation.booleanReturn true if this activity is stepping.protected StringDeprecated.see http://code.google.com/p/piccolo2d/issues/detail?id=99longprocessStep(long currentTime) The activity scheduler calls this method and it is here that the activity decides if it should do a step or not for the given time.voidsetActivityScheduler(PActivityScheduler aScheduler) Informs the activity of the scheduler that will be responsible for scheduling it.voidsetDelegate(PActivity.PActivityDelegate delegate) Set the delegate for this activity.voidsetDuration(long aDuration) Set the amount of time that this activity should take to complete, after the startStepping method is called.voidsetStartTime(long aTriggerTime) Set the time that this activity should start running in PRoot global time.voidsetStepRate(long aStepRate) Set the amount of time that this activity should delay between steps.voidstartAfter(PActivity first) Schedules this activity to start after the first activity has finished.voidStop this activity immediately, and remove it from the activity scheduler.voidterminate(int terminationBehavior) Stop this activity immediately, and remove it from the activity scheduler.
-
Field Details
-
TERMINATE_WITHOUT_FINISHING
public static final int TERMINATE_WITHOUT_FINISHINGParameter for terminate that signifies that activity should bail out immediately without flagging activity as finished.- See Also:
-
TERMINATE_AND_FINISH
public static final int TERMINATE_AND_FINISHParameter for terminate that signifies that activity should bail out immediately, but flag activity as finished.- See Also:
-
TERMINATE_AND_FINISH_IF_STEPPING
public static final int TERMINATE_AND_FINISH_IF_STEPPINGParameter for terminate that signifies that activity should bail out immediately, if currently active.- See Also:
-
-
Constructor Details
-
PActivity
public PActivity(long aDuration) Constructs a new PActivity.- Parameters:
aDuration- the amount of time that this activity should take to complete, -1 for infinite.
-
PActivity
public PActivity(long aDuration, long aStepRate) Constructs a new PActivity.- Parameters:
aDuration- the amount of time that this activity should take to complete, -1 for infinite.aStepRate- the maximum rate that this activity should receive step events.
-
PActivity
public PActivity(long aDuration, long aStepRate, long aStartTime) Constructs a new PActivity.- Parameters:
aDuration- the amount of time that this activity should take to complete, -1 for infinite.aStepRate- the maximum rate that this activity should receive step events.aStartTime- the time (relative to System.currentTimeMillis()) that this activity should start.
-
-
Method Details
-
getStartTime
public long getStartTime()Return the time that this activity should start running in PRoot global time. When this time is reached (or soon after) this activity will have its startStepping() method called.- Returns:
- time at which this activity should start in PRoot global time.
-
setStartTime
public void setStartTime(long aTriggerTime) Set the time that this activity should start running in PRoot global time. When this time is reached (or soon after) this activity will have its startStepping() method called.- Parameters:
aTriggerTime- time at which you want this activity to begin in PRoot global time
-
getStepRate
public long getStepRate()Return the amount of time that this activity should delay between steps.- Returns:
- the desired milliseconds between steps
-
setStepRate
public void setStepRate(long aStepRate) Set the amount of time that this activity should delay between steps.- Parameters:
aStepRate- desired step rate in milliseconds between steps
-
getNextStepTime
public long getNextStepTime()Gets the next step time desired for this activity. Exists since some steps might eat into the step rate otherwise.- Returns:
- next calculated step time
-
getDuration
public long getDuration()Return the amount of time that this activity should take to complete, after the startStepping method is called.- Returns:
- time that this activity should take to complete
-
setDuration
public void setDuration(long aDuration) Set the amount of time that this activity should take to complete, after the startStepping method is called.- Parameters:
aDuration- desired duration this activity should take (-1 for infinite) once it begins stepping
-
getActivityScheduler
Returns the activity scheduler associated with this activity.- Returns:
- associated scheduler
-
setActivityScheduler
Informs the activity of the scheduler that will be responsible for scheduling it.- Parameters:
aScheduler- scheduler to associate with this activity
-
isStepping
public boolean isStepping()Return true if this activity is stepping.- Returns:
- whether this activity is stepping
-
isAnimation
protected boolean isAnimation()Return true if this activity is performing an animation. This is used by the PCanvas to determine if it should set the render quality to PCanvas.animatingRenderQuality or not for each frame it renders.- Returns:
- whether this activity is an animation, subclasses can override this.
-
activityStarted
protected void activityStarted()This method is called right before an activity is scheduled to start running. After this method is called step() will be called until the activity finishes. -
activityStep
protected void activityStep(long elapsedTime) This is the method that most activities override to perform their behavior. It will be called repeatedly when the activity is running.- Parameters:
elapsedTime- the amount of time that has passed relative to the activities startTime.
-
activityFinished
protected void activityFinished()This method is called after an activity is has finished running and the activity has been removed from the PActivityScheduler queue. -
getDelegate
Get the delegate for this activity. The delegate is notified when the activity starts and stops stepping.- Returns:
- delegate of this activity, may be null
-
setDelegate
Set the delegate for this activity. The delegate is notified when the activity starts and stops stepping.- Parameters:
delegate- delegate that should be informed of activity events
-
startAfter
Schedules this activity to start after the first activity has finished. Note that no link is created between these activities, if the startTime or duration of the first activity is later changed this activities start time will not be updated to reflect that change.- Parameters:
first- activity after which this activity should be scheduled
-
terminate
public void terminate()Stop this activity immediately, and remove it from the activity scheduler. The default termination behavior is call activityFinished if the activity is currently stepping. Use terminate(terminationBehavior) use a different termination behavior. -
terminate
public void terminate(int terminationBehavior) Stop this activity immediately, and remove it from the activity scheduler. The termination behavior determines when and if activityStarted and activityFinished get called. The possible termination behaviors are as follow: TERMINATE_WITHOUT_FINISHING - The method activityFinished will never get called and so the activity will be terminated midway. TERMINATE_AND_FINISH - The method activityFinished will always get called. And so the activity will always end in it's completed state. If the activity has not yet started the method activityStarted will also be called. TERMINATE_AND_FINISH_IF_STEPPING - The method activityFinished will only be called if the activity has previously started.- Parameters:
terminationBehavior- behavior to use regarding delegate notification and event firing
-
processStep
public long processStep(long currentTime) The activity scheduler calls this method and it is here that the activity decides if it should do a step or not for the given time.- Parameters:
currentTime- in global root time- Returns:
- number of milliseconds in global root time before processStep should be called again, -1 if never
-
getStopTime
public long getStopTime()Return the time when this activity should finish running. At this time (or soon after) the stoppedStepping method will be called- Returns:
- time at which this activity should be stopped
-
paramString
Deprecated.see http://code.google.com/p/piccolo2d/issues/detail?id=99- Returns:
- string representation of this activity
-