001package jmri.jmrix.marklin.cdb;
002
003import java.util.Comparator;
004import java.util.ResourceBundle;
005
006import jmri.*;
007import jmri.util.NamedBeanComparator;
008
009import jmri.jmrix.marklin.MarklinTrafficController;
010//import jmri.jmrix.marklin.MarklinProgrammer;
011//import jmri.jmrix.marklin.MarklinProgrammerManager;
012import jmri.jmrix.marklin.MarklinSensorManager;
013import jmri.jmrix.marklin.MarklinThrottleManager;
014import jmri.jmrix.marklin.MarklinTurnoutManager;
015import jmri.jmrix.marklin.MarklinPowerManager;
016import jmri.jmrix.marklin.MarklinSystemConnectionMemo;
017
018/**
019 * Lightweight class to denote that a system is active, and provide general
020 * information.
021 * <p>
022 * Objects of specific subtypes are registered in the instance manager to
023 * activate their particular system.
024 *
025 * Based on work by Bob Jacobsen
026 *
027 * @author Kevin Dickerson Copyright (C) 2012
028 */
029public class CdBSystemConnectionMemo extends MarklinSystemConnectionMemo {
030
031    public CdBSystemConnectionMemo(MarklinTrafficController et) {
032        super("M", "CdB");
033        this.et = et;
034        et.setAdapterMemo(this);
035        InstanceManager.store(this, CdBSystemConnectionMemo.class);
036        InstanceManager.store(cf = new jmri.jmrix.marklin.swing.MarklinComponentFactory(this),
037                jmri.jmrix.swing.ComponentFactory.class);
038    }
039
040    public CdBSystemConnectionMemo() {
041        super("M", "CdB");
042        InstanceManager.store(this, CdBSystemConnectionMemo.class);
043        InstanceManager.store(cf = new jmri.jmrix.marklin.swing.MarklinComponentFactory(this),
044                jmri.jmrix.swing.ComponentFactory.class);
045    }
046
047    jmri.jmrix.swing.ComponentFactory cf = null;
048
049    /**
050     * Provides access to the TrafficController for this particular connection.
051     * @return Marklin Traffic Controller.
052     */
053    @Override
054    public MarklinTrafficController getTrafficController() {
055        return et;
056    }
057
058    @Override
059    public void setMarklinTrafficController(MarklinTrafficController et) {
060        this.et = et;
061        et.setAdapterMemo(this);
062    }
063    private MarklinTrafficController et;
064
065    /**
066     * This puts the common manager config in one place.
067     */
068    @Override
069    public void configureManagers() {
070
071        MarklinPowerManager powerManager = new MarklinPowerManager(getTrafficController());
072        InstanceManager.store(powerManager, jmri.PowerManager.class);
073        store(powerManager, jmri.PowerManager.class);
074
075/*        MarklinProgrammerManager programmerManager = getProgrammerManager();
076        InstanceManager.store(programmerManager, GlobalProgrammerManager.class);
077        InstanceManager.store(programmerManager, AddressedProgrammerManager.class);*/
078
079        TurnoutManager turnoutManager = new MarklinTurnoutManager(this);
080        InstanceManager.setTurnoutManager(turnoutManager);
081        store(turnoutManager,TurnoutManager.class);
082
083        ThrottleManager throttleManager = new MarklinThrottleManager(this);
084        InstanceManager.setThrottleManager(throttleManager);
085        store(throttleManager,ThrottleManager.class);
086
087        SensorManager sensorManager = new MarklinSensorManager(this);
088        InstanceManager.setSensorManager(sensorManager);
089        store(throttleManager,ThrottleManager.class);
090
091        register();
092    }
093
094    @Override
095    protected ResourceBundle getActionModelResourceBundle() {
096        return ResourceBundle.getBundle("jmri.jmrix.marklin.MarklinActionListBundle");
097    }
098
099    @Override
100    public <B extends NamedBean> Comparator<B> getNamedBeanComparator(Class<B> type) {
101        return new NamedBeanComparator<>();
102    }
103
104    /**
105     * Provides access to the Programmer for this particular connection.
106     * NOTE: Programmer defaults to null
107     * @return programmer manager.
108     */
109    /*  public MarklinProgrammerManager getProgrammerManager() {
110        return (MarklinProgrammerManager) classObjectMap.computeIfAbsent(MarklinProgrammerManager.class, (Class<?> c) -> new MarklinProgrammerManager(new MarklinProgrammer(getTrafficController()),this));
111    }
112
113    public void setProgrammerManager(MarklinProgrammerManager p) {
114        store(p,TamsProgrammerManager.class);
115    }*/
116
117    @Override
118    public MarklinTurnoutManager getTurnoutManager() {
119        return (MarklinTurnoutManager) classObjectMap.computeIfAbsent(TurnoutManager.class, (Class<?> c) -> { return new MarklinTurnoutManager(this); });
120    }
121
122    @Override
123    public MarklinSensorManager getSensorManager() {
124        return (MarklinSensorManager) classObjectMap.computeIfAbsent(SensorManager.class, (Class<?> c) -> { return new MarklinSensorManager(this); });
125    }
126
127    @Override
128    public MarklinThrottleManager getThrottleManager() {
129        return (MarklinThrottleManager) classObjectMap.computeIfAbsent(ThrottleManager.class, (Class<?> c) -> { return new MarklinThrottleManager(this); });
130    }
131
132    @Override
133    public MarklinPowerManager getPowerManager() {
134        return (MarklinPowerManager) classObjectMap.computeIfAbsent(PowerManager.class, (Class<?> c) -> { return new MarklinPowerManager(getTrafficController()); });
135    }
136
137    @Override
138    public void dispose() {
139        et = null;
140        InstanceManager.deregister(this, CdBSystemConnectionMemo.class);
141        if (cf != null) {
142            InstanceManager.deregister(cf, jmri.jmrix.swing.ComponentFactory.class);
143        }
144
145        super.dispose();
146    }
147}
148
149
150