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

Last change on this file since 16509 was 16509, checked in by GerdP, 5 years ago

see #19296: Actions should avoid to install listeners which are not needed

  • either don't call installAdapters() or overwrite listenToSelectionChange()
  • partly reverts previous changes so that installAdapters() is not overwritten

One has to be careful because installAdapters() also calls initEnabledState()

File size: 2.1 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.actions.downloadtasks.DownloadOsmTask;
10import org.openstreetmap.josm.actions.downloadtasks.DownloadParams;
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.NetworkManager;
16import 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 */
23public 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}
Note: See TracBrowser for help on using the repository browser.