source: josm/trunk/src/org/openstreetmap/josm/actions/HelpAction.java@ 14182

Last change on this file since 14182 was 14153, checked in by Don-vip, 6 years ago

see #15229 - deprecate Main.parent and Main itself

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Component;
7import java.awt.Point;
8import java.awt.event.ActionEvent;
9import java.awt.event.KeyEvent;
10import java.util.Optional;
11
12import javax.swing.SwingUtilities;
13
14import org.openstreetmap.josm.gui.MainApplication;
15import org.openstreetmap.josm.gui.help.HelpBrowser;
16import org.openstreetmap.josm.gui.help.HelpUtil;
17import org.openstreetmap.josm.io.NetworkManager;
18import org.openstreetmap.josm.io.OnlineResource;
19import org.openstreetmap.josm.tools.Shortcut;
20
21/**
22 * Open a help browser and displays lightweight online help.
23 * @since 155
24 */
25public class HelpAction extends JosmAction {
26
27 /**
28 * Constructs a new {@code HelpAction}.
29 */
30 public HelpAction() {
31 this(true);
32 }
33
34 private HelpAction(boolean shortcut) {
35 super(tr("Help"), "help", null,
36 shortcut ? Shortcut.registerShortcut("system:help", tr("Help"), KeyEvent.VK_F1, Shortcut.DIRECT) : null,
37 true);
38 setEnabled(!NetworkManager.isOffline(OnlineResource.JOSM_WEBSITE));
39 }
40
41 /**
42 * Constructs a new {@code HelpAction} without assigning a shortcut.
43 * @return a new {@code HelpAction}
44 */
45 public static HelpAction createWithoutShortcut() {
46 return new HelpAction(false);
47 }
48
49 @Override
50 public void actionPerformed(ActionEvent e) {
51 if (e.getActionCommand() == null) {
52 String topic;
53 if (e.getSource() instanceof Component) {
54 Component c = SwingUtilities.getRoot((Component) e.getSource());
55 Point mouse = c.getMousePosition();
56 if (mouse != null) {
57 c = SwingUtilities.getDeepestComponentAt(c, mouse.x, mouse.y);
58 topic = HelpUtil.getContextSpecificHelpTopic(c);
59 } else {
60 topic = null;
61 }
62 } else {
63 Point mouse = MainApplication.getMainFrame().getMousePosition();
64 topic = HelpUtil.getContextSpecificHelpTopic(
65 SwingUtilities.getDeepestComponentAt(MainApplication.getMainFrame(), mouse.x, mouse.y));
66 }
67 HelpBrowser.setUrlForHelpTopic(Optional.ofNullable(topic).orElse("/"));
68 } else {
69 HelpBrowser.setUrlForHelpTopic("/");
70 }
71 }
72}
Note: See TracBrowser for help on using the repository browser.