001package jmri.jmrit.operations.trains;
002
003import java.awt.Color;
004import java.awt.Dimension;
005import java.util.List;
006import java.util.ResourceBundle;
007
008import javax.swing.*;
009
010import jmri.InstanceManager;
011import jmri.jmrit.operations.OperationsFrame;
012import jmri.jmrit.operations.OperationsXml;
013import jmri.jmrit.operations.automation.AutomationsTableFrameAction;
014import jmri.jmrit.operations.locations.Location;
015import jmri.jmrit.operations.locations.LocationManager;
016import jmri.jmrit.operations.rollingstock.cars.CarManagerXml;
017import jmri.jmrit.operations.rollingstock.engines.EngineManagerXml;
018import jmri.jmrit.operations.setup.*;
019import jmri.jmrit.operations.trains.excel.SetupExcelProgramFrameAction;
020import jmri.jmrit.operations.trains.excel.TrainCustomManifest;
021import jmri.jmrit.operations.trains.schedules.*;
022import jmri.jmrit.operations.trains.tools.*;
023import jmri.swing.JTablePersistenceManager;
024import jmri.util.swing.JmriJOptionPane;
025
026/**
027 * Frame for adding and editing the train roster for operations.
028 *
029 * @author Bob Jacobsen Copyright (C) 2001
030 * @author Daniel Boudreau Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013,
031 *         2014
032 */
033public class TrainsTableFrame extends OperationsFrame implements java.beans.PropertyChangeListener {
034
035    public static final String MOVE = Bundle.getMessage("Move");
036    public static final String TERMINATE = Bundle.getMessage("Terminate");
037    public static final String RESET = Bundle.getMessage("Reset");
038    public static final String CONDUCTOR = Bundle.getMessage("Conductor");
039
040    CarManagerXml carManagerXml = InstanceManager.getDefault(CarManagerXml.class); // load cars
041    EngineManagerXml engineManagerXml = InstanceManager.getDefault(EngineManagerXml.class); // load engines
042    TrainManager trainManager = InstanceManager.getDefault(TrainManager.class);
043    TrainManagerXml trainManagerXml = InstanceManager.getDefault(TrainManagerXml.class);
044    LocationManager locationManager = InstanceManager.getDefault(LocationManager.class);
045
046    public TrainsTableModel trainsModel;
047    JTable trainsTable;
048    JScrollPane trainsPane;
049
050    // labels
051    JLabel numTrains = new JLabel();
052    JLabel textTrains = new JLabel(Bundle.getMessage("trains"));
053    JLabel textSep1 = new JLabel("      ");
054
055    // radio buttons
056    JRadioButton showTime = new JRadioButton(Bundle.getMessage("Time"));
057    JRadioButton showId = new JRadioButton(Bundle.getMessage("Id"));
058
059    JRadioButton moveRB = new JRadioButton(MOVE);
060    JRadioButton terminateRB = new JRadioButton(TERMINATE);
061    JRadioButton resetRB = new JRadioButton(RESET);
062    JRadioButton conductorRB = new JRadioButton(CONDUCTOR);
063
064    // major buttons
065    JButton addButton = new JButton(Bundle.getMessage("AddTrain"));
066    JButton buildButton = new JButton(Bundle.getMessage("Build"));
067    JButton printButton = new JButton(Bundle.getMessage("Print"));
068    JButton openFileButton = new JButton(Bundle.getMessage("OpenFile"));
069    JButton runFileButton = new JButton(Bundle.getMessage("RunFile"));
070    JButton switchListsButton = new JButton(Bundle.getMessage("SwitchLists"));
071    JButton terminateButton = new JButton(Bundle.getMessage("Terminate"));
072    JButton saveButton = new JButton(Bundle.getMessage("SaveBuilds"));
073
074    // check boxes
075    JCheckBox buildMsgBox = new JCheckBox(Bundle.getMessage("BuildMessages"));
076    JCheckBox buildReportBox = new JCheckBox(Bundle.getMessage("BuildReport"));
077    JCheckBox printPreviewBox = new JCheckBox(Bundle.getMessage("Preview"));
078    JCheckBox openFileBox = new JCheckBox(Bundle.getMessage("OpenFile"));
079    JCheckBox runFileBox = new JCheckBox(Bundle.getMessage("RunFile"));
080    public JCheckBox showAllBox = new JCheckBox(Bundle.getMessage("ShowAllTrains"));
081
082    public TrainsTableFrame() {
083        super();
084
085        updateTitle();
086
087        // create ShutDownTasks
088        createShutDownTask();
089        // always check for dirty operations files
090        setModifiedFlag(true);
091
092        // general GUI configuration
093        getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
094
095        // Set up the jtable in a Scroll Pane..
096        trainsModel = new TrainsTableModel();
097        trainsTable = new JTable(trainsModel);
098        trainsPane = new JScrollPane(trainsTable);
099        trainsModel.initTable(trainsTable, this);
100
101        // Set up the control panel
102        // row 1
103        JPanel cp1 = new JPanel();
104        cp1.setLayout(new BoxLayout(cp1, BoxLayout.X_AXIS));
105
106        JPanel show = new JPanel();
107        show.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("ShowClickToSort")));
108        show.add(showTime);
109        show.add(showId);
110
111        JPanel build = new JPanel();
112        build.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Build")));
113        build.add(showAllBox);
114
115        JPanel function = new JPanel();
116        function.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Function")));
117        function.add(printPreviewBox);
118        function.add(openFileBox);
119        function.add(runFileBox);
120
121        JPanel options = new JPanel();
122        options.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Options")));
123        options.add(buildMsgBox);
124        options.add(buildReportBox);
125
126        JPanel action = new JPanel();
127        action.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Action")));
128        action.add(moveRB);
129        action.add(conductorRB);
130        action.add(terminateRB);
131        action.add(resetRB);
132
133        cp1.add(show);
134        cp1.add(build);
135        cp1.add(function);
136        cp1.add(options);
137        cp1.add(action);
138
139        // tool tips, see setPrintButtonText() for more tool tips
140        addButton.setToolTipText(Bundle.getMessage("AddTrainTip"));
141        buildButton.setToolTipText(Bundle.getMessage("BuildSelectedTip"));
142        switchListsButton.setToolTipText(Bundle.getMessage("PreviewPrintSwitchListsTip"));
143
144        terminateButton.setToolTipText(Bundle.getMessage("TerminateSelectedTip"));
145        saveButton.setToolTipText(Bundle.getMessage("SaveBuildsTip"));
146        openFileButton.setToolTipText(Bundle.getMessage("OpenFileButtonTip"));
147        runFileButton.setToolTipText(Bundle.getMessage("RunFileButtonTip"));
148        buildMsgBox.setToolTipText(Bundle.getMessage("BuildMessagesTip"));
149        printPreviewBox.setToolTipText(Bundle.getMessage("PreviewTip"));
150        openFileBox.setToolTipText(Bundle.getMessage("OpenFileTip"));
151        runFileBox.setToolTipText(Bundle.getMessage("RunFileTip"));
152        showAllBox.setToolTipText(Bundle.getMessage("ShowAllTrainsTip"));
153
154        moveRB.setToolTipText(Bundle.getMessage("MoveTip"));
155        terminateRB.setToolTipText(Bundle.getMessage("TerminateTip"));
156        resetRB.setToolTipText(Bundle.getMessage("ResetTip"));
157        conductorRB.setToolTipText(Bundle.getMessage("ConductorTip"));
158
159        // row 2
160        JPanel addTrain = new JPanel();
161        addTrain.setBorder(BorderFactory.createTitledBorder(""));
162        addTrain.add(numTrains);
163        addTrain.add(textTrains);
164        addTrain.add(textSep1);
165        addTrain.add(addButton);
166
167        numTrains.setText(Integer.toString(trainManager.getNumEntries()));
168
169        JPanel select = new JPanel();
170        select.setBorder(BorderFactory.createTitledBorder(""));
171        select.add(buildButton);
172        select.add(printButton);
173        select.add(openFileButton);
174        select.add(runFileButton);
175        select.add(switchListsButton);
176        select.add(terminateButton);
177
178        JPanel save = new JPanel();
179        save.setBorder(BorderFactory.createTitledBorder(""));
180        save.add(saveButton);
181
182        JPanel cp2 = new JPanel();
183        cp2.setLayout(new BoxLayout(cp2, BoxLayout.X_AXIS));
184        cp2.add(addTrain);
185        cp2.add(select);
186        cp2.add(save);
187
188        // place controls in scroll pane
189        JPanel controlPanel = new JPanel();
190        controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.Y_AXIS));
191        controlPanel.add(cp1);
192        controlPanel.add(cp2);
193
194        JScrollPane controlPane = new JScrollPane(controlPanel);
195
196        getContentPane().add(trainsPane);
197        getContentPane().add(controlPane);
198
199        // setup buttons
200        addButtonAction(addButton);
201        addButtonAction(buildButton);
202        addButtonAction(printButton);
203        addButtonAction(openFileButton);
204        addButtonAction(runFileButton);
205        addButtonAction(switchListsButton);
206        addButtonAction(terminateButton);
207        addButtonAction(saveButton);
208
209        ButtonGroup showGroup = new ButtonGroup();
210        showGroup.add(showTime);
211        showGroup.add(showId);
212        showTime.setSelected(true);
213
214        ButtonGroup actionGroup = new ButtonGroup();
215        actionGroup.add(moveRB);
216        actionGroup.add(conductorRB);
217        actionGroup.add(terminateRB);
218        actionGroup.add(resetRB);
219
220        addRadioButtonAction(showTime);
221        addRadioButtonAction(showId);
222
223        addRadioButtonAction(moveRB);
224        addRadioButtonAction(terminateRB);
225        addRadioButtonAction(resetRB);
226        addRadioButtonAction(conductorRB);
227
228        buildMsgBox.setSelected(trainManager.isBuildMessagesEnabled());
229        buildReportBox.setSelected(trainManager.isBuildReportEnabled());
230        printPreviewBox.setSelected(trainManager.isPrintPreviewEnabled());
231        openFileBox.setSelected(trainManager.isOpenFileEnabled());
232        runFileBox.setSelected(trainManager.isRunFileEnabled());
233        showAllBox.setSelected(trainsModel.isShowAll());
234
235        // show open files only if create csv is enabled
236        updateRunAndOpenButtons();
237
238        addCheckBoxAction(buildMsgBox);
239        addCheckBoxAction(buildReportBox);
240        addCheckBoxAction(printPreviewBox);
241        addCheckBoxAction(showAllBox);
242        addCheckBoxAction(openFileBox);
243        addCheckBoxAction(runFileBox);
244
245        // Set the button text to Print or Preview
246        setPrintButtonText();
247        // Set the train action button text to Move or Terminate
248        setTrainActionButton();
249
250        // build menu
251        JMenuBar menuBar = new JMenuBar();
252        JMenu toolMenu = new JMenu(Bundle.getMessage("MenuTools"));
253        toolMenu.add(new OptionAction());
254        toolMenu.add(new PrintOptionAction());
255        toolMenu.add(new BuildReportOptionAction());
256        toolMenu.addSeparator();
257        toolMenu.add(new TrainsByCarTypeAction());
258        toolMenu.add(new ChangeDepartureTimesAction());
259        toolMenu.add(new TrainsScheduleAction());
260        toolMenu.add(new TrainsTableSetColorAction());
261        toolMenu.add(new TrainCopyAction());
262        toolMenu.addSeparator();
263        toolMenu.add(new TrainsScriptAction(this));
264        toolMenu.add(new AutomationsTableFrameAction());
265        toolMenu.add(new SetupExcelProgramFrameAction());
266        toolMenu.addSeparator();
267        toolMenu.add(new ExportTrainRosterAction());
268        toolMenu.add(new ExportTimetableAction());
269        toolMenu.add(new ExportTrainLineupsAction());
270        toolMenu.addSeparator();
271        toolMenu.add(new TrainByCarTypeAction(null));
272        toolMenu.addSeparator();
273        toolMenu.add(new PrintTrainsAction(false, this));
274        toolMenu.add(new PrintTrainsAction(true, this));
275        toolMenu.add(new PrintSavedTrainManifestAction(false, null));
276        toolMenu.add(new PrintSavedTrainManifestAction(true, null));
277
278        menuBar.add(toolMenu);
279        menuBar.add(new jmri.jmrit.operations.OperationsMenu());
280        setJMenuBar(menuBar);
281
282        // add help menu to window
283        addHelpMenu("package.jmri.jmrit.operations.Operations_Trains", true); // NOI18N
284
285        initMinimumSize(new Dimension(Control.panelWidth700, Control.panelHeight250));
286
287        addHorizontalScrollBarKludgeFix(controlPane, controlPanel);
288
289        // listen for train schedule changes
290        InstanceManager.getDefault(TrainScheduleManager.class).addPropertyChangeListener(this);
291        // listen for changes in the number of trains
292        trainManager.addPropertyChangeListener(this);
293        Setup.getDefault().addPropertyChangeListener(this);
294        // listen for location switch list changes
295        addPropertyChangeLocations();
296
297        // auto save
298        AutoSave.start();
299    }
300
301    @Override
302    public void radioButtonActionPerformed(java.awt.event.ActionEvent ae) {
303        log.debug("radio button activated");
304        // clear any sorts by column
305        clearTableSort(trainsTable);
306        if (ae.getSource() == showId) {
307            trainsModel.setSort(trainsModel.SORTBYID);
308        }
309        if (ae.getSource() == showTime) {
310            trainsModel.setSort(trainsModel.SORTBYTIME);
311        }
312        if (ae.getSource() == moveRB) {
313            trainManager.setTrainsFrameTrainAction(MOVE);
314        }
315        if (ae.getSource() == terminateRB) {
316            trainManager.setTrainsFrameTrainAction(TERMINATE);
317        }
318        if (ae.getSource() == resetRB) {
319            trainManager.setTrainsFrameTrainAction(RESET);
320        }
321        if (ae.getSource() == conductorRB) {
322            trainManager.setTrainsFrameTrainAction(CONDUCTOR);
323        }
324    }
325
326    TrainSwitchListEditFrame tslef;
327
328    // add, build, print, switch lists, terminate, and save buttons
329    @Override
330    public void buttonActionPerformed(java.awt.event.ActionEvent ae) {
331        // log.debug("train button activated");
332        if (ae.getSource() == addButton) {
333            new TrainEditFrame(null);
334        }
335        if (ae.getSource() == buildButton) {
336            runFileButton.setEnabled(false);
337            // uses a thread which allows table updates during build
338            trainManager.buildSelectedTrains(getSortByList());
339        }
340        if (ae.getSource() == printButton) {
341            trainManager.printSelectedTrains(getSortByList());
342        }
343        if (ae.getSource() == openFileButton) {
344            // open the csv files
345            List<Train> trains = getSortByList();
346            for (Train train : trains) {
347                if (train.isBuildEnabled()) {
348                    if (!train.isBuilt() && trainManager.isBuildMessagesEnabled()) {
349                        int response = JmriJOptionPane.showConfirmDialog(this,
350                                Bundle.getMessage("NeedToBuildBeforeOpenFile",
351                                        train.getName()),
352                                Bundle.getMessage("ErrorTitle"), JmriJOptionPane.OK_CANCEL_OPTION);
353                        if (response != JmriJOptionPane.OK_OPTION ) {
354                            break;
355                        }
356                    } else if (train.isBuilt()) {
357                        train.openFile();
358                    }
359                }
360            }
361        }
362        if (ae.getSource() == runFileButton) {
363            // Processes the CSV Manifest files using an external custom program.
364            TrainCustomManifest tcm = InstanceManager.getDefault(TrainCustomManifest.class);
365            if (!tcm.excelFileExists()) {
366                log.warn("Manifest creator file not found!, directory path: {}, file name: {}", tcm.getDirectoryPathName(),
367                        tcm.getFileName());
368                JmriJOptionPane.showMessageDialog(this,
369                        Bundle.getMessage("LoadDirectoryNameFileName",
370                                tcm.getDirectoryPathName(), tcm.getFileName()),
371                        Bundle.getMessage("ManifestCreatorNotFound"), JmriJOptionPane.ERROR_MESSAGE);
372                return;
373            }
374            List<Train> trains = getSortByList();
375            for (Train train : trains) {
376                if (train.isBuildEnabled()) {
377                    if (!train.isBuilt() && trainManager.isBuildMessagesEnabled()) {
378                        int response = JmriJOptionPane.showConfirmDialog(this,
379                                Bundle.getMessage("NeedToBuildBeforeRunFile",
380                                        train.getName()),
381                                Bundle.getMessage("ErrorTitle"), JmriJOptionPane.OK_CANCEL_OPTION);
382                        if (response != JmriJOptionPane.OK_OPTION ) {
383                            break;
384                        }
385                    } else if (train.isBuilt()) {
386                        // Add csv manifest file to our collection to be processed.
387                        tcm.addCsvFile(train.createCsvManifestFile());
388                        train.setPrinted(true);
389                    }
390                }
391            }
392            // Now run the user specified custom Manifest processor program
393            tcm.process();
394        }
395        if (ae.getSource() == switchListsButton) {
396            if (tslef != null) {
397                tslef.dispose();
398            }
399            tslef = new TrainSwitchListEditFrame();
400            tslef.initComponents();
401        }
402        if (ae.getSource() == terminateButton) {
403            trainManager.terminateSelectedTrains(getSortByList());
404        }
405        if (ae.getSource() == saveButton) {
406            storeValues();
407        }
408    }
409
410    SortOrder _status = SortOrder.ASCENDING;
411
412    public String getSortBy() {
413        // set the defaults
414        String sortBy = TrainsTableModel.TIMECOLUMNNAME;
415        _status = SortOrder.ASCENDING;
416        // now look to see if a sort is active
417        for (RowSorter.SortKey key : trainsTable.getRowSorter().getSortKeys()) {
418            String name = trainsModel.getColumnName(key.getColumn());
419            SortOrder status = key.getSortOrder();
420            // log.debug("Column {} status {}", name, status);
421            if (!status.equals(SortOrder.UNSORTED) && !name.isEmpty()) {
422                sortBy = name;
423                _status = status;
424                break;
425            }
426        }
427        return sortBy;
428    }
429
430    public List<Train> getSortByList() {
431        return getSortByList(getSortBy());
432    }
433
434    public List<Train> getSortByList(String sortBy) {
435        List<Train> sysList;
436
437        if (sortBy.equals(TrainsTableModel.IDCOLUMNNAME)) {
438            sysList = trainManager.getTrainsByIdList();
439        } else if (sortBy.equals(TrainsTableModel.TIMECOLUMNNAME)) {
440            sysList = trainManager.getTrainsByTimeList();
441        } else if (sortBy.equals(TrainsTableModel.DEPARTSCOLUMNNAME)) {
442            sysList = trainManager.getTrainsByDepartureList();
443        } else if (sortBy.equals(TrainsTableModel.TERMINATESCOLUMNNAME)) {
444            sysList = trainManager.getTrainsByTerminatesList();
445        } else if (sortBy.equals(TrainsTableModel.ROUTECOLUMNNAME)) {
446            sysList = trainManager.getTrainsByRouteList();
447        } else if (sortBy.equals(TrainsTableModel.STATUSCOLUMNNAME)) {
448            sysList = trainManager.getTrainsByStatusList();
449        } else if (sortBy.equals(TrainsTableModel.DESCRIPTIONCOLUMNNAME)) {
450            sysList = trainManager.getTrainsByDescriptionList();
451        } else {
452            sysList = trainManager.getTrainsByNameList();
453        }
454        return sysList;
455    }
456
457    // Modifies button text and tool tips
458    private void setPrintButtonText() {
459        if (printPreviewBox.isSelected()) {
460            printButton.setText(Bundle.getMessage("Preview"));
461            printButton.setToolTipText(Bundle.getMessage("PreviewSelectedTip"));
462            buildReportBox.setToolTipText(Bundle.getMessage("BuildReportPreviewTip"));
463        } else {
464            printButton.setText(Bundle.getMessage("Print"));
465            printButton.setToolTipText(Bundle.getMessage("PrintSelectedTip"));
466            buildReportBox.setToolTipText(Bundle.getMessage("BuildReportPrintTip"));
467        }
468    }
469
470    private void setTrainActionButton() {
471        moveRB.setSelected(trainManager.getTrainsFrameTrainAction().equals(TrainsTableFrame.MOVE));
472        terminateRB.setSelected(trainManager.getTrainsFrameTrainAction().equals(TrainsTableFrame.TERMINATE));
473        resetRB.setSelected(trainManager.getTrainsFrameTrainAction().equals(TrainsTableFrame.RESET));
474        conductorRB.setSelected(trainManager.getTrainsFrameTrainAction().equals(TrainsTableFrame.CONDUCTOR));
475    }
476
477    @Override
478    public void checkBoxActionPerformed(java.awt.event.ActionEvent ae) {
479        if (ae.getSource() == buildMsgBox) {
480            trainManager.setBuildMessagesEnabled(buildMsgBox.isSelected());
481        }
482        if (ae.getSource() == buildReportBox) {
483            trainManager.setBuildReportEnabled(buildReportBox.isSelected());
484        }
485        if (ae.getSource() == printPreviewBox) {
486            trainManager.setPrintPreviewEnabled(printPreviewBox.isSelected());
487            setPrintButtonText(); // set the button text for Print or Preview
488        }
489        if (ae.getSource() == openFileBox) {
490            trainManager.setOpenFileEnabled(openFileBox.isSelected());
491            runFileBox.setSelected(false);
492            trainManager.setRunFileEnabled(false);
493        }
494        if (ae.getSource() == runFileBox) {
495            trainManager.setRunFileEnabled(runFileBox.isSelected());
496            openFileBox.setSelected(false);
497            trainManager.setOpenFileEnabled(false);
498        }
499        if (ae.getSource() == showAllBox) {
500            trainsModel.setShowAll(showAllBox.isSelected());
501        }
502    }
503
504    private void updateTitle() {
505        String title = Bundle.getMessage("TitleTrainsTable");
506        TrainSchedule sch = InstanceManager.getDefault(TrainScheduleManager.class).getActiveSchedule();
507        if (sch != null) {
508            title = title + " " + sch.getName();
509        }
510        setTitle(title);
511    }
512
513    private void updateSwitchListButton() {
514        List<Location> locations = locationManager.getList();
515        for (Location location : locations) {
516            if (location != null && location.isSwitchListEnabled() && location.getStatus().equals(Location.MODIFIED)) {
517                switchListsButton.setBackground(Color.RED);
518                return;
519            }
520        }
521        switchListsButton.setBackground(Color.GREEN);
522    }
523
524    // show open files only if create csv is enabled
525    private void updateRunAndOpenButtons() {
526        openFileBox.setVisible(Setup.isGenerateCsvManifestEnabled());
527        openFileButton.setVisible(Setup.isGenerateCsvManifestEnabled());
528        runFileBox.setVisible(Setup.isGenerateCsvManifestEnabled());
529        runFileButton.setVisible(Setup.isGenerateCsvManifestEnabled());
530    }
531
532    private synchronized void addPropertyChangeLocations() {
533        List<Location> locations = locationManager.getList();
534        for (Location location : locations) {
535            location.addPropertyChangeListener(this);
536        }
537    }
538
539    private synchronized void removePropertyChangeLocations() {
540        List<Location> locations = locationManager.getList();
541        for (Location location : locations) {
542            location.removePropertyChangeListener(this);
543        }
544    }
545
546    @Override
547    public void dispose() {
548        trainsModel.dispose();
549        trainManager.runShutDownScripts();
550        trainManager.removePropertyChangeListener(this);
551        InstanceManager.getDefault(TrainScheduleManager.class).removePropertyChangeListener(this);
552        Setup.getDefault().removePropertyChangeListener(this);
553        removePropertyChangeLocations();
554        setModifiedFlag(false);
555        InstanceManager.getOptionalDefault(JTablePersistenceManager.class).ifPresent(tpm -> {
556            tpm.stopPersisting(trainsTable);
557        });
558        super.dispose();
559    }
560
561    @Override
562    protected void handleModified() {
563        if (!getModifiedFlag()) {
564            return;
565        }
566        if (Setup.isAutoSaveEnabled()) {
567            storeValues();
568            return;
569        }
570        if (OperationsXml.areFilesDirty()) {
571            int result = JmriJOptionPane.showOptionDialog(this, Bundle.getMessage("PromptQuitWindowNotWritten"),
572                    Bundle.getMessage("PromptSaveQuit"), JmriJOptionPane.YES_NO_OPTION,
573                    JmriJOptionPane.WARNING_MESSAGE, null,
574                    new String[] { ResourceBundle.getBundle("jmri.util.UtilBundle").getString("WarnYesSave"), // NOI18N
575                            ResourceBundle.getBundle("jmri.util.UtilBundle").getString("WarnNoClose") }, // NOI18N
576                    ResourceBundle.getBundle("jmri.util.UtilBundle").getString("WarnYesSave"));
577            if (result == JmriJOptionPane.YES_OPTION) {
578                // user wants to save
579                storeValues();
580            }
581        }
582    }
583
584    @Override
585    protected void storeValues() {
586        super.storeValues();
587    }
588
589    @Override
590    public void propertyChange(java.beans.PropertyChangeEvent e) {
591        if (Control.SHOW_PROPERTY) {
592            log.debug("Property change: ({}) old: ({}) new: ({})", e.getPropertyName(), e.getOldValue(),
593                    e.getNewValue());
594        }
595        if (e.getPropertyName().equals(TrainScheduleManager.SCHEDULE_ID_CHANGED_PROPERTY)) {
596            updateTitle();
597        }
598        if (e.getPropertyName().equals(Location.STATUS_CHANGED_PROPERTY) ||
599                e.getPropertyName().equals(Location.SWITCHLIST_CHANGED_PROPERTY)) {
600            log.debug("update switch list button location ({})", e.getSource());
601            updateSwitchListButton();
602        }
603        if (e.getPropertyName().equals(Setup.MANIFEST_CSV_PROPERTY_CHANGE)) {
604            updateRunAndOpenButtons();
605        }
606        if (e.getPropertyName().equals(TrainManager.LISTLENGTH_CHANGED_PROPERTY)) {
607            numTrains.setText(Integer.toString(trainManager.getNumEntries()));
608        }
609        if (e.getPropertyName().equals(TrainManager.TRAINS_BUILT_CHANGED_PROPERTY)) {
610            runFileButton.setEnabled(true);
611        }
612    }
613
614    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(TrainsTableFrame.class);
615}