001package jmri.jmrix.qsi;
002
003import java.util.Comparator;
004import java.util.ResourceBundle;
005
006import jmri.jmrix.ConfiguringSystemConnectionMemo;
007import jmri.GlobalProgrammerManager;
008import jmri.InstanceManager;
009import jmri.NamedBean;
010import jmri.jmrix.DefaultSystemConnectionMemo;
011import jmri.managers.DefaultProgrammerManager;
012import jmri.util.NamedBeanComparator;
013
014/**
015 * Lightweight class to denote that a system is active, and provide general
016 * information.
017 * <p>
018 * Objects of specific subtypes are registered in the instance manager to
019 * activate their particular system.
020 *
021 * @author Kevin Dickerson Copyright (C) 2012
022 * @author Bob Jacobsen Copyright (C) 2010
023 */
024public class QsiSystemConnectionMemo extends DefaultSystemConnectionMemo implements ConfiguringSystemConnectionMemo {
025
026    public QsiSystemConnectionMemo(QsiTrafficController st) {
027        super("Q", "Quantum Programmer");
028        this.st = st;
029        InstanceManager.store(QsiSystemConnectionMemo.this, QsiSystemConnectionMemo.class); // also register as specific type
030        InstanceManager.store(cf = new jmri.jmrix.qsi.swing.QsiComponentFactory(this),
031        jmri.jmrix.swing.ComponentFactory.class);
032    }
033
034    public QsiSystemConnectionMemo() {
035        super("Q", "Quantum Programmer"); // "Quantum Programmer"
036        register(); // registers general type
037        InstanceManager.store(QsiSystemConnectionMemo.this, QsiSystemConnectionMemo.class); // also register as specific type
038
039        InstanceManager.store(cf = new jmri.jmrix.qsi.swing.QsiComponentFactory(this),
040        jmri.jmrix.swing.ComponentFactory.class);
041    }
042
043    jmri.jmrix.swing.ComponentFactory cf = null;
044
045    /**
046     * Provides access to the TrafficController for this particular connection.
047     * @return the QSI traffic controller.
048     */
049    public QsiTrafficController getQsiTrafficController() {
050        return st;
051    }
052
053    public void setQsiTrafficController(QsiTrafficController st) {
054        this.st = st;
055    }
056    private QsiTrafficController st;
057
058    /**
059     * Provide a menu with all items attached to this system connection.
060     * @return new QSIMenu.
061     */
062    public javax.swing.JMenu getMenu() {
063        return new QSIMenu("QSI",this);
064    }
065
066    /**
067     * Configure the common managers for Qsi connections. This puts the common
068     * manager config in one place.
069     */
070    @Override
071    public void configureManagers() {
072        store(getProgrammerManager(), jmri.AddressedProgrammerManager.class);
073        InstanceManager.store(getProgrammerManager(), jmri.AddressedProgrammerManager.class);
074        store(getProgrammerManager(), GlobalProgrammerManager.class);
075        InstanceManager.store(getProgrammerManager(), GlobalProgrammerManager.class);
076        register();
077    }
078
079    public DefaultProgrammerManager getProgrammerManager() {
080        return (DefaultProgrammerManager) classObjectMap.computeIfAbsent(DefaultProgrammerManager.class,(Class<?> c) -> new DefaultProgrammerManager(new QsiProgrammer(this),this));
081    }
082
083    public void setProgrammerManager(DefaultProgrammerManager p) {
084        store(p,DefaultProgrammerManager.class);
085    }
086
087    @Override
088    protected ResourceBundle getActionModelResourceBundle() {
089        return ResourceBundle.getBundle("jmri.jmrix.qsi.QsiActionListBundle");
090    }
091
092    @Override
093    public <B extends NamedBean> Comparator<B> getNamedBeanComparator(Class<B> type) {
094        return new NamedBeanComparator<>();
095    }
096
097    @Override
098    public void dispose() {
099        st = null;
100        InstanceManager.deregister(this, QsiSystemConnectionMemo.class);
101        if (cf != null) {
102            InstanceManager.deregister(cf, jmri.jmrix.swing.ComponentFactory.class);
103        }
104        super.dispose();
105    }
106
107}