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 |
|
---|
10 | import javax.swing.JCheckBox;
|
---|
11 | import javax.swing.JLabel;
|
---|
12 | import javax.swing.JPanel;
|
---|
13 | import javax.swing.JTextField;
|
---|
14 |
|
---|
15 | import org.openstreetmap.josm.Main;
|
---|
16 | import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
|
---|
17 | import org.openstreetmap.josm.gui.ExtendedDialog;
|
---|
18 | import org.openstreetmap.josm.tools.GBC;
|
---|
19 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Open an URL input dialog and load data from the given URL.
|
---|
23 | *
|
---|
24 | * @author imi
|
---|
25 | */
|
---|
26 | public class OpenLocationAction extends JosmAction {
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Create an open action. The name is "Open a file".
|
---|
30 | */
|
---|
31 | public OpenLocationAction() {
|
---|
32 | super(tr("Open Location..."), "openlocation", tr("Open an URL."),
|
---|
33 | Shortcut.registerShortcut("system:open_location", tr("File: {0}", tr("Open Location...")), KeyEvent.VK_L, Shortcut.GROUP_MENU), true);
|
---|
34 | }
|
---|
35 |
|
---|
36 | public void actionPerformed(ActionEvent e) {
|
---|
37 |
|
---|
38 | JCheckBox layer = new JCheckBox(tr("Separate Layer"));
|
---|
39 | layer.setSelected(Main.pref.getBoolean("download.newlayer"));
|
---|
40 | JPanel all = new JPanel(new GridBagLayout());
|
---|
41 | all.add(new JLabel(tr("Enter URL to download:")), GBC.eol());
|
---|
42 | JTextField urltext = new JTextField(40);
|
---|
43 | all.add(urltext, GBC.eol());
|
---|
44 | all.add(layer, GBC.eol());
|
---|
45 | int answer = new ExtendedDialog(Main.parent,
|
---|
46 | tr("Download Location"),
|
---|
47 | all,
|
---|
48 | new String[] {tr("Download URL"), tr("Cancel")},
|
---|
49 | new String[] {"download.png", "cancel.png"}).getValue();
|
---|
50 | if (answer != 1) return;
|
---|
51 | openUrl(layer.isSelected(), urltext.getText());
|
---|
52 | }
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Open the given file.
|
---|
56 | */
|
---|
57 | public void openUrl(boolean new_layer, String url) {
|
---|
58 | new DownloadOsmTask().loadUrl(new_layer, url);
|
---|
59 | }
|
---|
60 |
|
---|
61 | }
|
---|