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

Last change on this file since 10433 was 9320, checked in by simon04, 8 years ago

Refactoring (make Help a JosmAction)

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