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    @Override
060    public void configureManagers() {
061
062        TamsPowerManager powerManager = new TamsPowerManager(getTrafficController());
063        InstanceManager.store(powerManager, jmri.PowerManager.class);
064        store(powerManager, jmri.PowerManager.class);
065
066        TamsProgrammerManager programmerManager = getProgrammerManager();
067        InstanceManager.store(programmerManager, GlobalProgrammerManager.class);
068        InstanceManager.store(programmerManager, AddressedProgrammerManager.class);
069
070        TurnoutManager turnoutManager = new TamsTurnoutManager(this);
071        InstanceManager.setTurnoutManager(turnoutManager);
072        store(turnoutManager,TurnoutManager.class);
073
074        ThrottleManager throttleManager = new TamsThrottleManager(this);
075        InstanceManager.setThrottleManager(throttleManager);
076        store(throttleManager,ThrottleManager.class);
077
078        SensorManager sensorManager = new TamsSensorManager(this);
079        InstanceManager.setSensorManager(sensorManager);
080        store(throttleManager,ThrottleManager.class);
081
082        register();
083    }
084
085    @Override
086    protected ResourceBundle getActionModelResourceBundle() {
087        return ResourceBundle.getBundle("jmri.jmrix.tams.TamsActionListBundle");
088    }
089
090    @Override
091    public <B extends NamedBean> Comparator<B> getNamedBeanComparator(Class<B> type) {
092        return new NamedBeanComparator<>();
093    }
094
095    /**
096     * Provides access to the Programmer for this particular connection.
097     * NOTE: Programmer defaults to null
098     * @return programmer manager.
099     */
100    public TamsProgrammerManager getProgrammerManager() {
101        return (TamsProgrammerManager) classObjectMap.computeIfAbsent(TamsProgrammerManager.class, (Class<?> c) -> new TamsProgrammerManager(new TamsProgrammer(getTrafficController()),this));
102    }
103
104    public void setProgrammerManager(TamsProgrammerManager p) {
105        store(p,TamsProgrammerManager.class);
106    }
107
108    public TamsTurnoutManager getTurnoutManager() {
109        return (TamsTurnoutManager) classObjectMap.computeIfAbsent(TurnoutManager.class, (Class<?> c) -> { return new TamsTurnoutManager(this); });
110    }
111
112    public TamsSensorManager getSensorManager() {
113        return (TamsSensorManager) classObjectMap.computeIfAbsent(SensorManager.class, (Class<?> c) -> { return new TamsSensorManager(this); });
114    }
115
116    public TamsThrottleManager getThrottleManager() {
117        return (TamsThrottleManager) classObjectMap.computeIfAbsent(ThrottleManager.class, (Class<?> c) -> { return new TamsThrottleManager(this); });
118    }
119
120    public TamsPowerManager getPowerManager() {
121        return (TamsPowerManager) classObjectMap.computeIfAbsent(PowerManager.class, (Class<?> c) -> { return new TamsPowerManager(getTrafficController()); });
122    }
123
124    @Override
125    public void dispose() {
126        et = null;
127        InstanceManager.deregister(this, TamsSystemConnectionMemo.class);
128        if (cf != null) {
129            InstanceManager.deregister(cf, jmri.jmrix.swing.ComponentFactory.class);
130        }
131
132        super.dispose();
133    }
134}
135
136
137