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

Last change on this file since 411 was 411, checked in by gebner, 17 years ago

Free the download dialog after use. Patch by petr.nejedly@… in bug #432.

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 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 */
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
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 dialog = null;
70 dlg.dispose();
71 }
72}
Note: See TracBrowser for help on using the repository browser.