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