|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread acm.util.Animator
public class Animator
This class extends Thread
to provide several features that make it
easier to build animations. These features include a pause
method that does not raise an exception and a requestTermination
method that signals that the execution of this thread should stop at its
next opportunity. It also includes hooks to support a start/stop/single-step
model for algorithm animation.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
Thread.State, Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
static int |
CALLING
Constant indicating that the animator is running until the end of the current call. |
static int |
FINISHED
Constant indicating that the animator has finished its run method. |
static int |
INITIAL
Constant indicating that the animator has not yet started. |
static int |
RUNNING
Constant indicating that the animator is running. |
static int |
STEPPING
Constant indicating that the animator is running in single-step mode. |
static int |
STOPPED
Constant indicating that the animator is suspended waiting for restart. |
static int |
STOPPING
Constant indicating that the animator should stop at the next trace point. |
static int |
TERMINATING
Constant indicating that the animator has been asked to terminate. |
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
Animator()
Creates a new Animator object. |
|
Animator(Runnable runnable)
Creates a new Animator object with the specified runnable object. |
|
Animator(ThreadGroup group)
Creates a new Animator object and assigns it to the
specified thread group. |
|
Animator(ThreadGroup group,
Runnable runnable)
Creates a new Animator object with the specified runnable object
and assigns it to the specified thread group. |
Method Summary | |
---|---|
protected void |
breakHook()
This method is called before the animator executes a breakpoint. |
void |
breakpoint()
Suspends the animator until one of the restart actions is triggered. |
boolean |
buttonAction(String actionCommand)
Triggers an action for the action specified by the action command. |
void |
callAction()
Triggers a "call" action, as if the Call button
is pushed. |
void |
checkForTermination()
Checks to see whether this Animator has been asked
to terminate. |
protected void |
controllerHook()
This method is called before the animator changes state in a way that might interest a controller. |
void |
delay()
Delays the calling thread according to the speed. |
protected void |
delayHook()
This method is called before the animator enters a timing delay. |
int |
getAnimatorState()
Returns the state of the animator. |
double |
getSpeed()
Returns the speed parameter for the animator. |
Component |
getSpeedBar()
Returns the speed bar for the animator, if any. |
void |
pause(double milliseconds)
Delays this thread for the specified time, which is expressed in milliseconds. |
void |
registerSpeedBar(JScrollBar scrollBar)
Registers the specified scroll bar as the delay controller for the animator. |
void |
registerSpeedBar(JSlider slider)
Registers the specified slider as the delay controller for the animator. |
void |
requestTermination()
Signals the Animator that it should stop running at the
next available opportunity, which is when the client next calls
pause or checkForTermination . |
protected void |
resumeHook()
This method is called before the animator starts or restarts after a breakpoint. |
void |
run()
Specifies the code for the animator. |
void |
setSpeed(double speed)
Sets the speed parameter for the animator. |
static void |
shutdown(Applet applet)
Destroys all animator threads started by the specified applet. |
void |
start()
Starts the thread. |
void |
startAction()
Triggers a "start" action, as if the Start button
is pushed. |
void |
stepAction()
Triggers a "step" action, as if the Step button
is pushed. |
void |
stopAction()
Triggers a "stop" action, as if the Stop button
is pushed. |
void |
trace()
Checks the state of the animator and executes any actions have been requested. |
void |
trace(int depth)
Checks the state of the animator and executes any actions have been requested to occur at the specified call stack depth. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int CALLING
public static final int FINISHED
run
method.
public static final int INITIAL
public static final int RUNNING
public static final int STEPPING
public static final int STOPPED
public static final int STOPPING
public static final int TERMINATING
Constructor Detail |
---|
public Animator()
Animator
object.
public Animator(Runnable runnable)
Animator
object with the specified runnable object.
runnable
- Any object that implements the Runnable
interfacepublic Animator(ThreadGroup group)
Animator
object and assigns it to the
specified thread group.
group
- The ThreadGroup
to which the new thread is assignedpublic Animator(ThreadGroup group, Runnable runnable)
Animator
object with the specified runnable object
and assigns it to the specified thread group.
group
- The ThreadGroup
to which the new thread is assignedrunnable
- Any object that implements the Runnable
interfaceMethod Detail |
---|
protected void breakHook()
public void breakpoint()
public boolean buttonAction(String actionCommand)
actionCommand
- The action command from the button
true
if the action command is recognizedpublic void callAction()
"call"
action, as if the Call
button
is pushed.
public void checkForTermination()
Animator
has been asked
to terminate. If so, the Animator
stops running,
and the call never returns. If not, other threads are given a
chance to run, after which this Animator
will return
to the caller.
protected void controllerHook()
public void delay()
protected void delayHook()
public int getAnimatorState()
INITIAL
,
RUNNING
,
STEPPING
,
CALLING
,
STOPPING
,
STOPPED
,
FINISHED
, or
TERMINATING
,
as defined in this class.
public double getSpeed()
double
between 0.0 and 1.0, for which 0.0 is very slow and 1.0 is as fast as the
system can manage.
public Component getSpeedBar()
JSlider
or a JScrollBar
; it is the caller's
responsibility to cast the result to the appropriate class.
null
if none existspublic void pause(double milliseconds)
Thread.sleep
, this method never
throws an exception.
milliseconds
- The sleep time in millisecondspublic void registerSpeedBar(JScrollBar scrollBar)
scrollBar
- The scroll bar which will serve as the speed bar for this animatorpublic void registerSpeedBar(JSlider slider)
slider
- The slider which will serve as the speed bar for this animatorpublic void requestTermination()
Animator
that it should stop running at the
next available opportunity, which is when the client next calls
pause
or checkForTermination
. Making this
check at well-managed times makes it possible for the client to
ensure that objects are left in a consistent state and thereby
avoids the problems that led Sun to deprecate Thread.stop
.
protected void resumeHook()
public void run()
run
in interface Runnable
run
in class Thread
public void setSpeed(double speed)
double
between 0.0 and 1.0, for which 0.0 is very slow and 1.0 is as fast as the
system can manage.
speed
- A double between 0.0 (slow) and 1.0 (fast)public static void shutdown(Applet applet)
applet
- The applet that is ending its executionpublic void start()
start
in class Thread
public void startAction()
"start"
action, as if the Start
button
is pushed.
public void stepAction()
"step"
action, as if the Step
button
is pushed.
public void stopAction()
"stop"
action, as if the Stop
button
is pushed.
public void trace()
public void trace(int depth)
Call
button functionality.
depth
- The current call stack depth.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |