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

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

see #15182 - deprecate Main.getLayerManager(). Replacement: gui.MainApplication.getLayerManager()

File size: 1.9 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.gui.MainApplication;
14import org.openstreetmap.josm.io.BoundingBoxDownloader;
15import 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 */
22public 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}
Note: See TracBrowser for help on using the repository browser.