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

Last change on this file since 2476 was 2330, checked in by Gubaer, 15 years ago

fixed #3794: not download the correct area

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