source: josm/trunk/src/org/openstreetmap/josm/gui/help/ContextSensitiveHelpAction.java@ 13490

Last change on this file since 13490 was 11553, checked in by Don-vip, 7 years ago

refactor handling of null values - use Java 8 Optional where possible

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.help;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.ActionEvent;
8import java.util.Optional;
9
10import javax.swing.AbstractAction;
11
12import org.openstreetmap.josm.Main;
13import org.openstreetmap.josm.io.OnlineResource;
14import 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 */
21public 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}
Note: See TracBrowser for help on using the repository browser.