| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.gui.help;
|
|---|
| 3 |
|
|---|
| 4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
|---|
| 5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 6 |
|
|---|
| 7 | import java.awt.event.ActionEvent;
|
|---|
| 8 |
|
|---|
| 9 | import javax.swing.AbstractAction;
|
|---|
| 10 |
|
|---|
| 11 | import org.openstreetmap.josm.Main;
|
|---|
| 12 | import org.openstreetmap.josm.io.OnlineResource;
|
|---|
| 13 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| 14 |
|
|---|
| 15 | /**
|
|---|
| 16 | * This is the standard help action to be used with help buttons for
|
|---|
| 17 | * context sensitive help
|
|---|
| 18 | * @since 2289
|
|---|
| 19 | */
|
|---|
| 20 | public class ContextSensitiveHelpAction extends AbstractAction {
|
|---|
| 21 |
|
|---|
| 22 | private String helpTopic;
|
|---|
| 23 |
|
|---|
| 24 | /**
|
|---|
| 25 | * Sets the help topic.
|
|---|
| 26 | *
|
|---|
| 27 | * @param relativeHelpTopic the relative help topic
|
|---|
| 28 | */
|
|---|
| 29 | public void setHelpTopic(String relativeHelpTopic) {
|
|---|
| 30 | if (relativeHelpTopic == null)
|
|---|
| 31 | relativeHelpTopic = "/";
|
|---|
| 32 | this.helpTopic = relativeHelpTopic;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | /**
|
|---|
| 36 | * Constructs a new {@code ContextSensitiveHelpAction} for the root help topic.
|
|---|
| 37 | */
|
|---|
| 38 | public ContextSensitiveHelpAction() {
|
|---|
| 39 | this(ht("/"));
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | /**
|
|---|
| 43 | * Constructs a new {@code ContextSensitiveHelpAction} for a given help topic.
|
|---|
| 44 | * @param helpTopic The help topic
|
|---|
| 45 | */
|
|---|
| 46 | public ContextSensitiveHelpAction(String helpTopic) {
|
|---|
| 47 | putValue(SHORT_DESCRIPTION, tr("Show help information"));
|
|---|
| 48 | putValue(NAME, tr("Help"));
|
|---|
| 49 | putValue(SMALL_ICON, ImageProvider.get("help"));
|
|---|
| 50 | this.helpTopic = helpTopic;
|
|---|
| 51 | setEnabled(!Main.isOffline(OnlineResource.JOSM_WEBSITE));
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | @Override
|
|---|
| 55 | public void actionPerformed(ActionEvent e) {
|
|---|
| 56 | if (helpTopic != null) {
|
|---|
| 57 | HelpBrowser.setUrlForHelpTopic(helpTopic);
|
|---|
| 58 | }
|
|---|
| 59 | }
|
|---|
| 60 | }
|
|---|