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.InputEvent;
|
---|
9 | import java.awt.event.KeyEvent;
|
---|
10 |
|
---|
11 | import javax.swing.JDialog;
|
---|
12 | import javax.swing.JOptionPane;
|
---|
13 | import javax.swing.JPanel;
|
---|
14 |
|
---|
15 | import org.openstreetmap.josm.Main;
|
---|
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 |
|
---|
20 | /**
|
---|
21 | * Action that opens a connection to the osm server and download 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."), KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK, true);
|
---|
34 | }
|
---|
35 |
|
---|
36 | public void actionPerformed(ActionEvent e) {
|
---|
37 | dialog = new DownloadDialog();
|
---|
38 |
|
---|
39 | JPanel downPanel = new JPanel(new GridBagLayout());
|
---|
40 | downPanel.add(dialog, GBC.eol().fill(GBC.BOTH));
|
---|
41 |
|
---|
42 | JOptionPane pane = new JOptionPane(downPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
|
---|
43 | JDialog dlg = pane.createDialog(Main.parent, tr("Download"));
|
---|
44 |
|
---|
45 | if (dlg.getWidth() > 1000)
|
---|
46 | dlg.setSize(1000, dlg.getHeight());
|
---|
47 | if (dlg.getHeight() > 600)
|
---|
48 | dlg.setSize(dlg.getWidth(),600);
|
---|
49 |
|
---|
50 | boolean finish = false;
|
---|
51 | while (!finish) {
|
---|
52 | dlg.setVisible(true);
|
---|
53 | Main.pref.put("download.newlayer", dialog.newLayer.isSelected());
|
---|
54 | if (pane.getValue() instanceof Integer && (Integer)pane.getValue() == JOptionPane.OK_OPTION) {
|
---|
55 | Main.pref.put("download.tab", Integer.toString(dialog.getSelectedTab()));
|
---|
56 | for (DownloadTask task : dialog.downloadTasks) {
|
---|
57 | Main.pref.put("download."+task.getPreferencesSuffix(), task.getCheckBox().isSelected());
|
---|
58 | if (task.getCheckBox().isSelected()) {
|
---|
59 | task.download(this, dialog.minlat, dialog.minlon, dialog.maxlat, dialog.maxlon);
|
---|
60 | finish = true;
|
---|
61 | }
|
---|
62 | }
|
---|
63 | } else
|
---|
64 | finish = true;
|
---|
65 | if (!finish)
|
---|
66 | JOptionPane.showMessageDialog(Main.parent, tr("Please select at least one task to download"));
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|