| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.actions;
|
|---|
| 3 |
|
|---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 5 |
|
|---|
| 6 | import java.awt.event.ActionEvent;
|
|---|
| 7 | import java.awt.event.KeyEvent;
|
|---|
| 8 | import java.util.concurrent.Future;
|
|---|
| 9 |
|
|---|
| 10 | import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesTask;
|
|---|
| 11 | import org.openstreetmap.josm.actions.downloadtasks.DownloadParams;
|
|---|
| 12 | import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
|
|---|
| 13 | import org.openstreetmap.josm.data.Bounds;
|
|---|
| 14 | import org.openstreetmap.josm.gui.MainApplication;
|
|---|
| 15 | import org.openstreetmap.josm.io.NetworkManager;
|
|---|
| 16 | import org.openstreetmap.josm.io.OnlineResource;
|
|---|
| 17 | import org.openstreetmap.josm.tools.Shortcut;
|
|---|
| 18 |
|
|---|
| 19 | /**
|
|---|
| 20 | * Action that downloads the notes within the current view from the server.
|
|---|
| 21 | *
|
|---|
| 22 | * No interaction is required.
|
|---|
| 23 | */
|
|---|
| 24 | public final class DownloadNotesInViewAction extends JosmAction {
|
|---|
| 25 |
|
|---|
| 26 | private DownloadNotesInViewAction(String iconName) {
|
|---|
| 27 | super(tr("Download notes in current view"), iconName, tr("Download notes in current view"),
|
|---|
| 28 | Shortcut.registerShortcut("file:downloadnotesinview",
|
|---|
| 29 | tr("File: {0}", tr("Download notes in current view")), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false,
|
|---|
| 30 | "dialogs/notes/download_in_view", true);
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | /**
|
|---|
| 34 | * Constructs a new {@code DownloadNotesInViewAction} with note icon.
|
|---|
| 35 | * @return a new {@code DownloadNotesInViewAction} with note icon
|
|---|
| 36 | */
|
|---|
| 37 | public static DownloadNotesInViewAction newActionWithNoteIcon() {
|
|---|
| 38 | return new DownloadNotesInViewAction("dialogs/notes/note_open");
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | /**
|
|---|
| 42 | * Constructs a new {@code DownloadNotesInViewAction} with download icon.
|
|---|
| 43 | * @return a new {@code DownloadNotesInViewAction} with download icon
|
|---|
| 44 | */
|
|---|
| 45 | public static DownloadNotesInViewAction newActionWithDownloadIcon() {
|
|---|
| 46 | return new DownloadNotesInViewAction("download_in_view");
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | @Override
|
|---|
| 50 | public void actionPerformed(ActionEvent e) {
|
|---|
| 51 | final Bounds bounds = MainApplication.getMap().mapView.getRealBounds();
|
|---|
| 52 | DownloadNotesTask task = new DownloadNotesTask();
|
|---|
| 53 | task.setZoomAfterDownload(false);
|
|---|
| 54 | Future<?> future = task.download(new DownloadParams(), bounds, null);
|
|---|
| 55 | MainApplication.worker.submit(new PostDownloadHandler(task, future));
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | @Override
|
|---|
| 59 | protected boolean listenToSelectionChange() {
|
|---|
| 60 | return false;
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | @Override
|
|---|
| 64 | protected void updateEnabledState() {
|
|---|
| 65 | setEnabled(getLayerManager().getActiveLayer() != null
|
|---|
| 66 | && !NetworkManager.isOffline(OnlineResource.OSM_API));
|
|---|
| 67 | }
|
|---|
| 68 | }
|
|---|