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