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 | import java.util.Optional;
|
---|
9 |
|
---|
10 | import javax.swing.AbstractAction;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.Main;
|
---|
13 | import org.openstreetmap.josm.io.OnlineResource;
|
---|
14 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * This is the standard help action to be used with help buttons for
|
---|
18 | * context sensitive help
|
---|
19 | * @since 2289
|
---|
20 | */
|
---|
21 | public class ContextSensitiveHelpAction extends AbstractAction {
|
---|
22 |
|
---|
23 | private String helpTopic;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Sets the help topic.
|
---|
27 | *
|
---|
28 | * @param relativeHelpTopic the relative help topic
|
---|
29 | */
|
---|
30 | public void setHelpTopic(String relativeHelpTopic) {
|
---|
31 | helpTopic = Optional.ofNullable(relativeHelpTopic).orElse("/");
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Constructs a new {@code ContextSensitiveHelpAction} for the root help topic.
|
---|
36 | */
|
---|
37 | public ContextSensitiveHelpAction() {
|
---|
38 | this(ht("/"));
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Constructs a new {@code ContextSensitiveHelpAction} for a given help topic.
|
---|
43 | * @param helpTopic The help topic
|
---|
44 | */
|
---|
45 | public ContextSensitiveHelpAction(String helpTopic) {
|
---|
46 | putValue(SHORT_DESCRIPTION, tr("Show help information"));
|
---|
47 | putValue(NAME, tr("Help"));
|
---|
48 | new ImageProvider("help").getResource().attachImageIcon(this);
|
---|
49 | this.helpTopic = helpTopic;
|
---|
50 | setEnabled(!Main.isOffline(OnlineResource.JOSM_WEBSITE));
|
---|
51 | }
|
---|
52 |
|
---|
53 | @Override
|
---|
54 | public void actionPerformed(ActionEvent e) {
|
---|
55 | if (helpTopic != null) {
|
---|
56 | HelpBrowser.setUrlForHelpTopic(helpTopic);
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|