001package jmri.managers; 002 003import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 004 005import javax.annotation.*; 006 007import java.beans.PropertyChangeEvent; 008 009import jmri.InstanceManager; 010import jmri.Light; 011import jmri.LightManager; 012import jmri.Manager; 013import jmri.VariableLight; 014import jmri.VariableLightManager; 015import jmri.SystemConnectionMemo; 016 017/** 018 * Default implementation of a VariableLightManager. 019 * 020 * @author Bob Jacobsen Copyright (C) 2004 021 * @author Daniel Bergqvist Copyright (C) 2020 022 */ 023public class DefaultVariableLightManager extends AbstractManager<VariableLight> 024 implements VariableLightManager { 025 026 /** 027 * Create a new VariableLightManager instance. 028 * 029 * @param memo the system connection 030 */ 031 public DefaultVariableLightManager(SystemConnectionMemo memo) { 032 super(memo); 033 } 034 035 /** 036 * Initializes a new VariableLightManager instance. 037 * @return itself 038 */ 039 public DefaultVariableLightManager init() { 040 LightManager lm = InstanceManager.getDefault(LightManager.class); 041 lm.addPropertyChangeListener("beans", this); 042 for (Light l : lm.getNamedBeanSet()) { 043 if (l instanceof VariableLight) { 044 super.register((VariableLight) l); 045 } 046 } 047 return this; 048 } 049 050 /** {@inheritDoc} */ 051 @Override 052 public void dispose() { 053 super.dispose(); 054 } 055 056 /** {@inheritDoc} */ 057 @Override 058 public int getXMLOrder() { 059 return Manager.LIGHTS; 060 } 061 062 /** {@inheritDoc} */ 063 @Override 064 public char typeLetter() { 065 return 'L'; 066 } 067 068 /** {@inheritDoc} */ 069 @Override 070 @Nonnull 071 public String getBeanTypeHandled(boolean plural) { 072 return Bundle.getMessage(plural ? "BeanNameVariableLights" : "BeanNameVariableLight"); 073 } 074 075 /** 076 * {@inheritDoc} 077 */ 078 @Override 079 public Class<VariableLight> getNamedBeanClass() { 080 return VariableLight.class; 081 } 082 083 /** {@inheritDoc} */ 084 @Override 085 @SuppressFBWarnings(value = "OVERRIDING_METHODS_MUST_INVOKE_SUPER", 086 justification = "This method must never be called") 087 public final void register(@Nonnull VariableLight s) { 088 throw new UnsupportedOperationException("Not supported. Use LightManager.register() instead"); 089 } 090 091 /** {@inheritDoc} */ 092 @Override 093 @SuppressFBWarnings(value = "OVERRIDING_METHODS_MUST_INVOKE_SUPER", 094 justification = "This method must never be called") 095 public final void deregister(@Nonnull VariableLight s) { 096 throw new UnsupportedOperationException("Not supported. Use LightManager.deregister() instead"); 097 } 098 099 /** {@inheritDoc} */ 100 @Override 101 @SuppressFBWarnings(value = "OVERRIDING_METHODS_MUST_INVOKE_SUPER", 102 justification = "This method must never be called") 103 public final void deleteBean(@Nonnull VariableLight n, @Nonnull String property) { 104 throw new UnsupportedOperationException("Not supported. Use LightManager.deleteBean() instead"); 105 } 106 107 @Override 108 public void propertyChange(PropertyChangeEvent e) { 109 super.propertyChange(e); 110 111 if ("beans".equals(e.getPropertyName())) { 112 113 // A NamedBean is added 114 if ((e.getNewValue() != null) 115 && (e.getNewValue() instanceof VariableLight)) { 116 super.register((VariableLight) e.getNewValue()); 117 } 118 119 // A NamedBean is removed 120 if ((e.getOldValue() != null) 121 && (e.getOldValue() instanceof VariableLight)) { 122 super.deregister((VariableLight) e.getOldValue()); 123 } 124 } 125 } 126 127 128// private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(DefaultVariableLightManager.class); 129 130}