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    @Override
078    public void configureManagers(){
079        setTurnoutManager(new SerialTurnoutManager(this));
080        InstanceManager.setTurnoutManager(getTurnoutManager());
081        setLightManager(new SerialLightManager(this));
082        InstanceManager.setLightManager(getLightManager());
083        setSensorManager(new SerialSensorManager(this));
084        InstanceManager.setSensorManager(getSensorManager());
085
086        register();
087    }
088
089    /**
090     * Provide access to the SensorManager for this particular connection.
091     * <p>
092     * NOTE: SensorManager defaults to NULL
093     * @return sensor manager.
094     */
095    public SensorManager getSensorManager() {
096        return get(SensorManager.class);
097    }
098
099    public void setSensorManager(SerialSensorManager s) {
100        store(s,SensorManager.class);
101        getTrafficController().setSensorManager(s);
102    }
103
104    /**
105     * Provide access to the TurnoutManager for this particular connection.
106     * <p>
107     * NOTE: TurnoutManager defaults to NULL
108     * @return turnout manager.
109     */
110    public TurnoutManager getTurnoutManager() {
111        return get(TurnoutManager.class);
112
113    }
114
115    public void setTurnoutManager(SerialTurnoutManager t) {
116        store(t,TurnoutManager.class);
117    }
118
119    /**
120     * Provide access to the LightManager for this particular connection.
121     * <p>
122     * NOTE: LightManager defaults to NULL
123     * @return light manager.
124     */
125    public LightManager getLightManager() {
126        return get(LightManager.class);
127    }
128
129    public void setLightManager(SerialLightManager l) {
130        store(l,LightManager.class);
131    }
132
133    // no dispose() for Maple
134
135    private final static Logger log = LoggerFactory.getLogger(MapleSystemConnectionMemo.class);
136
137}