Package examples

Class 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 Task progress property 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 done method. See SingleFrameExample5.java for an example.

    Resources for this class are in the resources/LoadImageTask.properties ResourceBundle.

    • 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:
        doInBackground in class javax.swing.SwingWorker<java.awt.image.BufferedImage,​java.lang.Void>
      • cancelled

        protected void cancelled()
        Description copied from class: Task
        Called when this Task has been cancelled by SwingWorker.cancel(boolean).

        This method runs on the EDT. It does nothing by default.

        Overrides:
        cancelled in class Task<java.awt.image.BufferedImage,​java.lang.Void>
        See Also:
        Task.done()
      • interrupted

        protected void interrupted​(java.lang.InterruptedException e)
        Description copied from class: Task
        Called if the Task's Thread is interrupted but not explicitly cancelled.

        This method runs on the EDT. It does nothing by default.

        Overrides:
        interrupted in class Task<java.awt.image.BufferedImage,​java.lang.Void>
        Parameters:
        e - the InterruptedException thrown by get
        See Also:
        SwingWorker.cancel(boolean), Task.done(), SwingWorker.get()
      • succeeded

        protected void succeeded​(java.awt.image.BufferedImage image)
        Description copied from class: Task
        Called when this Task has successfully completed, i.e. when its get method returns a value. Tasks that compute a value should override this method.

        This method runs on the EDT. It does nothing by default.

        Overrides:
        succeeded in class Task<java.awt.image.BufferedImage,​java.lang.Void>
        Parameters:
        image - the value returned by the get method
        See Also:
        Task.done(), SwingWorker.get(), Task.failed(java.lang.Throwable)
      • failed

        protected void failed​(java.lang.Throwable e)
        Description copied from class: Task
        Called when an execution of this Task fails and an ExecutionExecption is thrown by get.

        This method runs on the EDT. It Logs an error message by default.

        Overrides:
        failed in class Task<java.awt.image.BufferedImage,​java.lang.Void>
        Parameters:
        e - the cause of the ExecutionException
        See Also:
        Task.done(), SwingWorker.get(), Task.failed(java.lang.Throwable)
      • finished

        protected void finished()
        Description copied from class: Task
        Called unconditionally (in a finally clause) after one of the completion methods, succeeded, failed, cancelled, or interrupted, runs. Subclasses can override this method to cleanup before the done method returns.

        This method runs on the EDT. It does nothing by default.

        Overrides:
        finished in class Task<java.awt.image.BufferedImage,​java.lang.Void>
        See Also:
        Task.done(), SwingWorker.get(), Task.failed(java.lang.Throwable)