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

Last change on this file since 2001 was 1847, checked in by Gubaer, 15 years ago

replaced calls to JOptionPane.* by calls to OptionPaneUtil.*

  • Property svn:eol-style set to native
File size: 3.1 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.OptionPaneUtil;
16import org.openstreetmap.josm.gui.download.DownloadDialog;
17import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask;
18import org.openstreetmap.josm.tools.GBC;
19import org.openstreetmap.josm.tools.Shortcut;
20
21/**
22 * Action that opens a connection to the osm server and downloads map data.
23 *
24 * An dialog is displayed asking the user to specify a rectangle to grab.
25 * The url and account settings from the preferences are used.
26 *
27 * @author imi
28 */
29public class DownloadAction extends JosmAction {
30
31 public DownloadDialog dialog;
32
33 public DownloadAction() {
34 super(tr("Download from OSM..."), "download", tr("Download map data from the OSM server."),
35 Shortcut.registerShortcut("file:download", tr("File: {0}", tr("Download from OSM...")), KeyEvent.VK_D, Shortcut.GROUPS_ALT1+Shortcut.GROUP_HOTKEY), true);
36 }
37
38 public void actionPerformed(ActionEvent e) {
39 dialog = new DownloadDialog();
40
41 JPanel downPanel = new JPanel(new GridBagLayout());
42 downPanel.add(dialog, GBC.eol().fill(GBC.BOTH));
43
44 JOptionPane pane = new JOptionPane(downPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
45 JDialog dlg = pane.createDialog(Main.parent, tr("Download"));
46 dlg.setResizable(true);
47 dialog.setOptionPane(pane);
48
49 if (dlg.getWidth() > 1000) {
50 dlg.setSize(1000, dlg.getHeight());
51 }
52 if (dlg.getHeight() > 600) {
53 dlg.setSize(dlg.getWidth(),600);
54 }
55
56 boolean finish = false;
57 while (!finish) {
58 dlg.setVisible(true);
59 Main.pref.put("download.newlayer", dialog.newLayer.isSelected());
60 if (pane.getValue() instanceof Integer && (Integer)pane.getValue() == JOptionPane.OK_OPTION) {
61 Main.pref.put("download.tab", Integer.toString(dialog.getSelectedTab()));
62 for (DownloadTask task : dialog.downloadTasks) {
63 Main.pref.put("download."+task.getPreferencesSuffix(), task.getCheckBox().isSelected());
64 if (task.getCheckBox().isSelected()) {
65 task.download(this, dialog.minlat, dialog.minlon, dialog.maxlat, dialog.maxlon, null);
66 finish = true;
67 }
68 }
69 } else {
70 finish = true;
71 }
72 if (!finish) {
73 OptionPaneUtil.showMessageDialog(
74 Main.parent,
75 tr("Please select at least one task to download"),
76 tr("Error"),
77 JOptionPane.ERROR_MESSAGE
78 );
79 }
80 }
81
82 dialog = null;
83 dlg.dispose();
84 }
85}
Note: See TracBrowser for help on using the repository browser.