source: josm/trunk/src/org/openstreetmap/josm/actions/DownloadAction.java@ 729

Last change on this file since 729 was 655, checked in by ramack, 16 years ago

patch by bruce89, closes #812; thanks bruce

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.GridBagLayout;
7import java.awt.event.ActionEvent;
8import java.awt.event.InputEvent;
9import java.awt.event.KeyEvent;
10
11import javax.swing.JDialog;
12import javax.swing.JOptionPane;
13import javax.swing.JPanel;
14
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.gui.download.DownloadDialog;
17import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask;
18import org.openstreetmap.josm.tools.GBC;
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 */
28public 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 dialog.setOptionPane(pane);
45
46 if (dlg.getWidth() > 1000)
47 dlg.setSize(1000, dlg.getHeight());
48 if (dlg.getHeight() > 600)
49 dlg.setSize(dlg.getWidth(),600);
50
51 boolean finish = false;
52 while (!finish) {
53 dlg.setVisible(true);
54 Main.pref.put("download.newlayer", dialog.newLayer.isSelected());
55 if (pane.getValue() instanceof Integer && (Integer)pane.getValue() == JOptionPane.OK_OPTION) {
56 Main.pref.put("download.tab", Integer.toString(dialog.getSelectedTab()));
57 for (DownloadTask task : dialog.downloadTasks) {
58 Main.pref.put("download."+task.getPreferencesSuffix(), task.getCheckBox().isSelected());
59 if (task.getCheckBox().isSelected()) {
60 task.download(this, dialog.minlat, dialog.minlon, dialog.maxlat, dialog.maxlon);
61 finish = true;
62 }
63 }
64 } else
65 finish = true;
66 if (!finish)
67 JOptionPane.showMessageDialog(Main.parent, tr("Please select at least one task to download"));
68 }
69
70 dialog = null;
71 dlg.dispose();
72 }
73}
Note: See TracBrowser for help on using the repository browser.