1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Component;
|
---|
7 | import java.awt.Point;
|
---|
8 | import java.awt.event.ActionEvent;
|
---|
9 |
|
---|
10 | import javax.swing.AbstractAction;
|
---|
11 | import javax.swing.SwingUtilities;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.Main;
|
---|
14 | import org.openstreetmap.josm.gui.help.HelpBrowser;
|
---|
15 | import org.openstreetmap.josm.gui.help.HelpUtil;
|
---|
16 | import org.openstreetmap.josm.io.OnlineResource;
|
---|
17 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Open a help browser and displays lightweight online help.
|
---|
21 | * @since 155
|
---|
22 | */
|
---|
23 | public 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 | }
|
---|