source: josm/trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadTask.java@ 5691

Last change on this file since 5691 was 5691, checked in by Don-vip, 11 years ago

see #8148 - Remote control: URL validation in import handler + find suitable download tasks + dynamic width of confirmation dialog box

  • Property svn:eol-style set to native
File size: 4.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions.downloadtasks;
3
4import java.net.URL;
5import java.util.List;
6import java.util.concurrent.Future;
7
8import org.openstreetmap.josm.data.Bounds;
9import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
10import org.openstreetmap.josm.gui.progress.ProgressMonitor;
11
12/**
13 * Interface defining a general download task used to download geographic data (OSM data, GPX tracks, etc.) for a given URL or geographic area.
14 */
15public interface DownloadTask {
16
17 /**
18 * Asynchronously launches the download task for a given bounding box.
19 *
20 * Set <code>progressMonitor</code> to null, if the task should create, open, and close a progress monitor.
21 * Set progressMonitor to {@link NullProgressMonitor#INSTANCE} if progress information is to
22 * be discarded.
23 *
24 * You can wait for the asynchronous download task to finish by synchronizing on the returned
25 * {@link Future}, but make sure not to freeze up JOSM. Example:
26 * <pre>
27 * Future<?> future = task.download(...);
28 * // DON'T run this on the Swing EDT or JOSM will freeze
29 * future.get(); // waits for the dowload task to complete
30 * </pre>
31 *
32 * The following example uses a pattern which is better suited if a task is launched from
33 * the Swing EDT:
34 * <pre>
35 * final Future<?> future = task.download(...);
36 * Runnable runAfterTask = new Runnable() {
37 * public void run() {
38 * // this is not strictly necessary because of the type of executor service
39 * // Main.worker is initialized with, but it doesn't harm either
40 * //
41 * future.get(); // wait for the download task to complete
42 * doSomethingAfterTheTaskCompleted();
43 * }
44 * }
45 * Main.worker.submit(runAfterTask);
46 * </pre>
47 *
48 * @param newLayer true, if the data is to be downloaded into a new layer. If false, the task
49 * selects one of the existing layers as download layer, preferably the active layer.
50 *
51 * @param downloadArea the area to download
52 * @param progressMonitor the progressMonitor
53 * @return the future representing the asynchronous task
54 */
55 Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor);
56
57 /**
58 * Asynchronously launches the download task for a given bounding URL.
59 *
60 * Set progressMonitor to null, if the task should create, open, and close a progress monitor.
61 * Set progressMonitor to {@link NullProgressMonitor#INSTANCE} if progress information is to
62 * be discarded.
63
64 * @param newLayer newLayer true, if the data is to be downloaded into a new layer. If false, the task
65 * selects one of the existing layers as download layer, preferably the active layer.
66 * @param url the url to download from
67 * @param progressMonitor the progressMonitor
68 * @return the future representing the asynchronous task
69 *
70 * @see #download(boolean, Bounds, ProgressMonitor)
71 */
72 Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor);
73
74 /**
75 * Returns true if the task is able to open the given URL, false otherwise.
76 * @param url the url to download from
77 * @return True if the task is able to open the given URL, false otherwise.
78 */
79 boolean acceptsUrl(String url);
80
81 /**
82 * Replies the error objects of the task. Empty list, if no error messages are available.
83 *
84 * Error objects are either {@link String}s with error messages or {@link Exception}s.
85 *
86 * @return the list of error objects
87 */
88 List<Object> getErrorObjects();
89
90 /**
91 * Cancels the asynchronous download task.
92 *
93 */
94 public void cancel();
95
96 /**
97 * Replies the HTML-formatted confirmation message to be shown to user when the given URL needs to be confirmed before loading.
98 * @param url The URL to be confirmed
99 * @return The HTML-formatted confirmation message to be shown to user
100 * @since
101 */
102 public String getConfirmationMessage(URL url);
103}
Note: See TracBrowser for help on using the repository browser.