001package jmri.jmrix.xpa; 002 003import java.util.Comparator; 004import java.util.ResourceBundle; 005import jmri.InstanceManager; 006import jmri.NamedBean; 007import jmri.PowerManager; 008import jmri.ThrottleManager; 009import jmri.TurnoutManager; 010import jmri.jmrix.DefaultSystemConnectionMemo; 011import jmri.util.NamedBeanComparator; 012 013/** 014 * Provide the required SystemConnectionMemo for the XPA+Modem adapters. 015 * 016 * @author Randall Wood randall.h.wood@alexandriasoftware.com 017 * @author Paul Bender Copyright (C) 2016,2020 018 */ 019public class XpaSystemConnectionMemo extends DefaultSystemConnectionMemo { 020 021 public XpaSystemConnectionMemo() { 022 this("P", "XPA"); // Prefix from XpaTurnoutManager, UserName from XpaThrottleManager 023 } 024 025 public XpaSystemConnectionMemo(String prefix, String userName){ 026 super(prefix, userName); 027 InstanceManager.store(this,XpaSystemConnectionMemo.class); 028 // create and register the XNetComponentFactory 029 InstanceManager.store(cf = new jmri.jmrix.xpa.swing.XpaComponentFactory(this), 030 jmri.jmrix.swing.ComponentFactory.class); 031 032 } 033 034 @Override 035 protected ResourceBundle getActionModelResourceBundle() { 036 return null; 037 } 038 039 @Override 040 public <B extends NamedBean> Comparator<B> getNamedBeanComparator(Class<B> type) { 041 return new NamedBeanComparator<>(); 042 } 043 044 final jmri.jmrix.swing.ComponentFactory cf; 045 046 /* manage the associated traffic controller */ 047 private XpaTrafficController tc = null; 048 049 /** 050 * Set the XpaTrafficController associated with this memo. 051 * 052 * @param t is the XpaTrafficController memo to set 053 */ 054 public void setXpaTrafficController(XpaTrafficController t){ 055 if(t == null) throw new java.lang.IllegalArgumentException("Traffic Controller cannot be set to null."); 056 tc = t; 057 } 058 059 /** 060 * Get the XpaTrafficController associated with this memo. 061 * 062 * @return XpaTrafficController assocated with this memo 063 */ 064 public XpaTrafficController getXpaTrafficController(){ 065 return tc; 066 } 067 068 /* 069 * Provide access to the Throttle Manager for this particular connection. 070 */ 071 public ThrottleManager getThrottleManager() { 072 return (ThrottleManager)classObjectMap.computeIfAbsent(ThrottleManager.class, (Class<?> c) -> { return new XpaThrottleManager(this);}); 073 } 074 075 076 public void setThrottleManager(ThrottleManager t) { 077 store(t,ThrottleManager.class); 078 } 079 080 /* 081 * Provide access to the PowerManager for this particular connection. 082 */ 083 public PowerManager getPowerManager() { 084 return (PowerManager) classObjectMap.computeIfAbsent(PowerManager.class,(Class<?> c) -> { return new XpaPowerManager(this); }); 085 } 086 087 public void setPowerManager(PowerManager p) { 088 store(p,PowerManager.class); 089 } 090 091 /* 092 * Provide access to the TurnoutManager for this particular connection. 093 */ 094 public TurnoutManager getTurnoutManager() { 095 return (TurnoutManager) classObjectMap.computeIfAbsent(TurnoutManager.class,(Class<?> c) -> { return new XpaTurnoutManager(this); }); 096 } 097 098 public void setTurnoutManager(TurnoutManager t) { 099 store(t,TurnoutManager.class); 100 } 101 102 @Override 103 public void dispose() { 104 tc = null; 105 InstanceManager.deregister(this, XpaSystemConnectionMemo.class); 106 if (cf != null) { 107 InstanceManager.deregister(cf, jmri.jmrix.swing.ComponentFactory.class); 108 } 109 super.dispose(); 110 } 111 112}