001package jmri.jmrix.mrc.swing;
002
003import javax.annotation.Nonnull;
004import javax.swing.JMenu;
005import jmri.jmrix.mrc.MrcSystemConnectionMemo;
006
007/**
008 * Create a "Systems" menu containing the JMRI MRC-specific tools.
009 *
010 * @author Bob Jacobsen Copyright 2003, 2010 Copied from nce.swing
011 * @author Ken Cameron 2014
012 * @author Kevin Dickerson 2014
013 */
014public class MrcMenu extends JMenu {
015
016    /**
017     * Create an MRC menu and load the MrcSystemConnectionMemo to the various
018     * actions. Actions will open new windows.
019     *
020     * @param memo sytem connection memo
021     */
022    // Need to Sort out the MRC server menu items;
023    public MrcMenu(@Nonnull MrcSystemConnectionMemo memo) {
024        super();
025
026        setText(memo.getUserName());
027
028        jmri.util.swing.WindowInterface wi = new jmri.util.swing.sdi.JmriJFrameInterface();
029
030        for (Item item : panelItems) {
031            if (item == null) {
032                add(new javax.swing.JSeparator());
033            } else {
034                MrcNamedPaneAction a = new MrcNamedPaneAction(Bundle.getMessage(item.name), wi, item.load, memo);
035                add(a);
036            }
037        }
038
039        // do we have an MrcTrafficController?
040        setEnabled(memo.getMrcTrafficController() != null); // disable menu, no connection, no tools!
041
042        add(new javax.swing.JSeparator());
043    }
044
045    private Item[] panelItems = new Item[]{
046        new Item("MenuItemCommandMonitor", "jmri.jmrix.mrc.swing.monitor.MrcMonPanel"), // NOI18N
047        new Item("MenuItemSendCommand", "jmri.jmrix.mrc.swing.packetgen.MrcPacketGenPanel"), // NOI18N
048    };
049
050    static class Item {
051
052        Item(String name, String load) {
053            this.name = name;
054            this.load = load;
055        }
056        String name;
057        String load;
058    }
059
060}