001package jmri.jmrix.oaktree; 002 003import java.util.Comparator; 004import java.util.ResourceBundle; 005import javax.annotation.Nonnull; 006 007import jmri.*; 008import jmri.jmrix.ConfiguringSystemConnectionMemo; 009import jmri.jmrix.DefaultSystemConnectionMemo; 010import jmri.util.NamedBeanComparator; 011 012import org.slf4j.Logger; 013import org.slf4j.LoggerFactory; 014 015/** 016 * Minimum required SystemConnectionMemo. 017 * 018 * @author Randall Wood randall.h.wood@alexandriasoftware.com 019 */ 020public class OakTreeSystemConnectionMemo extends DefaultSystemConnectionMemo implements ConfiguringSystemConnectionMemo { 021 022 public OakTreeSystemConnectionMemo(@Nonnull String prefix, @Nonnull String userName) { 023 super(prefix, userName); 024 InstanceManager.store(this, OakTreeSystemConnectionMemo.class); 025 026 // create and register the ComponentFactory 027 InstanceManager.store(new jmri.jmrix.oaktree.swing.OakTreeComponentFactory(this), 028 jmri.jmrix.swing.ComponentFactory.class); 029 030 log.debug("Created OakTreeSystemConnectionMemo"); 031 } 032 033 public OakTreeSystemConnectionMemo() { 034 this("O", SerialConnectionTypeList.OAK); 035 log.debug("Created nameless OakTreeSystemConnectionMemo"); 036 } 037 038 private SerialTrafficController tc = null; 039 040 /** 041 * Set the traffic controller instance associated with this connection memo. 042 * 043 * @param s jmri.jmrix.oaktree.SerialTrafficController object to use. 044 */ 045 public void setTrafficController(SerialTrafficController s){ 046 tc = s; 047 } 048 049 /** 050 * Get the traffic controller instance associated with this connection memo. 051 * @return traffic controller, new instance created if null. 052 */ 053 public SerialTrafficController getTrafficController() { 054 if (tc == null) { 055 setTrafficController(new SerialTrafficController(this)); 056 log.debug("Auto create of OakTree SerialTrafficController for initial configuration"); 057 } 058 return tc; 059 } 060 // would more stuff for traffic controller etc be useful here? 061 062 @Override 063 protected ResourceBundle getActionModelResourceBundle() { 064 return null; 065 } 066 067 @Override 068 public <B extends NamedBean> Comparator<B> getNamedBeanComparator(Class<B> type) { 069 return new NamedBeanComparator<>(); 070 } 071 072 @Override 073 public void configureManagers(){ 074 setTurnoutManager(new SerialTurnoutManager(this)); 075 InstanceManager.setTurnoutManager(getTurnoutManager()); 076 077 setLightManager(new SerialLightManager(this)); 078 InstanceManager.setLightManager(getLightManager()); 079 080 setSensorManager(new SerialSensorManager(this)); 081 InstanceManager.setSensorManager(getSensorManager()); 082 register(); 083 } 084 085 /** 086 * Provide access to the SensorManager for this particular connection. 087 * <p> 088 * NOTE: SensorManager defaults to NULL 089 * @return sensor manager. 090 */ 091 public SensorManager getSensorManager() { 092 return get(SensorManager.class); 093 } 094 095 public void setSensorManager(SerialSensorManager s) { 096 store(s,SensorManager.class); 097 getTrafficController().setSensorManager(s); 098 } 099 100 /** 101 * Provide access to the TurnoutManager for this particular connection. 102 * <p> 103 * NOTE: TurnoutManager defaults to NULL 104 * @return turnout manager. 105 */ 106 public TurnoutManager getTurnoutManager() { 107 return get(TurnoutManager.class); 108 109 } 110 111 public void setTurnoutManager(SerialTurnoutManager t) { 112 store(t,TurnoutManager.class); 113 } 114 115 /** 116 * Provide access to the LightManager for this particular connection. 117 * <p> 118 * NOTE: LightManager defaults to NULL 119 * @return light manager. 120 */ 121 public LightManager getLightManager() { 122 return get(LightManager.class); 123 124 } 125 126 public void setLightManager(SerialLightManager l) { 127 store(l,LightManager.class); 128 } 129 130 private final static Logger log = LoggerFactory.getLogger(OakTreeSystemConnectionMemo.class); 131 132}