001package jmri.jmrix.rfid;
002
003import java.util.Comparator;
004import java.util.ResourceBundle;
005import jmri.InstanceManager;
006import jmri.NamedBean;
007import jmri.ReporterManager;
008import jmri.SensorManager;
009import jmri.jmrix.DefaultSystemConnectionMemo;
010import jmri.jmrix.rfid.swing.RfidComponentFactory;
011import jmri.jmrix.swing.ComponentFactory;
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 * <hr>
021 * This file is part of JMRI.
022 * <p>
023 * JMRI is free software; you can redistribute it and/or modify it under the
024 * terms of version 2 of the GNU General Public License as published by the Free
025 * Software Foundation. See the "COPYING" file for a copy of this license.
026 * <p>
027 * JMRI is distributed in the hope that it will be useful, but WITHOUT ANY
028 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
029 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
030 *
031 * @author Bob Jacobsen Copyright (C) 2010
032 * @author Matthew Harris Copyright (C) 2011
033 */
034public class RfidSystemConnectionMemo extends DefaultSystemConnectionMemo {
035
036    private RfidTrafficController rt;
037    private RfidProtocol protocol;
038
039    public RfidSystemConnectionMemo(RfidTrafficController rt) {
040        this();
041        setRfidTrafficController(rt);
042    }
043
044    public RfidSystemConnectionMemo() {
045        super("F", "Rfid");
046        InstanceManager.store(this, RfidSystemConnectionMemo.class);
047
048        // Create and register the ComponentFactory
049        InstanceManager.store(new RfidComponentFactory(this),
050                ComponentFactory.class);
051    }
052
053    public RfidTrafficController getTrafficController() {
054        return rt;
055    }
056
057    public final void setRfidTrafficController(RfidTrafficController rt) {
058        this.rt = rt;
059        rt.setAdapterMemo(this);
060    }
061
062    public void configureManagers(RfidSensorManager sensorManager, RfidReporterManager reporterManager) {
063        store(sensorManager, SensorManager.class);
064        store(reporterManager, ReporterManager.class);
065        InstanceManager.setSensorManager(sensorManager);
066        InstanceManager.setReporterManager(reporterManager);
067        register();
068    }
069
070    public RfidProtocol getProtocol() {
071        return protocol;
072    }
073
074    public final void setProtocol(RfidProtocol protocol) {
075        this.protocol = protocol;
076    }
077
078    public RfidSensorManager getSensorManager() {
079        return (RfidSensorManager)get(SensorManager.class);
080    }
081
082    public RfidReporterManager getReporterManager() {
083        return (RfidReporterManager)get(ReporterManager.class);
084    }
085
086    @Override
087    protected ResourceBundle getActionModelResourceBundle() {
088        return ResourceBundle.getBundle("jmri.jmrix.rfid.RfidActionListBundle");
089    }
090
091    @Override
092    public <B extends NamedBean> Comparator<B> getNamedBeanComparator(Class<B> type) {
093        return new NamedBeanComparator<>();
094    }
095
096    @Override
097    public void dispose() {
098        rt = null;
099        InstanceManager.deregister(this, RfidSystemConnectionMemo.class);
100        protocol = null;
101        super.dispose();
102    }
103
104}