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    // Allow is-a relation between sub types, i.e. CdB and Marklin
023    protected MarklinSystemConnectionMemo(String prefix, String userName) {
024        super(prefix, userName);
025    }
026    public MarklinSystemConnectionMemo(MarklinTrafficController et) {
027        super("M", "Marklin-CS2");
028        this.et = et;
029        et.setAdapterMemo(this);
030        InstanceManager.store(this, MarklinSystemConnectionMemo.class); // also register as specific type
031        InstanceManager.store(cf = new jmri.jmrix.marklin.swing.MarklinComponentFactory(this),
032                jmri.jmrix.swing.ComponentFactory.class);
033    }
034
035    public MarklinSystemConnectionMemo() {
036        super("M", "Marklin-CS2");
037        register(); // registers general type
038        InstanceManager.store(this, MarklinSystemConnectionMemo.class); // also register as specific type
039        //Needs to be implemented
040        InstanceManager.store(cf = new jmri.jmrix.marklin.swing.MarklinComponentFactory(this),
041                jmri.jmrix.swing.ComponentFactory.class);
042    }
043
044    jmri.jmrix.swing.ComponentFactory cf = null;
045
046    /**
047     * Provides access to the TrafficController for this particular connection.
048     * @return the traffic controller.
049     */
050    public MarklinTrafficController getTrafficController() {
051        return et;
052    }
053
054    public void setMarklinTrafficController(MarklinTrafficController et) {
055        this.et = et;
056        et.setAdapterMemo(this);
057    }
058    private MarklinTrafficController et;
059
060    /**
061     * This puts the common manager config in one place.
062     */
063    @Override
064    public void configureManagers() {
065
066        PowerManager powerManager = new MarklinPowerManager(getTrafficController());
067        store(powerManager, PowerManager.class);
068        jmri.InstanceManager.store(powerManager, PowerManager.class);
069
070        TurnoutManager turnoutManager = new MarklinTurnoutManager(this);
071        store(turnoutManager, TurnoutManager.class);
072        jmri.InstanceManager.setTurnoutManager(turnoutManager);
073
074        ThrottleManager throttleManager = new MarklinThrottleManager(this);
075        store(throttleManager, ThrottleManager.class);
076        jmri.InstanceManager.setThrottleManager(throttleManager);
077
078        SensorManager sensorManager = new jmri.jmrix.marklin.MarklinSensorManager(this);
079        store(sensorManager, SensorManager.class);
080        jmri.InstanceManager.setSensorManager(sensorManager);
081
082        register();
083    }
084
085    @Override
086    protected ResourceBundle getActionModelResourceBundle() {
087        return ResourceBundle.getBundle("jmri.jmrix.marklin.MarklinActionListBundle");
088    }
089
090    @Override
091    public <B extends NamedBean> Comparator<B> getNamedBeanComparator(Class<B> type) {
092        return new NamedBeanComparator<>();
093    }
094
095    public MarklinTurnoutManager getTurnoutManager() {
096        return (MarklinTurnoutManager)get(TurnoutManager.class);
097    }
098
099    public MarklinSensorManager getSensorManager() {
100        return (MarklinSensorManager)get(SensorManager.class);
101    }
102
103    public MarklinThrottleManager getThrottleManager() {
104        return (MarklinThrottleManager)get(ThrottleManager.class);
105    }
106
107    public MarklinPowerManager getPowerManager() {
108        return (MarklinPowerManager)get(PowerManager.class);
109    }
110
111    @Override
112    public void dispose() {
113        et = null;
114        InstanceManager.deregister(this, MarklinSystemConnectionMemo.class);
115        if (cf != null) {
116            InstanceManager.deregister(cf, jmri.jmrix.swing.ComponentFactory.class);
117        }
118
119        super.dispose();
120    }
121
122}