Package examples
Class LoadImageTask
- java.lang.Object
-
- javax.swing.SwingWorker<T,V>
-
- org.jdesktop.application.Task<java.awt.image.BufferedImage,java.lang.Void>
-
- examples.LoadImageTask
-
- All Implemented Interfaces:
java.lang.Runnable,java.util.concurrent.Future<java.awt.image.BufferedImage>,java.util.concurrent.RunnableFuture<java.awt.image.BufferedImage>
public class LoadImageTask extends Task<java.awt.image.BufferedImage,java.lang.Void>
A Task that loads an image from a URL. Loading and decoding progress is reported via the Taskprogressproperty and messages are generated when the Task begins and when it finishes. If errors occur then warnings are logged and the Task's value is null.Applications would typically use LoadImageTask by creating a private subclass that overrode the
donemethod. See SingleFrameExample5.java for an example.Resources for this class are in the
resources/LoadImageTask.propertiesResourceBundle.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.jdesktop.application.Task
Task.BlockingScope, Task.InputBlocker
-
-
Constructor Summary
Constructors Constructor Description LoadImageTask(Application app, java.net.URL url)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcancelled()Called when this Task has been cancelled bySwingWorker.cancel(boolean).protected java.awt.image.BufferedImagedoInBackground()protected voidfailed(java.lang.Throwable e)Called when an execution of this Task fails and anExecutionExecptionis thrown byget.protected voidfinished()Called unconditionally (in afinallyclause) after one of the completion methods,succeeded,failed,cancelled, orinterrupted, runs.protected java.net.URLgetImageURL()protected voidinterrupted(java.lang.InterruptedException e)Called if the Task's Thread is interrupted but not explicitly cancelled.protected voidsucceeded(java.awt.image.BufferedImage image)Called when this Task has successfully completed, i.e.-
Methods inherited from class org.jdesktop.application.Task
addTaskListener, done, getApplication, getContext, getDescription, getExecutionDuration, getInputBlocker, getMessage, getMessageDuration, getResourceMap, getTaskListeners, getTaskService, getTitle, getUserCanCancel, isPending, isProgressPropertyValid, isStarted, message, process, removeTaskListener, resourceName, setDescription, setInputBlocker, setMessage, setProgress, setProgress, setProgress, setTitle, setUserCanCancel
-
-
-
-
Constructor Detail
-
LoadImageTask
public LoadImageTask(Application app, java.net.URL url)
-
-
Method Detail
-
getImageURL
protected final java.net.URL getImageURL()
-
doInBackground
protected java.awt.image.BufferedImage doInBackground()
- Specified by:
doInBackgroundin classjavax.swing.SwingWorker<java.awt.image.BufferedImage,java.lang.Void>
-
cancelled
protected void cancelled()
Description copied from class:TaskCalled when this Task has been cancelled bySwingWorker.cancel(boolean).This method runs on the EDT. It does nothing by default.
- Overrides:
cancelledin classTask<java.awt.image.BufferedImage,java.lang.Void>- See Also:
Task.done()
-
interrupted
protected void interrupted(java.lang.InterruptedException e)
Description copied from class:TaskCalled if the Task's Thread is interrupted but not explicitly cancelled.This method runs on the EDT. It does nothing by default.
- Overrides:
interruptedin classTask<java.awt.image.BufferedImage,java.lang.Void>- Parameters:
e- theInterruptedExceptionthrown byget- See Also:
SwingWorker.cancel(boolean),Task.done(),SwingWorker.get()
-
succeeded
protected void succeeded(java.awt.image.BufferedImage image)
Description copied from class:TaskCalled when this Task has successfully completed, i.e. when itsgetmethod returns a value. Tasks that compute a value should override this method.This method runs on the EDT. It does nothing by default.
- Overrides:
succeededin classTask<java.awt.image.BufferedImage,java.lang.Void>- Parameters:
image- the value returned by thegetmethod- See Also:
Task.done(),SwingWorker.get(),Task.failed(java.lang.Throwable)
-
failed
protected void failed(java.lang.Throwable e)
Description copied from class:TaskCalled when an execution of this Task fails and anExecutionExecptionis thrown byget.This method runs on the EDT. It Logs an error message by default.
- Overrides:
failedin classTask<java.awt.image.BufferedImage,java.lang.Void>- Parameters:
e- thecauseof theExecutionException- See Also:
Task.done(),SwingWorker.get(),Task.failed(java.lang.Throwable)
-
finished
protected void finished()
Description copied from class:TaskCalled unconditionally (in afinallyclause) after one of the completion methods,succeeded,failed,cancelled, orinterrupted, runs. Subclasses can override this method to cleanup before thedonemethod returns.This method runs on the EDT. It does nothing by default.
- Overrides:
finishedin classTask<java.awt.image.BufferedImage,java.lang.Void>- See Also:
Task.done(),SwingWorker.get(),Task.failed(java.lang.Throwable)
-
-