001package jmri.jmrix.powerline; 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 copied from NCE into Powerline for 018 * multiple connections by 019 * @author Ken Cameron Copyright (C) 2011 020 */ 021public class SerialSystemConnectionMemo extends jmri.jmrix.DefaultSystemConnectionMemo implements ConfiguringSystemConnectionMemo { 022 023 public SerialSystemConnectionMemo() { 024 super("P", "Powerline"); 025 InstanceManager.store(this, SerialSystemConnectionMemo.class); // also register as specific type 026 027 // create and register the ComponentFactory 028 InstanceManager.store(componentFactory = new jmri.jmrix.powerline.swing.PowerlineComponentFactory(this), 029 jmri.jmrix.swing.ComponentFactory.class); 030 } 031 032 jmri.jmrix.swing.ComponentFactory componentFactory = null; 033 034 /** 035 * Provides access to the TrafficController for this particular connection. 036 * 037 * @return tc 038 */ 039 public SerialTrafficController getTrafficController() { 040 return serialTrafficController; 041 } 042 private SerialTrafficController serialTrafficController; 043 044 public void setTrafficController(SerialTrafficController tc) { 045 serialTrafficController = tc; 046 } 047 048 /** 049 * Provide access to the serial port for this connection 050 * @return SerialPort 051 */ 052 public com.fazecast.jSerialComm.SerialPort getActiveSerialPort() { 053 return serialPort; 054 } 055 private com.fazecast.jSerialComm.SerialPort serialPort; 056 public void setActiveSerialPort(com.fazecast.jSerialComm.SerialPort sp) { 057 serialPort = sp; 058 } 059 /** 060 * Provide access to a serialAddress for this particular connection 061 * 062 * @return serialAddress 063 */ 064 public SerialAddress getSerialAddress() { 065 return serialAddress; 066 } 067 private SerialAddress serialAddress; 068 069 public void setSerialAddress(SerialAddress sa) { 070 serialAddress = sa; 071 } 072 073 /** 074 * Configure the common managers for Powerline connections. This puts the 075 * common manager config in one place. 076 */ 077 @Override 078 public void configureManagers() { 079 // now does nothing here, it's done by the specific class 080 register(); // registers general type 081 } 082 083 // menu support parts 084 // subclasses can override to change menu items 085 086 public static class MenuItem { 087 MenuItem(String name, String load) { 088 this.name = name; 089 this.load = load; 090 } 091 public String name; 092 public String load; 093 } 094 private final MenuItem[] panelItems = new MenuItem[]{ 095 new MenuItem("MenuItemCommandMonitor", "jmri.jmrix.powerline.swing.serialmon.SerialMonPane"), 096 new MenuItem("MenuItemSendCommand", "jmri.jmrix.powerline.swing.packetgen.SerialPacketGenPane") 097 }; 098 099 public MenuItem[] provideMenuItemList() { 100 return panelItems; 101 } 102 103 public SerialTurnoutManager getTurnoutManager() { 104 return (SerialTurnoutManager)get(TurnoutManager.class); 105 } 106 107 public SerialLightManager getLightManager() { 108 return (SerialLightManager)get(LightManager.class); 109 } 110 111 public SerialSensorManager getSensorManager() { 112 return (SerialSensorManager)get(SensorManager.class); 113 } 114 115 public void setTurnoutManager(SerialTurnoutManager m) { 116 store(m,TurnoutManager.class); 117 } 118 119 public void setLightManager(SerialLightManager m) { 120 store(m,LightManager.class); 121 } 122 123 public void setSensorManager(SerialSensorManager m) { 124 store(m,SensorManager.class); 125 } 126 127 @Override 128 protected ResourceBundle getActionModelResourceBundle() { 129 return ResourceBundle.getBundle("jmri.jmrix.powerline.PowerlineActionListBundle"); 130 } 131 132 @Override 133 public <B extends NamedBean> Comparator<B> getNamedBeanComparator(Class<B> type) { 134 return new NamedBeanComparator<>(); 135 } 136 137 @Override 138 public void dispose() { 139 serialTrafficController = null; 140 InstanceManager.deregister(this, SerialSystemConnectionMemo.class); 141 super.dispose(); 142 } 143 144}