fable.thread
Class FableThread

java.lang.Object
  extended by java.lang.Thread
      extended by fable.thread.FableThread
All Implemented Interfaces:
FableListener, FeedDeletedListener, FolderDeletedListener, java.lang.Runnable, java.util.EventListener

public class FableThread
extends java.lang.Thread
implements FeedDeletedListener, FolderDeletedListener

FableThread is a thread that is used in Fable. It executes a series of Runnable(s) linearly.

FableThread can execute both normal Runnables, which is sync'ed with the parent SWT thread, as well as Non-GUI tasks, that are usually slow, that are not sync'ed with the GUI.

FableThread recognizes FableNonGUITask(s) as non-GUI tasks and all other runnable objects as GUI tasks.

FableThread is a daemon and terminates when the program stops.

Author:
Christopher Moh
Specification Fields :
tasksToDo Sequential list of tasks to do

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
FableThread(Display display)
          Creates a new FableThread.
 
Method Summary
 void addTask(java.lang.Runnable newTask, FableComponent parentComponent)
          Adds a task to the list of tasks needed to do
 void feedDeleted(FeedDeletedEvent fde)
          Do appropriate action according to the event.
 void folderDeleted(FolderDeletedEvent fde)
          Do appropriate action according to the event.
 boolean hasTasks()
          Checks if this thread still has tasks to do
 void run()
          Starts the execution of the Thread
 void stopThread()
          Stops the thread
 
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, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FableThread

public FableThread(Display display)
Creates a new FableThread. Because this is an SWT thread, there needs to be a link to the parent display

Parameters:
display - Display of the SWT GUI
Requires:
display != null
Effects:
Creates a new FableThread
Modifies:
this
Method Detail

run

public void run()
Starts the execution of the Thread

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

stopThread

public void stopThread()
Stops the thread


addTask

public void addTask(java.lang.Runnable newTask,
                    FableComponent parentComponent)
Adds a task to the list of tasks needed to do

Parameters:
newTask - New task to add
parentComponent - The parent component in the GUI (Folder or Feed) that this task adds to
Requires:
newTask, parentComponent != null
Effects:
Adds newTask to the end of tasksToDo
Modifies:
tasksToDo

hasTasks

public boolean hasTasks()
Checks if this thread still has tasks to do

Returns:
true if it still has tasks, false otherwise

feedDeleted

public void feedDeleted(FeedDeletedEvent fde)
Description copied from interface: FeedDeletedListener
Do appropriate action according to the event.

Specified by:
feedDeleted in interface FeedDeletedListener
Parameters:
fde - an event object contains relevant information about the event.

folderDeleted

public void folderDeleted(FolderDeletedEvent fde)
Description copied from interface: FolderDeletedListener
Do appropriate action according to the event.

Specified by:
folderDeleted in interface FolderDeletedListener
Parameters:
fde - an event object contains relevant information about the event.