[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;
|
---|
| 9 |
|
---|
| 10 | import javax.swing.AbstractAction;
|
---|
| 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;
|
---|
[155] | 17 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
| 18 |
|
---|
| 19 | /**
|
---|
| 20 | * Open a help browser and displays lightweight online help.
|
---|
[7434] | 21 | * @since 155
|
---|
[155] | 22 | */
|
---|
| 23 | public class HelpAction extends AbstractAction {
|
---|
| 24 |
|
---|
[7434] | 25 | /**
|
---|
| 26 | * Constructs a new {@code HelpAction}.
|
---|
| 27 | */
|
---|
[1169] | 28 | public HelpAction() {
|
---|
[7694] | 29 | super(tr("Help"));
|
---|
| 30 | new ImageProvider("help").getResource().getImageIcon(this);
|
---|
[4139] | 31 | putValue("toolbar", "help");
|
---|
[7434] | 32 | setEnabled(!Main.isOffline(OnlineResource.JOSM_WEBSITE));
|
---|
[1169] | 33 | }
|
---|
[155] | 34 |
|
---|
[6084] | 35 | @Override
|
---|
[1169] | 36 | public void actionPerformed(ActionEvent e) {
|
---|
[2252] | 37 | if (e.getActionCommand() == null) {
|
---|
[2990] | 38 | String topic;
|
---|
[2250] | 39 | if (e.getSource() instanceof Component) {
|
---|
| 40 | Component c = SwingUtilities.getRoot((Component)e.getSource());
|
---|
| 41 | Point mouse = c.getMousePosition();
|
---|
[2274] | 42 | if (mouse != null) {
|
---|
| 43 | c = SwingUtilities.getDeepestComponentAt(c, mouse.x, mouse.y);
|
---|
[2308] | 44 | topic = HelpUtil.getContextSpecificHelpTopic(c);
|
---|
[2274] | 45 | } else {
|
---|
| 46 | topic = null;
|
---|
| 47 | }
|
---|
[2250] | 48 | } else {
|
---|
| 49 | Point mouse = Main.parent.getMousePosition();
|
---|
[2308] | 50 | topic = HelpUtil.getContextSpecificHelpTopic(SwingUtilities.getDeepestComponentAt(Main.parent, mouse.x, mouse.y));
|
---|
[1820] | 51 | }
|
---|
[1169] | 52 | if (topic == null) {
|
---|
[2715] | 53 | HelpBrowser.setUrlForHelpTopic("/");
|
---|
[1820] | 54 | } else {
|
---|
[2715] | 55 | HelpBrowser.setUrlForHelpTopic(topic);
|
---|
[1820] | 56 | }
|
---|
[1169] | 57 | } else {
|
---|
[2715] | 58 | HelpBrowser.setUrlForHelpTopic("/");
|
---|
[1169] | 59 | }
|
---|
| 60 | }
|
---|
[155] | 61 | }
|
---|