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.data.notes.Note; 011import org.openstreetmap.josm.data.osm.IPrimitive; 012import org.openstreetmap.josm.data.osm.OsmPrimitive; 013import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 014import org.openstreetmap.josm.gui.MainApplication; 015import org.openstreetmap.josm.spi.preferences.Config; 016import org.openstreetmap.josm.tools.Shortcut; 017 018/** 019 * Display object information about OSM nodes, ways, or relations in web browser. 020 * @since 4408 021 */ 022public class InfoWebAction extends AbstractInfoAction { 023 024 /** 025 * Constructs a new {@code InfoWebAction}. 026 */ 027 public InfoWebAction() { 028 super(tr("Advanced info (web)"), "info", 029 tr("Display object information about OSM nodes, ways, or relations in web browser."), 030 Shortcut.registerShortcut("core:infoweb", 031 tr("View: {0}", tr("Advanced info (web)")), KeyEvent.VK_I, Shortcut.CTRL_SHIFT), 032 true, "action/infoweb", true); 033 setHelpId(ht("/Action/InfoAboutElementsWeb")); 034 } 035 036 @Override 037 protected String createInfoUrl(Object infoObject) { 038 if (infoObject instanceof IPrimitive) { 039 IPrimitive primitive = (IPrimitive) infoObject; 040 return Config.getUrls().getBaseBrowseUrl() + '/' + OsmPrimitiveType.from(primitive).getAPIName() + '/' + primitive.getOsmId(); 041 } else if (infoObject instanceof Note) { 042 Note note = (Note) infoObject; 043 return Config.getUrls().getBaseBrowseUrl() + "/note/" + note.getId(); 044 } else { 045 return null; 046 } 047 } 048 049 @Override 050 protected void updateEnabledState() { 051 super.updateEnabledState(); 052 updateEnabledStateWithNotes(); 053 } 054 055 @Override 056 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 057 super.updateEnabledState(selection); 058 updateEnabledStateWithNotes(); 059 } 060 061 private void updateEnabledStateWithNotes() { 062 // Allows enabling if a note is selected, even if no OSM object is selected 063 if (!isEnabled() && MainApplication.isDisplayingMapView() && MainApplication.getMap().noteDialog.getSelectedNote() != null) { 064 setEnabled(true); 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}