001package jmri.implementation; 002 003import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 004import jmri.NamedBeanHandle; 005import jmri.Turnout; 006import org.slf4j.Logger; 007import org.slf4j.LoggerFactory; 008 009/** 010 * Implement SignalHead for Littfinski Daten Technik (LDT) signals. 011 * <p> 012 * These decoders can display up to 8 aspects. One position of a turnout is 013 * associated with one signal aspect. The class assigns turnout positions to all 014 * 7 JMRI signal aspects. 015 * <p> 016 * For more info on the signals, see 017 * <A HREF="http://www.ldt-infocenter.com">http://www.ldt-infocenter.com</a>. 018 * 019 * @author Petr Koud'a Copyright (C) 2007 020 */ 021public class LsDecSignalHead extends DefaultSignalHead { 022 023 public LsDecSignalHead(String sys, String user, NamedBeanHandle<Turnout> t1, int s1, NamedBeanHandle<Turnout> t2, int s2, NamedBeanHandle<Turnout> t3, int s3, NamedBeanHandle<Turnout> t4, int s4, NamedBeanHandle<Turnout> t5, int s5, NamedBeanHandle<Turnout> t6, int s6, NamedBeanHandle<Turnout> t7, int s7) { 024 super(sys, user); 025 mGreen = t1; 026 mYellow = t2; 027 mRed = t3; 028 mFlashGreen = t4; 029 mFlashYellow = t5; 030 mFlashRed = t6; 031 mDark = t7; 032 mGreenState = s1; 033 mYellowState = s2; 034 mRedState = s3; 035 mFlashGreenState = s4; 036 mFlashYellowState = s5; 037 mFlashRedState = s6; 038 mDarkState = s7; 039 } 040 041 public LsDecSignalHead(String sys, NamedBeanHandle<Turnout> t1, int s1, NamedBeanHandle<Turnout> t2, int s2, NamedBeanHandle<Turnout> t3, int s3, NamedBeanHandle<Turnout> t4, int s4, NamedBeanHandle<Turnout> t5, int s5, NamedBeanHandle<Turnout> t6, int s6, NamedBeanHandle<Turnout> t7, int s7) { 042 super(sys); 043 mGreen = t1; 044 mYellow = t2; 045 mRed = t3; 046 mFlashGreen = t4; 047 mFlashYellow = t5; 048 mFlashRed = t6; 049 mDark = t7; 050 mGreenState = s1; 051 mYellowState = s2; 052 mRedState = s3; 053 mFlashGreenState = s4; 054 mFlashYellowState = s5; 055 mFlashRedState = s6; 056 mDarkState = s7; 057 } 058 059 /* 060 * Modified from DefaultSignalHead 061 * removed software flashing!!! 062 */ 063 @Override 064 public void setAppearance(int newAppearance) { 065 int oldAppearance = mAppearance; 066 mAppearance = newAppearance; 067 068 if (oldAppearance != newAppearance) { 069 updateOutput(); 070 071 // notify listeners, if any 072 firePropertyChange("Appearance", Integer.valueOf(oldAppearance), Integer.valueOf(newAppearance)); 073 } 074 } 075 076 @Override 077 public void setLit(boolean newLit) { 078 boolean oldLit = mLit; 079 mLit = newLit; 080 if (oldLit != newLit) { 081 updateOutput(); 082 // notify listeners, if any 083 firePropertyChange("Lit", Boolean.valueOf(oldLit), Boolean.valueOf(newLit)); 084 } 085 } 086 087 @SuppressWarnings("fallthrough") 088 @SuppressFBWarnings(value = "SF_SWITCH_FALLTHROUGH") 089 @Override 090 protected void updateOutput() { 091 // assumes that writing a turnout to an existing state is cheap! 092 if (mLit == false) { 093 mDark.getBean().setCommandedState(mDarkState); 094 return; 095 } else { 096 switch (mAppearance) { 097 case RED: 098 mRed.getBean().setCommandedState(mRedState); 099 break; 100 case FLASHRED: 101 mFlashRed.getBean().setCommandedState(mFlashRedState); 102 break; 103 case YELLOW: 104 mYellow.getBean().setCommandedState(mYellowState); 105 break; 106 case FLASHYELLOW: 107 mFlashYellow.getBean().setCommandedState(mFlashYellowState); 108 break; 109 case GREEN: 110 mGreen.getBean().setCommandedState(mGreenState); 111 break; 112 case FLASHGREEN: 113 mFlashGreen.getBean().setCommandedState(mFlashGreenState); 114 break; 115 default: 116 log.warn("Unexpected new appearance: {}", mAppearance); 117 // go dark by falling through 118 case DARK: 119 mDark.getBean().setCommandedState(mDarkState); 120 break; 121 } 122 } 123 } 124 125 /** 126 * Remove references to and from this object, so that it can eventually be 127 * garbage-collected. 128 */ 129 @Override 130 public void dispose() { 131 mRed = null; 132 mYellow = null; 133 mGreen = null; 134 mFlashRed = null; 135 mFlashYellow = null; 136 mFlashGreen = null; 137 mDark = null; 138 super.dispose(); 139 } 140 141 NamedBeanHandle<Turnout> mRed; 142 NamedBeanHandle<Turnout> mYellow; 143 NamedBeanHandle<Turnout> mGreen; 144 NamedBeanHandle<Turnout> mFlashRed; 145 NamedBeanHandle<Turnout> mFlashYellow; 146 NamedBeanHandle<Turnout> mFlashGreen; 147 NamedBeanHandle<Turnout> mDark; 148 149 int mRedState; 150 int mYellowState; 151 int mGreenState; 152 int mFlashRedState; 153 int mFlashYellowState; 154 int mFlashGreenState; 155 int mDarkState; 156 157 public NamedBeanHandle<Turnout> getRed() { 158 return mRed; 159 } 160 161 public NamedBeanHandle<Turnout> getYellow() { 162 return mYellow; 163 } 164 165 public NamedBeanHandle<Turnout> getGreen() { 166 return mGreen; 167 } 168 169 public NamedBeanHandle<Turnout> getFlashRed() { 170 return mFlashRed; 171 } 172 173 public NamedBeanHandle<Turnout> getFlashYellow() { 174 return mFlashYellow; 175 } 176 177 public NamedBeanHandle<Turnout> getFlashGreen() { 178 return mFlashGreen; 179 } 180 181 public NamedBeanHandle<Turnout> getDark() { 182 return mDark; 183 } 184 185 public int getRedState() { 186 return mRedState; 187 } 188 189 public int getYellowState() { 190 return mYellowState; 191 } 192 193 public int getGreenState() { 194 return mGreenState; 195 } 196 197 public int getFlashRedState() { 198 return mFlashRedState; 199 } 200 201 public int getFlashYellowState() { 202 return mFlashYellowState; 203 } 204 205 public int getFlashGreenState() { 206 return mFlashGreenState; 207 } 208 209 public int getDarkState() { 210 return mDarkState; 211 } 212 213 public void setRed(NamedBeanHandle<Turnout> t) { 214 mRed = t; 215 } 216 217 public void setYellow(NamedBeanHandle<Turnout> t) { 218 mYellow = t; 219 } 220 221 public void setGreen(NamedBeanHandle<Turnout> t) { 222 mGreen = t; 223 } 224 225 public void setFlashRed(NamedBeanHandle<Turnout> t) { 226 mFlashRed = t; 227 } 228 229 public void setFlashYellow(NamedBeanHandle<Turnout> t) { 230 mFlashYellow = t; 231 } 232 233 public void setFlashGreen(NamedBeanHandle<Turnout> t) { 234 mFlashGreen = t; 235 } 236 237 public void setDark(NamedBeanHandle<Turnout> t) { 238 mDark = t; 239 } 240 241 public void setRedState(int i) { 242 mRedState = i; 243 } 244 245 public void setYellowState(int i) { 246 mYellowState = i; 247 } 248 249 public void setGreenState(int i) { 250 mGreenState = i; 251 } 252 253 public void setFlashRedState(int i) { 254 mFlashRedState = i; 255 } 256 257 public void setFlashYellowState(int i) { 258 mFlashYellowState = i; 259 } 260 261 public void setFlashGreenState(int i) { 262 mFlashGreenState = i; 263 } 264 265 public void setDarkState(int i) { 266 mDarkState = i; 267 } 268 269 @Override 270 public boolean isTurnoutUsed(Turnout t) { 271 if (getRed() != null && t.equals(getRed().getBean())) { 272 return true; 273 } 274 if (getYellow() != null && t.equals(getYellow().getBean())) { 275 return true; 276 } 277 if (getGreen() != null && t.equals(getGreen().getBean())) { 278 return true; 279 } 280 if (getFlashRed() != null && t.equals(getFlashRed().getBean())) { 281 return true; 282 } 283 if (getFlashYellow() != null && t.equals(getFlashYellow().getBean())) { 284 return true; 285 } 286 if (getFlashGreen() != null && t.equals(getFlashGreen().getBean())) { 287 return true; 288 } 289 if (getDark() != null && t.equals(getDark().getBean())) { 290 return true; 291 } 292 return false; 293 } 294 295 private final static Logger log = LoggerFactory.getLogger(LsDecSignalHead.class); 296 297}