1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.GridBagLayout;
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.awt.event.KeyEvent;
|
---|
9 |
|
---|
10 | import javax.swing.JDialog;
|
---|
11 | import javax.swing.JOptionPane;
|
---|
12 | import javax.swing.JPanel;
|
---|
13 |
|
---|
14 | import org.openstreetmap.josm.Main;
|
---|
15 | import org.openstreetmap.josm.gui.OptionPaneUtil;
|
---|
16 | import org.openstreetmap.josm.gui.download.DownloadDialog;
|
---|
17 | import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask;
|
---|
18 | import org.openstreetmap.josm.tools.GBC;
|
---|
19 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Action that opens a connection to the osm server and downloads map data.
|
---|
23 | *
|
---|
24 | * An dialog is displayed asking the user to specify a rectangle to grab.
|
---|
25 | * The url and account settings from the preferences are used.
|
---|
26 | *
|
---|
27 | * @author imi
|
---|
28 | */
|
---|
29 | public class DownloadAction extends JosmAction {
|
---|
30 |
|
---|
31 | public DownloadDialog dialog;
|
---|
32 |
|
---|
33 | public DownloadAction() {
|
---|
34 | super(tr("Download from OSM..."), "download", tr("Download map data from the OSM server."),
|
---|
35 | Shortcut.registerShortcut("file:download", tr("File: {0}", tr("Download from OSM...")), KeyEvent.VK_D, Shortcut.GROUPS_ALT1+Shortcut.GROUP_HOTKEY), true);
|
---|
36 | }
|
---|
37 |
|
---|
38 | public void actionPerformed(ActionEvent e) {
|
---|
39 | dialog = new DownloadDialog();
|
---|
40 |
|
---|
41 | JPanel downPanel = new JPanel(new GridBagLayout());
|
---|
42 | downPanel.add(dialog, GBC.eol().fill(GBC.BOTH));
|
---|
43 |
|
---|
44 | JOptionPane pane = new JOptionPane(downPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
|
---|
45 | JDialog dlg = pane.createDialog(Main.parent, tr("Download"));
|
---|
46 | dlg.setResizable(true);
|
---|
47 | dialog.setOptionPane(pane);
|
---|
48 |
|
---|
49 | if (dlg.getWidth() > 1000) {
|
---|
50 | dlg.setSize(1000, dlg.getHeight());
|
---|
51 | }
|
---|
52 | if (dlg.getHeight() > 600) {
|
---|
53 | dlg.setSize(dlg.getWidth(),600);
|
---|
54 | }
|
---|
55 |
|
---|
56 | boolean finish = false;
|
---|
57 | while (!finish) {
|
---|
58 | dlg.setVisible(true);
|
---|
59 | Main.pref.put("download.newlayer", dialog.newLayer.isSelected());
|
---|
60 | if (pane.getValue() instanceof Integer && (Integer)pane.getValue() == JOptionPane.OK_OPTION) {
|
---|
61 | Main.pref.put("download.tab", Integer.toString(dialog.getSelectedTab()));
|
---|
62 | for (DownloadTask task : dialog.downloadTasks) {
|
---|
63 | Main.pref.put("download."+task.getPreferencesSuffix(), task.getCheckBox().isSelected());
|
---|
64 | if (task.getCheckBox().isSelected()) {
|
---|
65 | task.download(this, dialog.minlat, dialog.minlon, dialog.maxlat, dialog.maxlon, null);
|
---|
66 | finish = true;
|
---|
67 | }
|
---|
68 | }
|
---|
69 | } else {
|
---|
70 | finish = true;
|
---|
71 | }
|
---|
72 | if (!finish) {
|
---|
73 | OptionPaneUtil.showMessageDialog(
|
---|
74 | Main.parent,
|
---|
75 | tr("Please select at least one task to download"),
|
---|
76 | tr("Error"),
|
---|
77 | JOptionPane.ERROR_MESSAGE
|
---|
78 | );
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | dialog = null;
|
---|
83 | dlg.dispose();
|
---|
84 | }
|
---|
85 | }
|
---|