1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.GridBagLayout;
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.awt.event.KeyEvent;
|
---|
9 | import java.io.InputStream;
|
---|
10 | import java.io.File;
|
---|
11 | import java.io.FileInputStream;
|
---|
12 | import java.io.FileNotFoundException;
|
---|
13 | import java.io.IOException;
|
---|
14 | import java.util.zip.GZIPInputStream;
|
---|
15 |
|
---|
16 | import javax.swing.JCheckBox;
|
---|
17 | import javax.swing.JFileChooser;
|
---|
18 | import javax.swing.JLabel;
|
---|
19 | import javax.swing.JOptionPane;
|
---|
20 | import javax.swing.JPanel;
|
---|
21 | import javax.swing.JTextField;
|
---|
22 |
|
---|
23 | import org.openstreetmap.josm.Main;
|
---|
24 | import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
|
---|
25 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
26 | import org.openstreetmap.josm.gui.layer.GpxLayer;
|
---|
27 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
28 | import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
|
---|
29 | import org.openstreetmap.josm.io.GpxReader;
|
---|
30 | import org.openstreetmap.josm.io.NmeaReader;
|
---|
31 | import org.openstreetmap.josm.io.OsmReader;
|
---|
32 | import org.openstreetmap.josm.io.OsmServerLocationReader;
|
---|
33 | import org.xml.sax.SAXException;
|
---|
34 | import org.openstreetmap.josm.tools.GBC;
|
---|
35 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Open an URL input dialog and load data from the given URL.
|
---|
39 | *
|
---|
40 | * @author imi
|
---|
41 | */
|
---|
42 | public class OpenLocationAction extends JosmAction {
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Create an open action. The name is "Open a file".
|
---|
46 | */
|
---|
47 | public OpenLocationAction() {
|
---|
48 | super(tr("Open Location..."), "openlocation", tr("Open an URL."),
|
---|
49 | Shortcut.registerShortcut("system:open_location", tr("File: {0}", tr("Open Location...")), KeyEvent.VK_L, Shortcut.GROUP_MENU), true);
|
---|
50 | }
|
---|
51 |
|
---|
52 | public void actionPerformed(ActionEvent e) {
|
---|
53 |
|
---|
54 | JCheckBox layer = new JCheckBox(tr("Separate Layer"));
|
---|
55 | layer.setSelected(Main.pref.getBoolean("download.newlayer"));
|
---|
56 | JPanel all = new JPanel(new GridBagLayout());
|
---|
57 | all.add(new JLabel("Enter URL to download:"), GBC.eol());
|
---|
58 | JTextField urltext = new JTextField(40);
|
---|
59 | all.add(urltext, GBC.eol());
|
---|
60 | all.add(layer, GBC.eol());
|
---|
61 | int answer = JOptionPane.showConfirmDialog(Main.parent, all, tr("Download Location"), JOptionPane.OK_CANCEL_OPTION);
|
---|
62 | if (answer != JOptionPane.OK_OPTION)
|
---|
63 | return;
|
---|
64 | openUrl(layer.isSelected(), urltext.getText());
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Open the given file.
|
---|
69 | */
|
---|
70 | public void openUrl(boolean new_layer, String url) {
|
---|
71 | new DownloadOsmTask().loadUrl(new_layer, url);
|
---|
72 | }
|
---|
73 |
|
---|
74 | }
|
---|