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