[298] | 1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
[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;
|
---|
[155] | 16 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
| 17 |
|
---|
| 18 | /**
|
---|
| 19 | * Open a help browser and displays lightweight online help.
|
---|
| 20 | *
|
---|
| 21 | */
|
---|
| 22 | public class HelpAction extends AbstractAction {
|
---|
| 23 |
|
---|
[1169] | 24 | public HelpAction() {
|
---|
| 25 | super(tr("Help"), ImageProvider.get("help"));
|
---|
| 26 | }
|
---|
[155] | 27 |
|
---|
[1169] | 28 | public void actionPerformed(ActionEvent e) {
|
---|
[2252] | 29 | if (e.getActionCommand() == null) {
|
---|
[2990] | 30 | String topic;
|
---|
[2250] | 31 | if (e.getSource() instanceof Component) {
|
---|
| 32 | Component c = SwingUtilities.getRoot((Component)e.getSource());
|
---|
| 33 | Point mouse = c.getMousePosition();
|
---|
[2274] | 34 | if (mouse != null) {
|
---|
| 35 | c = SwingUtilities.getDeepestComponentAt(c, mouse.x, mouse.y);
|
---|
[2308] | 36 | topic = HelpUtil.getContextSpecificHelpTopic(c);
|
---|
[2274] | 37 | } else {
|
---|
| 38 | topic = null;
|
---|
| 39 | }
|
---|
[2250] | 40 | } else {
|
---|
| 41 | Point mouse = Main.parent.getMousePosition();
|
---|
[2308] | 42 | topic = HelpUtil.getContextSpecificHelpTopic(SwingUtilities.getDeepestComponentAt(Main.parent, mouse.x, mouse.y));
|
---|
[1820] | 43 | }
|
---|
[1169] | 44 | if (topic == null) {
|
---|
[2715] | 45 | HelpBrowser.setUrlForHelpTopic("/");
|
---|
[1820] | 46 | } else {
|
---|
[2715] | 47 | HelpBrowser.setUrlForHelpTopic(topic);
|
---|
[1820] | 48 | }
|
---|
[1169] | 49 | } else {
|
---|
[2715] | 50 | HelpBrowser.setUrlForHelpTopic("/");
|
---|
[1169] | 51 | }
|
---|
| 52 | }
|
---|
[155] | 53 | }
|
---|