edu.umd.cs.piccolox.swt
Class SWTTimerQueue

java.lang.Object
  extended by edu.umd.cs.piccolox.swt.SWTTimerQueue
All Implemented Interfaces:
java.lang.Runnable

public class SWTTimerQueue
extends java.lang.Object
implements java.lang.Runnable

The SWTTimerQueue is a queue of timers. It has been implemented as a linked list of SWTTimer objects.

Author:
Lance Good

Nested Class Summary
protected static class SWTTimerQueue.SWTTimerQueueRestart
          Runnable that will message the shared instance of the Timer Queue to restart.
 
Constructor Summary
SWTTimerQueue(org.eclipse.swt.widgets.Display display)
          Creates a timer queue that will be attached the the provided display.
 
Method Summary
(package private)  void addTimer(SWTTimer timer, long expirationTime)
          Adds the provided timer to the queue of scheduled timers.
(package private)  boolean containsTimer(SWTTimer timer)
          Returns true if this timer queue contains the given timer.
(package private)  void removeTimer(SWTTimer timer)
          Removes the provided timer from the Timer Queue.
 void run()
          Dispatches work to timers until the queue is told to stop running.
static SWTTimerQueue sharedInstance(org.eclipse.swt.widgets.Display display)
          Returns the singleton instance of the SWTTimerQueue.
(package private)  void start()
          Starts the timer queue.
(package private)  void stop()
          Stops the TimerQueue Thread.
 java.lang.String toString()
          Generates a string handy for debugging the contents of the timer queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SWTTimerQueue

public SWTTimerQueue(org.eclipse.swt.widgets.Display display)
Creates a timer queue that will be attached the the provided display. It's Timers are expected to modify only this display, or none.

Parameters:
display - the display that will get updated by this queue's timers.
Method Detail

sharedInstance

public static SWTTimerQueue sharedInstance(org.eclipse.swt.widgets.Display display)
Returns the singleton instance of the SWTTimerQueue. Take note that even when called with different displays it will always return the same result as the first call.

Parameters:
display - display to associate with this Timer Queue's Activities
Returns:
singleton instance of SWTTimerQueue

start

void start()
Starts the timer queue. If it is already running, a RuntimeException will be thrown.


stop

void stop()
Stops the TimerQueue Thread.


addTimer

void addTimer(SWTTimer timer,
              long expirationTime)
Adds the provided timer to the queue of scheduled timers.

Parameters:
timer - timer to add
expirationTime - time at which the timer is to be stopped and removed from the queue. Given in unix time.

removeTimer

void removeTimer(SWTTimer timer)
Removes the provided timer from the Timer Queue. If it is not found, then nothing happens.

Parameters:
timer - timer to remove from the queue

containsTimer

boolean containsTimer(SWTTimer timer)
Returns true if this timer queue contains the given timer.

Parameters:
timer - timer being checked
Returns:
true if timer is scheduled in this queue

run

public void run()
Dispatches work to timers until the queue is told to stop running.

Specified by:
run in interface java.lang.Runnable

toString

public java.lang.String toString()
Generates a string handy for debugging the contents of the timer queue.

Overrides:
toString in class java.lang.Object
Returns:
String representation of the queue for use in debugging


Copyright © 1995-2011 Piccolo2D. All Rights Reserved.