uk.ac.starlink.table.gui
Class LoadWorker

java.lang.Object
  |
  +--uk.ac.starlink.table.gui.LoadWorker

public abstract class LoadWorker
extends Object

Handles asynchronous table loading. In conjunction with a TableConsumer, this can be used to ensure that a table is loaded out of the event dispatch thread, so that the GUI remains responsive during what might potentially be a slow load process.

To use it, implement the abstract attemptLoad() method to load a table, and then call invoke() from the event dispatch thread. This will cause a table to be loaded asynchronously and the TableConsumer to be notified accordingly.

It will often be convenient to extend and use this via an anonymous class. For example:

     final String location = getFileName();
     new LoadWorker( tableEater, location ) {
         protected StarTable attemptLoad() throws IOException {
             return new StarTableFactory().makeStarTable( location );
         }
     }.invoke();
 

Since:
29 Nov 2004

Constructor Summary
LoadWorker(TableConsumer eater, String id)
          Constructor for a loader which will attempt to feed a loaded table to a given consumer.
 
Method Summary
protected abstract  StarTable attemptLoad()
          Performs a table load.
 void invoke()
          Causes the attemptLoad() method to be called from a new thread, and notifies the table consumer accordingly.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LoadWorker

public LoadWorker(TableConsumer eater,
                  String id)
Constructor for a loader which will attempt to feed a loaded table to a given consumer.

Parameters:
eater - table consumer which will be notified about the table load process
id - string identifier for the table such as its filename. This may be used in messages to the user
Method Detail

attemptLoad

protected abstract StarTable attemptLoad()
                                  throws IOException
Performs a table load. This method will be invoked from a thread other than the event dispatch thread. It is permitted to return null from this method, but throwing an exception is preferred if the requested table cannot be loaded.

Returns:
loaded table
Throws:
IOException - if something goes wrong

invoke

public void invoke()
Causes the attemptLoad() method to be called from a new thread, and notifies the table consumer accordingly. This method may only be invoked once for each instance of this class. It should be invoked from the event dispatch thread (and will execute quickly).


Copyright © 2004 CLRC: Central Laboratory of the Research Councils. All rights reserved.