| [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;
|
|---|
| [17049] | 7 | import java.awt.event.KeyEvent;
|
|---|
| [10816] | 8 | import java.util.concurrent.Future;
|
|---|
| 9 |
|
|---|
| 10 | import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
|
|---|
| [13927] | 11 | import org.openstreetmap.josm.actions.downloadtasks.DownloadParams;
|
|---|
| [10816] | 12 | import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
|
|---|
| 13 | import org.openstreetmap.josm.data.Bounds;
|
|---|
| [12630] | 14 | import org.openstreetmap.josm.gui.MainApplication;
|
|---|
| [10848] | 15 | import org.openstreetmap.josm.io.BoundingBoxDownloader;
|
|---|
| [14121] | 16 | import org.openstreetmap.josm.io.NetworkManager;
|
|---|
| [10816] | 17 | import org.openstreetmap.josm.io.OnlineResource;
|
|---|
| [17049] | 18 | import org.openstreetmap.josm.tools.Shortcut;
|
|---|
| [10816] | 19 |
|
|---|
| 20 | /**
|
|---|
| 21 | * Action that downloads the OSM data within the current view from the server.
|
|---|
| 22 | *
|
|---|
| 23 | * No interaction is required.
|
|---|
| 24 | */
|
|---|
| 25 | public final class DownloadOsmInViewAction extends JosmAction {
|
|---|
| 26 |
|
|---|
| 27 | /**
|
|---|
| 28 | * Creates a new {@code DownloadOsmInViewAction}.
|
|---|
| 29 | */
|
|---|
| 30 | public DownloadOsmInViewAction() {
|
|---|
| [17049] | 31 | super(tr("Download in current view"), "download_in_view", tr("Download map data from the OSM server in current view"),
|
|---|
| 32 | Shortcut.registerShortcut("file:downloadosminview",
|
|---|
| [17052] | 33 | tr("File: {0}", tr("Download in current view")), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false,
|
|---|
| [10816] | 34 | "dialogs/download_in_view", true);
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | @Override
|
|---|
| 38 | public void actionPerformed(ActionEvent e) {
|
|---|
| [12630] | 39 | final Bounds bounds = MainApplication.getMap().mapView.getRealBounds();
|
|---|
| [10848] | 40 | DownloadOsmInViewTask task = new DownloadOsmInViewTask();
|
|---|
| [11743] | 41 | task.setZoomAfterDownload(false);
|
|---|
| [10848] | 42 | Future<?> future = task.download(bounds);
|
|---|
| [12634] | 43 | MainApplication.worker.submit(new PostDownloadHandler(task, future));
|
|---|
| [10816] | 44 | }
|
|---|
| 45 |
|
|---|
| 46 | @Override
|
|---|
| [16509] | 47 | protected boolean listenToSelectionChange() {
|
|---|
| 48 | return false;
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | @Override
|
|---|
| [10816] | 52 | protected void updateEnabledState() {
|
|---|
| [12636] | 53 | setEnabled(getLayerManager().getActiveLayer() != null
|
|---|
| [14121] | 54 | && !NetworkManager.isOffline(OnlineResource.OSM_API));
|
|---|
| [10816] | 55 | }
|
|---|
| [10848] | 56 |
|
|---|
| 57 | private static class DownloadOsmInViewTask extends DownloadOsmTask {
|
|---|
| [10910] | 58 | Future<?> download(Bounds downloadArea) {
|
|---|
| [13927] | 59 | return download(new DownloadTask(new DownloadParams(), new BoundingBoxDownloader(downloadArea), null, false), downloadArea);
|
|---|
| [10848] | 60 | }
|
|---|
| 61 | }
|
|---|
| [10816] | 62 | }
|
|---|