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

Last change on this file since 4175 was 4045, checked in by stoecker, 13 years ago

fix #6097 - i18n issues

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