source: josm/trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java@ 2308

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

fixed #3762: Deleted relation still referenced when deleting former member
Clean up of Delete command. New: only one confirmation dialog for all parent relations of deleted objects, see help.
Improved infrastructure for context-sensitive help, improved internal help browser.

File size: 4.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.GridBagConstraints;
7import java.awt.GridBagLayout;
8import java.awt.event.ActionEvent;
9import java.awt.event.KeyEvent;
10import java.util.Collections;
11import java.util.LinkedList;
12import java.util.List;
13
14import javax.swing.JCheckBox;
15import javax.swing.JLabel;
16import javax.swing.JPanel;
17
18import org.openstreetmap.josm.Main;
19import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
20import org.openstreetmap.josm.gui.ExtendedDialog;
21import org.openstreetmap.josm.gui.widgets.HistoryComboBox;
22import org.openstreetmap.josm.tools.GBC;
23import org.openstreetmap.josm.tools.Shortcut;
24
25/**
26 * Open an URL input dialog and load data from the given URL.
27 *
28 * @author imi
29 */
30public class OpenLocationAction extends JosmAction {
31
32 /**
33 * Create an open action. The name is "Open a file".
34 */
35 public OpenLocationAction() {
36 super(tr("Open Location..."), "openlocation", tr("Open an URL."),
37 Shortcut.registerShortcut("system:open_location", tr("File: {0}", tr("Open Location...")), KeyEvent.VK_L, Shortcut.GROUP_MENU), true);
38 }
39
40 /**
41 * Restore the current history from the preferences
42 *
43 * @param cbHistory
44 */
45 protected void restoreUploadAddressHistory(HistoryComboBox cbHistory) {
46 List<String> cmtHistory = new LinkedList<String>(Main.pref.getCollection(getClass().getName() + ".uploadAddressHistory", new LinkedList<String>()));
47 // we have to reverse the history, because ComboBoxHistory will reverse it again
48 // in addElement()
49 //
50 Collections.reverse(cmtHistory);
51 cbHistory.setPossibleItems(cmtHistory);
52 }
53
54 /**
55 * Remind the current history in the preferences
56 * @param cbHistory
57 */
58 protected void remindUploadAddressHistory(HistoryComboBox cbHistory) {
59 cbHistory.addCurrentItemToHistory();
60 Main.pref.putCollection(getClass().getName() + ".uploadAddressHistory", cbHistory.getHistory());
61 }
62
63 public void actionPerformed(ActionEvent e) {
64
65 JCheckBox layer = new JCheckBox(tr("Separate Layer"));
66 layer.setToolTipText(tr("Select if the data should be downloaded in a new layer"));
67 layer.setSelected(Main.pref.getBoolean("download.newlayer"));
68 JPanel all = new JPanel(new GridBagLayout());
69 GridBagConstraints gc = new GridBagConstraints();
70 gc.fill = GridBagConstraints.HORIZONTAL;
71 gc.weightx = 1.0;
72 gc.anchor = GridBagConstraints.FIRST_LINE_START;
73 all.add(new JLabel(tr("Enter URL to download:")), gc);
74 HistoryComboBox uploadAdresses = new HistoryComboBox();
75 uploadAdresses.setToolTipText(tr("Enter an URL from where data should be downloaded"));
76 restoreUploadAddressHistory(uploadAdresses);
77 gc.gridy = 1;
78 all.add(uploadAdresses, gc);
79 gc.gridy = 2;
80 gc.fill = GridBagConstraints.BOTH;
81 gc.weighty = 1.0;
82 all.add(layer, gc);
83 ExtendedDialog dialog = new ExtendedDialog(Main.parent,
84 tr("Download Location"),
85 new String[] {tr("Download URL"), tr("Cancel")}
86 );
87 dialog.setContent(all, false /* don't embedded content in JScrollpane */);
88 dialog.setButtonIcons(new String[] {"download.png", "cancel.png"});
89 dialog.setToolTipTexts(new String[] {
90 tr("Start downloading data"),
91 tr("Close dialog and cancel downloading")
92 });
93 dialog.configureContextsensitiveHelp("/Action/OpenLocation", true /* show help button */);
94 dialog.showDialog();
95 if (dialog.getValue() != 1) return;
96 remindUploadAddressHistory(uploadAdresses);
97 openUrl(layer.isSelected(), uploadAdresses.getText());
98 }
99
100 /**
101 * Open the given file.
102 */
103 public void openUrl(boolean new_layer, String url) {
104 new DownloadOsmTask().loadUrl(new_layer, url, null);
105 }
106}
Note: See TracBrowser for help on using the repository browser.