001package jmri.jmrix.loconet.se8; 002 003import java.awt.FlowLayout; 004import javax.swing.JCheckBox; 005import javax.swing.JComboBox; 006import javax.swing.JLabel; 007import javax.swing.JPanel; 008import jmri.jmrix.loconet.AbstractBoardProgPanel; 009import org.slf4j.Logger; 010import org.slf4j.LoggerFactory; 011 012/** 013 * Display and modify an SE8c configuration. 014 * <p> 015 * The read and write require a sequence of operations, which we handle with a 016 * superclass. 017 * <p> 018 * Programming of the SE8c is done via configuration messages, so the SE8c 019 * should not be put into programming mode via the built-in pushbutton while 020 * this tool is in use. 021 * <p> 022 * Throughout, the terminology is "closed" == true, "thrown" == false. Variables 023 * are named for their closed state. 024 * <p> 025 * Some of the message formats used in this class are Copyright Digitrax, Inc. 026 * and used with permission as part of the JMRI project. That permission does 027 * not extend to uses in other software products. If you wish to use this code, 028 * algorithm or these message formats outside of JMRI, please contact Digitrax 029 * Inc for separate permission. 030 * 031 * @author Bob Jacobsen Copyright (C) 2003, 2004, 2007, 2010 032 */ 033public class SE8Panel extends AbstractBoardProgPanel { 034 035 public SE8Panel() { 036 this(1); 037 } 038 039 public SE8Panel(int boardNum) { 040 super(boardNum, false, "SE8C"); 041 042 appendLine(provideAddressing()); // add read/write buttons, address // NOI18N 043 044 JPanel panel2; 045 appendLine(fullmode); 046 appendLine(twoaspects); 047 panel2 = new JPanel(); 048 panel2.setLayout(new FlowLayout()); 049 panel2.add(new JLabel(Bundle.getMessage("CablesXYLabel", 1, 4))); 050 panel2.add(section1to4mode); 051 appendLine(panel2); 052 panel2 = new JPanel(); 053 panel2.setLayout(new FlowLayout()); 054 panel2.add(new JLabel(Bundle.getMessage("CablesXYLabel", 5, 8))); 055 panel2.add(section5to8mode); 056 appendLine(panel2); 057 panel2 = new JPanel(); 058 panel2.setLayout(new FlowLayout()); 059 panel2.add(new JLabel(Bundle.getMessage("Aspect4Label"))); 060 panel2.add(fourthAspect); 061 appendLine(panel2); 062 appendLine(semaphore); 063 appendLine(pulsed); 064 appendLine(disableDS); 065 appendLine(fromloconet); 066 appendLine(disablelocal); 067 appendLine(sigaddress); 068 appendLine(bcastaddress); 069 appendLine(semaddress); 070 appendLine(setdefault); 071 appendLine(exercise); 072 073 appendLine(provideStatusLine()); 074 setStatus(Bundle.getMessage("Status1")); 075 076 setTypeWord(0x72); // configure SE8 message type 077 078 panelToScroll(); 079 080 } 081 082 @Override 083 public String getHelpTarget() { 084 return "package.jmri.jmrix.loconet.se8.SE8Frame"; // NOI18N 085 } 086 087 @Override 088 public String getTitle() { 089 return getTitle(Bundle.getMessage("MenuItemSE8cProgrammer")); 090 } 091 092 /** 093 * Copy from the GUI to the opsw array. 094 * <p> 095 * Used before write operations start 096 */ 097 @Override 098 protected void copyToOpsw() { 099 opsw[1] = fullmode.isSelected(); 100 opsw[2] = twoaspects.isSelected(); 101 102 opsw[11] = semaphore.isSelected(); 103 opsw[12] = pulsed.isSelected(); 104 opsw[13] = disableDS.isSelected(); 105 opsw[14] = fromloconet.isSelected(); 106 opsw[15] = disablelocal.isSelected(); 107 opsw[17] = sigaddress.isSelected(); 108 opsw[18] = bcastaddress.isSelected(); 109 opsw[19] = semaddress.isSelected(); 110 opsw[20] = setdefault.isSelected(); 111 opsw[21] = exercise.isSelected(); 112 113 // value based 114 int value = section1to4mode.getSelectedIndex(); 115 if ((value & 0x01) != 0) { 116 opsw[5] = true; 117 } else { 118 opsw[5] = false; 119 } 120 if ((value & 0x02) != 0) { 121 opsw[4] = true; 122 } else { 123 opsw[4] = false; 124 } 125 if ((value & 0x04) != 0) { 126 opsw[3] = true; 127 } else { 128 opsw[3] = false; 129 } 130 131 value = section5to8mode.getSelectedIndex(); 132 if ((value & 0x01) != 0) { 133 opsw[8] = true; 134 } else { 135 opsw[8] = false; 136 } 137 if ((value & 0x02) != 0) { 138 opsw[7] = true; 139 } else { 140 opsw[7] = false; 141 } 142 if ((value & 0x04) != 0) { 143 opsw[6] = true; 144 } else { 145 opsw[6] = false; 146 } 147 148 value = fourthAspect.getSelectedIndex(); 149 if ((value & 0x01) != 0) { 150 opsw[10] = true; 151 } else { 152 opsw[10] = false; 153 } 154 if ((value & 0x02) != 0) { 155 opsw[9] = true; 156 } else { 157 opsw[9] = false; 158 } 159 } 160 161 @Override 162 protected void updateDisplay() { 163 // binary switches 164 fullmode.setSelected(opsw[1]); 165 twoaspects.setSelected(opsw[2]); 166 semaphore.setSelected(opsw[11]); 167 pulsed.setSelected(opsw[12]); 168 disableDS.setSelected(opsw[13]); 169 fromloconet.setSelected(opsw[14]); 170 disablelocal.setSelected(opsw[15]); 171 sigaddress.setSelected(opsw[17]); 172 bcastaddress.setSelected(opsw[18]); 173 semaddress.setSelected(opsw[19]); 174 setdefault.setSelected(opsw[20]); 175 exercise.setSelected(opsw[21]); 176 177 // value-based switches 178 int value = 0; 179 if (opsw[5]) { 180 value += 1; 181 } 182 if (opsw[4]) { 183 value += 2; 184 } 185 if (opsw[3]) { 186 value += 4; 187 } 188 section1to4mode.setSelectedIndex(value); 189 190 value = 0; 191 if (opsw[8]) { 192 value += 1; 193 } 194 if (opsw[7]) { 195 value += 2; 196 } 197 if (opsw[6]) { 198 value += 4; 199 } 200 section5to8mode.setSelectedIndex(value); 201 202 value = 0; 203 if (opsw[10]) { 204 value += 1; 205 } 206 if (opsw[9]) { 207 value += 2; 208 } 209 fourthAspect.setSelectedIndex(value); 210 211 } 212 213 @Override 214 protected int nextState(int state) { 215 switch (state) { 216 case 1: 217 return 2; 218 case 2: 219 return 3; 220 case 3: 221 return 4; 222 case 4: 223 return 5; 224 case 5: 225 return 6; 226 case 6: 227 return 7; 228 case 7: 229 return 8; 230 case 8: 231 return 9; 232 case 9: 233 return 10; 234 case 10: 235 return 11; 236 case 11: 237 return 12; 238 case 12: 239 return 13; 240 case 13: 241 return 14; 242 case 14: 243 return 15; 244 case 15: 245 return 17; 246 case 17: 247 return 18; 248 case 18: 249 return 19; 250 case 19: 251 return 20; 252 case 20: 253 return 21; 254 case 21: 255 return 0; // done! 256 default: 257 log.error("unexpected state {}", state); 258 return 0; 259 } 260 } 261 262 JCheckBox fullmode = new JCheckBox(Bundle.getMessage("Box1")); // opsw 01 263 JCheckBox twoaspects = new JCheckBox(Bundle.getMessage("Box2")); // opsw 02 264 JComboBox<String> section1to4mode = new JComboBox<String>(new String[]{ 265 Bundle.getMessage("Box3a"), 266 Bundle.getMessage("Box3b"), 267 Bundle.getMessage("Box3c"), 268 Bundle.getMessage("Box3d"), 269 Bundle.getMessage("Box4"), 270 Bundle.getMessage("Box5"), 271 Bundle.getMessage("Box3e"), 272 Bundle.getMessage("Box3f") 273 }); // opsw 3, 4, 5 274 JComboBox<String> section5to8mode = new JComboBox<String>(new String[]{ 275 Bundle.getMessage("Box3a"), 276 Bundle.getMessage("Box3b"), 277 Bundle.getMessage("Box3c"), 278 Bundle.getMessage("Box3d"), 279 Bundle.getMessage("Box4"), 280 Bundle.getMessage("Box5"), 281 Bundle.getMessage("Box3e"), 282 Bundle.getMessage("Box3f") 283 }); // opsw 6, 7, 8 284 JComboBox<String> fourthAspect = new JComboBox<String>(new String[]{ 285 Bundle.getMessage("SignalHeadStateFlashingYellow"), 286 Bundle.getMessage("SignalHeadStateFlashingRed"), 287 Bundle.getMessage("SignalHeadStateDark"), 288 Bundle.getMessage("SignalHeadStateFlashingGreen") 289 }); // opsw 9, 10 290 JCheckBox semaphore = new JCheckBox(Bundle.getMessage("Box11")); // opsw 11 291 JCheckBox pulsed = new JCheckBox(Bundle.getMessage("Box12")); // opsw 12 292 JCheckBox disableDS = new JCheckBox(Bundle.getMessage("Box13")); // opsw 13 293 JCheckBox fromloconet = new JCheckBox(Bundle.getMessage("Box14")); // opsw 14 294 JCheckBox disablelocal = new JCheckBox(Bundle.getMessage("Box15")); // opsw 15 295 JCheckBox sigaddress = new JCheckBox(Bundle.getMessage("Box17")); // opsw 17 296 JCheckBox bcastaddress = new JCheckBox(Bundle.getMessage("Box18")); // opsw 18 297 JCheckBox semaddress = new JCheckBox(Bundle.getMessage("Box19")); // opsw 19 298 JCheckBox setdefault = new JCheckBox(Bundle.getMessage("Box20")); // opsw 20 299 JCheckBox exercise = new JCheckBox(Bundle.getMessage("Box21")); // opsw 21 300 301 private final static Logger log = LoggerFactory.getLogger(SE8Panel.class); 302 303}