001 // License: GPL. For details, see LICENSE file. 002 package org.openstreetmap.josm.gui.help; 003 004 import java.awt.event.ActionEvent; 005 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 006 007 import javax.swing.AbstractAction; 008 import static org.openstreetmap.josm.tools.I18n.tr; 009 010 import 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 */ 017 public 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 public void actionPerformed(ActionEvent e) { 053 if (helpTopic != null) { 054 HelpBrowser.setUrlForHelpTopic(helpTopic); 055 } 056 } 057 }