001package jmri.jmrix.marklin;
002
003import java.util.Comparator;
004import java.util.ResourceBundle;
005
006import jmri.*;
007import jmri.jmrix.ConfiguringSystemConnectionMemo;
008import jmri.util.NamedBeanComparator;
009
010/**
011 * Lightweight class to denote that a system is active, and provide general
012 * information.
013 * <p>
014 * Objects of specific subtypes are registered in the instance manager to
015 * activate their particular system.
016 *
017 * @author Bob Jacobsen Copyright (C) 2010
018 * @author Kevin Dickerson Copyright (C) 2012
019 */
020public class MarklinSystemConnectionMemo extends jmri.jmrix.DefaultSystemConnectionMemo implements ConfiguringSystemConnectionMemo {
021
022    public MarklinSystemConnectionMemo(MarklinTrafficController et) {
023        super("M", "Marklin-CS2");
024        this.et = et;
025        et.setAdapterMemo(this);
026        InstanceManager.store(this, MarklinSystemConnectionMemo.class); // also register as specific type
027        InstanceManager.store(cf = new jmri.jmrix.marklin.swing.MarklinComponentFactory(this),
028                jmri.jmrix.swing.ComponentFactory.class);
029    }
030
031    public MarklinSystemConnectionMemo() {
032        super("M", "Marklin-CS2");
033        register(); // registers general type
034        InstanceManager.store(this, MarklinSystemConnectionMemo.class); // also register as specific type
035        //Needs to be implemented
036        InstanceManager.store(cf = new jmri.jmrix.marklin.swing.MarklinComponentFactory(this),
037                jmri.jmrix.swing.ComponentFactory.class);
038    }
039
040    jmri.jmrix.swing.ComponentFactory cf = null;
041
042    /**
043     * Provides access to the TrafficController for this particular connection.
044     * @return the traffic controller.
045     */
046    public MarklinTrafficController getTrafficController() {
047        return et;
048    }
049
050    public void setMarklinTrafficController(MarklinTrafficController et) {
051        this.et = et;
052        et.setAdapterMemo(this);
053    }
054    private MarklinTrafficController et;
055
056    /**
057     * This puts the common manager config in one place.
058     */
059    public void configureManagers() {
060
061        PowerManager powerManager = new MarklinPowerManager(getTrafficController());
062        store(powerManager, PowerManager.class);
063        jmri.InstanceManager.store(powerManager, PowerManager.class);
064
065        TurnoutManager turnoutManager = new MarklinTurnoutManager(this);
066        store(turnoutManager, TurnoutManager.class);
067        jmri.InstanceManager.setTurnoutManager(turnoutManager);
068
069        ThrottleManager throttleManager = new MarklinThrottleManager(this);
070        store(throttleManager, ThrottleManager.class);
071        jmri.InstanceManager.setThrottleManager(throttleManager);
072
073        SensorManager sensorManager = new jmri.jmrix.marklin.MarklinSensorManager(this);
074        store(sensorManager, SensorManager.class);
075        jmri.InstanceManager.setSensorManager(sensorManager);
076
077        register();
078    }
079
080    @Override
081    protected ResourceBundle getActionModelResourceBundle() {
082        return ResourceBundle.getBundle("jmri.jmrix.marklin.MarklinActionListBundle");
083    }
084
085    @Override
086    public <B extends NamedBean> Comparator<B> getNamedBeanComparator(Class<B> type) {
087        return new NamedBeanComparator<>();
088    }
089
090    public MarklinTurnoutManager getTurnoutManager() {
091        return get(TurnoutManager.class);
092    }
093
094    public MarklinSensorManager getSensorManager() {
095        return get(SensorManager.class);
096    }
097
098    public MarklinThrottleManager getThrottleManager() {
099        return get(ThrottleManager.class);
100    }
101
102    public MarklinPowerManager getPowerManager() {
103        return get(PowerManager.class);
104    }
105
106    @Override
107    public void dispose() {
108        et = null;
109        InstanceManager.deregister(this, MarklinSystemConnectionMemo.class);
110        if (cf != null) {
111            InstanceManager.deregister(cf, jmri.jmrix.swing.ComponentFactory.class);
112        }
113
114        super.dispose();
115    }
116
117}