[10816] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.actions;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
| 6 | import java.awt.event.ActionEvent;
|
---|
| 7 | import java.util.concurrent.Future;
|
---|
| 8 |
|
---|
| 9 | import org.openstreetmap.josm.Main;
|
---|
| 10 | import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
|
---|
| 11 | import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
|
---|
| 12 | import org.openstreetmap.josm.data.Bounds;
|
---|
[10848] | 13 | import org.openstreetmap.josm.io.BoundingBoxDownloader;
|
---|
[10816] | 14 | import org.openstreetmap.josm.io.OnlineResource;
|
---|
| 15 |
|
---|
| 16 | /**
|
---|
| 17 | * Action that downloads the OSM data within the current view from the server.
|
---|
| 18 | *
|
---|
| 19 | * No interaction is required.
|
---|
| 20 | */
|
---|
| 21 | public final class DownloadOsmInViewAction extends JosmAction {
|
---|
| 22 |
|
---|
| 23 | /**
|
---|
| 24 | * Creates a new {@code DownloadOsmInViewAction}.
|
---|
| 25 | */
|
---|
| 26 | public DownloadOsmInViewAction() {
|
---|
| 27 | super(tr("Download in current view"), "download_in_view", tr("Download map data from the OSM server in current view"), null, false,
|
---|
| 28 | "dialogs/download_in_view", true);
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | @Override
|
---|
| 32 | public void actionPerformed(ActionEvent e) {
|
---|
| 33 | final Bounds bounds = Main.map.mapView.getRealBounds();
|
---|
[10848] | 34 | DownloadOsmInViewTask task = new DownloadOsmInViewTask();
|
---|
[11743] | 35 | task.setZoomAfterDownload(false);
|
---|
[10848] | 36 | Future<?> future = task.download(bounds);
|
---|
[10816] | 37 | Main.worker.submit(new PostDownloadHandler(task, future));
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | @Override
|
---|
| 41 | protected void updateEnabledState() {
|
---|
| 42 | setEnabled(Main.getLayerManager().getActiveLayer() != null
|
---|
| 43 | && !Main.isOffline(OnlineResource.OSM_API));
|
---|
| 44 | }
|
---|
[10848] | 45 |
|
---|
| 46 | private static class DownloadOsmInViewTask extends DownloadOsmTask {
|
---|
[10910] | 47 | Future<?> download(Bounds downloadArea) {
|
---|
[10848] | 48 | return download(new DownloadTask(false, new BoundingBoxDownloader(downloadArea), null, false), downloadArea);
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
[10816] | 51 | }
|
---|