001package jmri.jmrix.lenz; 002 003import java.util.Comparator; 004import java.util.ResourceBundle; 005 006import jmri.*; 007import jmri.jmrix.DefaultSystemConnectionMemo; 008import jmri.util.NamedBeanComparator; 009 010import org.slf4j.Logger; 011import org.slf4j.LoggerFactory; 012 013/** 014 * Lightweight class to denote that a system is active and provide general 015 * information 016 * <p> 017 * Objects of specific subtypes are registered in the instance manager to 018 * activate their particular system. 019 * 020 * @author Paul Bender Copyright (C) 2010 021 */ 022public class XNetSystemConnectionMemo extends DefaultSystemConnectionMemo { 023 024 public XNetSystemConnectionMemo(XNetTrafficController xt) { 025 super("X", Bundle.getMessage("MenuXpressNet")); 026 this.xt = xt; 027 xt.setSystemConnectionMemo(this); 028 this.setLenzCommandStation(xt.getCommandStation()); 029 commonInit(); 030 } 031 032 public XNetSystemConnectionMemo() { 033 super("X", Bundle.getMessage("MenuXpressNet")); 034 commonInit(); 035 } 036 037 private void commonInit() { 038 register(); // registers general type 039 InstanceManager.store(this, XNetSystemConnectionMemo.class); // also register as specific type 040 041 // create and register the XNetComponentFactory 042 cf = new jmri.jmrix.lenz.swing.XNetComponentFactory(this); 043 InstanceManager.store(cf, jmri.jmrix.swing.ComponentFactory.class); 044 045 log.debug("Created XNetSystemConnectionMemo"); 046 } 047 048 private jmri.jmrix.swing.ComponentFactory cf; 049 050 /** 051 * Provide access to the TrafficController for this particular connection. 052 * @return traffic controller. 053 */ 054 public XNetTrafficController getXNetTrafficController() { 055 return xt; 056 } 057 058 private XNetTrafficController xt; 059 060 public void setXNetTrafficController(XNetTrafficController xt) { 061 this.xt = xt; 062 // in addition to setting the traffic controller in this object, 063 // set the systemConnectionMemo in the traffic controller 064 xt.setSystemConnectionMemo(this); 065 // and make sure the Lenz command station is set. 066 this.setLenzCommandStation(xt.getCommandStation()); 067 } 068 069 /** 070 * Provide access to the Programmer for this particular connection. 071 * <p> 072 * NOTE: Programmer defaults to null 073 * @return programmer manager. 074 */ 075 public XNetProgrammerManager getProgrammerManager() { 076 return get(XNetProgrammerManager.class); 077 } 078 079 public void setProgrammerManager(XNetProgrammerManager p) { 080 store(p,XNetProgrammerManager.class); 081 if(p.isGlobalProgrammerAvailable()) { 082 store(p,GlobalProgrammerManager.class); 083 } 084 if(p.isAddressedModePossible()){ 085 store(p,AddressedProgrammerManager.class); 086 } 087 } 088 089 /* 090 * Provide access to the Throttle Manager for this particular connection. 091 */ 092 public ThrottleManager getThrottleManager() { 093 return get(ThrottleManager.class); 094 } 095 096 public void setThrottleManager(ThrottleManager t) { 097 store(t,ThrottleManager.class); 098 } 099 100 /* 101 * Provide access to the PowerManager for this particular connection. 102 */ 103 public PowerManager getPowerManager() { 104 return get(PowerManager.class); 105 } 106 107 public void setPowerManager(PowerManager p) { 108 store(p,PowerManager.class); 109 } 110 111 /** 112 * Provide access to the SensorManager for this particular connection. 113 * <p> 114 * NOTE: SensorManager defaults to NULL 115 * @return sensor manager. 116 */ 117 public SensorManager getSensorManager() { 118 return get(SensorManager.class); 119 } 120 121 public void setSensorManager(SensorManager s) { 122 store(s, SensorManager.class); 123 } 124 125 /** 126 * Provide access to the TurnoutManager for this particular connection. 127 * <p> 128 * NOTE: TurnoutManager defaults to NULL 129 * @return turnout manager. 130 */ 131 public TurnoutManager getTurnoutManager() { 132 return get(TurnoutManager.class); 133 134 } 135 136 public void setTurnoutManager(TurnoutManager t) { 137 store(t,TurnoutManager.class); 138 } 139 140 /** 141 * Provide access to the LightManager for this particular connection. 142 * <p> 143 * NOTE: LightManager defaults to NULL 144 * @return light manager. 145 */ 146 public LightManager getLightManager() { 147 return get(LightManager.class); 148 149 } 150 151 public void setLightManager(LightManager l) { 152 store(l,LightManager.class); 153 } 154 155 /** 156 * Provide access to the Command Station for this particular connection. 157 * <p> 158 * NOTE: Command Station defaults to NULL 159 * @return command station. 160 */ 161 public CommandStation getCommandStation() { 162 return get(CommandStation.class); 163 } 164 165 public void setCommandStation(CommandStation c) { 166 167 if (c instanceof LenzCommandStation ) { 168 setLenzCommandStation((LenzCommandStation) c); 169 // don't set as command station object if instruction 170 // not supported (Lenz Compact) 171 if(((LenzCommandStation)c).getCommandStationType()!=0x02) { 172 store(c, CommandStation.class); 173 } 174 } else { 175 store(c,CommandStation.class); 176 } 177 } 178 179 /** 180 * Provide access to the Lenz Command Station for this particular connection. 181 * <p> 182 * NOTE: Lenz Command Station defaults to NULL 183 * @return Lenz command station. 184 */ 185 public LenzCommandStation getLenzCommandStation() { 186 return get(LenzCommandStation.class); 187 } 188 189 public void setLenzCommandStation(LenzCommandStation c) { 190 store(c,LenzCommandStation.class); 191 c.setTrafficController(xt); 192 c.setSystemConnectionMemo(this); 193 } 194 195 @Override 196 protected ResourceBundle getActionModelResourceBundle() { 197 return ResourceBundle.getBundle("jmri.jmrix.lenz.XNetActionListBundle"); 198 } 199 200 @Override 201 public <B extends NamedBean> Comparator<B> getNamedBeanComparator(Class<B> type) { 202 return new NamedBeanComparator<>(); 203 } 204 205 @Override 206 public void dispose() { 207 xt = null; 208 InstanceManager.deregister(this, XNetSystemConnectionMemo.class); 209 if (cf != null) { 210 InstanceManager.deregister(cf, jmri.jmrix.swing.ComponentFactory.class); 211 } 212 super.dispose(); 213 } 214 215 private static final Logger log = LoggerFactory.getLogger(XNetSystemConnectionMemo.class); 216 217}