001package jmri.jmrit.ctc.editor.gui;
002
003import java.util.ArrayList;
004
005import javax.swing.DefaultListModel;
006
007import jmri.jmrit.ctc.NBHSensor;
008import jmri.jmrit.ctc.editor.code.AwtWindowProperties;
009import jmri.jmrit.ctc.editor.code.CheckJMRIObject;
010import jmri.jmrit.ctc.editor.code.CommonSubs;
011import jmri.jmrit.ctc.ctcserialdata.CTCSerialData;
012import jmri.jmrit.ctc.ctcserialdata.CodeButtonHandlerData;
013import jmri.jmrit.ctc.ctcserialdata.TrafficLockingData;
014import jmri.util.swing.JmriJOptionPane;
015
016/**
017 * Maintain the set of traffic locking rules.  There is an east set and a west set
018 * in CodeButtonHandlerData.
019 * <p>
020 * When the form is invoked, trafficLockingRules points to either the east set or the west set.
021 * The contents of the set is then loaded into _mTrafficLockingModel for display by JList.
022 * When changes are made, the related entries in the model are updated.
023 * <p>
024 * When the save and close button is pressed, the model contents replace the contents of
025 * the related traffic locking rules ArrayList in the current CodeButtonHandlerData object.
026 *
027 * @author Gregory J. Bedlek Copyright (C) 2018, 2019
028 */
029public class FrmTRL_Rules extends javax.swing.JFrame {
030
031    /**
032     * Creates new form DlgTRL_Rules
033     */
034    private static final String FORM_PROPERTIES = "DlgTRL_Rules";   // NOI18N
035    private final AwtWindowProperties _mAwtWindowProperties;
036    private boolean _mClosedNormally = false;
037    public boolean closedNormally() { return _mClosedNormally; }
038    private final CodeButtonHandlerData _mCodeButtonHandlerData;
039    private final boolean _mIsLeftTraffic;
040    private final CTCSerialData _mCTCSerialData;
041    private final CheckJMRIObject _mCheckJMRIObject;
042    private final ArrayList<Integer> _mArrayListOfSelectableOSSectionUniqueIDs;
043    private boolean _mAddNewPressed;
044
045    private final DefaultListModel<TrafficLockingData> _mTrafficLockingModel;
046    private final ArrayList<TrafficLockingData> _mTrafficLockingRulesOrig = new ArrayList<>();
047
048    private void initOrig() {
049        for (int index = 0; index < _mTrafficLockingModel.size(); index++) {
050            _mTrafficLockingRulesOrig.add(_mTrafficLockingModel.get(index));
051        }
052    }
053
054    private boolean dataChanged() {
055        int ruleListSize = _mTrafficLockingModel.size();
056        if (ruleListSize != _mTrafficLockingRulesOrig.size()) return true;
057        for (int index = 0; index < ruleListSize; index++) {
058            if (!_mTrafficLockingModel.get(index).equals(_mTrafficLockingRulesOrig.get(index))) return true;
059        }
060        return false;
061    }
062
063    public FrmTRL_Rules(AwtWindowProperties awtWindowProperties, CodeButtonHandlerData codeButtonHandlerData,
064                        boolean isLeftTraffic,
065                        CTCSerialData ctcSerialData, CheckJMRIObject checkJMRIObject) {
066        super();
067        initComponents();
068        CommonSubs.addHelpMenu(this, "package.jmri.jmrit.ctc.CTC_frmTRL", true);  // NOI18N
069        _mAwtWindowProperties = awtWindowProperties;
070        _mCodeButtonHandlerData = codeButtonHandlerData;
071        _mIsLeftTraffic = isLeftTraffic;
072        _mCTCSerialData = ctcSerialData;
073        _mCheckJMRIObject = checkJMRIObject;
074        _mArrayListOfSelectableOSSectionUniqueIDs = CommonSubs.getArrayListOfSelectableOSSectionUniqueIDs(_mCTCSerialData.getCodeButtonHandlerDataArrayList());
075        String identifier = codeButtonHandlerData.myShortStringNoComma();
076
077        ArrayList<TrafficLockingData> trafficLockingRules;
078        if (isLeftTraffic) {
079            this.setTitle(Bundle.getMessage("TitleDlgTRLRulesLeft") + " " + identifier);    // NOI18N
080            _mRulesInfo.setText(Bundle.getMessage("LabelDlgTRLRulesLeftInfo"));             // NOI18N
081            trafficLockingRules = _mCodeButtonHandlerData._mTRL_LeftTrafficLockingRules;
082        } else {
083            this.setTitle(Bundle.getMessage("TitleDlgTRLRulesRight") + " " + identifier);   // NOI18N
084            _mRulesInfo.setText(Bundle.getMessage("LabelDlgTRLRulesRightInfo"));            // NOI18N
085            trafficLockingRules = _mCodeButtonHandlerData._mTRL_RightTrafficLockingRules;
086        }
087        _mTrafficLockingModel = new DefaultListModel<>();
088        _mTRL_TrafficLockingRules.setModel(_mTrafficLockingModel);
089        trafficLockingRules.forEach(rule -> {
090            _mTrafficLockingModel.addElement(rule);
091        });
092        int ruleNumber = 1;
093        for (int index = 0; index < _mTrafficLockingModel.size(); index++) {
094            _mTrafficLockingModel.set(index, renumberRule(_mTrafficLockingModel.get(index), ruleNumber++));
095        }
096        initOrig();
097        _mAwtWindowProperties.setWindowState(this, FORM_PROPERTIES);
098        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor1, "Sensor", null, true);
099        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor2, "Sensor", null, true);
100        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor3, "Sensor", null, true);
101        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor4, "Sensor", null, true);
102        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor5, "Sensor", null, true);
103        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor6, "Sensor", null, true);
104        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor7, "Sensor", null, true);
105        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor8, "Sensor", null, true);
106        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor9, "Sensor", null, true);
107        CommonSubs.populateJComboBoxWithBeans(_mOptionalExternalSensor1, "Sensor", null, true);
108        CommonSubs.populateJComboBoxWithBeans(_mOptionalExternalSensor2, "Sensor", null, true);
109        CommonSubs.populateJComboBoxWithColumnDescriptions(_mOS_NumberEntry1, _mCTCSerialData);
110        CommonSubs.populateJComboBoxWithColumnDescriptions(_mOS_NumberEntry2, _mCTCSerialData);
111        CommonSubs.populateJComboBoxWithColumnDescriptions(_mOS_NumberEntry3, _mCTCSerialData);
112        CommonSubs.populateJComboBoxWithColumnDescriptions(_mOS_NumberEntry4, _mCTCSerialData);
113        CommonSubs.populateJComboBoxWithColumnDescriptions(_mOS_NumberEntry5, _mCTCSerialData);
114        String[] normalAndReverse = new String[] { Bundle.getMessage("TLE_Normal"), Bundle.getMessage("TLE_Reverse") }; // NOI18N
115        _mSwitchAlignment1.setModel(new javax.swing.DefaultComboBoxModel<>(normalAndReverse));
116        _mSwitchAlignment2.setModel(new javax.swing.DefaultComboBoxModel<>(normalAndReverse));
117        _mSwitchAlignment3.setModel(new javax.swing.DefaultComboBoxModel<>(normalAndReverse));
118        _mSwitchAlignment4.setModel(new javax.swing.DefaultComboBoxModel<>(normalAndReverse));
119        _mSwitchAlignment5.setModel(new javax.swing.DefaultComboBoxModel<>(normalAndReverse));
120        enableTopPart(true);
121        _mEditBelow.setEnabled(false);
122        _mDelete.setEnabled(false);
123        _mDupToEnd.setEnabled(false);
124    }
125
126    /**
127     * This method is called from within the constructor to initialize the form.
128     * WARNING: Do NOT modify this code. The content of this method is always
129     * regenerated by the Form Editor.
130     */
131    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
132    private void initComponents() {
133
134        _mSaveAndClose = new javax.swing.JButton();
135        jLabel2 = new javax.swing.JLabel();
136        jScrollPane1 = new javax.swing.JScrollPane();
137        _mTRL_TrafficLockingRules = new javax.swing.JList<>();
138        _mAddNew = new javax.swing.JButton();
139        _mEditBelow = new javax.swing.JButton();
140        _mDelete = new javax.swing.JButton();
141        _mGroupingListAddReplace = new javax.swing.JButton();
142        jLabel1 = new javax.swing.JLabel();
143        jLabel8 = new javax.swing.JLabel();
144        jLabel7 = new javax.swing.JLabel();
145        _mRulesInfo = new javax.swing.JLabel();
146        _mCancel = new javax.swing.JButton();
147        jLabel4 = new javax.swing.JLabel();
148        jLabel10 = new javax.swing.JLabel();
149        _mRuleEnabled = new javax.swing.JCheckBox();
150        _mEnableALLRules = new javax.swing.JButton();
151        _mDisableALLRules = new javax.swing.JButton();
152        _mOS_NumberEntry1 = new javax.swing.JComboBox<>();
153        _mOS_NumberEntry2 = new javax.swing.JComboBox<>();
154        _mOS_NumberEntry3 = new javax.swing.JComboBox<>();
155        _mOS_NumberEntry4 = new javax.swing.JComboBox<>();
156        _mOS_NumberEntry5 = new javax.swing.JComboBox<>();
157        _mSwitchAlignment1 = new javax.swing.JComboBox<>();
158        _mSwitchAlignment2 = new javax.swing.JComboBox<>();
159        _mSwitchAlignment3 = new javax.swing.JComboBox<>();
160        _mSwitchAlignment4 = new javax.swing.JComboBox<>();
161        _mSwitchAlignment5 = new javax.swing.JComboBox<>();
162        jLabel5 = new javax.swing.JLabel();
163        _mOccupancyExternalSensor1 = new javax.swing.JComboBox<>();
164        _mOccupancyExternalSensor2 = new javax.swing.JComboBox<>();
165        _mOccupancyExternalSensor3 = new javax.swing.JComboBox<>();
166        _mOccupancyExternalSensor4 = new javax.swing.JComboBox<>();
167        _mOccupancyExternalSensor5 = new javax.swing.JComboBox<>();
168        _mOccupancyExternalSensor6 = new javax.swing.JComboBox<>();
169        _mOccupancyExternalSensor7 = new javax.swing.JComboBox<>();
170        _mOccupancyExternalSensor8 = new javax.swing.JComboBox<>();
171        _mOccupancyExternalSensor9 = new javax.swing.JComboBox<>();
172        _mOptionalExternalSensor1 = new javax.swing.JComboBox<>();
173        _mOptionalExternalSensor2 = new javax.swing.JComboBox<>();
174        _mDupToEnd = new javax.swing.JButton();
175        _mDestinationSignalOrCommentPrompt = new javax.swing.JLabel();
176        _mDestinationSignalOrComment = new javax.swing.JTextField();
177
178        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
179        setTitle(Bundle.getMessage("TitleDlgTRLRules"));
180        addWindowListener(new java.awt.event.WindowAdapter() {
181            @Override
182            public void windowClosing(java.awt.event.WindowEvent evt) {
183                formWindowClosing(evt);
184            }
185        });
186
187        _mSaveAndClose.setText(Bundle.getMessage("ButtonSaveClose"));
188        _mSaveAndClose.addActionListener(new java.awt.event.ActionListener() {
189            @Override
190            public void actionPerformed(java.awt.event.ActionEvent evt) {
191                _mSaveAndCloseActionPerformed(evt);
192            }
193        });
194
195        jLabel2.setText(Bundle.getMessage("LabelDlgTRLRulesRules"));
196
197        _mTRL_TrafficLockingRules.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
198            @Override
199            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
200                _mTRL_TrafficLockingRulesValueChanged(evt);
201            }
202        });
203        jScrollPane1.setViewportView(_mTRL_TrafficLockingRules);
204
205        _mAddNew.setText(Bundle.getMessage("ButtonAddNew"));
206        _mAddNew.addActionListener(new java.awt.event.ActionListener() {
207            @Override
208            public void actionPerformed(java.awt.event.ActionEvent evt) {
209                _mAddNewActionPerformed(evt);
210            }
211        });
212
213        _mEditBelow.setText(Bundle.getMessage("ButtonEditBelow"));
214        _mEditBelow.addActionListener(new java.awt.event.ActionListener() {
215            @Override
216            public void actionPerformed(java.awt.event.ActionEvent evt) {
217                _mEditBelowActionPerformed(evt);
218            }
219        });
220
221        _mDelete.setText(Bundle.getMessage("ButtonDelete"));
222        _mDelete.addActionListener(new java.awt.event.ActionListener() {
223            @Override
224            public void actionPerformed(java.awt.event.ActionEvent evt) {
225                _mDeleteActionPerformed(evt);
226            }
227        });
228
229        _mGroupingListAddReplace.setText(Bundle.getMessage("ButtonDlgTRLRulesUpdate"));
230        _mGroupingListAddReplace.setEnabled(false);
231        _mGroupingListAddReplace.addActionListener(new java.awt.event.ActionListener() {
232            @Override
233            public void actionPerformed(java.awt.event.ActionEvent evt) {
234                _mGroupingListAddReplaceActionPerformed(evt);
235            }
236        });
237
238        jLabel1.setText(Bundle.getMessage("InfoDlgTRLRulesSep1"));
239
240        jLabel8.setText(Bundle.getMessage("InfoDlgTRLRulesSection"));
241
242        jLabel7.setText(Bundle.getMessage("InfoDlgTRLRulesSep2"));
243
244        _mRulesInfo.setText(Bundle.getMessage("InfoDlgTRLRulesNote1"));
245
246        _mCancel.setText(Bundle.getMessage("ButtonCancel"));
247        _mCancel.addActionListener(new java.awt.event.ActionListener() {
248            @Override
249            public void actionPerformed(java.awt.event.ActionEvent evt) {
250                _mCancelActionPerformed(evt);
251            }
252        });
253
254        jLabel4.setText(Bundle.getMessage("InfoDlgTRLRulesNote2"));
255
256        jLabel10.setText(Bundle.getMessage("InfoDlgTRLRulesNote3"));
257
258        _mRuleEnabled.setText(Bundle.getMessage("LabelDlgTRLRulesEnabled"));
259
260        _mEnableALLRules.setText(Bundle.getMessage("ButtonDlgTRLRulesEnable"));
261        _mEnableALLRules.addActionListener(new java.awt.event.ActionListener() {
262            @Override
263            public void actionPerformed(java.awt.event.ActionEvent evt) {
264                _mEnableALLRulesActionPerformed(evt);
265            }
266        });
267
268        _mDisableALLRules.setText(Bundle.getMessage("ButtonDlgTRLRulesDisable"));
269        _mDisableALLRules.addActionListener(new java.awt.event.ActionListener() {
270            @Override
271            public void actionPerformed(java.awt.event.ActionEvent evt) {
272                _mDisableALLRulesActionPerformed(evt);
273            }
274        });
275
276        jLabel5.setText(Bundle.getMessage("InfoDlgTRLRulesSensor"));
277
278        _mDupToEnd.setText(Bundle.getMessage("ButtonDlgTRLRules"));
279        _mDupToEnd.addActionListener(new java.awt.event.ActionListener() {
280            @Override
281            public void actionPerformed(java.awt.event.ActionEvent evt) {
282                _mDupToEndActionPerformed(evt);
283            }
284        });
285
286        _mDestinationSignalOrCommentPrompt.setText(Bundle.getMessage("InfoDlgTRLRulesDestinationSignalOrCommentPrompt")
287        );
288
289        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
290        getContentPane().setLayout(layout);
291        layout.setHorizontalGroup(
292            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
293            .addGroup(layout.createSequentialGroup()
294                .addContainerGap()
295                .addComponent(jLabel2)
296                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
297                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
298                    .addGroup(layout.createSequentialGroup()
299                        .addGap(3, 3, 3)
300                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
301                            .addComponent(jLabel8)
302                            .addComponent(jLabel7)
303                            .addComponent(jLabel1)
304                            .addComponent(jLabel5)
305                            .addGroup(layout.createSequentialGroup()
306                                .addComponent(_mSwitchAlignment1, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
307                                .addGap(18, 18, 18)
308                                .addComponent(_mSwitchAlignment2, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
309                                .addGap(18, 18, 18)
310                                .addComponent(_mSwitchAlignment3, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
311                                .addGap(18, 18, 18)
312                                .addComponent(_mSwitchAlignment4, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
313                                .addGap(18, 18, 18)
314                                .addComponent(_mSwitchAlignment5, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
315                            .addGroup(layout.createSequentialGroup()
316                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
317                                    .addComponent(_mOccupancyExternalSensor1, 0, 280, Short.MAX_VALUE)
318                                    .addComponent(_mOccupancyExternalSensor4, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
319                                    .addComponent(_mOccupancyExternalSensor7, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
320                                .addGap(18, 18, 18)
321                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
322                                    .addComponent(_mOccupancyExternalSensor2, 0, 280, Short.MAX_VALUE)
323                                    .addComponent(_mOccupancyExternalSensor5, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
324                                    .addComponent(_mOccupancyExternalSensor8, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
325                                .addGap(18, 18, 18)
326                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
327                                    .addComponent(_mOccupancyExternalSensor3, 0, 280, Short.MAX_VALUE)
328                                    .addComponent(_mOccupancyExternalSensor6, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
329                                    .addComponent(_mOccupancyExternalSensor9, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
330                            .addGroup(layout.createSequentialGroup()
331                                .addComponent(_mOptionalExternalSensor1, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE)
332                                .addGap(18, 18, 18)
333                                .addComponent(_mOptionalExternalSensor2, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
334                                .addGap(36, 36, 36)
335                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
336                                    .addComponent(_mSaveAndClose)
337                                    .addGroup(layout.createSequentialGroup()
338                                        .addComponent(_mGroupingListAddReplace, javax.swing.GroupLayout.PREFERRED_SIZE, 312, javax.swing.GroupLayout.PREFERRED_SIZE)
339                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
340                                        .addComponent(_mCancel))))
341                            .addGroup(layout.createSequentialGroup()
342                                .addComponent(_mOS_NumberEntry1, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
343                                .addGap(18, 18, 18)
344                                .addComponent(_mOS_NumberEntry2, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
345                                .addGap(18, 18, 18)
346                                .addComponent(_mOS_NumberEntry3, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
347                                .addGap(18, 18, 18)
348                                .addComponent(_mOS_NumberEntry4, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
349                                .addGap(18, 18, 18)
350                                .addComponent(_mOS_NumberEntry5, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))))
351                    .addComponent(jLabel10)
352                    .addGroup(layout.createSequentialGroup()
353                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
354                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 786, javax.swing.GroupLayout.PREFERRED_SIZE)
355                            .addGroup(layout.createSequentialGroup()
356                                .addComponent(_mRuleEnabled)
357                                .addGap(18, 18, 18)
358                                .addComponent(_mEnableALLRules, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
359                                .addGap(18, 18, 18)
360                                .addComponent(_mDisableALLRules, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
361                                .addGap(18, 18, 18)
362                                .addComponent(_mDestinationSignalOrCommentPrompt)
363                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
364                                .addComponent(_mDestinationSignalOrComment, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
365                            .addGroup(layout.createSequentialGroup()
366                                .addComponent(_mRulesInfo)
367                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
368                                .addComponent(jLabel4)))
369                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
370                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
371                            .addComponent(_mEditBelow, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
372                            .addComponent(_mAddNew, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
373                            .addComponent(_mDelete, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
374                            .addComponent(_mDupToEnd))))
375                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
376        );
377        layout.setVerticalGroup(
378            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
379            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
380                .addGap(18, 18, 18)
381                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
382                    .addComponent(jLabel2)
383                    .addGroup(layout.createSequentialGroup()
384                        .addComponent(_mAddNew)
385                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
386                        .addComponent(_mEditBelow)
387                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
388                        .addComponent(_mDelete)
389                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
390                        .addComponent(_mDupToEnd))
391                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))
392                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
393                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
394                    .addComponent(_mRulesInfo)
395                    .addComponent(jLabel4))
396                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
397                .addComponent(jLabel10)
398                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
399                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
400                    .addComponent(_mRuleEnabled)
401                    .addComponent(_mEnableALLRules)
402                    .addComponent(_mDisableALLRules)
403                    .addComponent(_mDestinationSignalOrCommentPrompt)
404                    .addComponent(_mDestinationSignalOrComment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
405                .addGap(18, 18, Short.MAX_VALUE)
406                .addComponent(jLabel1)
407                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
408                .addComponent(jLabel8)
409                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
410                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
411                    .addComponent(_mOS_NumberEntry1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
412                    .addComponent(_mOS_NumberEntry2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
413                    .addComponent(_mOS_NumberEntry3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
414                    .addComponent(_mOS_NumberEntry4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
415                    .addComponent(_mOS_NumberEntry5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
416                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
417                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
418                    .addComponent(_mSwitchAlignment1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
419                    .addComponent(_mSwitchAlignment2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
420                    .addComponent(_mSwitchAlignment3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
421                    .addComponent(_mSwitchAlignment4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
422                    .addComponent(_mSwitchAlignment5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
423                .addGap(18, 18, Short.MAX_VALUE)
424                .addComponent(jLabel5)
425                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
426                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
427                    .addComponent(_mOccupancyExternalSensor1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
428                    .addComponent(_mOccupancyExternalSensor2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
429                    .addComponent(_mOccupancyExternalSensor3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
430                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
431                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
432                    .addComponent(_mOccupancyExternalSensor4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
433                    .addComponent(_mOccupancyExternalSensor5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
434                    .addComponent(_mOccupancyExternalSensor6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
435                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
436                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
437                    .addComponent(_mOccupancyExternalSensor7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
438                    .addComponent(_mOccupancyExternalSensor8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
439                    .addComponent(_mOccupancyExternalSensor9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
440                .addGap(18, 18, 18)
441                .addComponent(jLabel7)
442                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
443                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
444                    .addComponent(_mGroupingListAddReplace)
445                    .addComponent(_mCancel)
446                    .addComponent(_mOptionalExternalSensor1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
447                    .addComponent(_mOptionalExternalSensor2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
448                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
449                .addComponent(_mSaveAndClose)
450                .addGap(13, 13, 13))
451        );
452
453        pack();
454    }// </editor-fold>//GEN-END:initComponents
455
456    private void _mSaveAndCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__mSaveAndCloseActionPerformed
457        ArrayList<TrafficLockingData> trafficLockingRules;
458        if (_mIsLeftTraffic) {
459            trafficLockingRules = _mCodeButtonHandlerData._mTRL_LeftTrafficLockingRules;
460        } else {
461            trafficLockingRules = _mCodeButtonHandlerData._mTRL_RightTrafficLockingRules;
462        }
463
464        int size = _mTrafficLockingModel.getSize();
465        trafficLockingRules.clear();
466        for (int index = 0; index < size; index++) {
467            trafficLockingRules.add(_mTrafficLockingModel.getElementAt(index));
468        }
469        _mClosedNormally = true;
470        _mAwtWindowProperties.saveWindowState(this, FORM_PROPERTIES);
471        dispose();
472    }//GEN-LAST:event__mSaveAndCloseActionPerformed
473
474    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
475        _mAwtWindowProperties.saveWindowState(this, FORM_PROPERTIES);
476        if (CommonSubs.allowClose(this, dataChanged())) dispose();
477    }//GEN-LAST:event_formWindowClosing
478
479    private void _mTRL_TrafficLockingRulesValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event__mTRL_TrafficLockingRulesValueChanged
480        if (_mTRL_TrafficLockingRules.isSelectionEmpty()) {
481            _mEditBelow.setEnabled(false);
482            _mDelete.setEnabled(false);
483            _mDupToEnd.setEnabled(false);
484        } else {
485            _mEditBelow.setEnabled(true);
486            _mDelete.setEnabled(true);
487            _mDupToEnd.setEnabled(true);
488        }
489    }//GEN-LAST:event__mTRL_TrafficLockingRulesValueChanged
490
491    private void _mAddNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__mAddNewActionPerformed
492        _mAddNewPressed = true;
493        enableTopPart(false);
494        _mTRL_TrafficLockingRules.setEnabled(false);
495        _mTRL_TrafficLockingRules.clearSelection();
496        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor1, "Sensor", null, true);
497        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor2, "Sensor", null, true);
498        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor3, "Sensor", null, true);
499        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor4, "Sensor", null, true);
500        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor5, "Sensor", null, true);
501        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor6, "Sensor", null, true);
502        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor7, "Sensor", null, true);
503        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor8, "Sensor", null, true);
504        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor9, "Sensor", null, true);
505        CommonSubs.populateJComboBoxWithBeans(_mOptionalExternalSensor1, "Sensor", null, true);
506        CommonSubs.populateJComboBoxWithBeans(_mOptionalExternalSensor2, "Sensor", null, true);
507        _mOS_NumberEntry1.setSelectedIndex(0);
508        _mOS_NumberEntry2.setSelectedIndex(0);
509        _mOS_NumberEntry3.setSelectedIndex(0);
510        _mOS_NumberEntry4.setSelectedIndex(0);
511        _mOS_NumberEntry5.setSelectedIndex(0);
512        _mSwitchAlignment1.setSelectedIndex(0);
513        _mSwitchAlignment2.setSelectedIndex(0);
514        _mSwitchAlignment3.setSelectedIndex(0);
515        _mSwitchAlignment4.setSelectedIndex(0);
516        _mSwitchAlignment5.setSelectedIndex(0);
517        _mGroupingListAddReplace.setText(Bundle.getMessage("TextDlgTRLRulesAddThis"));  // NOI18N
518        _mGroupingListAddReplace.setEnabled(true);
519        _mRuleEnabled.setSelected(true);
520        _mDestinationSignalOrComment.setText("");
521        _mOS_NumberEntry1.requestFocusInWindow();
522    }//GEN-LAST:event__mAddNewActionPerformed
523
524    private void _mEditBelowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__mEditBelowActionPerformed
525        _mAddNewPressed = false;
526        int selectedIndex = _mTRL_TrafficLockingRules.getSelectedIndex();
527        enableTopPart(false);
528        _mTRL_TrafficLockingRules.setEnabled(false);
529
530        TrafficLockingData trafficLockingData = _mTrafficLockingModel.get(selectedIndex);
531
532        ArrayList<NBHSensor> occupancySensors = trafficLockingData.getOccupancySensors();
533        ArrayList<NBHSensor> optionalSensors = trafficLockingData.getOptionalSensors();
534        ArrayList<Integer> ids = trafficLockingData.getUniqueIDs();
535        ArrayList<String> alignments = trafficLockingData.getAlignments();
536
537        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor1, "Sensor", occupancySensors.get(0).getHandleName(), true);
538        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor2, "Sensor", occupancySensors.get(1).getHandleName(), true);
539        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor3, "Sensor", occupancySensors.get(2).getHandleName(), true);
540        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor4, "Sensor", occupancySensors.get(3).getHandleName(), true);
541        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor5, "Sensor", occupancySensors.get(4).getHandleName(), true);
542        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor6, "Sensor", occupancySensors.get(5).getHandleName(), true);
543        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor7, "Sensor", occupancySensors.get(6).getHandleName(), true);
544        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor8, "Sensor", occupancySensors.get(7).getHandleName(), true);
545        CommonSubs.populateJComboBoxWithBeans(_mOccupancyExternalSensor9, "Sensor", occupancySensors.get(8).getHandleName(), true);
546
547        CommonSubs.populateJComboBoxWithBeans(_mOptionalExternalSensor1, "Sensor", optionalSensors.get(0).getHandleName(), true);
548        CommonSubs.populateJComboBoxWithBeans(_mOptionalExternalSensor2, "Sensor", optionalSensors.get(1).getHandleName(), true);
549
550        CommonSubs.setSelectedIndexOfJComboBoxViaUniqueID(_mOS_NumberEntry1, _mCTCSerialData, ids.get(0));
551        CommonSubs.setSelectedIndexOfJComboBoxViaUniqueID(_mOS_NumberEntry2, _mCTCSerialData, ids.get(1));
552        CommonSubs.setSelectedIndexOfJComboBoxViaUniqueID(_mOS_NumberEntry3, _mCTCSerialData, ids.get(2));
553        CommonSubs.setSelectedIndexOfJComboBoxViaUniqueID(_mOS_NumberEntry4, _mCTCSerialData, ids.get(3));
554        CommonSubs.setSelectedIndexOfJComboBoxViaUniqueID(_mOS_NumberEntry5, _mCTCSerialData, ids.get(4));
555
556        _mSwitchAlignment1.setSelectedItem(alignments.get(0));
557        _mSwitchAlignment2.setSelectedItem(alignments.get(1));
558        _mSwitchAlignment3.setSelectedItem(alignments.get(2));
559        _mSwitchAlignment4.setSelectedItem(alignments.get(3));
560        _mSwitchAlignment5.setSelectedItem(alignments.get(4));
561        _mGroupingListAddReplace.setText(Bundle.getMessage("TextDlgTRLRulesUpdateThis"));       // NOI18N
562        _mGroupingListAddReplace.setEnabled(true);
563        _mRuleEnabled.setSelected(!trafficLockingData._mRuleEnabled.equals(Bundle.getMessage("TLE_RuleDisabled")));  // NOI18N  Default if invalid is ENABLED
564        _mDestinationSignalOrComment.setText(trafficLockingData._mDestinationSignalOrComment);
565        _mOS_NumberEntry1.requestFocusInWindow();
566    }//GEN-LAST:event__mEditBelowActionPerformed
567
568    private void _mDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__mDeleteActionPerformed
569        _mTrafficLockingModel.remove(_mTRL_TrafficLockingRules.getSelectedIndex());
570        for (int index = 0; index < _mTrafficLockingModel.size(); index++) {
571            _mTrafficLockingModel.set(index, renumberRule(_mTrafficLockingModel.get(index), index + 1));
572        }
573        enableTopPart(true);
574    }//GEN-LAST:event__mDeleteActionPerformed
575
576    private void _mGroupingListAddReplaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__mGroupingListAddReplaceActionPerformed
577        TrafficLockingData trafficLockingData = new TrafficLockingData();
578        trafficLockingData._mRuleEnabled = _mRuleEnabled.isSelected() ? Bundle.getMessage("TLE_RuleEnabled") : Bundle.getMessage("TLE_RuleDisabled");  // NOI18N
579        trafficLockingData._mDestinationSignalOrComment = _mDestinationSignalOrComment.getText();
580
581        ArrayList<NBHSensor> occupancySensors = new ArrayList<>();
582        CommonSubs.addSensorToSensorList(occupancySensors, (String)_mOccupancyExternalSensor1.getSelectedItem());
583        CommonSubs.addSensorToSensorList(occupancySensors, (String)_mOccupancyExternalSensor2.getSelectedItem());
584        CommonSubs.addSensorToSensorList(occupancySensors, (String)_mOccupancyExternalSensor3.getSelectedItem());
585        CommonSubs.addSensorToSensorList(occupancySensors, (String)_mOccupancyExternalSensor4.getSelectedItem());
586        CommonSubs.addSensorToSensorList(occupancySensors, (String)_mOccupancyExternalSensor5.getSelectedItem());
587        CommonSubs.addSensorToSensorList(occupancySensors, (String)_mOccupancyExternalSensor6.getSelectedItem());
588        CommonSubs.addSensorToSensorList(occupancySensors, (String)_mOccupancyExternalSensor7.getSelectedItem());
589        CommonSubs.addSensorToSensorList(occupancySensors, (String)_mOccupancyExternalSensor8.getSelectedItem());
590        CommonSubs.addSensorToSensorList(occupancySensors, (String)_mOccupancyExternalSensor9.getSelectedItem());
591        trafficLockingData._mOccupancyExternalSensors = occupancySensors;
592
593        ArrayList<NBHSensor> optionalSensors = new ArrayList<>();
594        CommonSubs.addSensorToSensorList(optionalSensors, (String)_mOptionalExternalSensor1.getSelectedItem());
595        CommonSubs.addSensorToSensorList(optionalSensors, (String)_mOptionalExternalSensor2.getSelectedItem());
596        trafficLockingData._mOptionalExternalSensors = optionalSensors;
597
598        TrafficLockingData.TRLSwitch trlSwitch;
599        ArrayList<TrafficLockingData.TRLSwitch> switchAlignments = new ArrayList<>();
600        trlSwitch = getSwitchAllignment(_mOS_NumberEntry1, _mSwitchAlignment1);
601        if (trlSwitch != null) switchAlignments.add(trlSwitch);
602        trlSwitch = getSwitchAllignment(_mOS_NumberEntry2, _mSwitchAlignment2);
603        if (trlSwitch != null) switchAlignments.add(trlSwitch);
604        trlSwitch = getSwitchAllignment(_mOS_NumberEntry3, _mSwitchAlignment3);
605        if (trlSwitch != null) switchAlignments.add(trlSwitch);
606        trlSwitch = getSwitchAllignment(_mOS_NumberEntry4, _mSwitchAlignment4);
607        if (trlSwitch != null) switchAlignments.add(trlSwitch);
608        trlSwitch = getSwitchAllignment(_mOS_NumberEntry5, _mSwitchAlignment5);
609        if (trlSwitch != null) switchAlignments.add(trlSwitch);
610        trafficLockingData._mSwitchAlignments = switchAlignments;
611
612        CheckJMRIObject.VerifyClassReturnValue verifyClassReturnValue = _mCheckJMRIObject.verifyClass(trafficLockingData);
613        if (verifyClassReturnValue != null) { // Error:
614            JmriJOptionPane.showMessageDialog(this, verifyClassReturnValue.toString(),
615                    Bundle.getMessage("ErrorTitle"), JmriJOptionPane.ERROR_MESSAGE);  // NOI18N
616            return;
617        }
618
619        _mGroupingListAddReplace.setEnabled(false);
620        enableTopPart(true);
621        if (_mAddNewPressed) {
622            trafficLockingData._mUserRuleNumber = getRuleNumberString(_mTrafficLockingModel.size() + 1);
623            _mTrafficLockingModel.addElement(trafficLockingData);
624        }
625        else {
626            int selectedIndex = _mTRL_TrafficLockingRules.getSelectedIndex();
627            trafficLockingData._mUserRuleNumber = getRuleNumberString(selectedIndex + 1);
628            _mTrafficLockingModel.set(selectedIndex, trafficLockingData);
629        }
630        _mTRL_TrafficLockingRules.setEnabled(true);
631    }//GEN-LAST:event__mGroupingListAddReplaceActionPerformed
632
633    private void _mCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__mCancelActionPerformed
634        enableTopPart(true);
635        _mTRL_TrafficLockingRules.setEnabled(true);
636    }//GEN-LAST:event__mCancelActionPerformed
637
638    private void _mEnableALLRulesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__mEnableALLRulesActionPerformed
639        for (int index = 0; index < _mTrafficLockingModel.getSize(); index++) {
640            TrafficLockingData trafficLockingData = _mTrafficLockingModel.get(index);
641            trafficLockingData._mRuleEnabled = Bundle.getMessage("TLE_RuleEnabled");   // NOI18N
642            _mTrafficLockingModel.set(index, trafficLockingData);
643        }
644    }//GEN-LAST:event__mEnableALLRulesActionPerformed
645
646    private void _mDisableALLRulesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__mDisableALLRulesActionPerformed
647        for (int index = 0; index < _mTrafficLockingModel.getSize(); index++) {
648            TrafficLockingData trafficLockingData = _mTrafficLockingModel.get(index);
649            trafficLockingData._mRuleEnabled = Bundle.getMessage("TLE_RuleDisabled");  // NOI18N
650            _mTrafficLockingModel.set(index, trafficLockingData);
651        }
652    }//GEN-LAST:event__mDisableALLRulesActionPerformed
653
654    private void _mDupToEndActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__mDupToEndActionPerformed
655        TrafficLockingData trafficLockingData = _mTrafficLockingModel.get(_mTRL_TrafficLockingRules.getSelectedIndex());
656        trafficLockingData._mUserRuleNumber = getRuleNumberString(_mTrafficLockingModel.size() + 1);
657        _mTrafficLockingModel.addElement(trafficLockingData);
658    }//GEN-LAST:event__mDupToEndActionPerformed
659
660    private TrafficLockingData renumberRule(TrafficLockingData rule, int number) {
661        rule._mUserRuleNumber = getRuleNumberString(number);
662        return rule;
663    }
664
665    public static String getRuleNumberString(int ruleNumber) { return " " + Bundle.getMessage("InfoDlgTRLRuleNumber") + Integer.toString(ruleNumber); }   // NOI18N
666
667    public static String getRuleEnabledString() { return Bundle.getMessage("TLE_RuleEnabled"); }
668
669    public TrafficLockingData.TRLSwitch getSwitchAllignment(javax.swing.JComboBox<String> userText, javax.swing.JComboBox<String> alignment) {
670        TrafficLockingData.TRLSwitch trlSwitch = null;
671        int osNumberSelectedIndex = userText.getSelectedIndex();
672        if (osNumberSelectedIndex > 0) {
673            trlSwitch = new TrafficLockingData.TRLSwitch(
674                    (String)userText.getSelectedItem(),
675                    (String)alignment.getSelectedItem(),
676                    _mArrayListOfSelectableOSSectionUniqueIDs.get(osNumberSelectedIndex - 1));
677        }
678        return trlSwitch;
679    }
680
681    private void enableTopPart(boolean enabled) {
682        _mAddNew.setEnabled(enabled);
683        _mDestinationSignalOrComment.setEnabled(!enabled);
684        _mOccupancyExternalSensor1.setEnabled(!enabled);
685        _mOccupancyExternalSensor2.setEnabled(!enabled);
686        _mOccupancyExternalSensor3.setEnabled(!enabled);
687        _mOccupancyExternalSensor4.setEnabled(!enabled);
688        _mOccupancyExternalSensor5.setEnabled(!enabled);
689        _mOccupancyExternalSensor6.setEnabled(!enabled);
690        _mOccupancyExternalSensor7.setEnabled(!enabled);
691        _mOccupancyExternalSensor8.setEnabled(!enabled);
692        _mOccupancyExternalSensor9.setEnabled(!enabled);
693        _mOptionalExternalSensor1.setEnabled(!enabled);
694        _mOptionalExternalSensor2.setEnabled(!enabled);
695        _mOS_NumberEntry1.setEnabled(!enabled);
696        _mOS_NumberEntry2.setEnabled(!enabled);
697        _mOS_NumberEntry3.setEnabled(!enabled);
698        _mOS_NumberEntry4.setEnabled(!enabled);
699        _mOS_NumberEntry5.setEnabled(!enabled);
700        _mRuleEnabled.setEnabled(!enabled);
701        _mSwitchAlignment1.setEnabled(!enabled);
702        _mSwitchAlignment2.setEnabled(!enabled);
703        _mSwitchAlignment3.setEnabled(!enabled);
704        _mSwitchAlignment4.setEnabled(!enabled);
705        _mSwitchAlignment5.setEnabled(!enabled);
706        _mGroupingListAddReplace.setEnabled(!enabled);
707        _mCancel.setEnabled(!enabled);
708        _mSaveAndClose.setEnabled(enabled);
709
710        if (enabled) this.getRootPane().setDefaultButton(_mSaveAndClose);
711        else this.getRootPane().setDefaultButton(_mGroupingListAddReplace);
712    }
713
714    // Variables declaration - do not modify//GEN-BEGIN:variables
715    private javax.swing.JButton _mAddNew;
716    private javax.swing.JButton _mCancel;
717    private javax.swing.JButton _mDelete;
718    private javax.swing.JTextField _mDestinationSignalOrComment;
719    private javax.swing.JLabel _mDestinationSignalOrCommentPrompt;
720    private javax.swing.JButton _mDisableALLRules;
721    private javax.swing.JButton _mDupToEnd;
722    private javax.swing.JButton _mEditBelow;
723    private javax.swing.JButton _mEnableALLRules;
724    private javax.swing.JButton _mGroupingListAddReplace;
725    private javax.swing.JComboBox<String> _mOS_NumberEntry1;
726    private javax.swing.JComboBox<String> _mOS_NumberEntry2;
727    private javax.swing.JComboBox<String> _mOS_NumberEntry3;
728    private javax.swing.JComboBox<String> _mOS_NumberEntry4;
729    private javax.swing.JComboBox<String> _mOS_NumberEntry5;
730    private javax.swing.JComboBox<String> _mOccupancyExternalSensor1;
731    private javax.swing.JComboBox<String> _mOccupancyExternalSensor2;
732    private javax.swing.JComboBox<String> _mOccupancyExternalSensor3;
733    private javax.swing.JComboBox<String> _mOccupancyExternalSensor4;
734    private javax.swing.JComboBox<String> _mOccupancyExternalSensor5;
735    private javax.swing.JComboBox<String> _mOccupancyExternalSensor6;
736    private javax.swing.JComboBox<String> _mOccupancyExternalSensor7;
737    private javax.swing.JComboBox<String> _mOccupancyExternalSensor8;
738    private javax.swing.JComboBox<String> _mOccupancyExternalSensor9;
739    private javax.swing.JComboBox<String> _mOptionalExternalSensor1;
740    private javax.swing.JComboBox<String> _mOptionalExternalSensor2;
741    private javax.swing.JCheckBox _mRuleEnabled;
742    private javax.swing.JLabel _mRulesInfo;
743    private javax.swing.JButton _mSaveAndClose;
744    private javax.swing.JComboBox<String> _mSwitchAlignment1;
745    private javax.swing.JComboBox<String> _mSwitchAlignment2;
746    private javax.swing.JComboBox<String> _mSwitchAlignment3;
747    private javax.swing.JComboBox<String> _mSwitchAlignment4;
748    private javax.swing.JComboBox<String> _mSwitchAlignment5;
749    private javax.swing.JList<TrafficLockingData> _mTRL_TrafficLockingRules;
750    private javax.swing.JLabel jLabel1;
751    private javax.swing.JLabel jLabel10;
752    private javax.swing.JLabel jLabel2;
753    private javax.swing.JLabel jLabel4;
754    private javax.swing.JLabel jLabel5;
755    private javax.swing.JLabel jLabel7;
756    private javax.swing.JLabel jLabel8;
757    private javax.swing.JScrollPane jScrollPane1;
758    // End of variables declaration//GEN-END:variables
759}