[8212] | 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.util.concurrent.Future;
|
---|
| 8 |
|
---|
| 9 | import org.openstreetmap.josm.Main;
|
---|
| 10 | import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesTask;
|
---|
| 11 | import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
|
---|
| 12 | import org.openstreetmap.josm.data.Bounds;
|
---|
[12630] | 13 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
[8212] | 14 | import org.openstreetmap.josm.io.OnlineResource;
|
---|
| 15 |
|
---|
| 16 | /**
|
---|
| 17 | * Action that downloads the notes within the current view from the server.
|
---|
| 18 | *
|
---|
| 19 | * No interaction is required.
|
---|
| 20 | */
|
---|
[8419] | 21 | public final class DownloadNotesInViewAction extends JosmAction {
|
---|
[8212] | 22 |
|
---|
| 23 | private DownloadNotesInViewAction(String iconName) {
|
---|
[8663] | 24 | super(tr("Download notes in current view"), iconName, tr("Download notes in current view"), null, false,
|
---|
| 25 | "dialogs/notes/download_in_view", true);
|
---|
[8212] | 26 | }
|
---|
| 27 |
|
---|
[11743] | 28 | /**
|
---|
| 29 | * Constructs a new {@code DownloadNotesInViewAction} with note icon.
|
---|
| 30 | * @return a new {@code DownloadNotesInViewAction} with note icon
|
---|
| 31 | */
|
---|
[8212] | 32 | public static DownloadNotesInViewAction newActionWithNoteIcon() {
|
---|
| 33 | return new DownloadNotesInViewAction("dialogs/notes/note_open");
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[11743] | 36 | /**
|
---|
| 37 | * Constructs a new {@code DownloadNotesInViewAction} with download icon.
|
---|
| 38 | * @return a new {@code DownloadNotesInViewAction} with download icon
|
---|
| 39 | */
|
---|
[8212] | 40 | public static DownloadNotesInViewAction newActionWithDownloadIcon() {
|
---|
| 41 | return new DownloadNotesInViewAction("download");
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | @Override
|
---|
| 45 | public void actionPerformed(ActionEvent e) {
|
---|
[12630] | 46 | final Bounds bounds = MainApplication.getMap().mapView.getRealBounds();
|
---|
[8212] | 47 | DownloadNotesTask task = new DownloadNotesTask();
|
---|
[11743] | 48 | task.setZoomAfterDownload(false);
|
---|
[8212] | 49 | Future<?> future = task.download(false, bounds, null);
|
---|
[12634] | 50 | MainApplication.worker.submit(new PostDownloadHandler(task, future));
|
---|
[8212] | 51 | }
|
---|
| 52 |
|
---|
| 53 | @Override
|
---|
| 54 | protected void updateEnabledState() {
|
---|
[12636] | 55 | setEnabled(getLayerManager().getActiveLayer() != null
|
---|
[9276] | 56 | && !Main.isOffline(OnlineResource.OSM_API));
|
---|
[8212] | 57 | }
|
---|
| 58 | }
|
---|