001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.help; 003 004import java.awt.event.ActionEvent; 005import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 006 007import javax.swing.AbstractAction; 008import static org.openstreetmap.josm.tools.I18n.tr; 009 010import org.openstreetmap.josm.tools.ImageProvider; 011 012/** 013 * This is the standard help action to be used with help buttons for 014 * context sensitive help 015 * 016 */ 017public class ContextSensitiveHelpAction extends AbstractAction { 018 019 /** the help topic */ 020 private String helpTopic; 021 022 /** 023 * Sets the help topic 024 * 025 * @param relativeHelpTopic the relative help topic 026 */ 027 public void setHelpTopic(String relativeHelpTopic) { 028 if (relativeHelpTopic == null) 029 relativeHelpTopic = "/"; 030 this.helpTopic = relativeHelpTopic; 031 } 032 033 /** 034 * Creates a help topic for the root help topic 035 * 036 */ 037 public ContextSensitiveHelpAction() { 038 this(ht("/")); 039 } 040 041 /** 042 * 043 * @param helpTopic 044 */ 045 public ContextSensitiveHelpAction(String helpTopic) { 046 putValue(SHORT_DESCRIPTION, tr("Show help information")); 047 putValue(NAME, tr("Help")); 048 putValue(SMALL_ICON, ImageProvider.get("help")); 049 this.helpTopic = helpTopic; 050 } 051 052 @Override 053 public void actionPerformed(ActionEvent e) { 054 if (helpTopic != null) { 055 HelpBrowser.setUrlForHelpTopic(helpTopic); 056 } 057 } 058}