Package: BlockBossFrame$1

BlockBossFrame$1

nameinstructionbranchcomplexitylinemethod
actionPerformed(ActionEvent)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
{...}
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package jmri.jmrit.blockboss;
2:
3: import java.awt.Color;
4: import java.awt.FlowLayout;
5: import java.awt.GridBagConstraints;
6: import java.awt.GridBagLayout;
7: import java.awt.Insets;
8: import java.awt.event.ActionListener;
9: import javax.annotation.Nonnull;
10: import javax.swing.*;
11:
12: import jmri.InstanceManager;
13: import jmri.Sensor;
14: import jmri.SensorManager;
15: import jmri.SignalHead;
16: import jmri.SignalHeadManager;
17: import jmri.Turnout;
18: import jmri.NamedBean.DisplayOptions;
19: import jmri.swing.NamedBeanComboBox;
20:
21: import org.slf4j.Logger;
22: import org.slf4j.LoggerFactory;
23:
24: /**
25: * Provide a GUI for configuring "Simple Signal Logic" (BlockBossLogic) objects.
26: * <p>
27: * Provides four panels, corresponding to the four possible modes described in
28: * {@link BlockBossLogic}, which are then selected via radio buttons in the GUI.
29: * <p>
30: * The four modes are:
31: * <ul>
32: * <li>Single block (s)
33: * <li>Facing point (f)
34: * <li>Trailing point main (tm)
35: * <li>Trailing point diverging (td)
36: * </ul>
37: * <p>
38: * The multiple-panel approach to the GUI is used to make layout easier; the
39: * code just flips from one to the other as the user selects a mode. The
40: * individual items all share data models to simplify the logic.
41: *
42: * @author Bob Jacobsen Copyright (C) 2003, 2005
43: * @author Dick Bronson 2006: Revisions to add facing point sensors,
44: * approach lighting, limited speed, changed layout, and tool tips.
45: * @author Egbert Broerse 2017
46: */
47: public class BlockBossFrame extends jmri.util.JmriJFrame {
48:
49: private static final String SIMPLE_SIGNAL_LOGIC = "Simple_Signal_Logic";
50: private static final String LIMITED_SPEED = "Limited_Speed";
51: private static final String RESTRICTING_SPEED = "Restricting_Speed";
52: private static final String WITH_FLASHING_YELLOW = "With_Flashing_Yellow";
53: private static final String PROTECTS_SENSOR = "ProtectsSensor";
54: private static final String IS_DISTANT_SIGNAL = "Is_Distant_Signal";
55: private static final String PROTECTS_SIGNAL = "Protects_Signal";
56: private final JPanel modeSingle = new JPanel();
57: private final JRadioButton buttonSingle;
58: private final transient NamedBeanComboBox<Sensor> sSensorComboBox1 = new NamedBeanComboBox<>(
59: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
60: private final transient NamedBeanComboBox<Sensor> sSensorComboBox2 = new NamedBeanComboBox<>(
61: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
62: private final transient NamedBeanComboBox<Sensor> sSensorComboBox3 = new NamedBeanComboBox<>(
63: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
64: private final transient NamedBeanComboBox<Sensor> sSensorComboBox4 = new NamedBeanComboBox<>(
65: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
66: private final transient NamedBeanComboBox<Sensor> sSensorComboBox5 = new NamedBeanComboBox<>(
67: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
68: private final transient NamedBeanComboBox<SignalHead> sNextSignalComboBox1 = new NamedBeanComboBox<>(
69: InstanceManager.getDefault(SignalHeadManager.class), null, DisplayOptions.DISPLAYNAME);
70: private final transient NamedBeanComboBox<SignalHead> sNextSignalComboBox1Alt = new NamedBeanComboBox<>(
71: InstanceManager.getDefault(SignalHeadManager.class), null, DisplayOptions.DISPLAYNAME);
72: private final JCheckBox sLimitBox;
73: private final JCheckBox sRestrictingBox;
74: private final JCheckBox sFlashBox;
75: private final JCheckBox sDistantBox;
76:
77: private final JPanel modeTrailMain = new JPanel();
78: private final JRadioButton buttonTrailMain;
79: private final transient NamedBeanComboBox<Sensor> tmSensorComboBox1 = new NamedBeanComboBox<>(
80: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
81: private final transient NamedBeanComboBox<Sensor> tmSensorComboBox2 = new NamedBeanComboBox<>(
82: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
83: private final transient NamedBeanComboBox<Sensor> tmSensorComboBox3 = new NamedBeanComboBox<>(
84: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
85: private final transient NamedBeanComboBox<Sensor> tmSensorComboBox4 = new NamedBeanComboBox<>(
86: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
87: private final transient NamedBeanComboBox<Sensor> tmSensorComboBox5 = new NamedBeanComboBox<>(
88: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
89: private final NamedBeanComboBox<Turnout> tmProtectTurnoutComboBox = new NamedBeanComboBox<>(
90: InstanceManager.turnoutManagerInstance(),
91: null, DisplayOptions.DISPLAYNAME);
92: private final transient NamedBeanComboBox<SignalHead> tmNextSignalComboBox1 = new NamedBeanComboBox<>(
93: InstanceManager.getDefault(SignalHeadManager.class), null, DisplayOptions.DISPLAYNAME);
94: private final transient NamedBeanComboBox<SignalHead> tmNextSignalComboBox1Alt = new NamedBeanComboBox<>(
95: InstanceManager.getDefault(SignalHeadManager.class), null, DisplayOptions.DISPLAYNAME);
96: private final JCheckBox tmLimitBox;
97: private final JCheckBox tmRestrictingBox;
98: private final JCheckBox tmFlashBox;
99: private final JCheckBox tmDistantBox;
100:
101: private final JPanel modeTrailDiv = new JPanel();
102: private final JRadioButton buttonTrailDiv;
103: private final transient NamedBeanComboBox<Sensor> tdSensorComboBox1 = new NamedBeanComboBox<>(
104: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
105: private final transient NamedBeanComboBox<Sensor> tdSensorComboBox2 = new NamedBeanComboBox<>(
106: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
107: private final transient NamedBeanComboBox<Sensor> tdSensorComboBox3 = new NamedBeanComboBox<>(
108: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
109: private final transient NamedBeanComboBox<Sensor> tdSensorComboBox4 = new NamedBeanComboBox<>(
110: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
111: private final transient NamedBeanComboBox<Sensor> tdSensorComboBox5 = new NamedBeanComboBox<>(
112: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
113: private final NamedBeanComboBox<Turnout> tdProtectTurnoutComboBox = new NamedBeanComboBox<>(
114: InstanceManager.turnoutManagerInstance(),
115: null, DisplayOptions.DISPLAYNAME);
116: private final transient NamedBeanComboBox<SignalHead> tdNextSignalComboBox1 = new NamedBeanComboBox<>(
117: InstanceManager.getDefault(SignalHeadManager.class), null, DisplayOptions.DISPLAYNAME);
118: private final transient NamedBeanComboBox<SignalHead> tdNextSignalComboBox1Alt = new NamedBeanComboBox<>(
119: InstanceManager.getDefault(SignalHeadManager.class), null, DisplayOptions.DISPLAYNAME);
120: private final JCheckBox tdLimitBox;
121: private final JCheckBox tdRestrictingBox;
122: private final JCheckBox tdFlashBox;
123: private final JCheckBox tdDistantBox;
124:
125: private final JPanel modeFacing = new JPanel();
126: private final JRadioButton buttonFacing;
127:
128: private final transient NamedBeanComboBox<Sensor> fSensorComboBox1 = new NamedBeanComboBox<>(
129: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
130: private final transient NamedBeanComboBox<Sensor> fSensorComboBox2 = new NamedBeanComboBox<>(
131: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
132: private final transient NamedBeanComboBox<Sensor> fSensorComboBox3 = new NamedBeanComboBox<>(
133: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
134: private final transient NamedBeanComboBox<Sensor> fSensorComboBox4 = new NamedBeanComboBox<>(
135: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
136: private final transient NamedBeanComboBox<Sensor> fSensorComboBox5 = new NamedBeanComboBox<>(
137: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
138: private final NamedBeanComboBox<Turnout> fProtectTurnoutComboBox = new NamedBeanComboBox<>(
139: InstanceManager.turnoutManagerInstance(),
140: null, DisplayOptions.DISPLAYNAME);
141: private final transient NamedBeanComboBox<SignalHead> fNextSignalComboBox1 = new NamedBeanComboBox<>(
142: InstanceManager.getDefault(SignalHeadManager.class), null, DisplayOptions.DISPLAYNAME);
143: private final transient NamedBeanComboBox<SignalHead> fNextSignalComboBox1Alt = new NamedBeanComboBox<>(
144: InstanceManager.getDefault(SignalHeadManager.class), null, DisplayOptions.DISPLAYNAME);
145: private final transient NamedBeanComboBox<SignalHead> fNextSignalComboBox2 = new NamedBeanComboBox<>(
146: InstanceManager.getDefault(SignalHeadManager.class), null, DisplayOptions.DISPLAYNAME);
147: private final transient NamedBeanComboBox<SignalHead> fNextSignalComboBox2Alt = new NamedBeanComboBox<>(
148: InstanceManager.getDefault(SignalHeadManager.class), null, DisplayOptions.DISPLAYNAME);
149: private final transient NamedBeanComboBox<Sensor> fNextSensorComboBox1 = new NamedBeanComboBox<>(
150: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
151: private final transient NamedBeanComboBox<Sensor> fNextSensorComboBox1Alt = new NamedBeanComboBox<>(
152: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
153: private final transient NamedBeanComboBox<Sensor> fNextSensorComboBox2 = new NamedBeanComboBox<>(
154: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
155: private final transient NamedBeanComboBox<Sensor> fNextSensorComboBox2Alt = new NamedBeanComboBox<>(
156: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
157: private final JCheckBox fmLimitBox;
158: private final JCheckBox fmRestrictingBox;
159: private final JCheckBox fdLimitBox;
160: private final JCheckBox fdRestrictingBox;
161: private final JCheckBox fFlashBox;
162: private final JCheckBox fDistantBox;
163:
164: private final transient NamedBeanComboBox<Sensor> approachSensor1ComboBox = new NamedBeanComboBox<>(
165: InstanceManager.getDefault(SensorManager.class), null, DisplayOptions.DISPLAYNAME);
166: private final transient NamedBeanComboBox<SignalHead> outSignalHeadComboBox = new NamedBeanComboBox<>(
167: InstanceManager.getDefault(SignalHeadManager.class), null, DisplayOptions.DISPLAYNAME);
168: private final JLabel statusBar;
169: private final JTextField commentField;
170: private final JButton cancel;
171:
172: // ToolTip strings
173: private final String buttonSingleTooltip = Bundle.getMessage("In_direction_of_traffic");
174: private final String buttonTrailMainTooltip = Bundle.getMessage("Signal_head_for_main_track")
175: + " " + Bundle.getMessage("through_turnout_in_either_direction");
176: private final String buttonTrailDivTooltip = Bundle.getMessage("Signal_head_for_branching_track")
177: + " " + Bundle.getMessage("through_turnout_in_either_direction");
178: private final String buttonFacingTooltip = Bundle.getMessage("Single_signal_head_on_single");
179: private final String outSignalHeadTooltip = "<html>"
180: + Bundle.getMessage("Enter_a_new_signal_head_number_or")
181: + "<br>" + Bundle.getMessage("then_hit_return_to_load_its_information.")
182: + "</html>";
183: private final String approachSensor1Tooltip = "<html>"
184: + Bundle.getMessage("Enter_sensor_that_lights_this_signal_or")
185: + "</html>";
186: private final String sensorFieldTooltip = Bundle.getMessage("Sensor_active_sets_this_signal_to_Red.");
187: private final String turnoutFieldTooltip = Bundle.getMessage("Enter_protected_turnout_number_here.");
188: private final String flashBoxTooltip = Bundle.getMessage("One_aspect_faster_than_yellow_displays")
189: + " " + Bundle.getMessage("flashing_yellow_rather_than_green");
190: private final String limitBoxTooltip = Bundle.getMessage("Limits_the_fastest_aspect_displayed")
191: + " " + Bundle.getMessage("to_yellow_rather_than_green");
192: private final String restrictingBoxTooltip = Bundle.getMessage("Limits_the_fastest_aspect_displayed")
193: + " " + Bundle.getMessage("to_flashingred_rather_than_green");
194: private final String nextSignalFieldTooltip = Bundle.getMessage("Enter_the_low_speed_signal_head_for_this_track.")
195: + " " + Bundle.getMessage("For_dual_head_signals_the_fastest_aspect_is_protected.");
196: private final String highSignalFieldTooltip = Bundle.getMessage("Enter_the_high_speed_signal_head_for_this_track.")
197: + " " + Bundle.getMessage("For_dual_head_signals_the_fastest_aspect_is_protected.");
198: private final String distantBoxTooltip = Bundle.getMessage("Mirrors_the_protected_(following)_signals_status")
199: + " " + Bundle.getMessage("unless_over_ridden_by_an_intermediate_stop_sensor.");
200:
201: private final transient BlockBossLogicProvider blockBossLogicProvider;
202:
203: /**
204: * Ctor for default SSL edit frame.
205: */
206: public BlockBossFrame() {
207: this(Bundle.getMessage(SIMPLE_SIGNAL_LOGIC));
208: }
209:
210: /**
211: * Ctor for named SSL edit frame.
212: *
213: * @param frameName the name to use for this frame
214: */
215: private BlockBossFrame(String frameName) {
216:
217: // create the frame
218: super(frameName, false, true);
219:
220: blockBossLogicProvider = InstanceManager.getDefault(BlockBossLogicProvider.class);
221:
222: getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
223:
224: // add save menu item
225: JMenuBar menuBar = new JMenuBar();
226: JMenu fileMenu = new JMenu(Bundle.getMessage("MenuFile"));
227: menuBar.add(fileMenu);
228: fileMenu.add(new jmri.configurexml.StoreMenu());
229: setJMenuBar(menuBar);
230: addHelpMenu("package.jmri.jmrit.blockboss.BlockBossFrame", true);
231:
232: // create GUI items
233: sLimitBox = new JCheckBox(Bundle.getMessage(LIMITED_SPEED));
234: sRestrictingBox = new JCheckBox(Bundle.getMessage(RESTRICTING_SPEED));
235: tmLimitBox = new JCheckBox(Bundle.getMessage(LIMITED_SPEED));
236: tmLimitBox.setModel(sLimitBox.getModel());
237: tmRestrictingBox = new JCheckBox(Bundle.getMessage(RESTRICTING_SPEED));
238: tmRestrictingBox.setModel(sRestrictingBox.getModel());
239: fmLimitBox = new JCheckBox(Bundle.getMessage(LIMITED_SPEED));
240: fmLimitBox.setModel(sLimitBox.getModel());
241: fmRestrictingBox = new JCheckBox(Bundle.getMessage(RESTRICTING_SPEED));
242: fmRestrictingBox.setModel(sRestrictingBox.getModel());
243:
244: tdLimitBox = new JCheckBox(Bundle.getMessage(LIMITED_SPEED));
245: tdRestrictingBox = new JCheckBox(Bundle.getMessage(RESTRICTING_SPEED));
246: fdLimitBox = new JCheckBox(Bundle.getMessage(LIMITED_SPEED));
247: fdLimitBox.setModel(tdLimitBox.getModel());
248: fdRestrictingBox = new JCheckBox(Bundle.getMessage(RESTRICTING_SPEED));
249: fdRestrictingBox.setModel(tdRestrictingBox.getModel());
250:
251: sFlashBox = new JCheckBox(Bundle.getMessage(WITH_FLASHING_YELLOW));
252: tmFlashBox = new JCheckBox(Bundle.getMessage(WITH_FLASHING_YELLOW));
253: tmFlashBox.setModel(sFlashBox.getModel());
254: tdFlashBox = new JCheckBox(Bundle.getMessage(WITH_FLASHING_YELLOW));
255: tdFlashBox.setModel(sFlashBox.getModel());
256: fFlashBox = new JCheckBox(Bundle.getMessage(WITH_FLASHING_YELLOW));
257: fFlashBox.setModel(sFlashBox.getModel());
258:
259: sDistantBox = new JCheckBox(Bundle.getMessage(IS_DISTANT_SIGNAL));
260: tmDistantBox = new JCheckBox(Bundle.getMessage(IS_DISTANT_SIGNAL));
261: tmDistantBox.setModel(sDistantBox.getModel());
262: tdDistantBox = new JCheckBox(Bundle.getMessage(IS_DISTANT_SIGNAL));
263: tdDistantBox.setModel(sDistantBox.getModel());
264: fDistantBox = new JCheckBox(Bundle.getMessage(IS_DISTANT_SIGNAL));
265: fDistantBox.setModel(sDistantBox.getModel());
266:
267: buttonSingle = new JRadioButton(Bundle.getMessage("On_Single_Block"));
268: buttonTrailMain = new JRadioButton(Bundle.getMessage("Main_Leg_of_Turnout"));
269: buttonTrailDiv = new JRadioButton(Bundle.getMessage("Diverging_Leg_of_Turnout"));
270: buttonFacing = new JRadioButton(Bundle.getMessage("On_Facing-Point_Turnout"));
271: ButtonGroup g = new ButtonGroup();
272: g.add(buttonSingle);
273: g.add(buttonTrailMain);
274: g.add(buttonTrailDiv);
275: g.add(buttonFacing);
276: ActionListener a = e -> buttonClicked();
277:
278: buttonSingle.addActionListener(a);
279: buttonTrailMain.addActionListener(a);
280: buttonTrailDiv.addActionListener(a);
281: buttonFacing.addActionListener(a);
282:
283: // share sensor data models
284: tmSensorComboBox1.setModel(sSensorComboBox1.getModel());
285: tdSensorComboBox1.setModel(sSensorComboBox1.getModel());
286: fSensorComboBox1.setModel(sSensorComboBox1.getModel());
287:
288: tmSensorComboBox2.setModel(sSensorComboBox2.getModel());
289: tdSensorComboBox2.setModel(sSensorComboBox2.getModel());
290: fSensorComboBox2.setModel(sSensorComboBox2.getModel());
291:
292: tmSensorComboBox3.setModel(sSensorComboBox3.getModel());
293: tdSensorComboBox3.setModel(sSensorComboBox3.getModel());
294: fSensorComboBox3.setModel(sSensorComboBox3.getModel());
295:
296: tmSensorComboBox4.setModel(sSensorComboBox4.getModel());
297: tdSensorComboBox4.setModel(sSensorComboBox4.getModel());
298: fSensorComboBox4.setModel(sSensorComboBox4.getModel());
299:
300: tmSensorComboBox5.setModel(sSensorComboBox5.getModel());
301: tdSensorComboBox5.setModel(sSensorComboBox5.getModel());
302: fSensorComboBox5.setModel(sSensorComboBox5.getModel());
303: // share turnout data model
304: tmProtectTurnoutComboBox.setModel(tdProtectTurnoutComboBox.getModel());
305: fProtectTurnoutComboBox.setModel(tdProtectTurnoutComboBox.getModel());
306:
307: tdNextSignalComboBox1.setModel(sNextSignalComboBox1.getModel());
308: tdNextSignalComboBox1Alt.setModel(sNextSignalComboBox1Alt.getModel());
309: tmNextSignalComboBox1.setModel(sNextSignalComboBox1.getModel());
310: tmNextSignalComboBox1Alt.setModel(sNextSignalComboBox1Alt.getModel());
311: fNextSignalComboBox1.setModel(sNextSignalComboBox1.getModel());
312: fNextSignalComboBox1Alt.setModel(sNextSignalComboBox1Alt.getModel());
313:
314: // configure sensor combobox options
315: setupComboBox(sSensorComboBox1, false, true, true);
316: setupComboBox(sSensorComboBox2, false, true, true);
317: setupComboBox(sSensorComboBox3, false, true, true);
318: setupComboBox(sSensorComboBox4, false, true, true);
319: setupComboBox(sSensorComboBox5, false, true, true);
320: setupComboBox(tmSensorComboBox1, false, true, true);
321: setupComboBox(tmSensorComboBox2, false, true, true);
322: setupComboBox(tmSensorComboBox3, false, true, true);
323: setupComboBox(tmSensorComboBox4, false, true, true);
324: setupComboBox(tmSensorComboBox5, false, true, true);
325: setupComboBox(tdSensorComboBox1, false, true, true);
326: setupComboBox(tdSensorComboBox2, false, true, true);
327: setupComboBox(tdSensorComboBox3, false, true, true);
328: setupComboBox(tdSensorComboBox4, false, true, true);
329: setupComboBox(tdSensorComboBox5, false, true, true);
330: setupComboBox(fSensorComboBox1, false, true, true);
331: setupComboBox(fSensorComboBox2, false, true, true);
332: setupComboBox(fSensorComboBox3, false, true, true);
333: setupComboBox(fSensorComboBox4, false, true, true);
334: setupComboBox(fSensorComboBox5, false, true, true);
335: // configure turnout combobox options
336: setupComboBox(tdProtectTurnoutComboBox, false, true, true);
337: setupComboBox(tmProtectTurnoutComboBox, false, true, true);
338: setupComboBox(fProtectTurnoutComboBox, false, true, true);
339: // configure next signal combobox options
340: setupComboBox(sNextSignalComboBox1, false, true, true);
341: setupComboBox(sNextSignalComboBox1Alt, false, true, true);
342: setupComboBox(tdNextSignalComboBox1, false, true, true);
343: setupComboBox(tdNextSignalComboBox1Alt, false, true, true);
344: setupComboBox(tmNextSignalComboBox1, false, true, true);
345: setupComboBox(tmNextSignalComboBox1Alt, false, true, true);
346: setupComboBox(fNextSignalComboBox1, false, true, true);
347: setupComboBox(fNextSignalComboBox1Alt, false, true, true);
348: setupComboBox(fNextSignalComboBox2, false, true, true);
349: setupComboBox(fNextSignalComboBox2Alt, false, true, true);
350: // configure next sensor combobox options
351: setupComboBox(fNextSensorComboBox1, false, true, true);
352: setupComboBox(fNextSensorComboBox1Alt, false, true, true);
353: setupComboBox(fNextSensorComboBox2, false, true, true);
354: setupComboBox(fNextSensorComboBox2Alt, false, true, true);
355:
356: // add top part of GUI, holds signal head name to drive
357: JPanel line = new JPanel();
358: line.add(new JLabel(Bundle.getMessage("SSLHeadNamedLabel")));
359: setupComboBox(outSignalHeadComboBox, true, true, true);
360: line.add(outSignalHeadComboBox);
361: outSignalHeadComboBox.setToolTipText(outSignalHeadTooltip);
362: outSignalHeadComboBox.addActionListener(e ->
363: // user hit enter, use this name to fill in the rest of the fields
364: activate());
365:
366: getContentPane().add(line);
367:
368: line = new JPanel();
369: line.setLayout(new BoxLayout(line, BoxLayout.Y_AXIS));
370: buttonSingle.setToolTipText(buttonSingleTooltip);
371: line.add(buttonSingle);
372: buttonTrailMain.setToolTipText(buttonTrailMainTooltip);
373: line.add(buttonTrailMain);
374: buttonTrailDiv.setToolTipText(buttonTrailDivTooltip);
375: line.add(buttonTrailDiv);
376: buttonFacing.setToolTipText(buttonFacingTooltip);
377: line.add(buttonFacing);
378: line.setAlignmentX(0.5f);
379: getContentPane().add(line);
380:
381: getContentPane().add(new JSeparator(SwingConstants.HORIZONTAL));
382:
383: // fill in the specific panels for the modes
384: getContentPane().add(fillModeSingle());
385: getContentPane().add(fillModeTrailMain());
386: getContentPane().add(fillModeTrailDiv());
387: getContentPane().add(fillModeFacing());
388:
389: line = new JPanel();
390: line.add(new JLabel(Bundle.getMessage("ApproachLightingSensorLabel")));
391: line.add(approachSensor1ComboBox);
392: setupComboBox(approachSensor1ComboBox, false, true, true);
393: approachSensor1ComboBox.setToolTipText(approachSensor1Tooltip);
394: line.setAlignmentX(0.5f);
395: getContentPane().add(line);
396:
397: // add comment element
398: line = new JPanel();
399: line.setLayout(new FlowLayout());
400: line.add(new JLabel(Bundle.getMessage("Comment")));
401: line.add(commentField = new JTextField(30));
402: commentField.setToolTipText(Bundle.getMessage("CommentToolTip"));
403: getContentPane().add(line);
404:
405: // add status bar above buttons
406: line = new JPanel();
407: line.setLayout(new FlowLayout());
408: statusBar = new JLabel(Bundle.getMessage("StatusSslStart"));
409: statusBar.setFont(statusBar.getFont().deriveFont(0.9f * commentField.getFont().getSize())); // a bit smaller
410: statusBar.setForeground(Color.gray);
411: line.add(statusBar);
412: getContentPane().add(line);
413:
414: getContentPane().add(new JSeparator(SwingConstants.HORIZONTAL));
415:
416: JPanel buttons = new JPanel();
417: buttons.setLayout(new FlowLayout());
418: // add OK button at bottom
419: cancel = new JButton(Bundle.getMessage("ButtonCancel"));
420: buttons.add(cancel);
421: cancel.addActionListener(e -> cancelPressed());
422: JButton apply = new JButton(Bundle.getMessage("ButtonApply"));
423: apply.setToolTipText(Bundle.getMessage("ApplyToolTip"));
424: buttons.add(apply);
425: apply.addActionListener(e -> applyPressed());
426: getContentPane().add(buttons);
427:
428: pack();
429: // set a definite mode selection, which also repacks.
430: buttonSingle.setSelected(true);
431: buttonClicked();
432: }
433:
434: // Panel arrangements all changed to use GridBagLayout format.
435:
436: private JPanel fillModeSingle() {
437: modeSingle.setLayout(new GridBagLayout());
438:
439: GridBagConstraints constraints = new GridBagConstraints();
440: constraints.anchor = GridBagConstraints.EAST;
441: constraints.gridheight = 1;
442: constraints.gridwidth = 1;
443: constraints.ipadx = 0;
444: constraints.ipady = 0;
445: Insets insets = new Insets(2, 3, 2, 3); // top, left, bottom, right
446: constraints.insets = insets;
447: constraints.weightx = 1;
448: constraints.weighty = 1;
449:
450: constraints.fill = GridBagConstraints.NONE;
451: constraints.gridx = 0;
452: constraints.gridy = 0;
453: insets.top = 9;
454: insets.bottom = 9;
455:
456: modeSingle.add(new JLabel(Bundle.getMessage(PROTECTS_SENSOR)), constraints);
457: constraints.fill = GridBagConstraints.HORIZONTAL;
458: constraints.gridx = 1;
459: sSensorComboBox1.setToolTipText(sensorFieldTooltip);
460: modeSingle.add(sSensorComboBox1, constraints);
461: constraints.gridx = 2;
462: sSensorComboBox2.setToolTipText(sensorFieldTooltip);
463: modeSingle.add(sSensorComboBox2, constraints);
464: constraints.gridx = 3;
465: sSensorComboBox3.setToolTipText(sensorFieldTooltip);
466: modeSingle.add(sSensorComboBox3, constraints);
467: constraints.gridx = 4;
468: sSensorComboBox4.setToolTipText(sensorFieldTooltip);
469: modeSingle.add(sSensorComboBox4, constraints);
470: constraints.gridx = 5;
471: sSensorComboBox5.setToolTipText(sensorFieldTooltip);
472: modeSingle.add(sSensorComboBox5, constraints);
473:
474: insets.top = 2;
475: constraints.gridx = 0;
476: constraints.gridy = 1;
477: constraints.fill = GridBagConstraints.NONE;
478:
479: modeSingle.add(new JLabel(Bundle.getMessage(PROTECTS_SIGNAL)), constraints);
480: constraints.fill = GridBagConstraints.HORIZONTAL;
481: constraints.gridx = 1;
482: sNextSignalComboBox1.setToolTipText(highSignalFieldTooltip);
483: modeSingle.add(sNextSignalComboBox1, constraints);
484: constraints.gridx = 2;
485: sNextSignalComboBox1Alt.setToolTipText(nextSignalFieldTooltip);
486: modeSingle.add(sNextSignalComboBox1Alt, constraints);
487: constraints.gridx = 3;
488: constraints.gridwidth = 2;
489: // ??
490: JPanel q = new JPanel();
491: q.setLayout(new FlowLayout());
492: q.add(sLimitBox);
493: q.add(sRestrictingBox);
494: sLimitBox.setToolTipText(limitBoxTooltip);
495: sRestrictingBox.setToolTipText(restrictingBoxTooltip);
496: modeSingle.add(q, constraints);
497:
498: constraints.gridy = 6;
499: constraints.gridx = 1;
500: constraints.gridwidth = 2;
501: constraints.anchor = GridBagConstraints.WEST;
502: insets.bottom = 9;
503: sFlashBox.setToolTipText(flashBoxTooltip);
504: modeSingle.add(sFlashBox, constraints);
505:
506: constraints.gridx = 3;
507: sDistantBox.setToolTipText(distantBoxTooltip);
508: modeSingle.add(sDistantBox, constraints);
509: return modeSingle;
510: }
511:
512: private JPanel fillModeTrailMain() {
513: modeTrailMain.setLayout(new GridBagLayout());
514:
515: GridBagConstraints constraints = new GridBagConstraints();
516: constraints.anchor = GridBagConstraints.EAST;
517: constraints.gridheight = 1;
518: constraints.gridwidth = 1;
519: constraints.ipadx = 0;
520: constraints.ipady = 0;
521: Insets insets = new Insets(2, 3, 2, 3); // top, left, bottom, right
522: constraints.insets = insets;
523: constraints.weightx = 1;
524: constraints.weighty = 1;
525:
526: constraints.fill = GridBagConstraints.NONE;
527: constraints.gridx = 0;
528: constraints.gridy = 0;
529: insets.top = 9;
530: insets.bottom = 9;
531: modeTrailMain.add(new JLabel(Bundle.getMessage(PROTECTS_SENSOR)), constraints);
532: constraints.fill = GridBagConstraints.HORIZONTAL;
533: constraints.gridx = 1;
534: tmSensorComboBox1.setToolTipText(sensorFieldTooltip);
535: modeTrailMain.add(tmSensorComboBox1, constraints);
536: constraints.gridx = 2;
537: tmSensorComboBox2.setToolTipText(sensorFieldTooltip);
538: modeTrailMain.add(tmSensorComboBox2, constraints);
539: constraints.gridx = 3;
540: tmSensorComboBox3.setToolTipText(sensorFieldTooltip);
541: modeTrailMain.add(tmSensorComboBox3, constraints);
542: constraints.gridx = 4;
543: tmSensorComboBox4.setToolTipText(sensorFieldTooltip);
544: modeTrailMain.add(tmSensorComboBox4, constraints);
545: constraints.gridx = 5;
546: tmSensorComboBox5.setToolTipText(sensorFieldTooltip);
547: modeTrailMain.add(tmSensorComboBox5, constraints);
548:
549: insets.top = 2;
550: constraints.fill = GridBagConstraints.NONE;
551: constraints.gridx = 0;
552: constraints.gridy = 1;
553: insets.bottom = 9;
554: modeTrailMain.add(new JLabel(Bundle.getMessage("Red_When_Turnout")), constraints);
555: constraints.fill = GridBagConstraints.HORIZONTAL;
556: constraints.gridx = 1;
557: tmProtectTurnoutComboBox.setToolTipText(turnoutFieldTooltip);
558: modeTrailMain.add(tmProtectTurnoutComboBox, constraints);
559: constraints.gridx = 2;
560: constraints.gridwidth = 2;
561: modeTrailMain.add(new JLabel(Bundle.getMessage("IsState", InstanceManager.turnoutManagerInstance().getThrownText())), constraints);
562: constraints.gridwidth = 1;
563:
564: constraints.fill = GridBagConstraints.NONE;
565: constraints.gridx = 0;
566: constraints.gridy = 4;
567: insets.bottom = 2;
568: modeTrailMain.add(new JLabel(Bundle.getMessage(PROTECTS_SIGNAL)), constraints);
569: constraints.fill = GridBagConstraints.HORIZONTAL;
570: constraints.gridx = 1;
571: tmNextSignalComboBox1.setToolTipText(highSignalFieldTooltip);
572: modeTrailMain.add(tmNextSignalComboBox1, constraints);
573: constraints.gridx = 2;
574: tmNextSignalComboBox1Alt.setToolTipText(nextSignalFieldTooltip);
575: modeTrailMain.add(tmNextSignalComboBox1Alt, constraints);
576: constraints.gridx = 3;
577: constraints.gridwidth = 2;
578: // ??
579: JPanel q = new JPanel();
580: q.setLayout(new FlowLayout());
581: q.add(tmLimitBox);
582: q.add(tmRestrictingBox);
583: tmLimitBox.setToolTipText(limitBoxTooltip);
584: tmRestrictingBox.setToolTipText(restrictingBoxTooltip);
585: modeTrailMain.add(q, constraints);
586:
587: constraints.gridy = 6;
588: constraints.gridx = 1;
589: constraints.gridwidth = 2;
590: constraints.anchor = GridBagConstraints.WEST;
591: insets.bottom = 9;
592: tmFlashBox.setToolTipText(flashBoxTooltip);
593: modeTrailMain.add(tmFlashBox, constraints);
594:
595: constraints.gridx = 3;
596: tmDistantBox.setToolTipText(distantBoxTooltip);
597: modeTrailMain.add(tmDistantBox, constraints);
598: return modeTrailMain;
599: }
600:
601: private JPanel fillModeTrailDiv() {
602: modeTrailDiv.setLayout(new GridBagLayout());
603:
604: GridBagConstraints constraints = new GridBagConstraints();
605: constraints.anchor = GridBagConstraints.EAST;
606: constraints.gridheight = 1;
607: constraints.gridwidth = 1;
608: constraints.ipadx = 0;
609: constraints.ipady = 0;
610: Insets insets = new Insets(2, 3, 2, 3); // top, left, bottom, right
611: constraints.insets = insets;
612: constraints.weightx = 1;
613: constraints.weighty = 1;
614:
615: constraints.fill = GridBagConstraints.NONE;
616: constraints.gridx = 0;
617: constraints.gridy = 0;
618: insets.top = 9;
619: insets.bottom = 9;
620: modeTrailDiv.add(new JLabel(Bundle.getMessage(PROTECTS_SENSOR)), constraints);
621: constraints.fill = GridBagConstraints.HORIZONTAL;
622: constraints.gridx = 1;
623: tdSensorComboBox1.setToolTipText(sensorFieldTooltip);
624: modeTrailDiv.add(tdSensorComboBox1, constraints);
625: constraints.gridx = 2;
626: tdSensorComboBox2.setToolTipText(sensorFieldTooltip);
627: modeTrailDiv.add(tdSensorComboBox2, constraints);
628: constraints.gridx = 3;
629: tdSensorComboBox3.setToolTipText(sensorFieldTooltip);
630: modeTrailDiv.add(tdSensorComboBox3, constraints);
631: constraints.gridx = 4;
632: tdSensorComboBox4.setToolTipText(sensorFieldTooltip);
633: modeTrailDiv.add(tdSensorComboBox4, constraints);
634: constraints.gridx = 5;
635: tdSensorComboBox5.setToolTipText(sensorFieldTooltip);
636: modeTrailDiv.add(tdSensorComboBox5, constraints);
637:
638: insets.top = 2;
639: constraints.fill = GridBagConstraints.NONE;
640: constraints.gridx = 0;
641: constraints.gridy = 1;
642: insets.bottom = 9;
643: modeTrailDiv.add(new JLabel(Bundle.getMessage("Red_When_Turnout")), constraints);
644: constraints.fill = GridBagConstraints.HORIZONTAL;
645: constraints.gridx = 1;
646: tdProtectTurnoutComboBox.setToolTipText(turnoutFieldTooltip);
647: modeTrailDiv.add(tdProtectTurnoutComboBox, constraints);
648: constraints.gridx = 2;
649: constraints.gridwidth = 2;
650: modeTrailDiv.add(new JLabel(Bundle.getMessage("IsState", InstanceManager.turnoutManagerInstance().getClosedText())), constraints);
651: constraints.gridwidth = 1;
652:
653: constraints.fill = GridBagConstraints.NONE;
654: constraints.gridx = 0;
655: constraints.gridy = 4;
656: insets.bottom = 2;
657: modeTrailDiv.add(new JLabel(Bundle.getMessage(PROTECTS_SIGNAL)), constraints);
658: constraints.fill = GridBagConstraints.HORIZONTAL;
659: constraints.gridx = 1;
660: tdNextSignalComboBox1.setToolTipText(highSignalFieldTooltip);
661: modeTrailDiv.add(tdNextSignalComboBox1, constraints);
662: constraints.gridx = 2;
663: tdNextSignalComboBox1Alt.setToolTipText(nextSignalFieldTooltip);
664: modeTrailDiv.add(tdNextSignalComboBox1Alt, constraints);
665: constraints.gridx = 3;
666: constraints.gridwidth = 2;
667: // ??
668: JPanel q = new JPanel();
669: q.setLayout(new FlowLayout());
670: q.add(tdLimitBox);
671: q.add(tdRestrictingBox);
672: tdLimitBox.setToolTipText(limitBoxTooltip);
673: tdRestrictingBox.setToolTipText(restrictingBoxTooltip);
674: modeTrailDiv.add(q, constraints);
675:
676: constraints.gridy = 6;
677: constraints.gridx = 1;
678: constraints.gridwidth = 2;
679: constraints.anchor = GridBagConstraints.WEST;
680: insets.bottom = 9;
681: tdFlashBox.setToolTipText(flashBoxTooltip);
682: modeTrailDiv.add(tdFlashBox, constraints);
683:
684: constraints.gridx = 3;
685: tdDistantBox.setToolTipText(distantBoxTooltip);
686: modeTrailDiv.add(tdDistantBox, constraints);
687:
688: return modeTrailDiv;
689: }
690:
691: private JPanel fillModeFacing() {
692: modeFacing.setLayout(new GridBagLayout());
693:
694: GridBagConstraints constraints = new GridBagConstraints();
695: constraints.anchor = GridBagConstraints.EAST;
696: constraints.gridheight = 1;
697: constraints.gridwidth = 1;
698: constraints.ipadx = 0;
699: constraints.ipady = 0;
700: Insets insets = new Insets(2, 3, 2, 3); // top, left, bottom, right
701: constraints.insets = insets;
702: constraints.weightx = 1;
703: constraints.weighty = 1;
704:
705: constraints.fill = GridBagConstraints.NONE;
706: constraints.gridx = 0;
707: constraints.gridy = 0;
708: insets.top = 9;
709: insets.bottom = 9;
710: modeFacing.add(new JLabel(Bundle.getMessage(PROTECTS_SENSOR)), constraints);
711: constraints.fill = GridBagConstraints.HORIZONTAL;
712: constraints.gridx = 1;
713: fSensorComboBox1.setToolTipText(sensorFieldTooltip);
714: modeFacing.add(fSensorComboBox1, constraints);
715: constraints.gridx = 2;
716: fSensorComboBox2.setToolTipText(sensorFieldTooltip);
717: modeFacing.add(fSensorComboBox2, constraints);
718: constraints.gridx = 3;
719: fSensorComboBox3.setToolTipText(sensorFieldTooltip);
720: modeFacing.add(fSensorComboBox3, constraints);
721: constraints.gridx = 4;
722: fSensorComboBox4.setToolTipText(sensorFieldTooltip);
723: modeFacing.add(fSensorComboBox4, constraints);
724: constraints.gridx = 5;
725: fSensorComboBox5.setToolTipText(sensorFieldTooltip);
726: modeFacing.add(fSensorComboBox5, constraints);
727:
728: insets.top = 2;
729: constraints.fill = GridBagConstraints.NONE;
730: constraints.gridx = 0;
731: constraints.gridy = 1;
732: insets.bottom = 9;
733: modeFacing.add(new JLabel(Bundle.getMessage("WatchesTurnout")), constraints);
734: constraints.fill = GridBagConstraints.HORIZONTAL;
735: constraints.gridx = 1;
736: fProtectTurnoutComboBox.setToolTipText(turnoutFieldTooltip);
737: modeFacing.add(fProtectTurnoutComboBox, constraints);
738:
739: constraints.fill = GridBagConstraints.NONE;
740: constraints.gridx = 0;
741: constraints.gridy = 2;
742: insets.bottom = 2;
743: modeFacing.add(new JLabel(Bundle.getMessage("To_Protect_Signal")), constraints);
744: constraints.fill = GridBagConstraints.HORIZONTAL;
745: constraints.gridx = 1;
746: fNextSignalComboBox1.setToolTipText(highSignalFieldTooltip);
747: modeFacing.add(fNextSignalComboBox1, constraints);
748: constraints.gridx = 2;
749: fNextSignalComboBox1Alt.setToolTipText(nextSignalFieldTooltip);
750: modeFacing.add(fNextSignalComboBox1Alt, constraints);
751: constraints.gridx = 3;
752: constraints.gridwidth = 2;
753: // ??
754: JPanel q = new JPanel();
755: q.setLayout(new FlowLayout());
756: q.add(fmLimitBox);
757: q.add(fmRestrictingBox);
758: fmLimitBox.setToolTipText(limitBoxTooltip);
759: fmRestrictingBox.setToolTipText(restrictingBoxTooltip);
760: modeFacing.add(q, constraints);
761:
762: constraints.fill = GridBagConstraints.NONE;
763: constraints.gridwidth = 1;
764: constraints.gridx = 0;
765: constraints.gridy = 3;
766: insets.bottom = 9;
767: modeFacing.add(new JLabel(Bundle.getMessage("And_Sensors")), constraints);
768: constraints.fill = GridBagConstraints.HORIZONTAL;
769: constraints.gridx = 1;
770: fNextSensorComboBox1.setToolTipText(sensorFieldTooltip);
771: modeFacing.add(fNextSensorComboBox1, constraints);
772: constraints.gridx = 2;
773: fNextSensorComboBox1Alt.setToolTipText(sensorFieldTooltip);
774: modeFacing.add(fNextSensorComboBox1Alt, constraints);
775: constraints.gridx = 3;
776: constraints.gridwidth = 2;
777: modeFacing.add(new JLabel(Bundle.getMessage("WhenTurnoutIsX", InstanceManager.turnoutManagerInstance().getClosedText())), constraints);
778: constraints.gridwidth = 1;
779:
780: constraints.fill = GridBagConstraints.NONE;
781: constraints.gridx = 0;
782: constraints.gridy = 4;
783: insets.bottom = 2;
784: modeFacing.add(new JLabel(Bundle.getMessage("And_Protect_Signal")), constraints);
785: constraints.fill = GridBagConstraints.HORIZONTAL;
786: constraints.gridx = 1;
787: fNextSignalComboBox2.setToolTipText(highSignalFieldTooltip);
788: modeFacing.add(fNextSignalComboBox2, constraints);
789: constraints.gridx = 2;
790: fNextSignalComboBox2Alt.setToolTipText(nextSignalFieldTooltip);
791: modeFacing.add(fNextSignalComboBox2Alt, constraints);
792: constraints.gridx = 3;
793: constraints.gridwidth = 2;
794:
795: q = new JPanel();
796: q.setLayout(new FlowLayout());
797: q.add(fdLimitBox);
798: q.add(fdRestrictingBox);
799: fdLimitBox.setToolTipText(limitBoxTooltip);
800: fdRestrictingBox.setToolTipText(restrictingBoxTooltip);
801: modeFacing.add(q, constraints);
802:
803: constraints.fill = GridBagConstraints.NONE;
804: constraints.gridwidth = 1;
805: constraints.gridx = 0;
806: constraints.gridy = 5;
807: insets.bottom = 9;
808: modeFacing.add(new JLabel(Bundle.getMessage("And_Sensors")), constraints);
809: constraints.fill = GridBagConstraints.HORIZONTAL;
810: constraints.gridx = 1;
811: fNextSensorComboBox2.setToolTipText(sensorFieldTooltip);
812: modeFacing.add(fNextSensorComboBox2, constraints);
813: constraints.gridx = 2;
814: fNextSensorComboBox2Alt.setToolTipText(sensorFieldTooltip);
815: modeFacing.add(fNextSensorComboBox2Alt, constraints);
816: constraints.gridx = 3;
817: constraints.gridwidth = 2;
818: modeFacing.add(new JLabel(Bundle.getMessage("WhenTurnoutIsX", InstanceManager.turnoutManagerInstance().getThrownText())), constraints);
819: constraints.gridwidth = 1;
820:
821: constraints.gridy = 6;
822: constraints.gridx = 1;
823: constraints.gridwidth = 2;
824: constraints.anchor = GridBagConstraints.WEST;
825: insets.bottom = 9;
826: fFlashBox.setToolTipText(flashBoxTooltip);
827: modeFacing.add(fFlashBox, constraints);
828:
829: constraints.gridx = 3;
830: fDistantBox.setToolTipText(distantBoxTooltip);
831: modeFacing.add(fDistantBox, constraints);
832:
833: return modeFacing;
834: }
835:
836: private void applyPressed() {
837: SignalHead head = sh; // temp used here for SignalHead being operated on
838:
839: // check signal head exists
840: if (head == null) {
841: if (outSignalHeadComboBox.getSelectedItem() == null) {
842: setTitle(Bundle.getMessage(SIMPLE_SIGNAL_LOGIC));
843: statusBar.setText(Bundle.getMessage("HeadXNotDefined", outSignalHeadComboBox.getSelectedItemDisplayName()));
844: return;
845: } else {
846: head = outSignalHeadComboBox.getSelectedItem();
847: if (head == null) {
848: // getting selected signal head failed for some reason
849: log.error("Could not create the Simple Signal Logic for {} because SignalHead could not be found", outSignalHeadComboBox.getSelectedItemDisplayName());
850: statusBar.setText(Bundle.getMessage("ApplyErrorDialog"));
851: return;
852: }
853: statusBar.setText(Bundle.getMessage("StatusSslCreated", outSignalHeadComboBox.getSelectedItemDisplayName()));
854: }
855: } else {
856: statusBar.setText(Bundle.getMessage("StatusSslUpdated", outSignalHeadComboBox.getSelectedItemDisplayName()));
857: }
858:
859: // it does
860: try {
861: BlockBossLogic b = BlockBossLogic.getStoppedObject(head);
862: b.setApproachSensor1(approachSensor1ComboBox.getSelectedItemDisplayName());
863: if (buttonSingle.isSelected()) {
864: loadSingle(b);
865: } else if (buttonTrailMain.isSelected()) {
866: loadTrailMain(b);
867: } else if (buttonTrailDiv.isSelected()) {
868: loadTrailDiv(b);
869: } else if (buttonFacing.isSelected()) {
870: loadFacing(b);
871: } else {
872: log.error("no SSL type radio button was selected"); // NOI18N
873: return;
874: }
875: cancel.setText(Bundle.getMessage("ButtonClose")); // when Apply has been clicked at least once, this is not Cancel
876: } catch (Exception e) {
877: log.error("An error occurred creating the Simple Signal Logic for{}", e);
878: statusBar.setText(Bundle.getMessage("ApplyErrorDialog"));
879: }
880: }
881:
882: private void cancelPressed() {
883: // close pane
884: this.setVisible(false);
885: statusBar.setText("");
886: super.dispose();
887: }
888:
889: private void loadSingle(BlockBossLogic b) {
890: b.setSensor1(sSensorComboBox1.getSelectedItemDisplayName());
891: b.setSensor2(sSensorComboBox2.getSelectedItemDisplayName());
892: b.setSensor3(sSensorComboBox3.getSelectedItemDisplayName());
893: b.setSensor4(sSensorComboBox4.getSelectedItemDisplayName());
894: b.setSensor5(sSensorComboBox5.getSelectedItemDisplayName());
895: b.setMode(BlockBossLogic.SINGLEBLOCK);
896:
897: b.setWatchedSignal1(sNextSignalComboBox1.getSelectedItemDisplayName(), sFlashBox.isSelected());
898: b.setWatchedSignal1Alt(sNextSignalComboBox1Alt.getSelectedItemDisplayName());
899: b.setLimitSpeed1(sLimitBox.isSelected());
900: b.setRestrictingSpeed1(sRestrictingBox.isSelected());
901: b.setDistantSignal(sDistantBox.isSelected());
902:
903: b.setComment(commentField.getText());
904:
905: blockBossLogicProvider.register(b);
906: b.start();
907: }
908:
909: private void loadTrailMain(BlockBossLogic b) {
910: b.setSensor1(tmSensorComboBox1.getSelectedItemDisplayName());
911: b.setSensor2(tmSensorComboBox2.getSelectedItemDisplayName());
912: b.setSensor3(tmSensorComboBox3.getSelectedItemDisplayName());
913: b.setSensor4(tmSensorComboBox4.getSelectedItemDisplayName());
914: b.setSensor5(tmSensorComboBox5.getSelectedItemDisplayName());
915: b.setMode(BlockBossLogic.TRAILINGMAIN);
916:
917: b.setTurnout(tmProtectTurnoutComboBox.getSelectedItemDisplayName());
918:
919: b.setWatchedSignal1(tmNextSignalComboBox1.getSelectedItemDisplayName(), tmFlashBox.isSelected());
920: b.setWatchedSignal1Alt(tmNextSignalComboBox1Alt.getSelectedItemDisplayName());
921: b.setLimitSpeed1(tmLimitBox.isSelected());
922: b.setRestrictingSpeed1(tmRestrictingBox.isSelected());
923: b.setDistantSignal(tmDistantBox.isSelected());
924:
925: b.setComment(commentField.getText());
926:
927: blockBossLogicProvider.register(b);
928: b.start();
929: }
930:
931: private void loadTrailDiv(BlockBossLogic b) {
932: b.setSensor1(tdSensorComboBox1.getSelectedItemDisplayName());
933: b.setSensor2(tdSensorComboBox2.getSelectedItemDisplayName());
934: b.setSensor3(tdSensorComboBox3.getSelectedItemDisplayName());
935: b.setSensor4(tdSensorComboBox4.getSelectedItemDisplayName());
936: b.setSensor5(tdSensorComboBox5.getSelectedItemDisplayName());
937: b.setMode(BlockBossLogic.TRAILINGDIVERGING);
938:
939: b.setTurnout(tdProtectTurnoutComboBox.getSelectedItemDisplayName());
940:
941: b.setWatchedSignal1(tdNextSignalComboBox1.getSelectedItemDisplayName(), tdFlashBox.isSelected());
942: b.setWatchedSignal1Alt(tdNextSignalComboBox1Alt.getSelectedItemDisplayName());
943: b.setLimitSpeed2(tdLimitBox.isSelected());
944: b.setRestrictingSpeed1(tdRestrictingBox.isSelected());
945: b.setDistantSignal(tdDistantBox.isSelected());
946:
947: b.setComment(commentField.getText());
948:
949: blockBossLogicProvider.register(b);
950: b.start();
951: }
952:
953: private void loadFacing(BlockBossLogic b) {
954: b.setSensor1(fSensorComboBox1.getSelectedItemDisplayName());
955: b.setSensor2(fSensorComboBox2.getSelectedItemDisplayName());
956: b.setSensor3(fSensorComboBox3.getSelectedItemDisplayName());
957: b.setSensor4(fSensorComboBox4.getSelectedItemDisplayName());
958: b.setSensor5(fSensorComboBox5.getSelectedItemDisplayName());
959: b.setMode(BlockBossLogic.FACING);
960:
961: b.setTurnout(fProtectTurnoutComboBox.getSelectedItemDisplayName());
962:
963: b.setWatchedSignal1(fNextSignalComboBox1.getSelectedItemDisplayName(), fFlashBox.isSelected());
964: b.setWatchedSignal1Alt(fNextSignalComboBox1Alt.getSelectedItemDisplayName());
965: b.setWatchedSignal2(fNextSignalComboBox2.getSelectedItemDisplayName());
966: b.setWatchedSignal2Alt(fNextSignalComboBox2Alt.getSelectedItemDisplayName());
967: b.setWatchedSensor1(fNextSensorComboBox1.getSelectedItemDisplayName());
968: b.setWatchedSensor1Alt(fNextSensorComboBox1Alt.getSelectedItemDisplayName());
969: b.setWatchedSensor2(fNextSensorComboBox2.getSelectedItemDisplayName());
970: b.setWatchedSensor2Alt(fNextSensorComboBox2Alt.getSelectedItemDisplayName());
971: b.setLimitSpeed1(fmLimitBox.isSelected());
972: b.setRestrictingSpeed1(fmRestrictingBox.isSelected());
973: b.setLimitSpeed2(fdLimitBox.isSelected());
974: b.setRestrictingSpeed2(fdRestrictingBox.isSelected());
975:
976: b.setDistantSignal(fDistantBox.isSelected());
977:
978: b.setComment(commentField.getText());
979:
980: blockBossLogicProvider.register(b);
981: b.start();
982: }
983:
984: private void activate() {
985: // check signal head exists
986: if (sh == null && outSignalHeadComboBox.getSelectedItem() == null) {
987: // head not exist, just title the window and leave
988: setTitle(Bundle.getMessage(SIMPLE_SIGNAL_LOGIC));
989: return;
990: }
991:
992: // find existing logic
993: BlockBossLogic b;
994: if (sh != null) {
995: b = blockBossLogicProvider.provide(sh);
996: } else {
997: b = blockBossLogicProvider.provide(outSignalHeadComboBox.getSelectedItem());
998: }
999:
1000: setTitle(Bundle.getMessage("SignalLogicForX", outSignalHeadComboBox.getSelectedItemDisplayName()));
1001:
1002: approachSensor1ComboBox.setSelectedItemByName(b.getApproachSensor1());
1003:
1004: sSensorComboBox1.setSelectedItemByName(b.getSensor1());
1005: sSensorComboBox2.setSelectedItemByName(b.getSensor2());
1006: sSensorComboBox3.setSelectedItemByName(b.getSensor3());
1007: sSensorComboBox4.setSelectedItemByName(b.getSensor4());
1008: sSensorComboBox5.setSelectedItemByName(b.getSensor5());
1009:
1010: tmProtectTurnoutComboBox.setSelectedItemByName(b.getTurnout());
1011:
1012: sNextSignalComboBox1.setSelectedItemByName(b.getWatchedSignal1());
1013: sNextSignalComboBox1Alt.setSelectedItemByName(b.getWatchedSignal1Alt());
1014:
1015: fNextSignalComboBox2.setSelectedItemByName(b.getWatchedSignal2());
1016: fNextSignalComboBox2Alt.setSelectedItemByName(b.getWatchedSignal2Alt());
1017:
1018: fNextSensorComboBox1.setSelectedItemByName(b.getWatchedSensor1());
1019: fNextSensorComboBox1Alt.setSelectedItemByName(b.getWatchedSensor1Alt());
1020: fNextSensorComboBox2.setSelectedItemByName(b.getWatchedSensor2());
1021: fNextSensorComboBox2Alt.setSelectedItemByName(b.getWatchedSensor2Alt());
1022:
1023: sLimitBox.setSelected(b.getLimitSpeed1());
1024: sRestrictingBox.setSelected(b.getRestrictingSpeed1());
1025: tdLimitBox.setSelected(b.getLimitSpeed2());
1026: tdRestrictingBox.setSelected(b.getRestrictingSpeed2());
1027: sFlashBox.setSelected(b.getUseFlash());
1028: sDistantBox.setSelected(b.getDistantSignal());
1029:
1030: commentField.setText(b.getComment());
1031:
1032: int mode = b.getMode();
1033: if (mode == BlockBossLogic.SINGLEBLOCK) {
1034: buttonSingle.setSelected(true);
1035: } else if (mode == BlockBossLogic.TRAILINGMAIN) {
1036: buttonTrailMain.setSelected(true);
1037: } else if (mode == BlockBossLogic.TRAILINGDIVERGING) {
1038: buttonTrailDiv.setSelected(true);
1039: } else if (mode == BlockBossLogic.FACING) {
1040: buttonFacing.setSelected(true);
1041: }
1042:
1043: statusBar.setText(Bundle.getMessage("StatusSslLoaded", Bundle.getMessage("ButtonApply")));
1044: // do setup of visible panels
1045: buttonClicked();
1046: }
1047:
1048: private void buttonClicked() {
1049: modeSingle.setVisible(false);
1050: modeTrailMain.setVisible(false);
1051: modeTrailDiv.setVisible(false);
1052: modeFacing.setVisible(false);
1053: if (buttonSingle.isSelected()) {
1054: modeSingle.setVisible(true);
1055: } else if (buttonTrailMain.isSelected()) {
1056: modeTrailMain.setVisible(true);
1057: } else if (buttonTrailDiv.isSelected()) {
1058: modeTrailDiv.setVisible(true);
1059: } else if (buttonFacing.isSelected()) {
1060: modeFacing.setVisible(true);
1061: } else {
1062: log.debug("buttonClicked(): no SSL type radio button was selected");
1063: }
1064: modeSingle.revalidate();
1065: modeTrailMain.revalidate();
1066: modeTrailDiv.revalidate();
1067: modeFacing.revalidate();
1068: pack();
1069: modeSingle.repaint();
1070: modeTrailMain.repaint();
1071: modeTrailDiv.repaint();
1072: modeFacing.repaint();
1073: }
1074:
1075: private SignalHead sh = null;
1076:
1077: /**
1078: * Programmatically open the frame to edit a specific SSL by signal head.
1079: *
1080: * @param sh signal head of which the name should be entered in the Edit pane
1081: */
1082: public void setSignal(SignalHead sh) {
1083: this.sh = sh;
1084: outSignalHeadComboBox.setSelectedItem(sh);
1085: outSignalHeadComboBox.setEnabled(false);
1086: activate();
1087: }
1088:
1089: /**
1090: * Programmatically open the frame to edit a specific SSL by signal head system name.
1091: *
1092: * @param name system or user name of the signal head to be entered in the Edit pane
1093: */
1094: public void setSignal(String name) {
1095: sh = null;
1096: outSignalHeadComboBox.setSelectedItemByName(name);
1097: outSignalHeadComboBox.setEnabled(true);
1098: activate();
1099: }
1100:
1101: /**
1102: * Set up editable NamedBeanComboBoxes for SSL pane.
1103: * Copied from LayoutEditor
1104: * @see jmri.jmrit.display.layoutEditor.LayoutEditor#setupComboBox(NamedBeanComboBox, boolean, boolean, boolean)
1105: * @author G. Warner 2017
1106: *
1107: * @param inComboBox the editable NamedBeanComboBoxes to set up
1108: * @param inValidateMode boolean: if true, typed in text is validated; if
1109: * false input text is not
1110: * @param inEnable boolean to enable / disable the NamedBeanComboBox
1111: * @param inFirstBlank boolean to enable / disable the first item being
1112: * blank
1113: */
1114: private static void setupComboBox(@Nonnull NamedBeanComboBox<?> inComboBox, boolean inValidateMode, boolean inEnable, boolean inFirstBlank) {
1115: inComboBox.setEnabled(inEnable);
1116: inComboBox.setEditable(false);
1117: inComboBox.setValidatingInput(inValidateMode);
1118: inComboBox.setSelectedItem(null);
1119: log.debug("SSL setupComboBox called");
1120: inComboBox.setMaximumRowCount(15); // no context sensitive calculation
1121: inComboBox.setAllowNull(inFirstBlank);
1122: inComboBox.setSelectedIndex(-1);
1123: }
1124:
1125: private static final Logger log = LoggerFactory.getLogger(BlockBossFrame.class);
1126:
1127: }