001package apps.swing;
002
003import java.util.*;
004
005import javax.annotation.Nonnull;
006import javax.swing.JMenuItem;
007import javax.swing.UIManager;
008
009import apps.*;
010import apps.plaf.macosx.Application;
011
012import jmri.jmrit.XmlFileLocationAction;
013import jmri.util.*;
014
015import org.openide.util.lookup.ServiceProvider;
016import org.slf4j.Logger;
017import org.slf4j.LoggerFactory;
018
019import apps.util.issuereporter.swing.IssueReporterAction;
020
021/**
022 * Common utility methods for working with Java Help.
023 * <p>
024 * This class was created to contain common Java Help information.
025 * <p>
026 * It assumes that Java Help 1.1.8 is in use
027 *
028 * @author Bob Jacobsen Copyright 2007
029 */
030@ServiceProvider(service = HelpUtil.MenuProvider.class)
031public class HelpMenuProvider implements HelpUtil.MenuProvider {
032
033    public HelpMenuProvider() {
034        // do nothing
035    }
036
037    @Nonnull
038    @Override
039    public List<JMenuItem> getHelpMenuItems() {
040        List<JMenuItem> items = new ArrayList<>();
041
042        JMenuItem item = new JMenuItem(Bundle.getMessage("MenuItemHelp"));
043        HelpUtil.enableHelpOnButton(item, "index");
044        items.add(item);
045
046        JMenuItem license = new JMenuItem(Bundle.getMessage("MenuItemLicense"));
047        items.add(license);
048        license.addActionListener(new LicenseAction());
049
050        JMenuItem directories = new JMenuItem(Bundle.getMessage("MenuItemFileLocations"));
051        items.add(directories);
052        directories.addActionListener(new XmlFileLocationAction());
053
054        JMenuItem updates = new JMenuItem(Bundle.getMessage("MenuItemCheckUpdates"));
055        items.add(updates);
056        updates.addActionListener(new CheckForUpdateAction());
057
058        JMenuItem context = new JMenuItem(Bundle.getMessage("MenuItemContext"));
059        items.add(context);
060        context.addActionListener(new ReportContextAction());
061
062        JMenuItem console = new JMenuItem(Bundle.getMessage("MenuItemConsole"));
063        items.add(console);
064        console.addActionListener(new SystemConsoleAction());
065
066        items.add(new JMenuItem(new IssueReporterAction()));
067
068        // Put about dialog in Apple's preferred area on Mac OS X
069        if (SystemType.isMacOSX()) {
070            try {
071                Objects.requireNonNull(Application.getApplication()).setAboutHandler((EventObject eo) ->
072                        new AboutDialog(null, true).setVisible(true));
073            } catch (java.lang.RuntimeException re) {
074                log.error("Unable to put About handler in default location", re);
075            }
076        }
077        // Include About in Help menu if not on Mac OS X or not using Aqua Look and Feel
078        if (!SystemType.isMacOSX() || !UIManager.getLookAndFeel().isNativeLookAndFeel()) {
079            items.add(null);
080            JMenuItem about = new JMenuItem(Bundle.getMessage("MenuItemAbout") + " " + jmri.Application.getApplicationName());
081            items.add(about);
082            about.addActionListener(new AboutAction());
083        }
084        return items;
085    }
086
087    // initialize logging
088    private static final Logger log = LoggerFactory.getLogger(HelpMenuProvider.class);
089}