uk.ac.starlink.util.gui
Class Downloader<T>

java.lang.Object
  extended by uk.ac.starlink.util.gui.Downloader<T>

public abstract class Downloader<T>
extends Object

Manages downloading of data that only needs to be got once.

Since:
13 Jun 2014
Author:
Mark Taylor

Constructor Summary
Downloader(Class<T> clazz, String dataDescription)
          Constructor.
 
Method Summary
 void addActionListener(ActionListener listener)
          Adds a listener that will be notified if the data acquisition status changes.
abstract  T attemptReadData()
          Performs the actual download.
 void clearData()
          Resets the state of this downloader, as if the no download attempt had been made.
 JComponent createMonitorComponent()
          Returns a little component that monitors status of this downloader.
 T getData()
          Immediately returns the downloaded data, or null if it has not been downloaded, or if a download has failed.
 boolean isComplete()
          Indicates whether the data has been downloaded.
 void removeActionListener(ActionListener listener)
          Removes a previously added listener.
 T waitForData()
          Downloads the data if necessary, and returns its content.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Downloader

public Downloader(Class<T> clazz,
                  String dataDescription)
Constructor.

Parameters:
clazz - type of data downloaded
dataDescription - short description of downloaded data, may be used in logging messages
Method Detail

attemptReadData

public abstract T attemptReadData()
                           throws IOException
Performs the actual download. Implementations are encouraged to log query and details of success if applicable at the INFO level, but an error will be logged by the Downloader.

Returns:
downloaded data
Throws:
IOException

isComplete

public boolean isComplete()
Indicates whether the data has been downloaded. If this method returns true, then getData() will return the result.

Returns:
true iff download has completed, successfully or otherwise

getData

public T getData()
Immediately returns the downloaded data, or null if it has not been downloaded, or if a download has failed.

Returns:
data

clearData

public void clearData()
Resets the state of this downloader, as if the no download attempt had been made.


waitForData

public T waitForData()
Downloads the data if necessary, and returns its content. If a download attempt has already been completed, this will return immediately, otherwise it will block. If the download failed, null will be returned.

Returns:
data or null on failure

createMonitorComponent

public JComponent createMonitorComponent()
Returns a little component that monitors status of this downloader. Currently, it is blank before the download has happened, then turns to green on success or red on failure.


addActionListener

public void addActionListener(ActionListener listener)
Adds a listener that will be notified if the data acquisition status changes.

Parameters:
listener - listener

removeActionListener

public void removeActionListener(ActionListener listener)
Removes a previously added listener.

Parameters:
listener - listener


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.