001 // License: GPL. Copyright 2007 by Immanuel Scholz and others
002 package org.openstreetmap.josm.actions;
003
004 import static org.openstreetmap.josm.tools.I18n.tr;
005
006 import java.awt.Component;
007 import java.awt.Point;
008 import java.awt.event.ActionEvent;
009
010 import javax.swing.AbstractAction;
011 import javax.swing.SwingUtilities;
012
013 import org.openstreetmap.josm.Main;
014 import org.openstreetmap.josm.gui.help.HelpBrowser;
015 import org.openstreetmap.josm.gui.help.HelpUtil;
016 import org.openstreetmap.josm.tools.ImageProvider;
017
018 /**
019 * Open a help browser and displays lightweight online help.
020 *
021 */
022 public class HelpAction extends AbstractAction {
023
024 public HelpAction() {
025 super(tr("Help"), ImageProvider.get("help"));
026 putValue("toolbar", "help");
027 }
028
029 public void actionPerformed(ActionEvent e) {
030 if (e.getActionCommand() == null) {
031 String topic;
032 if (e.getSource() instanceof Component) {
033 Component c = SwingUtilities.getRoot((Component)e.getSource());
034 Point mouse = c.getMousePosition();
035 if (mouse != null) {
036 c = SwingUtilities.getDeepestComponentAt(c, mouse.x, mouse.y);
037 topic = HelpUtil.getContextSpecificHelpTopic(c);
038 } else {
039 topic = null;
040 }
041 } else {
042 Point mouse = Main.parent.getMousePosition();
043 topic = HelpUtil.getContextSpecificHelpTopic(SwingUtilities.getDeepestComponentAt(Main.parent, mouse.x, mouse.y));
044 }
045 if (topic == null) {
046 HelpBrowser.setUrlForHelpTopic("/");
047 } else {
048 HelpBrowser.setUrlForHelpTopic(topic);
049 }
050 } else {
051 HelpBrowser.setUrlForHelpTopic("/");
052 }
053 }
054 }