001package jmri.jmrix.ecos.swing;
002
003import javax.swing.JMenu;
004
005import jmri.InstanceManager;
006import jmri.jmrix.ecos.EcosSystemConnectionMemo;
007import jmri.util.prefs.JmriPreferencesActionFactory;
008import org.slf4j.Logger;
009import org.slf4j.LoggerFactory;
010
011/**
012 * Create a "Systems" menu containing the Jmri ECoS-specific tools.
013 *
014 * @author Kevin Dickerson
015 */
016public class EcosMenu extends JMenu {
017
018    public EcosMenu(EcosSystemConnectionMemo memo) {
019        super();
020
021        String title;
022        if (memo != null) {
023            title = memo.getUserName();
024        } else {
025            title = Bundle.getMessage("MenuEcos");
026        }
027        setText(title);
028
029        jmri.util.swing.WindowInterface wi = new jmri.util.swing.sdi.JmriJFrameInterface();
030
031        for (Item item : panelItems) {
032            if (item == null) {
033                add(new javax.swing.JSeparator());
034            } else {
035                add(new EcosNamedPaneAction(Bundle.getMessage(item.name), wi, item.load, memo));
036            }
037        }
038
039        if (jmri.InstanceManager.getNullableDefault(jmri.jmrit.beantable.ListedTableFrame.class) == null) {
040            try {
041                new jmri.jmrit.beantable.ListedTableFrame<jmri.Turnout>();
042            } catch (java.lang.NullPointerException ex) {
043                log.error("Unable to register ECoS table");
044            }
045        }
046
047        add(new jmri.jmrit.beantable.ListedTableAction(Bundle.getMessage("MenuItemDatabase"), "jmri.jmrix.ecos.swing.locodatabase.EcosLocoTableTabAction"));
048        add(InstanceManager.getDefault(JmriPreferencesActionFactory.class).
049                getCategorizedAction(Bundle.getMessage("MenuItemECoSPrefs"), "ECoS", title));
050        if (memo != null) {
051            add(new jmri.jmrix.ecos.utilities.AddRosterEntryToEcos(Bundle.getMessage("MenuItemAddLocoToEcos"), memo));
052        }
053    }
054
055    Item[] panelItems = new Item[]{
056        new Item("MenuItemEcosMonitor", "jmri.jmrix.ecos.swing.monitor.EcosMonPane"),
057        new Item("MenuItemSendPacket", "jmri.jmrix.ecos.swing.packetgen.PacketGenPanel"),
058        new Item("MenuItemInfo", "jmri.jmrix.ecos.swing.statusframe.StatusPanel")
059
060    };
061
062    static class Item {
063
064        Item(String name, String load) {
065            this.name = name;
066            this.load = load;
067        }
068
069        String name;
070        String load;
071    }
072
073    private final static Logger log = LoggerFactory.getLogger(EcosMenu.class);
074
075}