Class DataLoader

java.lang.Object
   |
   +----DataLoader

public class DataLoader
extends Object
implements Runnable
This class is used to load the text data for TextScroll in an asynchronous way. It will also apply the automatic line wrapping to the data. It provides a refresh() method which can be used to force this DataLoader to reload the data from the URL it was given when it was constructed.


Variable Index

 o VERSION
The current version of this class.

Constructor Index

 o DataLoader(URL, Font, int)
Constructor.
 o DataLoader(URL, Font, int, boolean)
Constructor.

Method Index

 o dataReady()
Method for determining when the data has arrived.
 o errorOccurred()
Method for determining if an error has occurred.
 o getData()
Method for getting the actual data.
 o refresh()
This method is called to reload the data from the URL.
 o run()
This method actually loads the data.
 o start()
Method called when the thread is started.
 o stop()
Method called to terminate the Thread.

Variables

 o VERSION
 public static final String VERSION
The current version of this class.

Constructors

 o DataLoader
 public DataLoader(URL url,
                   Font startingFont,
                   int width)
Constructor. It expects the URL of the data file to load from. The constructed DataLoader will apply line wrapping to the retrieved data.

Parameters:
url - The URL to load the data from.
startingFont - The starting Font, used for line wrapping.
width - The width of the starting font, use for line wrapping.
 o DataLoader
 public DataLoader(URL url,
                   Font startingFont,
                   int width,
                   boolean shouldWrap)
Constructor. It expects the URL of the data file to load from. It returns immediately.

Parameters:
url - The URL to load the data from.
startingFont - The starting Font, used for line wrapping.
width - The width of the starting font, use for line wrapping.
shouldWrap - A boolean indicating whether or not this DataLoader should apply line wrapping or not.

Methods

 o refresh
 public void refresh()
This method is called to reload the data from the URL. It returns immediately. It performs automatic line wrapping based on the width and Font given in the constructor.

 o run
 public void run()
This method actually loads the data. It sets the internal flags appropriately, such that calls to dataReady() and errorOccurred will always return correct information.

 o stop
 public void stop()
Method called to terminate the Thread.

 o start
 public void start()
Method called when the thread is started.

 o dataReady
 public boolean dataReady()
Method for determining when the data has arrived.

Returns:
true if the data is ready, false otherwise.
 o errorOccurred
 public boolean errorOccurred()
Method for determining if an error has occurred.

Returns:
true if an error occurred, and the data is never going to arrive, false if no error has occurred.
 o getData
 public String[] getData()
Method for getting the actual data. If it hasn't arrived yet, this method returns null.

Returns:
The array of Strings which are the data, if it is here, or null if it is still loading or if an error occurred.