1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.awt.event.KeyEvent;
|
---|
9 | import java.util.concurrent.Future;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.Main;
|
---|
12 | import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask;
|
---|
13 | import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
|
---|
14 | import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
|
---|
15 | import org.openstreetmap.josm.data.Bounds;
|
---|
16 | import org.openstreetmap.josm.gui.download.DownloadDialog;
|
---|
17 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Action that opens a connection to the osm server and downloads map data.
|
---|
21 | *
|
---|
22 | * An dialog is displayed asking the user to specify a rectangle to grab.
|
---|
23 | * The url and account settings from the preferences are used.
|
---|
24 | *
|
---|
25 | * @author imi
|
---|
26 | */
|
---|
27 | public class DownloadAction extends JosmAction {
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Constructs a new {@code DownloadAction}.
|
---|
31 | */
|
---|
32 | public DownloadAction() {
|
---|
33 | super(tr("Download from OSM..."), "download", tr("Download map data from the OSM server."),
|
---|
34 | Shortcut.registerShortcut("file:download", tr("File: {0}", tr("Download from OSM...")), KeyEvent.VK_DOWN, Shortcut.CTRL_SHIFT), true);
|
---|
35 | putValue("help", ht("/Action/Download"));
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | public void actionPerformed(ActionEvent e) {
|
---|
40 | DownloadDialog dialog = DownloadDialog.getInstance();
|
---|
41 | dialog.restoreSettings();
|
---|
42 | dialog.setVisible(true);
|
---|
43 | if (! dialog.isCanceled()) {
|
---|
44 | dialog.rememberSettings();
|
---|
45 | Bounds area = dialog.getSelectedDownloadArea();
|
---|
46 | if (dialog.isDownloadOsmData()) {
|
---|
47 | DownloadOsmTask task = new DownloadOsmTask();
|
---|
48 | Future<?> future = task.download(dialog.isNewLayerRequired(), area, null);
|
---|
49 | Main.worker.submit(new PostDownloadHandler(task, future));
|
---|
50 | }
|
---|
51 | if (dialog.isDownloadGpxData()) {
|
---|
52 | DownloadGpsTask task = new DownloadGpsTask();
|
---|
53 | Future<?> future = task.download(dialog.isNewLayerRequired(),area, null);
|
---|
54 | Main.worker.submit(new PostDownloadHandler(task, future));
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|