source: josm/trunk/src/org/openstreetmap/josm/actions/AbstractInfoAction.java@ 7746

Last change on this file since 7746 was 7678, checked in by stoecker, 9 years ago

fix #9059 - no more assumptions about URL for element browsing - use OSM website as default and hidden option for changes

  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5import static org.openstreetmap.josm.tools.I18n.trn;
6
7import java.awt.event.ActionEvent;
8import java.util.ArrayList;
9import java.util.Collection;
10import java.util.Iterator;
11import java.util.List;
12import java.util.regex.Pattern;
13
14import javax.swing.JOptionPane;
15
16import org.openstreetmap.josm.Main;
17import org.openstreetmap.josm.data.osm.OsmPrimitive;
18import org.openstreetmap.josm.gui.HelpAwareOptionPane;
19import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
20import org.openstreetmap.josm.gui.help.HelpUtil;
21import org.openstreetmap.josm.io.OsmApi;
22import org.openstreetmap.josm.tools.ImageProvider;
23import org.openstreetmap.josm.tools.OpenBrowser;
24import org.openstreetmap.josm.tools.Shortcut;
25
26public abstract class AbstractInfoAction extends JosmAction {
27
28 public AbstractInfoAction(boolean installAdapters) {
29 super(installAdapters);
30 }
31
32 public AbstractInfoAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean register, String toolbarId, boolean installAdapters) {
33 super(name, iconName, tooltip, shortcut, register, toolbarId, installAdapters);
34 }
35
36 public static boolean confirmLaunchMultiple(int numBrowsers) {
37 String msg = /* for correct i18n of plural forms - see #9110 */ trn(
38 "You are about to launch {0} browser window.<br>"
39 + "This may both clutter your screen with browser windows<br>"
40 + "and take some time to finish.",
41 "You are about to launch {0} browser windows.<br>"
42 + "This may both clutter your screen with browser windows<br>"
43 + "and take some time to finish.", numBrowsers, numBrowsers);
44 msg = "<html>" + msg + "</html>";
45 ButtonSpec[] spec = new ButtonSpec[] {
46 new ButtonSpec(
47 tr("Continue"),
48 ImageProvider.get("ok"),
49 trn("Click to continue and to open {0} browser", "Click to continue and to open {0} browsers", numBrowsers, numBrowsers),
50 null // no specific help topic
51 ),
52 new ButtonSpec(
53 tr("Cancel"),
54 ImageProvider.get("cancel"),
55 tr("Click to abort launching external browsers"),
56 null // no specific help topic
57 )
58 };
59 int ret = HelpAwareOptionPane.showOptionDialog(
60 Main.parent,
61 msg,
62 tr("Warning"),
63 JOptionPane.WARNING_MESSAGE,
64 null,
65 spec,
66 spec[0],
67 HelpUtil.ht("/WarningMessages#ToManyBrowsersToOpen")
68 );
69 return ret == 0;
70 }
71
72 protected void launchInfoBrowsersForSelectedPrimitives() {
73 List<OsmPrimitive> primitivesToShow = new ArrayList<>(getCurrentDataSet().getAllSelected());
74
75 // filter out new primitives which are not yet uploaded to the server
76 //
77 Iterator<OsmPrimitive> it = primitivesToShow.iterator();
78 while(it.hasNext()) {
79 if (it.next().isNew()) {
80 it.remove();
81 }
82 }
83
84 if (primitivesToShow.isEmpty()) {
85 JOptionPane.showMessageDialog(
86 Main.parent,
87 tr("Please select at least one already uploaded node, way, or relation."),
88 tr("Warning"),
89 JOptionPane.WARNING_MESSAGE
90 );
91 return;
92 }
93
94 // don't launch more than 10 browser instances / browser windows
95 //
96 int max = Math.min(10, primitivesToShow.size());
97 if (primitivesToShow.size() > max && ! confirmLaunchMultiple(primitivesToShow.size()))
98 return;
99 for(int i = 0; i < max; i++) {
100 OpenBrowser.displayUrl(createInfoUrl(primitivesToShow.get(i)));
101 }
102 }
103
104 @Override
105 public void actionPerformed(ActionEvent e) {
106 launchInfoBrowsersForSelectedPrimitives();
107 }
108
109 protected abstract String createInfoUrl(Object infoObject);
110
111 @Override
112 protected void updateEnabledState() {
113 setEnabled(getCurrentDataSet() != null && !getCurrentDataSet().getSelected().isEmpty());
114 }
115
116 @Override
117 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
118 setEnabled(selection != null && !selection.isEmpty());
119 }
120}
Note: See TracBrowser for help on using the repository browser.