source: josm/trunk/src/org/openstreetmap/josm/actions/DownloadOsmInViewAction.java@ 12225

Last change on this file since 12225 was 11743, checked in by Don-vip, 7 years ago

fix #13922 - make sure Download*InViewAction download their respective data without changing the current view

File size: 1.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.util.concurrent.Future;
8
9import org.openstreetmap.josm.Main;
10import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
11import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
12import org.openstreetmap.josm.data.Bounds;
13import org.openstreetmap.josm.io.BoundingBoxDownloader;
14import 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 */
21public 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();
34 DownloadOsmInViewTask task = new DownloadOsmInViewTask();
35 task.setZoomAfterDownload(false);
36 Future<?> future = task.download(bounds);
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 }
45
46 private static class DownloadOsmInViewTask extends DownloadOsmTask {
47 Future<?> download(Bounds downloadArea) {
48 return download(new DownloadTask(false, new BoundingBoxDownloader(downloadArea), null, false), downloadArea);
49 }
50 }
51}
Note: See TracBrowser for help on using the repository browser.