001package jmri.jmrix.can.cbus.swing;
002
003import javax.swing.JMenu;
004import jmri.jmrix.can.CanSystemConnectionMemo;
005import jmri.jmrix.can.ConfigurationManager;
006import jmri.jmrix.can.swing.CanNamedPaneAction;
007
008/**
009 * Create a menu containing the Jmri CAN- and CBUS-specific tools
010 *
011 * @author Bob Jacobsen Copyright 2003, 2008, 2009
012 * @author Andrew Crosland 2008, 2020
013 */
014public class SprogCbusMenu extends JMenu {
015
016    Item[] panelItems;
017    
018    public SprogCbusMenu(CanSystemConnectionMemo memo) {
019        super();
020
021        if (memo != null) {
022            setText(memo.getUserName());
023        } else {
024            setText(Bundle.getMessage("MenuItemCBUS"));
025        }
026
027        jmri.util.swing.WindowInterface wi = new jmri.util.swing.sdi.JmriJFrameInterface();
028        
029        if (memo != null) {
030            panelItems = createPanelItems(memo);
031        }
032        
033        for (Item item : panelItems) {
034            if (item == null) {
035                add(new javax.swing.JSeparator());
036            } else {
037                add(new CanNamedPaneAction(Bundle.getMessage(item.name), wi, item.load, memo));
038            }
039        }
040        
041        // Not a CanNamedPane
042        add(new javax.swing.JSeparator());
043        if (memo != null) {
044            if (!memo.getProgModeSwitch().equals(ConfigurationManager.ProgModeSwitch.NONE)) {
045                // Hardware supports programming mode switching
046                add(new jmri.jmrix.can.cbus.swing.modeswitcher.SprogCbusModeSwitcherAction(Bundle.getMessage("MenuItemSPROGModeSwitcher"), memo));
047            }
048        }
049        // Added tools that can normally only be found in PanelPro tools menu so that they are available from DP3
050        add(new javax.swing.JSeparator());
051        add(new jmri.jmrit.swing.meter.MeterAction());
052
053    }
054
055    private Item[] createPanelItems(CanSystemConnectionMemo memo) {
056        if (memo.getSubProtocol().equals(ConfigurationManager.SubProtocol.CBUS)) {
057            return new Item[]{
058                new Item("MenuItemConsole", "jmri.jmrix.can.cbus.swing.console.CbusConsolePane"),
059                new Item("MenuItemSendFrame", "jmri.jmrix.can.swing.send.CanSendPane"),
060                new Item("MenuItemEventCapture", "jmri.jmrix.can.cbus.swing.configtool.ConfigToolPane"),
061                new Item("MenuItemEventTable", "jmri.jmrix.can.cbus.swing.eventtable.CbusEventTablePane"),
062                new Item("MenuItemNodeConfig", "jmri.jmrix.can.cbus.swing.nodeconfig.NodeConfigToolPane"),
063                new Item("MenuItemCbusSlotMonitor", "jmri.jmrix.can.cbus.swing.cbusslotmonitor.CbusSlotMonitorPane"),
064                new Item("MenuItemEvRequestMon", "jmri.jmrix.can.cbus.swing.eventrequestmonitor.CbusEventRequestTablePane"),
065                new Item("MenuItemNetworkSim", "jmri.jmrix.can.cbus.swing.simulator.SimulatorPane"),
066                new Item("MenuItemBootloader", "jmri.jmrix.can.cbus.swing.bootloader.CbusBootloaderPane"),
067                new Item("MenuItemCbusHub", "jmri.jmrix.can.cbus.swing.hubpane.CbusHubPane")
068            };
069        } else {
070            return new Item[]{
071                new Item("MenuItemSPROGConsole", "jmri.jmrix.can.cbus.swing.console.CbusConsolePane"),
072                new Item("MenuItemSendFrame", "jmri.jmrix.can.swing.send.CanSendPane"),
073                new Item("MenuItemSPROGNodeConfig", "jmri.jmrix.can.cbus.swing.nodeconfig.NodeConfigToolPane"),
074                new Item("MenuItemSPROGCbusSlotMonitor", "jmri.jmrix.can.cbus.swing.cbusslotmonitor.CbusSlotMonitorPane"),
075                new Item("MenuItemSPROGBootloader", "jmri.jmrix.can.cbus.swing.bootloader.CbusBootloaderPane")
076            };
077        }
078    }
079    
080    static class Item {
081
082        Item(String name, String load) {
083            this.name = name;
084            this.load = load;
085        }
086
087        String name;
088        String load;
089    }
090
091}