001package jmri.jmrix.marklin; 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 Bob Jacobsen Copyright (C) 2010 018 * @author Kevin Dickerson Copyright (C) 2012 019 */ 020public class MarklinSystemConnectionMemo extends jmri.jmrix.DefaultSystemConnectionMemo 021 implements ConfiguringSystemConnectionMemo { 022 023 // Allow is-a relation between sub types, i.e. CdB and Marklin 024 protected MarklinSystemConnectionMemo(String prefix, String userName) { 025 super(prefix, userName); 026 } 027 public MarklinSystemConnectionMemo(MarklinTrafficController et) { 028 super("M", "Marklin-CS2"); 029 this.et = et; 030 et.setAdapterMemo(this); 031 InstanceManager.store(this, MarklinSystemConnectionMemo.class); // also register as specific type 032 InstanceManager.store(cf = new jmri.jmrix.marklin.swing.MarklinComponentFactory(this), 033 jmri.jmrix.swing.ComponentFactory.class); 034 } 035 036 public MarklinSystemConnectionMemo() { 037 super("M", "Marklin-CS2"); 038 register(); // registers general type 039 InstanceManager.store(this, MarklinSystemConnectionMemo.class); // also register as specific type 040 //Needs to be implemented 041 InstanceManager.store(cf = new jmri.jmrix.marklin.swing.MarklinComponentFactory(this), 042 jmri.jmrix.swing.ComponentFactory.class); 043 } 044 045 jmri.jmrix.swing.ComponentFactory cf = null; 046 047 /** 048 * Provides access to the TrafficController for this particular connection. 049 * @return the traffic controller. 050 */ 051 public MarklinTrafficController getTrafficController() { 052 return et; 053 } 054 055 public void setMarklinTrafficController(MarklinTrafficController et) { 056 this.et = et; 057 et.setAdapterMemo(this); 058 } 059 private MarklinTrafficController et; 060 061 /** 062 * This puts the common manager config in one place. 063 */ 064 @Override 065 public void configureManagers() { 066 067 PowerManager powerManager = new MarklinPowerManager(getTrafficController()); 068 store(powerManager, PowerManager.class); 069 jmri.InstanceManager.store(powerManager, PowerManager.class); 070 071 TurnoutManager turnoutManager = new MarklinTurnoutManager(this); 072 store(turnoutManager, TurnoutManager.class); 073 jmri.InstanceManager.setTurnoutManager(turnoutManager); 074 075 ThrottleManager throttleManager = new MarklinThrottleManager(this); 076 store(throttleManager, ThrottleManager.class); 077 jmri.InstanceManager.setThrottleManager(throttleManager); 078 079 SensorManager sensorManager = new jmri.jmrix.marklin.MarklinSensorManager(this); 080 store(sensorManager, SensorManager.class); 081 jmri.InstanceManager.setSensorManager(sensorManager); 082 083 register(); 084 } 085 086 @Override 087 protected ResourceBundle getActionModelResourceBundle() { 088 return ResourceBundle.getBundle("jmri.jmrix.marklin.MarklinActionListBundle"); 089 } 090 091 @Override 092 public <B extends NamedBean> Comparator<B> getNamedBeanComparator(Class<B> type) { 093 return new NamedBeanComparator<>(); 094 } 095 096 public MarklinTurnoutManager getTurnoutManager() { 097 return (MarklinTurnoutManager)get(TurnoutManager.class); 098 } 099 100 public MarklinSensorManager getSensorManager() { 101 return (MarklinSensorManager)get(SensorManager.class); 102 } 103 104 public MarklinThrottleManager getThrottleManager() { 105 return (MarklinThrottleManager)get(ThrottleManager.class); 106 } 107 108 public MarklinPowerManager getPowerManager() { 109 return (MarklinPowerManager)get(PowerManager.class); 110 } 111 112 @Override 113 public void dispose() { 114 et = null; 115 InstanceManager.deregister(this, MarklinSystemConnectionMemo.class); 116 if (cf != null) { 117 InstanceManager.deregister(cf, jmri.jmrix.swing.ComponentFactory.class); 118 } 119 120 super.dispose(); 121 } 122 123}