001package jmri.jmrix.grapevine; 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 for Grapevine. 017 * Expanded for multichar/multiconnection support. Nodes are handled bij superclass. 018 * 019 * @author Randall Wood randall.h.wood@alexandriasoftware.com 020 */ 021public class GrapevineSystemConnectionMemo extends DefaultSystemConnectionMemo implements ConfiguringSystemConnectionMemo { 022 023 public GrapevineSystemConnectionMemo() { 024 this("G", Bundle.getMessage("MenuSystem")); 025 } 026 027 public GrapevineSystemConnectionMemo(@Nonnull String prefix, @Nonnull String name) { 028 super(prefix, name); 029 030 InstanceManager.store(this, GrapevineSystemConnectionMemo.class); 031 032 // create and register the ComponentFactory for the GUI (menu) 033 InstanceManager.store(cf = new jmri.jmrix.grapevine.swing.GrapevineComponentFactory(this), 034 jmri.jmrix.swing.ComponentFactory.class); 035 036 log.debug("Created GrapevineSystemConnectionMemo, prefix = {}", prefix); 037 } 038 039 private SerialTrafficController tc = null; 040 jmri.jmrix.swing.ComponentFactory cf = null; 041 042 /** 043 * Set the traffic controller instance associated with this connection memo. 044 * 045 * @param tc jmri.jmrix.grapevine.SerialTrafficController object to use. 046 */ 047 public void setTrafficController(SerialTrafficController tc){ 048 this.tc = tc; 049 log.debug("Memo {} set GrapevineTrafficController {}", getUserName(), tc); 050 } 051 052 /** 053 * Get the traffic controller instance associated with this connection memo. 054 * @return traffic controller, one is provided if null. 055 */ 056 public SerialTrafficController getTrafficController(){ 057 if (tc == null) { 058 setTrafficController(new SerialTrafficController(this)); 059 log.debug("Auto create of SerialTrafficController for initial configuration"); 060 } 061 return tc; 062 } 063 064 /** 065 * Provide Grapevine menu strings. 066 * 067 * @return bundle file containing action - menuitem pairs 068 */ 069 @Override 070 protected ResourceBundle getActionModelResourceBundle() { 071 return ResourceBundle.getBundle("jmri.jmrix.grapevine.GrapevineActionListBundle"); 072 } 073 074 @Override 075 public <B extends NamedBean> Comparator<B> getNamedBeanComparator(Class<B> type) { 076 return new NamedBeanComparator<>(); 077 } 078 079 /** 080 * Configure the common managers for Grapevine connections. This puts the 081 * common manager config in one place. 082 */ 083 public void configureManagers() { 084 setTurnoutManager(new SerialTurnoutManager(this)); 085 InstanceManager.setTurnoutManager(getTurnoutManager()); 086 087 setLightManager(new SerialLightManager(this)); 088 InstanceManager.setLightManager(getLightManager()); 089 090 setSensorManager(new SerialSensorManager(this)); 091 InstanceManager.setSensorManager(getSensorManager()); 092 093 register(); 094 } 095 096 /** 097 * Provide access to the SensorManager for this particular connection. 098 * <p> 099 * NOTE: SensorManager defaults to NULL 100 * @return sensor manager. 101 */ 102 public SensorManager getSensorManager() { 103 log.debug("getSensorManager {}", get(SensorManager.class) != null ? "OK": "returned NULL"); 104 return get(SensorManager.class); 105 } 106 107 public void setSensorManager(SerialSensorManager s) { 108 store(s,SensorManager.class); 109 getTrafficController().setSensorManager(s); 110 } 111 112 /** 113 * Provide access to the TurnoutManager for this particular connection. 114 * <p> 115 * NOTE: TurnoutManager defaults to NULL 116 * @return turnout manager. 117 */ 118 public TurnoutManager getTurnoutManager() { 119 log.debug("getTurnoutManager {}", get(TurnoutManager.class) != null ? "OK": "returned NULL"); 120 return get(TurnoutManager.class); 121 } 122 123 public void setTurnoutManager(SerialTurnoutManager t) { 124 store(t,TurnoutManager.class); 125 // not accessible, needed? 126 } 127 128 /** 129 * Provide access to the LightManager for this particular connection. 130 * <p> 131 * NOTE: LightManager defaults to NULL 132 * @return light manager. 133 */ 134 public LightManager getLightManager() { 135 log.debug("getLightManager {}", get(LightManager.class) != null ? "OK": "returned NULL"); 136 return get(LightManager.class); 137 138 } 139 140 public void setLightManager(SerialLightManager l) { 141 store(l,LightManager.class); 142 // not accessible, needed? 143 } 144 145 @Override 146 public void dispose() { 147 tc = null; 148 InstanceManager.deregister(this, GrapevineSystemConnectionMemo.class); 149 if (cf != null) { 150 InstanceManager.deregister(cf, jmri.jmrix.swing.ComponentFactory.class); 151 } 152 super.dispose(); 153 } 154 155 private final static Logger log = LoggerFactory.getLogger(GrapevineSystemConnectionMemo.class); 156 157}