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

Last change on this file since 242 was 242, checked in by imi, 17 years ago
  • fixed many java warnings
  • changed eclipse settings to use JUnit library instead of (deprecated) environment variable
File size: 2.1 KB
Line 
1package org.openstreetmap.josm.actions;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.awt.GridBagLayout;
6import java.awt.event.ActionEvent;
7import java.awt.event.InputEvent;
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;
18
19/**
20 * Action that opens a connection to the osm server and download map data.
21 *
22 * An dialog is displayed asking the user to specify a rectangle to grab.
23 * The url and account settings from the preferences are used.
24 *
25 * @author imi
26 */
27public class DownloadAction extends JosmAction {
28
29 public DownloadDialog dialog;
30
31 public DownloadAction() {
32 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);
33 }
34
35 public void actionPerformed(ActionEvent e) {
36 dialog = new DownloadDialog(Integer.parseInt(Main.pref.get("download.tab", "0")));
37
38 JPanel downPanel = new JPanel(new GridBagLayout());
39 downPanel.add(dialog, GBC.eol().fill(GBC.BOTH));
40
41 JOptionPane pane = new JOptionPane(downPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
42 JDialog dlg = pane.createDialog(Main.parent, tr("Download"));
43
44 if (dlg.getWidth() > 1000)
45 dlg.setSize(1000, dlg.getHeight());
46 if (dlg.getHeight() > 600)
47 dlg.setSize(dlg.getWidth(),600);
48
49 dlg.setVisible(true);
50 if (pane.getValue() instanceof Integer && (Integer)pane.getValue() == JOptionPane.OK_OPTION) {
51 Main.pref.put("download.tab", Integer.toString(dialog.getSelectedTab()));
52 for (DownloadTask task : dialog.downloadTasks) {
53 Main.pref.put("download."+task.getPreferencesSuffix(), task.getCheckBox().isSelected());
54 if (task.getCheckBox().isSelected()) {
55 task.download(this, dialog.minlat, dialog.minlon, dialog.maxlat, dialog.maxlon);
56 }
57 }
58 }
59 }
60}
Note: See TracBrowser for help on using the repository browser.