Package uk.ac.starlink.util.gui
Class Downloader<T>
java.lang.Object
uk.ac.starlink.util.gui.Downloader<T>
Manages downloading of data that only needs to be got once.
- Since:
- 13 Jun 2014
- Author:
- Mark Taylor
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addActionListener
(ActionListener listener) Adds a listener that will be notified if the data acquisition status changes.abstract T
Performs the actual download.void
Resets the state of this downloader, as if no download attempt had been made.Returns a little component that monitors status of this downloader.getData()
Immediately returns the downloaded data, or null if it has not been downloaded, or if a download has failed.boolean
Indicates whether the data has been downloaded.void
removeActionListener
(ActionListener listener) Removes a previously added listener.void
Sets the state of this downloader as if it had just downloaded the given data item.Downloads the data if necessary, and returns its content.
-
Constructor Details
-
Downloader
Constructor.- Parameters:
clazz
- type of data downloadeddataDescription
- short description of downloaded data, may be used in logging messages
-
-
Method Details
-
attemptReadData
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, thengetData()
will return the result.- Returns:
- true iff download has completed, successfully or otherwise
-
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 no download attempt had been made. -
setData
Sets the state of this downloader as if it had just downloaded the given data item. This can be necessary to restore its state, since it affects the monitor component.- Parameters:
value
- value that would have been downloaded
-
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
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
Adds a listener that will be notified if the data acquisition status changes.- Parameters:
listener
- listener
-
removeActionListener
Removes a previously added listener.- Parameters:
listener
- listener
-