[6380] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[155] | 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;
|
---|
[9320] | 9 | import java.awt.event.KeyEvent;
|
---|
[155] | 10 |
|
---|
| 11 | import javax.swing.SwingUtilities;
|
---|
| 12 |
|
---|
| 13 | import org.openstreetmap.josm.Main;
|
---|
[2715] | 14 | import org.openstreetmap.josm.gui.help.HelpBrowser;
|
---|
[2308] | 15 | import org.openstreetmap.josm.gui.help.HelpUtil;
|
---|
[7434] | 16 | import org.openstreetmap.josm.io.OnlineResource;
|
---|
[9320] | 17 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
[155] | 18 |
|
---|
| 19 | /**
|
---|
| 20 | * Open a help browser and displays lightweight online help.
|
---|
[7434] | 21 | * @since 155
|
---|
[155] | 22 | */
|
---|
[9320] | 23 | public class HelpAction extends JosmAction {
|
---|
[155] | 24 |
|
---|
[7434] | 25 | /**
|
---|
| 26 | * Constructs a new {@code HelpAction}.
|
---|
| 27 | */
|
---|
[1169] | 28 | public HelpAction() {
|
---|
[9320] | 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);
|
---|
[7434] | 36 | setEnabled(!Main.isOffline(OnlineResource.JOSM_WEBSITE));
|
---|
[1169] | 37 | }
|
---|
[155] | 38 |
|
---|
[9320] | 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 |
|
---|
[6084] | 47 | @Override
|
---|
[1169] | 48 | public void actionPerformed(ActionEvent e) {
|
---|
[2252] | 49 | if (e.getActionCommand() == null) {
|
---|
[2990] | 50 | String topic;
|
---|
[2250] | 51 | if (e.getSource() instanceof Component) {
|
---|
[8510] | 52 | Component c = SwingUtilities.getRoot((Component) e.getSource());
|
---|
[2250] | 53 | Point mouse = c.getMousePosition();
|
---|
[2274] | 54 | if (mouse != null) {
|
---|
| 55 | c = SwingUtilities.getDeepestComponentAt(c, mouse.x, mouse.y);
|
---|
[2308] | 56 | topic = HelpUtil.getContextSpecificHelpTopic(c);
|
---|
[2274] | 57 | } else {
|
---|
| 58 | topic = null;
|
---|
| 59 | }
|
---|
[2250] | 60 | } else {
|
---|
| 61 | Point mouse = Main.parent.getMousePosition();
|
---|
[2308] | 62 | topic = HelpUtil.getContextSpecificHelpTopic(SwingUtilities.getDeepestComponentAt(Main.parent, mouse.x, mouse.y));
|
---|
[1820] | 63 | }
|
---|
[1169] | 64 | if (topic == null) {
|
---|
[2715] | 65 | HelpBrowser.setUrlForHelpTopic("/");
|
---|
[1820] | 66 | } else {
|
---|
[2715] | 67 | HelpBrowser.setUrlForHelpTopic(topic);
|
---|
[1820] | 68 | }
|
---|
[1169] | 69 | } else {
|
---|
[2715] | 70 | HelpBrowser.setUrlForHelpTopic("/");
|
---|
[1169] | 71 | }
|
---|
| 72 | }
|
---|
[155] | 73 | }
|
---|