001package jmri.jmrix.nce.swing;
002
003import java.util.ResourceBundle;
004import javax.annotation.Nonnull;
005import javax.swing.JMenu;
006import jmri.jmrix.nce.NceSystemConnectionMemo;
007import jmri.jmrix.nce.NceTrafficController;
008
009/**
010 * Create a "Systems" menu containing the JMRI NCE-specific tools.
011 *
012 * @author Bob Jacobsen Copyright 2003, 2010 converted to multiple connection
013 * @author kcameron Copyright 2010, 2013
014 */
015public class NceMenu extends JMenu {
016
017    /**
018     * Create an NCE menu and load the NceSystemConnectionMemo to the various
019     * actions. Actions will open new windows.
020     *
021     * @param memo the system connection memo to associate menu items with
022     */
023    // TODO Need to Sort out the NCE server menu items
024    public NceMenu(@Nonnull NceSystemConnectionMemo memo) {
025        super();
026
027        ResourceBundle rb = ResourceBundle.getBundle("jmri.jmrix.JmrixSystemsBundle");
028
029        setText(memo.getUserName());
030
031        jmri.util.swing.WindowInterface wi = new jmri.util.swing.sdi.JmriJFrameInterface();
032
033        for (Item item : panelItems) {
034            if (item == null) {
035                add(new javax.swing.JSeparator());
036            } else {
037                NceNamedPaneAction a = new NceNamedPaneAction(rb.getString(item.name), wi, item.load, memo);
038                add(a);
039                if ((item.enable & memo.getNceCmdGroups()) != 0) {
040                    a.setEnabled(true);
041                } else {
042                    a.setEnabled(false);
043                }
044            }
045        }
046
047        // do we have an NceTrafficController?
048        setEnabled(memo.getNceTrafficController() != null); // disable menu, no connection, no tools!
049
050        add(new javax.swing.JSeparator());
051    }
052
053    private Item[] panelItems = new Item[]{
054        new Item("MenuItemCommandMonitor", "jmri.jmrix.nce.ncemon.NceMonPanel", NceTrafficController.CMDS_ALL_SYS),
055        new Item("MenuItemSendCommand", "jmri.jmrix.nce.packetgen.NcePacketGenPanel", NceTrafficController.CMDS_ALL_SYS),
056        new Item("MenuItemMacroCommand", "jmri.jmrix.nce.macro.NceMacroGenPanel", NceTrafficController.CMDS_ALL_SYS),
057        new Item("MenuItemMacroEdit", "jmri.jmrix.nce.macro.NceMacroEditPanel", NceTrafficController.CMDS_MEM),
058        new Item("MenuItemConsistEdit", "jmri.jmrix.nce.consist.NceConsistEditPanel", NceTrafficController.CMDS_MEM),
059        new Item("MenuItemTrackPacketMonitor", "jmri.jmrix.ncemonitor.NcePacketMonitorPanel", NceTrafficController.CMDS_ALL_SYS),
060        new Item("MenuItemClockMon", "jmri.jmrix.nce.clockmon.ClockMonPanel", NceTrafficController.CMDS_CLOCK),
061        new Item("MenuItemShowCabs", "jmri.jmrix.nce.cab.NceShowCabPanel", NceTrafficController.CMDS_MEM),
062        new Item("MenuItemBoosterProg", "jmri.jmrix.nce.boosterprog.BoosterProgPanel", NceTrafficController.CMDS_NOT_USB),
063        new Item("MenuItemUsbInt", "jmri.jmrix.nce.usbinterface.UsbInterfacePanel", NceTrafficController.CMDS_USB)
064    };
065
066    static class Item {
067
068        Item(String name, String load, long enable) {
069            this.name = name;
070            this.load = load;
071            this.enable = enable;
072        }
073        String name;
074        String load;
075        long enable;
076    }
077
078}