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