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.download.DownloadDialog;
|
---|
16 | import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask;
|
---|
17 | import org.openstreetmap.josm.tools.GBC;
|
---|
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 DownloadAction extends JosmAction {
|
---|
29 |
|
---|
30 | public DownloadDialog dialog;
|
---|
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: Download"), KeyEvent.VK_D, ShortCut.GROUPS_ALT1+ShortCut.GROUP_HOTKEY), true);
|
---|
35 | }
|
---|
36 |
|
---|
37 | public void actionPerformed(ActionEvent e) {
|
---|
38 | dialog = new DownloadDialog();
|
---|
39 |
|
---|
40 | JPanel downPanel = new JPanel(new GridBagLayout());
|
---|
41 | downPanel.add(dialog, GBC.eol().fill(GBC.BOTH));
|
---|
42 |
|
---|
43 | JOptionPane pane = new JOptionPane(downPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
|
---|
44 | JDialog dlg = pane.createDialog(Main.parent, tr("Download"));
|
---|
45 | dlg.setResizable(true);
|
---|
46 | dialog.setOptionPane(pane);
|
---|
47 |
|
---|
48 | if (dlg.getWidth() > 1000)
|
---|
49 | dlg.setSize(1000, dlg.getHeight());
|
---|
50 | if (dlg.getHeight() > 600)
|
---|
51 | dlg.setSize(dlg.getWidth(),600);
|
---|
52 |
|
---|
53 | boolean finish = false;
|
---|
54 | while (!finish) {
|
---|
55 | dlg.setVisible(true);
|
---|
56 | Main.pref.put("download.newlayer", dialog.newLayer.isSelected());
|
---|
57 | if (pane.getValue() instanceof Integer && (Integer)pane.getValue() == JOptionPane.OK_OPTION) {
|
---|
58 | Main.pref.put("download.tab", Integer.toString(dialog.getSelectedTab()));
|
---|
59 | for (DownloadTask task : dialog.downloadTasks) {
|
---|
60 | Main.pref.put("download."+task.getPreferencesSuffix(), task.getCheckBox().isSelected());
|
---|
61 | if (task.getCheckBox().isSelected()) {
|
---|
62 | task.download(this, dialog.minlat, dialog.minlon, dialog.maxlat, dialog.maxlon);
|
---|
63 | finish = true;
|
---|
64 | }
|
---|
65 | }
|
---|
66 | } else
|
---|
67 | finish = true;
|
---|
68 | if (!finish)
|
---|
69 | JOptionPane.showMessageDialog(Main.parent, tr("Please select at least one task to download"));
|
---|
70 | }
|
---|
71 |
|
---|
72 | dialog = null;
|
---|
73 | dlg.dispose();
|
---|
74 | }
|
---|
75 | }
|
---|