net.sf.freecol.client.control
Class InGameInputHandler.SwingTask

java.lang.Object
  extended by net.sf.freecol.client.control.InGameInputHandler.SwingTask
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
InGameInputHandler.NoResultCanvasSwingTask, InGameInputHandler.ReconnectSwingTask, InGameInputHandler.ShowConfirmDialogSwingTask, InGameInputHandler.ShowInputDialogSwingTask, InGameInputHandler.ShowMessageSwingTask, InGameInputHandler.ShowMonarchPanelSwingTask, InGameInputHandler.ShowSelectSwingTask
Enclosing class:
InGameInputHandler

abstract static class InGameInputHandler.SwingTask
extends java.lang.Object
implements java.lang.Runnable

This utility class is the base class for tasks that need to run in the event dispatch thread.


Field Summary
private  java.lang.Object _result
           
private  boolean _started
           
private  boolean _synchronous
           
private static java.util.logging.Logger taskLogger
           
 
Constructor Summary
InGameInputHandler.SwingTask()
           
 
Method Summary
protected abstract  java.lang.Object doWork()
          Override this method to do the actual work.
 java.lang.Object getResult()
          Get the return vale from doWork().
 java.lang.Object invokeAndWait()
          Run the task and wait for it to complete.
 void invokeLater()
          Run the task at some later time.
 java.lang.Object invokeSpecial()
           
private  boolean isSynchronous()
          Check if the client is waiting.
private  void markDone()
          Mark finished.
private  void markStarted(boolean synchronous)
          Mark started and set the synchronous flag.
 void run()
          Run method, call doWork() and save the return value.
private  void setResult(java.lang.Object r)
          Save result.
private  void verifyNotStarted()
          Throw an exception if the task is started.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

taskLogger

private static final java.util.logging.Logger taskLogger

_result

private java.lang.Object _result

_synchronous

private boolean _synchronous

_started

private boolean _started
Constructor Detail

InGameInputHandler.SwingTask

InGameInputHandler.SwingTask()
Method Detail

invokeAndWait

public java.lang.Object invokeAndWait()
                               throws java.lang.reflect.InvocationTargetException
Run the task and wait for it to complete.

Returns:
return value from doWork().
Throws:
java.lang.reflect.InvocationTargetException - on unexpected exceptions.

invokeLater

public void invokeLater()
Run the task at some later time. Any exceptions will occur in the event dispatch thread. The return value will be set, but at present there is no good way to know if it is valid yet.


invokeSpecial

public java.lang.Object invokeSpecial()
                               throws java.lang.reflect.InvocationTargetException
Throws:
java.lang.reflect.InvocationTargetException

markStarted

private void markStarted(boolean synchronous)
Mark started and set the synchronous flag.

Parameters:
synchronous - The synch/asynch flag.

markDone

private void markDone()
Mark finished.


verifyNotStarted

private void verifyNotStarted()
Throw an exception if the task is started.


isSynchronous

private boolean isSynchronous()
Check if the client is waiting.

Returns:
true if client is waiting for a result.

run

public final void run()
Run method, call doWork() and save the return value. Also catch any exceptions. In synchronous mode they will be rethrown to the original thread, in asynchronous mode they will be logged and ignored. Nothing is gained by crashing the event dispatch thread.

Specified by:
run in interface java.lang.Runnable

getResult

public java.lang.Object getResult()
Get the return vale from doWork().

Returns:
result.

setResult

private void setResult(java.lang.Object r)
Save result.

Parameters:
r - The result.

doWork

protected abstract java.lang.Object doWork()
Override this method to do the actual work.

Returns:
result.