001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.actions; 003 004import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 005import static org.openstreetmap.josm.tools.I18n.tr; 006 007import java.awt.event.KeyEvent; 008import java.util.Collection; 009 010import org.openstreetmap.josm.Main; 011import org.openstreetmap.josm.data.notes.Note; 012import org.openstreetmap.josm.data.osm.OsmPrimitive; 013import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 014import org.openstreetmap.josm.tools.Shortcut; 015 016/** 017 * Display object information about OSM nodes, ways, or relations in web browser. 018 * @since 4408 019 */ 020public class InfoWebAction extends AbstractInfoAction { 021 022 /** 023 * Constructs a new {@code InfoWebAction}. 024 */ 025 public InfoWebAction() { 026 super(tr("Advanced info (web)"), "info", 027 tr("Display object information about OSM nodes, ways, or relations in web browser."), 028 Shortcut.registerShortcut("core:infoweb", 029 tr("Advanced info (web)"), KeyEvent.VK_I, Shortcut.CTRL_SHIFT), 030 true, "action/infoweb", true); 031 putValue("help", ht("/Action/InfoAboutElementsWeb")); 032 } 033 034 @Override 035 protected String createInfoUrl(Object infoObject) { 036 if (infoObject instanceof OsmPrimitive) { 037 OsmPrimitive primitive = (OsmPrimitive) infoObject; 038 return Main.getBaseBrowseUrl() + '/' + OsmPrimitiveType.from(primitive).getAPIName() + '/' + primitive.getId(); 039 } else if (infoObject instanceof Note) { 040 Note note = (Note) infoObject; 041 return Main.getBaseBrowseUrl() + "/note/" + note.getId(); 042 } else { 043 return null; 044 } 045 } 046 047 @Override 048 protected void updateEnabledState() { 049 super.updateEnabledState(); 050 updateEnabledStateWithNotes(); 051 } 052 053 @Override 054 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 055 super.updateEnabledState(selection); 056 updateEnabledStateWithNotes(); 057 } 058 059 private void updateEnabledStateWithNotes() { 060 // Allows enabling if a note is selected, even if no OSM object is selected 061 if (!isEnabled() && Main.isDisplayingMapView()) { 062 if (Main.map.noteDialog.getSelectedNote() != null) { 063 setEnabled(true); 064 } 065 } 066 } 067 068 /** 069 * Called when the note selection has changed. 070 * TODO: make a proper listener mechanism to handle change of note selection 071 * @since 8475 072 */ 073 public final void noteSelectionChanged() { 074 updateEnabledState(); 075 } 076}