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.io.OnlineResource; 017import org.openstreetmap.josm.tools.ImageProvider; 018 019/** 020 * Open a help browser and displays lightweight online help. 021 * @since 155 022 */ 023public class HelpAction extends AbstractAction { 024 025 /** 026 * Constructs a new {@code HelpAction}. 027 */ 028 public HelpAction() { 029 super(tr("Help")); 030 new ImageProvider("help").getResource().getImageIcon(this); 031 putValue("toolbar", "help"); 032 setEnabled(!Main.isOffline(OnlineResource.JOSM_WEBSITE)); 033 } 034 035 @Override 036 public void actionPerformed(ActionEvent e) { 037 if (e.getActionCommand() == null) { 038 String topic; 039 if (e.getSource() instanceof Component) { 040 Component c = SwingUtilities.getRoot((Component) e.getSource()); 041 Point mouse = c.getMousePosition(); 042 if (mouse != null) { 043 c = SwingUtilities.getDeepestComponentAt(c, mouse.x, mouse.y); 044 topic = HelpUtil.getContextSpecificHelpTopic(c); 045 } else { 046 topic = null; 047 } 048 } else { 049 Point mouse = Main.parent.getMousePosition(); 050 topic = HelpUtil.getContextSpecificHelpTopic(SwingUtilities.getDeepestComponentAt(Main.parent, mouse.x, mouse.y)); 051 } 052 if (topic == null) { 053 HelpBrowser.setUrlForHelpTopic("/"); 054 } else { 055 HelpBrowser.setUrlForHelpTopic(topic); 056 } 057 } else { 058 HelpBrowser.setUrlForHelpTopic("/"); 059 } 060 } 061}