de.matthiasmann.twl
Class Timer

java.lang.Object
  extended by de.matthiasmann.twl.Timer

public final class Timer
extends java.lang.Object

A timer class for UI timing - like auto scrolling.


Constructor Summary
Timer(GUI gui)
          Constructs a new timer
 
Method Summary
 boolean isContinuous()
          Returns true if the timer is a continous firing timer.
 boolean isRunning()
          Returns true if the timer is already running.
 void setCallback(java.lang.Runnable callback)
          Sets the callback that should be executed once the timer expires.
 void setContinuous(boolean continuous)
          Sets the timer continous mode.
 void setDelay(int delay)
          Sets the delay in ms till next expiration.
 void start()
          Starts the timer.
 void stop()
          Stops the timer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Timer

public Timer(GUI gui)
Constructs a new timer

Parameters:
gui - the GUI instance
Throws:
java.lang.NullPointerException - when gui is null
Method Detail

isRunning

public boolean isRunning()
Returns true if the timer is already running.

Returns:
true if the timer is already running.

setDelay

public void setDelay(int delay)
Sets the delay in ms till next expiration.

Parameters:
delay - in ms
Throws:
java.lang.IllegalArgumentException - if delay < 1 ms

start

public void start()
Starts the timer. If it is already running then this method does nothing.


stop

public void stop()
Stops the timer. If the timer is not running then this method does nothing.


setCallback

public void setCallback(java.lang.Runnable callback)
Sets the callback that should be executed once the timer expires.

Parameters:
callback - the callback.

isContinuous

public boolean isContinuous()
Returns true if the timer is a continous firing timer.

Returns:
true if the timer is a continous firing timer.

setContinuous

public void setContinuous(boolean continuous)
Sets the timer continous mode. A timer in continous mode must be stopped manually.

Parameters:
continuous - true if the timer should auto restart after firing.