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

Last change on this file since 11713 was 10910, checked in by Don-vip, 8 years ago

improve javadoc, unit tests, reduce visibility of some public fields

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 Future<?> future = task.download(bounds);
36 Main.worker.submit(new PostDownloadHandler(task, future));
37 }
38
39 @Override
40 protected void updateEnabledState() {
41 setEnabled(Main.getLayerManager().getActiveLayer() != null
42 && !Main.isOffline(OnlineResource.OSM_API));
43 }
44
45 private static class DownloadOsmInViewTask extends DownloadOsmTask {
46 Future<?> download(Bounds downloadArea) {
47 return download(new DownloadTask(false, new BoundingBoxDownloader(downloadArea), null, false), downloadArea);
48 }
49 }
50}
Note: See TracBrowser for help on using the repository browser.