001package jmri.jmrix.jmriclient;
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 Paul Bender Copyright (C) 2010
018 */
019public class JMRIClientSystemConnectionMemo extends jmri.jmrix.DefaultSystemConnectionMemo implements ConfiguringSystemConnectionMemo {
020
021    public JMRIClientSystemConnectionMemo(JMRIClientTrafficController jt) {
022        super("J", "JMRI Client");
023        this.jt = jt;
024        InstanceManager.store(this, JMRIClientSystemConnectionMemo.class);
025
026        // create and register the JMRIClientComponentFactory
027        InstanceManager.store(cf = new jmri.jmrix.jmriclient.swing.JMRIClientComponentFactory(this),
028                jmri.jmrix.swing.ComponentFactory.class);
029    }
030
031    public JMRIClientSystemConnectionMemo() {
032        super("J", "JMRIClient");
033        this.jt = new JMRIClientTrafficController();
034        InstanceManager.store(this, JMRIClientSystemConnectionMemo.class);
035
036        // create and register the JMRIClientComponentFactory
037        InstanceManager.store(cf = new jmri.jmrix.jmriclient.swing.JMRIClientComponentFactory(this), 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 traffic controller.
045     */
046    public JMRIClientTrafficController getJMRIClientTrafficController() {
047        return jt;
048    }
049    private JMRIClientTrafficController jt;
050
051    public void setJMRIClientTrafficController(JMRIClientTrafficController jt) {
052        this.jt = jt;
053    }
054
055    @Override
056    public void dispose() {
057        jt = null;
058        InstanceManager.deregister(this, JMRIClientSystemConnectionMemo.class);
059        if (cf != null) {
060            InstanceManager.deregister(cf, jmri.jmrix.swing.ComponentFactory.class);
061        }
062        super.dispose();
063    }
064
065    /**
066     * Configure the common managers for Internal connections. This puts the
067     * common manager config in one place.
068     */
069    @Override
070    public void configureManagers() {
071
072        setPowerManager(new jmri.jmrix.jmriclient.JMRIClientPowerManager(this));
073        jmri.InstanceManager.store(getPowerManager(), jmri.PowerManager.class);
074        setTurnoutManager(new jmri.jmrix.jmriclient.JMRIClientTurnoutManager(this));
075        jmri.InstanceManager.setTurnoutManager(getTurnoutManager());
076        setSensorManager(new jmri.jmrix.jmriclient.JMRIClientSensorManager(this));
077        jmri.InstanceManager.setSensorManager(getSensorManager());
078        setLightManager(new jmri.jmrix.jmriclient.JMRIClientLightManager(this));
079        jmri.InstanceManager.setLightManager(getLightManager());
080        setReporterManager(new jmri.jmrix.jmriclient.JMRIClientReporterManager(this));
081        jmri.InstanceManager.setReporterManager(getReporterManager());
082
083        register();
084    }
085
086    /**
087     * Request all status from the configured managers.
088     */
089    public void requestAllStatus() {
090
091        getTurnoutManager().getNamedBeanSet().forEach((turn) -> {
092            ((JMRIClientTurnout)(turn)).requestUpdateFromLayout();
093        }); 
094        getSensorManager().getNamedBeanSet().forEach((sen) -> {
095            ((JMRIClientSensor)(sen)).requestUpdateFromLayout();
096        }); 
097        getLightManager().getNamedBeanSet().forEach((light) -> {
098            ((JMRIClientLight)light).requestUpdateFromLayout();
099        }); 
100        getReporterManager().getNamedBeanSet().forEach((rep) -> {
101            ((JMRIClientReporter)(rep)).requestUpdateFromLayout();
102        }); 
103    }
104
105    /*
106     * Provides access to the PowerManager for this particular connection.
107     */
108    public PowerManager getPowerManager() {
109        return get(PowerManager.class);
110    }
111
112    public void setPowerManager(PowerManager p) {
113        store(p,PowerManager.class);
114    }
115
116    /*
117     * Provides access to the SensorManager for this particular connection.
118     */
119    public SensorManager getSensorManager() {
120        return get(SensorManager.class);
121
122    }
123
124    public void setSensorManager(SensorManager s) {
125        store(s,SensorManager.class);
126    }
127
128    /*
129     * Provides access to the TurnoutManager for this particular connection.
130     * NOTE: TurnoutManager defaults to NULL
131     */
132    public TurnoutManager getTurnoutManager() {
133        return get(TurnoutManager.class);
134
135    }
136
137    public void setTurnoutManager(TurnoutManager t) {
138         store(t,TurnoutManager.class);
139    }
140
141    /*
142     * Provides access to the LightManager for this particular connection.
143     * NOTE: LightManager defaults to NULL
144     */
145    public LightManager getLightManager() {
146        return get(LightManager.class);
147    }
148
149    public void setLightManager(LightManager t) {
150        store(t,LightManager.class);
151    }
152
153    /*
154     * Provides access to the Reporter Manager for this particular connection.
155     * NOTE: Reporter manager defaults to NULL
156     */
157    public ReporterManager getReporterManager() {
158        return get(ReporterManager.class);
159    }
160
161    public void setReporterManager(ReporterManager t) {
162        store(t,ReporterManager.class);
163    }
164
165
166    public void setTransmitPrefix(String tPrefix) {
167        transmitPrefix = tPrefix;
168    }
169
170    public String getTransmitPrefix() {
171        if (transmitPrefix == null) {
172            return getSystemPrefix();
173        }
174        return transmitPrefix;
175    }
176
177    private String transmitPrefix = null;
178
179    @Override
180    protected ResourceBundle getActionModelResourceBundle() {
181        //No actions that can be loaded at startup
182        return null;
183    }
184
185    @Override
186    public <B extends NamedBean> Comparator<B> getNamedBeanComparator(Class<B> type) {
187        return new NamedBeanComparator<>();
188    }
189
190}