1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package mirrored_download;
|
---|
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.actions.JosmAction;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.Main;
|
---|
14 | import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask;
|
---|
15 | import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
|
---|
16 | import org.openstreetmap.josm.data.Bounds;
|
---|
17 | import org.openstreetmap.josm.gui.download.DownloadDialog;
|
---|
18 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Action that opens a connection to the osm server and downloads map data.
|
---|
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 DownloadAction2 extends JosmAction {
|
---|
29 | public DownloadAction2() {
|
---|
30 | super(tr("Download from OSM mirror..."), null, tr("Download map data from the OSM server."),
|
---|
31 | Shortcut.registerShortcut("mirror:download", tr("File: {0}", tr("Download from OSM mirror...")), KeyEvent.VK_DOWN, Shortcut.ALT_SHIFT),
|
---|
32 | true, "mirroreddownload/download", true);
|
---|
33 | putValue("help", ht("/Action/MirroredDownload"));
|
---|
34 | }
|
---|
35 |
|
---|
36 | public void actionPerformed(ActionEvent e) {
|
---|
37 | DownloadDialog dialog = DownloadDialog.getInstance();
|
---|
38 | dialog.restoreSettings();
|
---|
39 | dialog.setVisible(true);
|
---|
40 | if (! dialog.isCanceled()) {
|
---|
41 | dialog.rememberSettings();
|
---|
42 | Bounds area = dialog.getSelectedDownloadArea();
|
---|
43 | if (dialog.isDownloadOsmData()) {
|
---|
44 | DownloadOsmTask2 task = new DownloadOsmTask2();
|
---|
45 | Future<?> future = task.download(dialog.isNewLayerRequired(), area, null);
|
---|
46 | Main.worker.submit(new PostDownloadHandler(task, future));
|
---|
47 | }
|
---|
48 | if (dialog.isDownloadGpxData()) {
|
---|
49 | DownloadGpsTask task = new DownloadGpsTask();
|
---|
50 | Future<?> future = task.download(dialog.isNewLayerRequired(),area, null);
|
---|
51 | Main.worker.submit(new PostDownloadHandler(task, future));
|
---|
52 | }
|
---|
53 | }
|
---|
54 | }
|
---|
55 | }
|
---|