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.Main;
|
---|
11 | import org.openstreetmap.josm.data.notes.Note;
|
---|
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.tools.Shortcut;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Display object information about OSM nodes, ways, or relations in web browser.
|
---|
19 | * @since 4408
|
---|
20 | */
|
---|
21 | public 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 | }
|
---|