Interface DownloadTask

All Known Implementing Classes:
AbstractChangesetDownloadTask, AbstractDownloadTask, ChangesetContentDownloadTask, ChangesetHeaderDownloadTask, ChangesetQueryTask, DownloadGeoJsonTask, DownloadGpsTask, DownloadNotesTask, DownloadNotesUrlBoundsTask, DownloadNotesUrlIdTask, DownloadOsmChangeTask, DownloadOsmIdTask, DownloadOsmInViewAction.DownloadOsmInViewTask, DownloadOsmTask, DownloadOsmUrlTask, DownloadSessionTask

public interface DownloadTask
Interface defining a general download task used to download geographic data (OSM data, GPX tracks, etc.) for a given URL or geographic area.
  • Method Details

    • download

      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

      Future<?> loadUrl(DownloadParams settings, 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:
    • acceptsUrl

      boolean acceptsUrl(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

      Returns a short HTML documentation string, describing acceptable URLs.
      Returns:
      The HTML documentation
      Since:
      6031
    • getTitle

      Returns human-readable description of the task
      Returns:
      The task description
      Since:
      6031
    • getPatterns

      Returns regular expressions that match the URLs
      Returns:
      The array of accepted URL patterns
      Since:
      6031
    • 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

      Replies the error messages of the task. Empty list, if no error messages are available.
      Returns:
      the list of error messages
      Since:
      17330
    • providesOldData

      default boolean providesOldData()
      If this task provides potentially old data, this should return true. If so, it would be a good decision to prompt users to verify if they want the data to be downloaded to the current layer.
      Returns:
      true if the data could be old.
      Since:
      19550
    • cancel

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

      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