001package jmri.jmrix.powerline;
002
003import java.util.Comparator;
004import java.util.ResourceBundle;
005
006import jmri.*;
007import jmri.jmrix.AbstractSerialPortController.SerialPort;
008import jmri.jmrix.ConfiguringSystemConnectionMemo;
009import jmri.util.NamedBeanComparator;
010
011/**
012 * Lightweight class to denote that a system is active, and provide general
013 * information.
014 * <p>
015 * Objects of specific subtypes are registered in the instance manager to
016 * activate their particular system.
017 *
018 * @author Bob Jacobsen Copyright (C) 2010 copied from NCE into Powerline for
019 * multiple connections by
020 * @author Ken Cameron Copyright (C) 2011
021 */
022public class SerialSystemConnectionMemo extends jmri.jmrix.DefaultSystemConnectionMemo implements ConfiguringSystemConnectionMemo {
023
024    public SerialSystemConnectionMemo() {
025        super("P", "Powerline");
026        InstanceManager.store(this, SerialSystemConnectionMemo.class); // also register as specific type
027
028        // create and register the ComponentFactory
029        InstanceManager.store(componentFactory = new jmri.jmrix.powerline.swing.PowerlineComponentFactory(this),
030                jmri.jmrix.swing.ComponentFactory.class);
031    }
032
033    jmri.jmrix.swing.ComponentFactory componentFactory = null;
034
035    /**
036     * Provides access to the TrafficController for this particular connection.
037     *
038     * @return tc
039     */
040    public SerialTrafficController getTrafficController() {
041        return serialTrafficController;
042    }
043    private SerialTrafficController serialTrafficController;
044
045    public void setTrafficController(SerialTrafficController tc) {
046        serialTrafficController = tc;
047    }
048
049    /**
050     * Provide access to the serial port for this connection
051     * @return SerialPort
052     */
053    public SerialPort getActiveSerialPort() {
054        return serialPort;
055    }
056    private SerialPort serialPort;
057    public void setActiveSerialPort(SerialPort sp) {
058        serialPort = sp;
059    }
060    /**
061     * Provide access to a serialAddress for this particular connection
062     *
063     * @return serialAddress
064     */
065    public SerialAddress getSerialAddress() {
066        return serialAddress;
067    }
068    private SerialAddress serialAddress;
069
070    public void setSerialAddress(SerialAddress sa) {
071        serialAddress = sa;
072    }
073
074    /**
075     * Configure the common managers for Powerline connections. This puts the
076     * common manager config in one place.
077     */
078    @Override
079    public void configureManagers() {
080        // now does nothing here, it's done by the specific class
081        register(); // registers general type
082    }
083
084    // menu support parts
085    // subclasses can override to change menu items
086
087    public static class MenuItem {
088        MenuItem(String name, String load) {
089            this.name = name;
090            this.load = load;
091        }
092        public String name;
093        public String load;
094    }
095    private final MenuItem[] panelItems = new MenuItem[]{
096        new MenuItem("MenuItemCommandMonitor", "jmri.jmrix.powerline.swing.serialmon.SerialMonPane"),
097        new MenuItem("MenuItemSendCommand", "jmri.jmrix.powerline.swing.packetgen.SerialPacketGenPane")
098    };
099
100    public MenuItem[] provideMenuItemList() {
101        return panelItems;
102    }
103
104    public SerialTurnoutManager getTurnoutManager() {
105        return (SerialTurnoutManager)get(TurnoutManager.class);
106    }
107
108    public SerialLightManager getLightManager() {
109        return (SerialLightManager)get(LightManager.class);
110    }
111
112    public SerialSensorManager getSensorManager() {
113        return (SerialSensorManager)get(SensorManager.class);
114    }
115
116    public void setTurnoutManager(SerialTurnoutManager m) {
117        store(m,TurnoutManager.class);
118    }
119
120    public void setLightManager(SerialLightManager m) {
121        store(m,LightManager.class);
122    }
123
124    public void setSensorManager(SerialSensorManager m) {
125        store(m,SensorManager.class);
126    }
127
128    @Override
129    protected ResourceBundle getActionModelResourceBundle() {
130        return ResourceBundle.getBundle("jmri.jmrix.powerline.PowerlineActionListBundle");
131    }
132
133    @Override
134    public <B extends NamedBean> Comparator<B> getNamedBeanComparator(Class<B> type) {
135        return new NamedBeanComparator<>();
136    }
137
138    @Override
139    public void dispose() {
140        serialTrafficController = null;
141        InstanceManager.deregister(this, SerialSystemConnectionMemo.class);
142        super.dispose();
143    }
144
145}