edu.umd.cs.piccolo.activities
Class PActivity

java.lang.Object
  extended by edu.umd.cs.piccolo.activities.PActivity
Direct Known Subclasses:
PInterpolatingActivity

public class PActivity
extends java.lang.Object

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
static interface PActivity.PActivityDelegate
          PActivityDelegate 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
static int TERMINATE_AND_FINISH
           
static int TERMINATE_AND_FINISH_IF_STEPPING
           
static int TERMINATE_WITHOUT_FINISHING
           
 
Constructor Summary
PActivity(long aDuration)
          Constructs a new PActivity.
PActivity(long aDuration, long aStepRate)
          Constructs a new PActivity.
PActivity(long aDuration, long aStepRate, long aStartTime)
          Constructs a new PActivity.
 
Method Summary
protected  void activityFinished()
          This method is called after an activity is has finished running and the activity has been removed from the PActivityScheduler queue.
protected  void activityStarted()
          This method is called right before an activity is scheduled to start running.
protected  void activityStep(long elapsedTime)
          This is the method that most activities override to perform their behavior.
 PActivityScheduler getActivityScheduler()
           
 PActivity.PActivityDelegate getDelegate()
          Get the delegate for this activity.
 long getDuration()
          Return the amount of time that this activity should take to complete, after the startStepping method is called.
 long getNextStepTime()
           
 long getStartTime()
          Return the time that this activity should start running in PRoot global time.
 long getStepRate()
          Return the amount of time that this activity should delay between steps.
 long getStopTime()
          Return the time when this activity should finish running.
protected  boolean isAnimation()
          Return true if this activity is performing an animation.
 boolean isStepping()
          Return true if this activity is stepping.
protected  java.lang.String paramString()
          Returns a string representing the state of this node.
 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.
 void setActivityScheduler(PActivityScheduler aScheduler)
           
 void setDelegate(PActivity.PActivityDelegate delegate)
          Set the delegate for this activity.
 void setDuration(long aDuration)
          Set the amount of time that this activity should take to complete, after the startStepping method is called.
 void setStartTime(long aTriggerTime)
          Set the time that this activity should start running in PRoot global time.
 void setStepRate(long aStepRate)
          Set the amount of time that this activity should delay between steps.
 void startAfter(PActivity first)
          Schedules this activity to start after the first activity has finished.
 void terminate()
          Stop this activity immediately, and remove it from the activity scheduler.
 void terminate(int terminationBehavior)
          Stop this activity immediately, and remove it from the activity scheduler.
 java.lang.String toString()
          Returns a string representation of this object for debugging purposes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TERMINATE_WITHOUT_FINISHING

public static final int TERMINATE_WITHOUT_FINISHING
See Also:
Constant Field Values

TERMINATE_AND_FINISH

public static final int TERMINATE_AND_FINISH
See Also:
Constant Field Values

TERMINATE_AND_FINISH_IF_STEPPING

public static final int TERMINATE_AND_FINISH_IF_STEPPING
See Also:
Constant Field Values
Constructor Detail

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 Detail

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.


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.


getStepRate

public long getStepRate()
Return the amount of time that this activity should delay between steps.


setStepRate

public void setStepRate(long aStepRate)
Set the amount of time that this activity should delay between steps.


getNextStepTime

public long getNextStepTime()

getDuration

public long getDuration()
Return the amount of time that this activity should take to complete, after the startStepping method is called.


setDuration

public void setDuration(long aDuration)
Set the amount of time that this activity should take to complete, after the startStepping method is called.


getActivityScheduler

public PActivityScheduler getActivityScheduler()

setActivityScheduler

public void setActivityScheduler(PActivityScheduler aScheduler)

isStepping

public boolean isStepping()
Return true if 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.


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

public PActivity.PActivityDelegate getDelegate()
Get the delegate for this activity. The delegate is notified when the activity starts and stops stepping.


setDelegate

public void setDelegate(PActivity.PActivityDelegate delegate)
Set the delegate for this activity. The delegate is notified when the activity starts and stops stepping.


startAfter

public void startAfter(PActivity first)
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.


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.


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.


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


toString

public java.lang.String toString()
Returns a string representation of this object for debugging purposes.

Overrides:
toString in class java.lang.Object

paramString

protected java.lang.String paramString()
Returns a string representing the state of this node. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

Returns:
a string representation of this node's state


Copyright 2005 by University of Maryland, College Park, MD 20742, USA All rights reserved.

Web Accessibility