source: josm/trunk/src/org/openstreetmap/josm/actions/InfoWebAction.java@ 13346

Last change on this file since 13346 was 12630, checked in by Don-vip, 7 years ago

see #15182 - deprecate Main.map and Main.isDisplayingMapView(). Replacements: gui.MainApplication.getMap() / gui.MainApplication.isDisplayingMapView()

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
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.event.KeyEvent;
8import java.util.Collection;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.data.notes.Note;
12import org.openstreetmap.josm.data.osm.OsmPrimitive;
13import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
14import org.openstreetmap.josm.gui.MainApplication;
15import org.openstreetmap.josm.tools.Shortcut;
16
17/**
18 * Display object information about OSM nodes, ways, or relations in web browser.
19 * @since 4408
20 */
21public class InfoWebAction extends AbstractInfoAction {
22
23 /**
24 * Constructs a new {@code InfoWebAction}.
25 */
26 public InfoWebAction() {
27 super(tr("Advanced info (web)"), "info",
28 tr("Display object information about OSM nodes, ways, or relations in web browser."),
29 Shortcut.registerShortcut("core:infoweb",
30 tr("Advanced info (web)"), KeyEvent.VK_I, Shortcut.CTRL_SHIFT),
31 true, "action/infoweb", true);
32 putValue("help", ht("/Action/InfoAboutElementsWeb"));
33 }
34
35 @Override
36 protected String createInfoUrl(Object infoObject) {
37 if (infoObject instanceof OsmPrimitive) {
38 OsmPrimitive primitive = (OsmPrimitive) infoObject;
39 return Main.getBaseBrowseUrl() + '/' + OsmPrimitiveType.from(primitive).getAPIName() + '/' + primitive.getId();
40 } else if (infoObject instanceof Note) {
41 Note note = (Note) infoObject;
42 return Main.getBaseBrowseUrl() + "/note/" + note.getId();
43 } else {
44 return null;
45 }
46 }
47
48 @Override
49 protected void updateEnabledState() {
50 super.updateEnabledState();
51 updateEnabledStateWithNotes();
52 }
53
54 @Override
55 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
56 super.updateEnabledState(selection);
57 updateEnabledStateWithNotes();
58 }
59
60 private void updateEnabledStateWithNotes() {
61 // Allows enabling if a note is selected, even if no OSM object is selected
62 if (!isEnabled() && MainApplication.isDisplayingMapView() && MainApplication.getMap().noteDialog.getSelectedNote() != null) {
63 setEnabled(true);
64 }
65 }
66
67 /**
68 * Called when the note selection has changed.
69 * TODO: make a proper listener mechanism to handle change of note selection
70 * @since 8475
71 */
72 public final void noteSelectionChanged() {
73 updateEnabledState();
74 }
75}
Note: See TracBrowser for help on using the repository browser.