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