source: josm/trunk/src/org/openstreetmap/josm/actions/InfoWebAction.java@ 8851

Last change on this file since 8851 was 8846, checked in by Don-vip, 9 years ago

sonar - fb-contrib - minor performance improvements:

  • Method passes constant String of length 1 to character overridden method
  • Method needlessly boxes a boolean constant
  • Method uses iterator().next() on a List to get the first item
  • Method converts String to boxed primitive using excessive boxing
  • Method converts String to primitive using excessive boxing
  • Method creates array using constants
  • Class defines List based fields but uses them like Sets
  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.KeyEvent;
8import java.util.Collection;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.data.notes.Note;
12import org.openstreetmap.josm.data.osm.OsmPrimitive;
13import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
14import org.openstreetmap.josm.tools.Shortcut;
15
16/**
17 * Display object information about OSM nodes, ways, or relations in web browser.
18 * @since 4408
19 */
20public class InfoWebAction extends AbstractInfoAction {
21
22 /**
23 * Constructs a new {@code InfoWebAction}.
24 */
25 public InfoWebAction() {
26 super(tr("Advanced info (web)"), "info",
27 tr("Display object information about OSM nodes, ways, or relations in web browser."),
28 Shortcut.registerShortcut("core:infoweb",
29 tr("Advanced info (web)"), KeyEvent.VK_I, Shortcut.CTRL_SHIFT),
30 true, "action/infoweb", true);
31 putValue("help", ht("/Action/InfoAboutElementsWeb"));
32 }
33
34 @Override
35 protected String createInfoUrl(Object infoObject) {
36 if (infoObject instanceof OsmPrimitive) {
37 OsmPrimitive primitive = (OsmPrimitive) infoObject;
38 return Main.getBaseBrowseUrl() + '/' + OsmPrimitiveType.from(primitive).getAPIName() + '/' + primitive.getId();
39 } else if (infoObject instanceof Note) {
40 Note note = (Note) infoObject;
41 return Main.getBaseBrowseUrl() + "/note/" + note.getId();
42 } else {
43 return null;
44 }
45 }
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
61 if (!isEnabled() && Main.isDisplayingMapView()) {
62 if (Main.map.noteDialog.getSelectedNote() != null) {
63 setEnabled(true);
64 }
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}
Note: See TracBrowser for help on using the repository browser.