source: josm/trunk/src/org/openstreetmap/josm/actions/DownloadNotesInViewAction.java@ 10063

Last change on this file since 10063 was 9276, checked in by simon04, 8 years ago

fix #12283 - Download notes in current view: fix NPE

  • Property svn:eol-style set to native
File size: 1.7 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.DownloadNotesTask;
11import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
12import org.openstreetmap.josm.data.Bounds;
13import org.openstreetmap.josm.io.OnlineResource;
14
15/**
16 * Action that downloads the notes within the current view from the server.
17 *
18 * No interaction is required.
19 */
20public final class DownloadNotesInViewAction extends JosmAction {
21
22 private DownloadNotesInViewAction(String iconName) {
23 super(tr("Download notes in current view"), iconName, tr("Download notes in current view"), null, false,
24 "dialogs/notes/download_in_view", true);
25 }
26
27 public static DownloadNotesInViewAction newActionWithNoteIcon() {
28 return new DownloadNotesInViewAction("dialogs/notes/note_open");
29 }
30
31 public static DownloadNotesInViewAction newActionWithDownloadIcon() {
32 return new DownloadNotesInViewAction("download");
33 }
34
35 @Override
36 public void actionPerformed(ActionEvent e) {
37 final Bounds bounds = Main.map.mapView.getRealBounds();
38 DownloadNotesTask task = new DownloadNotesTask();
39 Future<?> future = task.download(false, bounds, null);
40 Main.worker.submit(new PostDownloadHandler(task, future));
41 }
42
43 @Override
44 protected void updateEnabledState() {
45 setEnabled(Main.isDisplayingMapView()
46 && Main.map.mapView.getActiveLayer() != null
47 && !Main.isOffline(OnlineResource.OSM_API));
48 }
49}
Note: See TracBrowser for help on using the repository browser.