001package jmri.jmrix.maple;
002
003import java.util.Comparator;
004import java.util.ResourceBundle;
005import javax.annotation.Nonnull;
006
007import jmri.*;
008import jmri.jmrix.ConfiguringSystemConnectionMemo;
009import jmri.jmrix.DefaultSystemConnectionMemo;
010import jmri.util.NamedBeanComparator;
011
012import org.slf4j.Logger;
013import org.slf4j.LoggerFactory;
014
015/**
016 * Minimum required SystemConnectionMemo for Maple.
017 * Expanded for multichar/multiconnection support.
018 *
019 * @author Randall Wood randall.h.wood@alexandriasoftware.com
020 */
021public class MapleSystemConnectionMemo extends DefaultSystemConnectionMemo implements ConfiguringSystemConnectionMemo {
022
023    public MapleSystemConnectionMemo() {
024        this("K", SerialConnectionTypeList.MAPLE);
025    }
026
027    public MapleSystemConnectionMemo(@Nonnull String prefix, @Nonnull String userName) {
028        super(prefix, userName);
029
030        InstanceManager.store(this, MapleSystemConnectionMemo.class);
031
032        // create and register the ComponentFactory
033        InstanceManager.store(new jmri.jmrix.maple.swing.MapleComponentFactory(this),
034                jmri.jmrix.swing.ComponentFactory.class);
035
036        log.debug("Created MapleSystemConnectionMemo");
037    }
038
039    private SerialTrafficController tc = null;
040
041    /**
042     * Set the traffic controller instance associated with this connection memo.
043     *
044     * @param s jmri.jmrix.maple.SerialTrafficController object to use.
045     */
046    public void setTrafficController(SerialTrafficController s){
047        tc = s;
048    }
049
050    /**
051     * Get the traffic controller instance associated with this connection memo.
052     * @return traffic controller, new instance if null.
053     */
054    public SerialTrafficController getTrafficController(){
055        if (tc == null) {
056            setTrafficController(new SerialTrafficController());
057            log.debug("Auto create of SerialTrafficController for initial configuration");
058        }
059        return tc;
060    }
061
062    /**
063     * Provide menu strings.
064     *
065     * @return null as there is no menu for Maple connections
066     */
067    @Override
068    protected ResourceBundle getActionModelResourceBundle() {
069        return null;
070    }
071
072    @Override
073    public <B extends NamedBean> Comparator<B> getNamedBeanComparator(Class<B> type) {
074        return new NamedBeanComparator<>();
075    }
076
077    public void configureManagers(){
078        setTurnoutManager(new SerialTurnoutManager(this));
079        InstanceManager.setTurnoutManager(getTurnoutManager());
080        setLightManager(new SerialLightManager(this));
081        InstanceManager.setLightManager(getLightManager());
082        setSensorManager(new SerialSensorManager(this));
083        InstanceManager.setSensorManager(getSensorManager());
084
085        register();
086    }
087
088    /**
089     * Provide access to the SensorManager for this particular connection.
090     * <p>
091     * NOTE: SensorManager defaults to NULL
092     * @return sensor manager.
093     */
094    public SensorManager getSensorManager() {
095        return get(SensorManager.class);
096    }
097
098    public void setSensorManager(SerialSensorManager s) {
099        store(s,SensorManager.class);
100        getTrafficController().setSensorManager(s);
101    }
102
103    /**
104     * Provide access to the TurnoutManager for this particular connection.
105     * <p>
106     * NOTE: TurnoutManager defaults to NULL
107     * @return turnout manager.
108     */
109    public TurnoutManager getTurnoutManager() {
110        return get(TurnoutManager.class);
111
112    }
113
114    public void setTurnoutManager(SerialTurnoutManager t) {
115        store(t,TurnoutManager.class);
116    }
117
118    /**
119     * Provide access to the LightManager for this particular connection.
120     * <p>
121     * NOTE: LightManager defaults to NULL
122     * @return light manager.
123     */
124    public LightManager getLightManager() {
125        return get(LightManager.class);
126    }
127
128    public void setLightManager(SerialLightManager l) {
129        store(l,LightManager.class);
130    }
131
132    // no dispose() for Maple
133
134    private final static Logger log = LoggerFactory.getLogger(MapleSystemConnectionMemo.class);
135
136}