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