Interface DownloadTask

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default java.lang.String acceptsDocumentationSummary()
      Returns a short HTML documentation string, describing acceptable URLs.
      boolean acceptsUrl​(java.lang.String url, boolean isRemotecontrol)
      Returns true if the task is able to open the given URL, false otherwise.
      void cancel()
      Cancels the asynchronous download task.
      java.util.concurrent.Future<?> download​(DownloadParams settings, Bounds downloadArea, ProgressMonitor progressMonitor)
      Asynchronously launches the download task for a given bounding box.
      java.lang.String getConfirmationMessage​(java.net.URL url)
      Replies the HTML-formatted confirmation message to be shown to user when the given URL needs to be confirmed before loading.
      default java.util.List<java.lang.String> getErrorMessages()
      Replies the error messages of the task.
      java.util.List<java.lang.Object> getErrorObjects()
      Replies the error objects of the task.
      java.lang.String[] getPatterns()
      Returns regular expressions that match the URLs
      java.lang.String getTitle()
      Returns human-readable description of the task
      java.util.concurrent.Future<?> loadUrl​(DownloadParams settings, java.lang.String url, ProgressMonitor progressMonitor)
      Asynchronously launches the download task for a given bounding URL.
      void setZoomAfterDownload​(boolean zoomAfterDownload)
      Sets whether the map view will zoom to download area after download
    • Method Detail

      • download

        java.util.concurrent.Future<?> download​(DownloadParams settings,
                                                Bounds downloadArea,
                                                ProgressMonitor progressMonitor)
        Asynchronously launches the download task for a given bounding box.

        Set progressMonitor to null, if the task should create, open, and close a progress monitor. Set progressMonitor to NullProgressMonitor.INSTANCE if progress information is to be discarded.

        You can wait for the asynchronous download task to finish by synchronizing on the returned Future, but make sure not to freeze up JOSM. Example:

            Future<?> future = task.download(...);
            // DON'T run this on the Swing EDT or JOSM will freeze
            future.get(); // waits for the dowload task to complete
         
        The following example uses a pattern which is better suited if a task is launched from the Swing EDT:
            final Future<?> future = task.download(...);
            Runnable runAfterTask = new Runnable() {
               public void run() {
                   // this is not strictly necessary because of the type of executor service
                   // Main.worker is initialized with, but it doesn't harm either
                   //
                   future.get(); // wait for the download task to complete
                   doSomethingAfterTheTaskCompleted();
               }
            }
            MainApplication.worker.submit(runAfterTask);
         
        Parameters:
        settings - download settings
        downloadArea - the area to download
        progressMonitor - the progressMonitor
        Returns:
        the future representing the asynchronous task
        Since:
        13927
      • loadUrl

        java.util.concurrent.Future<?> loadUrl​(DownloadParams settings,
                                               java.lang.String url,
                                               ProgressMonitor progressMonitor)
        Asynchronously launches the download task for a given bounding URL.

        Set progressMonitor to null, if the task should create, open, and close a progress monitor. Set progressMonitor to NullProgressMonitor.INSTANCE if progress information is to be discarded.

        Parameters:
        settings - download settings
        url - the url to download from
        progressMonitor - the progressMonitor
        Returns:
        the future representing the asynchronous task
        Since:
        13927
        See Also:
        download(DownloadParams, Bounds, ProgressMonitor)
      • acceptsUrl

        boolean acceptsUrl​(java.lang.String url,
                           boolean isRemotecontrol)
        Returns true if the task is able to open the given URL, false otherwise.
        Parameters:
        url - the url to download from
        isRemotecontrol - True if download request comes from remotecontrol.
        Returns:
        True if the task is able to open the given URL, false otherwise. Return false, if the request comes from remotecontrol, but the task is not safe for remotecontrol. A task is not safe for remotecontrol if it is possible to prepare a file for download which does something unintended, e.g. gain access to the local file system.
      • acceptsDocumentationSummary

        default java.lang.String acceptsDocumentationSummary()
        Returns a short HTML documentation string, describing acceptable URLs.
        Returns:
        The HTML documentation
        Since:
        6031
      • getTitle

        java.lang.String getTitle()
        Returns human-readable description of the task
        Returns:
        The task description
        Since:
        6031
      • getPatterns

        java.lang.String[] getPatterns()
        Returns regular expressions that match the URLs
        Returns:
        The array of accepted URL patterns
        Since:
        6031
      • getErrorObjects

        java.util.List<java.lang.Object> getErrorObjects()
        Replies the error objects of the task. Empty list, if no error messages are available.

        Error objects are either Strings with error messages or Exceptions.

        Returns:
        the list of error objects
      • getErrorMessages

        default java.util.List<java.lang.String> getErrorMessages()
        Replies the error messages of the task. Empty list, if no error messages are available.
        Returns:
        the list of error messages
        Since:
        17330
      • cancel

        void cancel()
        Cancels the asynchronous download task.
      • getConfirmationMessage

        java.lang.String getConfirmationMessage​(java.net.URL url)
        Replies the HTML-formatted confirmation message to be shown to user when the given URL needs to be confirmed before loading.
        Parameters:
        url - The URL to be confirmed
        Returns:
        The HTML-formatted confirmation message to be shown to user
        Since:
        5691
      • setZoomAfterDownload

        void setZoomAfterDownload​(boolean zoomAfterDownload)
        Sets whether the map view will zoom to download area after download
        Parameters:
        zoomAfterDownload - if true, the map view will zoom to download area after download
        Since:
        13261