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

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

checkstyle: enable relevant whitespace checks and fix them

  • Property svn:eol-style set to native
File size: 2.0 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;
9
10import javax.swing.AbstractAction;
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.ImageProvider;
18
19/**
20 * Open a help browser and displays lightweight online help.
21 * @since 155
22 */
23public class HelpAction extends AbstractAction {
24
25 /**
26 * Constructs a new {@code HelpAction}.
27 */
28 public HelpAction() {
29 super(tr("Help"));
30 new ImageProvider("help").getResource().getImageIcon(this);
31 putValue("toolbar", "help");
32 setEnabled(!Main.isOffline(OnlineResource.JOSM_WEBSITE));
33 }
34
35 @Override
36 public void actionPerformed(ActionEvent e) {
37 if (e.getActionCommand() == null) {
38 String topic;
39 if (e.getSource() instanceof Component) {
40 Component c = SwingUtilities.getRoot((Component) e.getSource());
41 Point mouse = c.getMousePosition();
42 if (mouse != null) {
43 c = SwingUtilities.getDeepestComponentAt(c, mouse.x, mouse.y);
44 topic = HelpUtil.getContextSpecificHelpTopic(c);
45 } else {
46 topic = null;
47 }
48 } else {
49 Point mouse = Main.parent.getMousePosition();
50 topic = HelpUtil.getContextSpecificHelpTopic(SwingUtilities.getDeepestComponentAt(Main.parent, mouse.x, mouse.y));
51 }
52 if (topic == null) {
53 HelpBrowser.setUrlForHelpTopic("/");
54 } else {
55 HelpBrowser.setUrlForHelpTopic(topic);
56 }
57 } else {
58 HelpBrowser.setUrlForHelpTopic("/");
59 }
60 }
61}
Note: See TracBrowser for help on using the repository browser.