001package jmri.jmrit.display.layoutEditor.LayoutEditorDialogs;
002
003import java.awt.*;
004import java.awt.event.*;
005import java.util.ArrayList;
006import java.util.List;
007
008import javax.annotation.Nonnull;
009import javax.swing.*;
010import javax.swing.border.TitledBorder;
011
012import jmri.NamedBean.DisplayOptions;
013import jmri.*;
014import jmri.jmrit.display.layoutEditor.*;
015import jmri.swing.NamedBeanComboBox;
016import jmri.util.JmriJFrame;
017
018/**
019 * MVC Editor component for LayoutTurnout objects.
020 *
021 * @author Bob Jacobsen  Copyright (c) 2020
022 * 
023 */
024public class LayoutTurnoutEditor extends LayoutTrackEditor {
025
026    /**
027     * constructor method.
028     * @param layoutEditor main layout editor.
029     */
030    public LayoutTurnoutEditor(@Nonnull LayoutEditor layoutEditor) {
031        super(layoutEditor);
032    }
033
034    /*===================*\
035    | Edit Layout Turnout |
036    \*===================*/
037    // variables for Edit Layout Turnout pane
038    protected LayoutTurnoutView layoutTurnoutView = null;
039    protected LayoutTurnout layoutTurnout = null;
040
041    protected JmriJFrame editLayoutTurnoutFrame = null;
042    protected NamedBeanComboBox<Turnout> editLayoutTurnout1stTurnoutComboBox = null;
043    protected NamedBeanComboBox<Turnout> editLayoutTurnout2ndTurnoutComboBox = null;
044    protected JLabel editLayoutTurnout2ndTurnoutLabel = null;
045    protected final NamedBeanComboBox<Block> editLayoutTurnoutBlockNameComboBox = new NamedBeanComboBox<>(
046            InstanceManager.getDefault(BlockManager.class), null, DisplayOptions.DISPLAYNAME);
047    protected final NamedBeanComboBox<Block> editLayoutTurnoutBlockBNameComboBox = new NamedBeanComboBox<>(
048            InstanceManager.getDefault(BlockManager.class), null, DisplayOptions.DISPLAYNAME);
049    protected final NamedBeanComboBox<Block> editLayoutTurnoutBlockCNameComboBox = new NamedBeanComboBox<>(
050            InstanceManager.getDefault(BlockManager.class), null, DisplayOptions.DISPLAYNAME);
051    protected final NamedBeanComboBox<Block> editLayoutTurnoutBlockDNameComboBox = new NamedBeanComboBox<>(
052            InstanceManager.getDefault(BlockManager.class), null, DisplayOptions.DISPLAYNAME);
053    protected final JComboBox<String> editLayoutTurnoutStateComboBox = new JComboBox<>();
054    protected JCheckBox editLayoutTurnoutHiddenCheckBox = null;
055    protected JButton editLayoutTurnoutBlockButton;
056    protected JButton editLayoutTurnoutBlockBButton;
057    protected JButton editLayoutTurnoutBlockCButton;
058    protected JButton editLayoutTurnoutBlockDButton;
059    protected final JCheckBox editLayoutTurnout2ndTurnoutCheckBox = new JCheckBox(Bundle.getMessage("SupportingTurnout"));  // NOI18N
060    protected final JCheckBox editLayoutTurnout2ndTurnoutInvertCheckBox = new JCheckBox(Bundle.getMessage("SecondTurnoutInvert"));  // NOI18N
061
062    protected boolean editLayoutTurnoutOpen = false;
063    protected boolean editLayoutTurnoutNeedRedraw = false;
064    protected boolean editLayoutTurnoutNeedsBlockUpdate = false;
065    protected int editLayoutTurnoutClosedIndex;
066    protected int editLayoutTurnoutThrownIndex;
067
068    /**
069     * Edit a Layout Turnout.
070     * Invoked for any of the subtypes, has conditional code for crossovers
071     */
072    @Override
073    public void editLayoutTrack(@Nonnull LayoutTrackView layoutTrackView) {
074        log.trace("LayoutTurnoutEditor.editLayoutTrack({}) of a {}", layoutTrackView, layoutTrackView.getClass());
075        if ( layoutTrackView instanceof LayoutTurnoutView ) {
076            this.layoutTurnoutView = (LayoutTurnoutView) layoutTrackView;
077            this.layoutTurnout = this.layoutTurnoutView.getLayoutTurnout();
078        } else {
079            log.error("editLayoutTrack called with wrong type {}", layoutTurnout, new Exception("traceback"));
080        }
081        sensorList.clear();
082
083        if (editLayoutTurnoutOpen) {
084            editLayoutTurnoutFrame.setVisible(true);
085        } else if (editLayoutTurnoutFrame == null) { // Initialize if needed
086            editLayoutTurnoutFrame = new JmriJFrame(Bundle.getMessage("EditTurnout"), false, true);  // NOI18N
087
088            editLayoutTurnoutFrame.addHelpMenu("package.jmri.jmrit.display.EditLayoutTurnout", true);  // NOI18N
089            editLayoutTurnoutFrame.setLocation(50, 30);
090            Container contentPane = editLayoutTurnoutFrame.getContentPane();
091            contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
092            // setup turnout name
093            JPanel panel1 = new JPanel();
094            panel1.setLayout(new FlowLayout());
095            JLabel turnoutNameLabel = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("BeanNameTurnout")));  // NOI18N
096            panel1.add(turnoutNameLabel);
097
098            // add combobox to select turnout
099            editLayoutTurnout1stTurnoutComboBox = new NamedBeanComboBox<>(
100                    InstanceManager.getDefault(TurnoutManager.class));
101            editLayoutTurnout1stTurnoutComboBox.setToolTipText(Bundle.getMessage("EditTurnoutToolTip"));
102            LayoutEditor.setupComboBox(editLayoutTurnout1stTurnoutComboBox, false, true, false);
103            turnoutNameLabel.setLabelFor(editLayoutTurnout1stTurnoutComboBox);
104
105            panel1.add(editLayoutTurnout1stTurnoutComboBox);
106            contentPane.add(panel1);
107
108            JPanel panel1a = new JPanel();
109            panel1a.setLayout(new BoxLayout(panel1a, BoxLayout.Y_AXIS));
110
111            editLayoutTurnout2ndTurnoutComboBox = new NamedBeanComboBox<>(
112                    InstanceManager.getDefault(TurnoutManager.class));
113            editLayoutTurnout2ndTurnoutComboBox.setToolTipText(Bundle.getMessage("EditTurnoutToolTip"));
114            LayoutEditor.setupComboBox(editLayoutTurnout2ndTurnoutComboBox, false, true, false);
115
116            editLayoutTurnout2ndTurnoutCheckBox.addActionListener((ActionEvent e) -> {
117                boolean additionalEnabled = editLayoutTurnout2ndTurnoutCheckBox.isSelected();
118                editLayoutTurnout2ndTurnoutLabel.setEnabled(additionalEnabled);
119                editLayoutTurnout2ndTurnoutComboBox.setEnabled(additionalEnabled);
120                editLayoutTurnout2ndTurnoutInvertCheckBox.setEnabled(additionalEnabled);
121            });
122            panel1a.add(editLayoutTurnout2ndTurnoutCheckBox);
123            contentPane.add(panel1a);
124
125            editLayoutTurnout2ndTurnoutLabel = new JLabel(Bundle.getMessage("Supporting", Bundle.getMessage("BeanNameTurnout")));  // NOI18N
126            editLayoutTurnout2ndTurnoutLabel.setEnabled(false);
127            JPanel panel1b = new JPanel();
128            panel1b.add(editLayoutTurnout2ndTurnoutLabel);
129            editLayoutTurnout2ndTurnoutLabel.setLabelFor(editLayoutTurnout2ndTurnoutComboBox);
130            panel1b.add(editLayoutTurnout2ndTurnoutComboBox);
131            editLayoutTurnout2ndTurnoutInvertCheckBox.addActionListener((ActionEvent e) -> layoutTurnout.setSecondTurnoutInverted(editLayoutTurnout2ndTurnoutInvertCheckBox.isSelected()));
132            editLayoutTurnout2ndTurnoutInvertCheckBox.setEnabled(false);
133            panel1b.add(editLayoutTurnout2ndTurnoutInvertCheckBox);
134            contentPane.add(panel1b);
135
136            // add continuing state choice
137            extendAddContinuingStateChoice(contentPane);
138
139            JPanel panel3a = new JPanel();
140            panel3a.setLayout(new FlowLayout());
141            editLayoutTurnoutHiddenCheckBox = new JCheckBox(Bundle.getMessage("HideTurnout"));  // NOI18N
142            editLayoutTurnoutHiddenCheckBox.setToolTipText(Bundle.getMessage("HiddenToolTip"));  // NOI18N
143            panel3a.add(editLayoutTurnoutHiddenCheckBox);
144            contentPane.add(panel3a);
145
146            TitledBorder border = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black));
147            border.setTitle(Bundle.getMessage("BeanNameBlock"));  // NOI18N
148            // setup block name
149            JPanel panel2 = new JPanel();
150            panel2.setBorder(border);
151            panel2.setLayout(new FlowLayout());
152            panel2.add(editLayoutTurnoutBlockNameComboBox);
153            LayoutEditor.setupComboBox(editLayoutTurnoutBlockNameComboBox, false, true, true);
154            editLayoutTurnoutBlockNameComboBox.setToolTipText(Bundle.getMessage("EditBlockNameHint"));  // NOI18N
155            panel2.add(editLayoutTurnoutBlockButton = new JButton(Bundle.getMessage("CreateEdit")));  // NOI18N
156            editLayoutTurnoutBlockButton.setToolTipText(Bundle.getMessage("EditBlockHint", "")); // empty value for block 1  // NOI18N
157            editLayoutTurnoutBlockButton.addActionListener(this::editLayoutTurnoutEditBlockPressed);
158            contentPane.add(panel2);
159
160            extendBlockBCDSetup(contentPane);
161            
162            // set up Edit Block, Done and Cancel buttons
163            JPanel panel5 = new JPanel();
164            panel5.setLayout(new FlowLayout());
165            // Edit Block
166
167            addDoneCancelButtons(panel5, editLayoutTurnoutFrame.getRootPane(),
168                    this::editLayoutTurnoutDonePressed, this::editLayoutTurnoutCancelPressed);
169            contentPane.add(panel5);
170        }
171
172        setUpForEdit();
173        
174        editLayoutTurnoutHiddenCheckBox.setSelected(layoutTurnoutView.isHidden());
175
176        List<Turnout> currentTurnouts = new ArrayList<>();
177        currentTurnouts.add(layoutTurnout.getTurnout());
178        currentTurnouts.add(layoutTurnout.getSecondTurnout());
179
180        editLayoutTurnout1stTurnoutComboBox.setSelectedItem(layoutTurnout.getTurnout());
181        editLayoutTurnout1stTurnoutComboBox.addPopupMenuListener(
182                layoutEditor.newTurnoutComboBoxPopupMenuListener(editLayoutTurnout1stTurnoutComboBox, currentTurnouts));
183
184        BlockManager bm = InstanceManager.getDefault(BlockManager.class);
185        editLayoutTurnoutBlockNameComboBox.getEditor().setItem(bm.getBlock(layoutTurnout.getBlockName()));
186        editLayoutTurnoutBlockNameComboBox.setEnabled(!hasNxSensorPairs(layoutTurnout.getLayoutBlock()));
187        
188        configureCheckBoxes(bm);
189
190        boolean enable2nd = !layoutTurnout.getSecondTurnoutName().isEmpty();
191        editLayoutTurnout2ndTurnoutCheckBox.setSelected(enable2nd);
192        editLayoutTurnout2ndTurnoutInvertCheckBox.setEnabled(enable2nd);
193        editLayoutTurnout2ndTurnoutLabel.setEnabled(enable2nd);
194        editLayoutTurnout2ndTurnoutComboBox.setEnabled(enable2nd);
195        if (enable2nd) {
196            editLayoutTurnout2ndTurnoutInvertCheckBox.setSelected(layoutTurnout.isSecondTurnoutInverted());
197            editLayoutTurnout2ndTurnoutComboBox.setSelectedItem(layoutTurnout.getSecondTurnout());
198        } else {
199            editLayoutTurnout2ndTurnoutInvertCheckBox.setSelected(false);
200            editLayoutTurnout2ndTurnoutComboBox.setSelectedItem(null);
201        }
202
203        setUpContinuingSense();
204        
205        editLayoutTurnoutFrame.addWindowListener(new WindowAdapter() {
206            @Override
207            public void windowClosing(WindowEvent e) {
208                editLayoutTurnoutCancelPressed(null);
209            }
210        });
211
212        editLayoutTurnoutFrame.pack();
213        editLayoutTurnoutFrame.setVisible(true);
214        editLayoutTurnoutOpen = true;
215        editLayoutTurnoutNeedsBlockUpdate = false;
216
217        showSensorMessage();
218    }
219
220
221    // add continuing state choice
222    protected void extendAddContinuingStateChoice(Container contentPane) {
223        JPanel panel3 = new JPanel();
224        panel3.setLayout(new FlowLayout());
225        editLayoutTurnoutStateComboBox.removeAllItems();
226        editLayoutTurnoutStateComboBox.addItem(InstanceManager.turnoutManagerInstance().getClosedText());
227        editLayoutTurnoutClosedIndex = 0;
228        editLayoutTurnoutStateComboBox.addItem(InstanceManager.turnoutManagerInstance().getThrownText());
229        editLayoutTurnoutThrownIndex = 1;
230        editLayoutTurnoutStateComboBox.setToolTipText(Bundle.getMessage("StateToolTip"));  // NOI18N
231        JLabel label3 = new JLabel(Bundle.getMessage("ContinuingState"));
232        panel3.add(label3);  // NOI18N
233        label3.setLabelFor(editLayoutTurnoutStateComboBox);
234        panel3.add(editLayoutTurnoutStateComboBox);
235        contentPane.add(panel3);
236    }
237
238    // for extension in e.g. XOver Editor
239    protected void extendBlockBCDSetup(Container contentPane) {}
240
241    protected void configureCheckBoxes(BlockManager bm) {
242        editLayoutTurnout2ndTurnoutCheckBox.setText(Bundle.getMessage("ThrowTwoTurnouts"));  // NOI18N
243    }
244
245    // Set up for Edit
246    protected void setUpForEdit() {
247        editLayoutTurnoutFrame.setTitle(Bundle.getMessage("EditTurnout"));
248        editLayoutTurnoutHiddenCheckBox.setText(Bundle.getMessage("HideTurnout"));
249    }
250
251    protected void setUpContinuingSense() {
252        if (layoutTurnout.getContinuingSense() == Turnout.CLOSED) {
253            editLayoutTurnoutStateComboBox.setSelectedIndex(editLayoutTurnoutClosedIndex);
254        } else {
255            editLayoutTurnoutStateComboBox.setSelectedIndex(editLayoutTurnoutThrownIndex);
256        }
257    }
258
259    private void editLayoutTurnoutEditBlockPressed(ActionEvent a) {
260        // check if a block name has been entered
261        String newName = editLayoutTurnoutBlockNameComboBox.getSelectedItemDisplayName();
262        if (newName == null) {
263            newName = "";
264        }
265        if (!layoutTurnout.getBlockName().equals(newName)) {
266            // get new block, or null if block has been removed
267            layoutTurnoutView.setLayoutBlock(layoutEditor.provideLayoutBlock(newName));
268            editLayoutTurnoutNeedRedraw = true;
269            editLayoutTurnoutNeedsBlockUpdate = true;
270        }
271        // check if a block exists to edit
272        if (layoutTurnout.getLayoutBlock() == null) {
273            JOptionPane.showMessageDialog(editLayoutTurnoutFrame,
274                    Bundle.getMessage("Error1"), // NOI18N
275                    Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);  // NOI18N
276            return;
277        }
278        layoutTurnout.getLayoutBlock().editLayoutBlock(editLayoutTurnoutFrame);
279        editLayoutTurnoutNeedRedraw = true;
280        layoutEditor.setDirty();
281    }
282
283    protected void editLayoutTurnoutEditBlockBPressed(ActionEvent a) {
284        // check if a block name has been entered
285        String newName = editLayoutTurnoutBlockBNameComboBox.getSelectedItemDisplayName();
286        if (newName == null) {
287            newName = "";
288        }
289        if (!layoutTurnout.getBlockBName().equals(newName)) {
290            // get new block, or null if block has been removed
291            layoutTurnoutView.setLayoutBlockB(layoutEditor.provideLayoutBlock(newName));
292            editLayoutTurnoutNeedRedraw = true;
293            editLayoutTurnoutNeedsBlockUpdate = true;
294        }
295        // check if a block exists to edit
296        if (layoutTurnout.getLayoutBlockB() == null) {
297            JOptionPane.showMessageDialog(editLayoutTurnoutFrame,
298                    Bundle.getMessage("Error1"), // NOI18N
299                    Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);  // NOI18N
300            return;
301        }
302        layoutTurnout.getLayoutBlockB().editLayoutBlock(editLayoutTurnoutFrame);
303        editLayoutTurnoutNeedRedraw = true;
304        layoutEditor.setDirty();
305    }
306
307    protected void editLayoutTurnoutEditBlockCPressed(ActionEvent a) {
308        // check if a block name has been entered
309        String newName = editLayoutTurnoutBlockCNameComboBox.getSelectedItemDisplayName();
310        if (newName == null) {
311            newName = "";
312        }
313        if (!layoutTurnout.getBlockCName().equals(newName)) {
314            // get new block, or null if block has been removed
315            layoutTurnoutView.setLayoutBlockC(layoutEditor.provideLayoutBlock(newName));
316            editLayoutTurnoutNeedRedraw = true;
317            editLayoutTurnoutNeedsBlockUpdate = true;
318        }
319        // check if a block exists to edit
320        if (layoutTurnout.getLayoutBlockC() == null) {
321            JOptionPane.showMessageDialog(editLayoutTurnoutFrame,
322                    Bundle.getMessage("Error1"), // NOI18N
323                    Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);  // NOI18N
324            return;
325        }
326        layoutTurnout.getLayoutBlockC().editLayoutBlock(editLayoutTurnoutFrame);
327        editLayoutTurnoutNeedRedraw = true;
328        layoutEditor.setDirty();
329    }
330
331    protected void editLayoutTurnoutEditBlockDPressed(ActionEvent a) {
332        // check if a block name has been entered
333        String newName = editLayoutTurnoutBlockDNameComboBox.getSelectedItemDisplayName();
334        if (newName == null) {
335            newName = "";
336        }
337        if (!layoutTurnout.getBlockDName().equals(newName)) {
338            // get new block, or null if block has been removed
339            layoutTurnoutView.setLayoutBlockD(layoutEditor.provideLayoutBlock(newName));
340            editLayoutTurnoutNeedRedraw = true;
341            editLayoutTurnoutNeedsBlockUpdate = true;
342        }
343        // check if a block exists to edit
344        if (layoutTurnout.getLayoutBlockD() == null) {
345            JOptionPane.showMessageDialog(editLayoutTurnoutFrame,
346                    Bundle.getMessage("Error1"), // NOI18N
347                    Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);  // NOI18N
348            return;
349        }
350        layoutTurnout.getLayoutBlockD().editLayoutBlock(editLayoutTurnoutFrame);
351        editLayoutTurnoutNeedRedraw = true;
352        layoutEditor.setDirty();
353    }
354
355    private void editLayoutTurnoutDonePressed(ActionEvent a) {
356        // check if Turnout changed
357        String newName = editLayoutTurnout1stTurnoutComboBox.getSelectedItemDisplayName();
358        if (newName == null) {
359            newName = "";
360        }
361        if (!layoutTurnout.getTurnoutName().equals(newName)) {
362            // turnout has changed, is it valid?
363            if (layoutEditor.validatePhysicalTurnout(
364                    newName, editLayoutTurnoutFrame)) {
365                layoutTurnout.setTurnout(newName);
366            } else {
367                layoutTurnout.setTurnout("");
368                editLayoutTurnout1stTurnoutComboBox.setSelectedItem(null);
369            }
370            editLayoutTurnoutNeedRedraw = true;
371        }
372
373        // check if 2nd Turnout changed
374        if (editLayoutTurnout2ndTurnoutCheckBox.isSelected()) {
375            newName = editLayoutTurnout2ndTurnoutComboBox.getSelectedItemDisplayName();
376            if (newName == null) {
377                newName = "";
378            }
379            if (!layoutTurnout.getSecondTurnoutName().equals(newName)) {
380                donePressedSecondTurnoutName(newName);
381            }
382        } else {
383            layoutTurnout.setSecondTurnout("");
384        }
385
386        // Do we have an infinite invert loop?
387        if (editLayoutTurnout2ndTurnoutCheckBox.isSelected()) {
388            Turnout turnout1 = layoutTurnout.getTurnout();
389            LayoutTurnout layoutTurnout2 = null;
390            int t1state = Turnout.CLOSED;
391            int t2state = t1state;  // start off the same
392            
393            // invert if 2nd is inverted
394            if (layoutTurnout.isSecondTurnoutInverted()) {
395                t2state = Turnout.invertTurnoutState(t2state);
396            }
397
398            LayoutEditorFindItems lf = layoutEditor.getFinder();
399            Turnout turnout2 = layoutTurnout.getSecondTurnout();
400            while ((turnout2 != null) && (turnout1 != turnout2)) {
401                // first try to find it using the system name
402                layoutTurnout2 = lf.findLayoutTurnoutByTurnoutName(turnout2.getSystemName());
403                if (layoutTurnout2 == null) {   // if we didn't find it
404                    //  then try to find it using the user name
405                    layoutTurnout2 = lf.findLayoutTurnoutByTurnoutName(turnout2.getUserName());
406                }
407                // if we found it
408                if (layoutTurnout2 != null) {
409                    // and its 2nd turnout is inverted
410                    if (layoutTurnout2.isSecondTurnoutInverted()) {
411                        //  then invert the expected state
412                        t2state = Turnout.invertTurnoutState(t2state);
413                    }
414                    // and get the next 2nd turnout
415                    turnout2 = layoutTurnout2.getSecondTurnout();
416                } else {
417                    break;  // we didn't find the next LayoutTurnout
418                }
419            }
420            // if we've come full circle
421            if (turnout1 == turnout2) {
422                // are the states different?
423                if (t1state != t2state) {
424                    // yes (infinite loop)
425                    if (layoutTurnout2 != null) {   // if 2nd LayoutTurnout is defined (to get here it should be)
426                        // then flip its 2nd turnout's inverted condition
427                        layoutTurnout2.setSecondTurnoutInverted(!layoutTurnout2.isSecondTurnoutInverted());
428                        log.warn("layoutTurnout2.setSecondTurnoutInverted() infinite loop prevented.");
429                    } else {    // (but just in case)
430                        // otherwise flip our 2nd turnout's inverted condition
431                        layoutTurnout.setSecondTurnoutInverted(!layoutTurnout.isSecondTurnoutInverted());
432                        log.warn("layoutTurnout.setSecondTurnoutInverted() infinite loop prevented.");
433                    }
434                }
435            }
436        }
437
438        setContinuingRouteTurnoutState();
439        
440        // check if Block changed
441        newName = editLayoutTurnoutBlockNameComboBox.getSelectedItemDisplayName();
442        if (newName == null) {
443            newName = "";
444        }
445        if (!layoutTurnout.getBlockName().equals(newName)) {
446            // get new block, or null if block has been removed
447            layoutTurnoutView.setLayoutBlock(layoutEditor.provideLayoutBlock(newName));
448            editLayoutTurnoutNeedRedraw = true;
449            editLayoutTurnoutNeedsBlockUpdate = true;
450        }
451        
452        checkBlock234Changed();
453                
454        // set hidden
455        boolean oldHidden = layoutTurnoutView.isHidden();
456        layoutTurnoutView.setHidden(editLayoutTurnoutHiddenCheckBox.isSelected());
457        if (oldHidden != layoutTurnoutView.isHidden()) {
458            editLayoutTurnoutNeedRedraw = true;
459        }
460        editLayoutTurnoutOpen = false;
461        editLayoutTurnoutFrame.setVisible(false);
462        editLayoutTurnoutFrame.dispose();
463        editLayoutTurnoutFrame = null;
464        if (editLayoutTurnoutNeedsBlockUpdate) {
465            layoutTurnout.updateBlockInfo();
466            layoutTurnout.reCheckBlockBoundary();
467        }
468        if (editLayoutTurnoutNeedRedraw) {
469            layoutEditor.redrawPanel();
470            layoutEditor.setDirty();
471            editLayoutTurnoutNeedRedraw = false;
472        }
473    }
474
475    protected void donePressedSecondTurnoutName(String newName) {
476        layoutTurnout.setSecondTurnout(newName);
477    }
478
479    // set the continuing route Turnout State
480    protected void setContinuingRouteTurnoutState() {
481        log.info("LayoutTurnoutEditor#setContinuingRouteTurnoutState should have been overridden in class {} object {}", this.getClass(), this);
482        if ((layoutTurnout.getTurnoutType() == LayoutTurnout.TurnoutType.RH_TURNOUT)
483                || (layoutTurnout.getTurnoutType() == LayoutTurnout.TurnoutType.LH_TURNOUT)
484                || (layoutTurnout.getTurnoutType() == LayoutTurnout.TurnoutType.WYE_TURNOUT)) {
485            layoutTurnout.setContinuingSense(Turnout.CLOSED);
486            if (editLayoutTurnoutStateComboBox.getSelectedIndex() == editLayoutTurnoutThrownIndex) {
487                layoutTurnout.setContinuingSense(Turnout.THROWN);
488            }
489        }
490    }
491
492    protected void checkBlock234Changed() {} 
493
494    private void editLayoutTurnoutCancelPressed(ActionEvent a) {
495        editLayoutTurnoutOpen = false;
496        editLayoutTurnoutFrame.setVisible(false);
497        editLayoutTurnoutFrame.dispose();
498        editLayoutTurnoutFrame = null;
499        if (editLayoutTurnoutNeedsBlockUpdate) {
500            layoutTurnout.updateBlockInfo();
501        }
502        if (editLayoutTurnoutNeedRedraw) {
503            layoutEditor.redrawPanel();
504            layoutEditor.setDirty();
505            editLayoutTurnoutNeedRedraw = false;
506        }
507    }
508    
509
510    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LayoutTurnoutEditor.class);
511}