| 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;
|
|---|
| 13 | import org.openstreetmap.josm.gui.MainApplication;
|
|---|
| 14 | import org.openstreetmap.josm.io.BoundingBoxDownloader;
|
|---|
| 15 | import org.openstreetmap.josm.io.OnlineResource;
|
|---|
| 16 |
|
|---|
| 17 | /**
|
|---|
| 18 | * Action that downloads the OSM data within the current view from the server.
|
|---|
| 19 | *
|
|---|
| 20 | * No interaction is required.
|
|---|
| 21 | */
|
|---|
| 22 | public final class DownloadOsmInViewAction extends JosmAction {
|
|---|
| 23 |
|
|---|
| 24 | /**
|
|---|
| 25 | * Creates a new {@code DownloadOsmInViewAction}.
|
|---|
| 26 | */
|
|---|
| 27 | public DownloadOsmInViewAction() {
|
|---|
| 28 | super(tr("Download in current view"), "download_in_view", tr("Download map data from the OSM server in current view"), null, false,
|
|---|
| 29 | "dialogs/download_in_view", true);
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | @Override
|
|---|
| 33 | public void actionPerformed(ActionEvent e) {
|
|---|
| 34 | final Bounds bounds = MainApplication.getMap().mapView.getRealBounds();
|
|---|
| 35 | DownloadOsmInViewTask task = new DownloadOsmInViewTask();
|
|---|
| 36 | task.setZoomAfterDownload(false);
|
|---|
| 37 | Future<?> future = task.download(bounds);
|
|---|
| 38 | MainApplication.worker.submit(new PostDownloadHandler(task, future));
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | @Override
|
|---|
| 42 | protected void updateEnabledState() {
|
|---|
| 43 | setEnabled(getLayerManager().getActiveLayer() != null
|
|---|
| 44 | && !Main.isOffline(OnlineResource.OSM_API));
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | private static class DownloadOsmInViewTask extends DownloadOsmTask {
|
|---|
| 48 | Future<?> download(Bounds downloadArea) {
|
|---|
| 49 | return download(new DownloadTask(false, new BoundingBoxDownloader(downloadArea), null, false), downloadArea);
|
|---|
| 50 | }
|
|---|
| 51 | }
|
|---|
| 52 | }
|
|---|