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