public class DownloadOsmTask extends AbstractDownloadTask
| Modifier and Type | Class and Description |
|---|---|
protected class |
DownloadOsmTask.DownloadTask |
| Modifier and Type | Field and Description |
|---|---|
protected Bounds |
currentBounds |
protected DataSet |
downloadedData |
protected DownloadOsmTask.DownloadTask |
downloadTask |
protected String |
newLayerName |
private static String |
PATTERN_EXTERNAL_OSM_FILE |
private static String |
PATTERN_OSM_API_URL |
private static String |
PATTERN_OVERPASS_API_URL |
private static String |
PATTERN_OVERPASS_API_XAPI_URL |
protected OsmDataLayer |
targetLayer |
| Constructor and Description |
|---|
DownloadOsmTask() |
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Cancels the asynchronous download task.
|
Future<?> |
download(boolean newLayer,
Bounds downloadArea,
ProgressMonitor progressMonitor)
Asynchronously launches the download task for a given bounding box.
|
protected Future<?> |
download(DownloadOsmTask.DownloadTask downloadTask,
Bounds downloadArea) |
Future<?> |
download(OsmServerReader reader,
boolean newLayer,
Bounds downloadArea,
ProgressMonitor progressMonitor)
Asynchronously launches the download task for a given bounding box.
|
protected String |
encodePartialUrl(String url,
String safePart) |
protected void |
extractOsmFilename(String pattern,
String url) |
String |
getConfirmationMessage(URL url)
Replies the HTML-formatted confirmation message to be shown to user when the given URL needs to be confirmed before loading.
|
DataSet |
getDownloadedData()
Replies the
DataSet containing the downloaded OSM data. |
String[] |
getPatterns()
Returns regular expressions that match the URLs
|
String |
getTitle()
Returns human-readable description of the task
|
Future<?> |
loadUrl(boolean new_layer,
String url,
ProgressMonitor progressMonitor)
Loads a given URL from the OSM Server
|
protected void |
rememberDownloadedData(DataSet ds) |
acceptsDocumentationSummary, acceptsUrl, getErrorObjects, isCanceled, isFailed, rememberErrorMessage, rememberException, setCanceled, setFailedprivate static final String PATTERN_OSM_API_URL
private static final String PATTERN_OVERPASS_API_URL
private static final String PATTERN_OVERPASS_API_XAPI_URL
private static final String PATTERN_EXTERNAL_OSM_FILE
protected Bounds currentBounds
protected DataSet downloadedData
protected DownloadOsmTask.DownloadTask downloadTask
protected OsmDataLayer targetLayer
protected String newLayerName
public DownloadOsmTask()
public String[] getPatterns()
DownloadTaskgetPatterns in interface DownloadTaskgetPatterns in class AbstractDownloadTaskpublic String getTitle()
DownloadTaskgetTitle in interface DownloadTaskgetTitle in class AbstractDownloadTaskprotected void rememberDownloadedData(DataSet ds)
public DataSet getDownloadedData()
DataSet containing the downloaded OSM data.DataSet containing the downloaded OSM data.public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor)
DownloadTaskprogressMonitor 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();
}
}
Main.worker.submit(runAfterTask);
newLayer - true, if the data is to be downloaded into a new layer. If false, the task
selects one of the existing layers as download layer, preferably the active layer.downloadArea - the area to downloadprogressMonitor - the progressMonitorpublic Future<?> download(OsmServerReader reader, boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor)
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();
}
}
Main.worker.submit(runAfterTask);
reader - the reader used to parse OSM data (see OsmServerReader.parseOsm(org.openstreetmap.josm.gui.progress.ProgressMonitor))newLayer - true, if the data is to be downloaded into a new layer. If false, the task
selects one of the existing layers as download layer, preferably the active layer.downloadArea - the area to downloadprogressMonitor - the progressMonitorprotected Future<?> download(DownloadOsmTask.DownloadTask downloadTask, Bounds downloadArea)
protected final String encodePartialUrl(String url, String safePart)
public Future<?> loadUrl(boolean new_layer, String url, ProgressMonitor progressMonitor)
new_layer - True if the data should be saved to a new layerurl - The URL as StringprogressMonitor - the progressMonitorDownloadTask.download(boolean, Bounds, ProgressMonitor)protected final void extractOsmFilename(String pattern, String url)
public void cancel()
DownloadTaskpublic String getConfirmationMessage(URL url)
DownloadTaskurl - The URL to be confirmed