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

Last change on this file since 1169 was 1169, checked in by stoecker, 15 years ago

removed usage of tab stops

  • Property svn:eol-style set to native
File size: 2.8 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.KeyEvent;
9
10import javax.swing.JDialog;
11import javax.swing.JOptionPane;
12import javax.swing.JPanel;
13
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.gui.download.DownloadDialog;
16import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask;
17import org.openstreetmap.josm.tools.GBC;
18import 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 */
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."),
34 Shortcut.registerShortcut("file:download", tr("File: {0}", tr("Download from OSM ...")), 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}
Note: See TracBrowser for help on using the repository browser.