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

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

removed OptionPaneUtil
cleanup of deprecated Layer API
cleanup of deprecated APIs in OsmPrimitive and Way
cleanup of imports

  • Property svn:eol-style set to native
File size: 3.0 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 }
51 if (dlg.getHeight() > 600) {
52 dlg.setSize(dlg.getWidth(),600);
53 }
54
55 boolean finish = false;
56 while (!finish) {
57 dlg.setVisible(true);
58 Main.pref.put("download.newlayer", dialog.newLayer.isSelected());
59 if (pane.getValue() instanceof Integer && (Integer)pane.getValue() == JOptionPane.OK_OPTION) {
60 Main.pref.put("download.tab", Integer.toString(dialog.getSelectedTab()));
61 for (DownloadTask task : dialog.downloadTasks) {
62 Main.pref.put("download."+task.getPreferencesSuffix(), task.getCheckBox().isSelected());
63 if (task.getCheckBox().isSelected()) {
64 task.download(this, dialog.minlat, dialog.minlon, dialog.maxlat, dialog.maxlon, null);
65 finish = true;
66 }
67 }
68 } else {
69 finish = true;
70 }
71 if (!finish) {
72 JOptionPane.showMessageDialog(
73 Main.parent,
74 tr("Please select at least one task to download"),
75 tr("Error"),
76 JOptionPane.ERROR_MESSAGE
77 );
78 }
79 }
80
81 dialog = null;
82 dlg.dispose();
83 }
84}
Note: See TracBrowser for help on using the repository browser.