[612] | 1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
| 2 | package org.openstreetmap.josm.actions;
|
---|
| 3 |
|
---|
[2327] | 4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
[612] | 5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 6 |
|
---|
| 7 | import java.awt.event.ActionEvent;
|
---|
| 8 | import java.awt.event.KeyEvent;
|
---|
[2322] | 9 | import java.util.concurrent.Future;
|
---|
[2330] | 10 | import java.util.logging.Logger;
|
---|
[612] | 11 |
|
---|
| 12 | import org.openstreetmap.josm.Main;
|
---|
[2327] | 13 | import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask;
|
---|
| 14 | import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
|
---|
[2322] | 15 | import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
|
---|
[2330] | 16 | import org.openstreetmap.josm.data.Bounds;
|
---|
[612] | 17 | import org.openstreetmap.josm.gui.download.DownloadDialog;
|
---|
[1084] | 18 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
[612] | 19 |
|
---|
| 20 | /**
|
---|
[655] | 21 | * Action that opens a connection to the osm server and downloads map data.
|
---|
[612] | 22 | *
|
---|
| 23 | * An dialog is displayed asking the user to specify a rectangle to grab.
|
---|
| 24 | * The url and account settings from the preferences are used.
|
---|
| 25 | *
|
---|
| 26 | * @author imi
|
---|
| 27 | */
|
---|
| 28 | public class DownloadAction extends JosmAction {
|
---|
[2990] | 29 | @SuppressWarnings("unused")
|
---|
[2330] | 30 | private static final Logger logger = Logger.getLogger(DownloadAction.class.getName());
|
---|
[2512] | 31 |
|
---|
[1169] | 32 | public DownloadAction() {
|
---|
[1212] | 33 | super(tr("Download from OSM..."), "download", tr("Download map data from the OSM server."),
|
---|
[1847] | 34 | Shortcut.registerShortcut("file:download", tr("File: {0}", tr("Download from OSM...")), KeyEvent.VK_D, Shortcut.GROUPS_ALT1+Shortcut.GROUP_HOTKEY), true);
|
---|
[2323] | 35 | putValue("help", ht("/Action/Download"));
|
---|
[1169] | 36 | }
|
---|
[612] | 37 |
|
---|
[2132] | 38 | public void actionPerformed(ActionEvent e) {
|
---|
[2331] | 39 | DownloadDialog dialog = DownloadDialog.getInstance();
|
---|
[2335] | 40 | dialog.restoreSettings();
|
---|
[2331] | 41 | dialog.setVisible(true);
|
---|
| 42 | if (! dialog.isCanceled()) {
|
---|
| 43 | dialog.rememberSettings();
|
---|
[2512] | 44 | Bounds area = dialog.getSelectedDownloadArea();
|
---|
[2331] | 45 | if (dialog.isDownloadOsmData()) {
|
---|
| 46 | DownloadOsmTask task = new DownloadOsmTask();
|
---|
| 47 | Future<?> future = task.download(dialog.isNewLayerRequired(), area, null);
|
---|
| 48 | Main.worker.submit(new PostDownloadHandler(task, future));
|
---|
[1847] | 49 | }
|
---|
[2331] | 50 | if (dialog.isDownloadGpxData()) {
|
---|
| 51 | DownloadGpsTask task = new DownloadGpsTask();
|
---|
| 52 | Future<?> future = task.download(dialog.isNewLayerRequired(),area, null);
|
---|
| 53 | Main.worker.submit(new PostDownloadHandler(task, future));
|
---|
[1847] | 54 | }
|
---|
[2512] | 55 | }
|
---|
| 56 | }
|
---|
[612] | 57 | }
|
---|