001package jmri.jmrit.operations.setup.gui;
002
003import java.awt.GridBagLayout;
004import java.awt.JobAttributes.SidesType;
005import java.awt.event.ActionEvent;
006import java.io.File;
007import java.util.*;
008
009import javax.swing.*;
010
011import jmri.InstanceManager;
012import jmri.jmrit.operations.setup.*;
013import jmri.jmrit.operations.trains.TrainManager;
014import jmri.jmrit.operations.trains.trainbuilder.TrainCommon;
015import jmri.util.FileUtil;
016import jmri.util.swing.FontComboUtil;
017import jmri.util.swing.JmriJOptionPane;
018
019/**
020 * Frame for user edit of manifest and switch list print options
021 *
022 * @author Dan Boudreau Copyright (C) 2008, 2010, 2011, 2012, 2013, 2025
023 */
024public class PrintOptionPanel extends OperationsPreferencesPanel implements java.beans.PropertyChangeListener {
025
026    private String ADD = "+";
027    private String DELETE = "-";
028
029    // labels
030    JLabel logoURL = new JLabel("");
031
032    // major buttons
033    JButton saveButton = new JButton(Bundle.getMessage("ButtonSave"));
034    JButton addLogoButton = new JButton(Bundle.getMessage("AddLogo"));
035    JButton removeLogoButton = new JButton(Bundle.getMessage("RemoveLogo"));
036
037    JButton addEngPickupComboboxButton = new JButton(ADD);
038    JButton deleteEngPickupComboboxButton = new JButton(DELETE);
039    JButton addEngDropComboboxButton = new JButton(ADD);
040    JButton deleteEngDropComboboxButton = new JButton(DELETE);
041    JButton addCarPickupComboboxButton = new JButton(ADD);
042    JButton deleteCarPickupComboboxButton = new JButton(DELETE);
043    JButton addCarDropComboboxButton = new JButton(ADD);
044    JButton deleteCarDropComboboxButton = new JButton(DELETE);
045    JButton addLocalComboboxButton = new JButton(ADD);
046    JButton deleteLocalComboboxButton = new JButton(DELETE);
047    JButton addSwitchListPickupComboboxButton = new JButton(ADD);
048    JButton deleteSwitchListPickupComboboxButton = new JButton(DELETE);
049    JButton addSwitchListDropComboboxButton = new JButton(ADD);
050    JButton deleteSwitchListDropComboboxButton = new JButton(DELETE);
051    JButton addSwitchListLocalComboboxButton = new JButton(ADD);
052    JButton deleteSwitchListLocalComboboxButton = new JButton(DELETE);
053
054    // check boxes
055    JCheckBox tabFormatCheckBox = new JCheckBox(Bundle.getMessage("TabFormat"));
056    JCheckBox formatSwitchListCheckBox = new JCheckBox(Bundle.getMessage("SameAsManifest"));
057    JCheckBox editManifestCheckBox = new JCheckBox(Bundle.getMessage("UseTextEditor"));
058    JCheckBox printLocCommentsCheckBox = new JCheckBox(Bundle.getMessage("PrintLocationComments"));
059    JCheckBox printRouteCommentsCheckBox = new JCheckBox(Bundle.getMessage("PrintRouteComments"));
060    JCheckBox printLoadsEmptiesCheckBox = new JCheckBox(Bundle.getMessage("PrintLoadsEmpties"));
061    JCheckBox printCabooseLoadCheckBox = new JCheckBox(Bundle.getMessage("PrintCabooseLoad"));
062    JCheckBox printPassengerLoadCheckBox = new JCheckBox(Bundle.getMessage("PrintPassengerLoad"));
063    JCheckBox printTrainScheduleNameCheckBox = new JCheckBox(Bundle.getMessage("PrintTrainScheduleName"));
064    JCheckBox use12hrFormatCheckBox = new JCheckBox(Bundle.getMessage("12hrFormat"));
065    JCheckBox printValidCheckBox = new JCheckBox(Bundle.getMessage("PrintValid"));
066    JCheckBox sortByTrackCheckBox = new JCheckBox(Bundle.getMessage("SortByTrack"));
067    JCheckBox noPageBreaksCheckBox = new JCheckBox(Bundle.getMessage("NoPageBreaks"));
068    JCheckBox printHeadersCheckBox = new JCheckBox(Bundle.getMessage("PrintHeaders"));
069    JCheckBox printPageHeaderCheckBox = new JCheckBox(Bundle.getMessage("PrintPageHeader"));
070    JCheckBox truncateCheckBox = new JCheckBox(Bundle.getMessage("Truncate"));
071    JCheckBox manifestDepartureTimeCheckBox = new JCheckBox(Bundle.getMessage("DepartureTime"));
072    JCheckBox switchListDepartureTimeCheckBox = new JCheckBox(Bundle.getMessage("DepartureTime"));
073    JCheckBox trackSummaryCheckBox = new JCheckBox(Bundle.getMessage("TrackSummary"));
074    JCheckBox routeLocationCheckBox = new JCheckBox(Bundle.getMessage("RouteLocation"));
075    JCheckBox groupCarMovesCheckBox = new JCheckBox(Bundle.getMessage("GroupCarMoves"));
076    JCheckBox printLocoLastCheckBox = new JCheckBox(Bundle.getMessage("PrintLocoLast"));
077
078    // text field
079    JTextField pickupEngPrefix = new JTextField(10);
080    JTextField dropEngPrefix = new JTextField(10);
081    JTextField pickupCarPrefix = new JTextField(10);
082    JTextField dropCarPrefix = new JTextField(10);
083    JTextField localPrefix = new JTextField(10);
084    JTextField switchListPickupCarPrefix = new JTextField(10);
085    JTextField switchListDropCarPrefix = new JTextField(10);
086    JTextField switchListLocalPrefix = new JTextField(10);
087    JTextField hazardousTextField = new JTextField(20);
088
089    // text area
090    JTextArea commentTextArea = new JTextArea(2, 90);
091
092    JScrollPane commentScroller = new JScrollPane(commentTextArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
093            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
094
095    // combo boxes
096    JComboBox<String> fontComboBox = new JComboBox<>();
097    JComboBox<String> manifestFormatComboBox = Setup.getManifestFormatComboBox();
098    JComboBox<String> manifestOrientationComboBox = Setup.getOrientationComboBox();
099    JComboBox<Integer> fontSizeComboBox = new JComboBox<>();
100    JComboBox<String> switchListOrientationComboBox = Setup.getOrientationComboBox();
101    JComboBox<SidesType> printDuplexComboBox = new JComboBox<>();
102    JColorChooser pickupEngineColorChooser = new JColorChooser();
103    JColorChooser dropEngineColorChooser = new JColorChooser();
104    JColorChooser pickupColorChooser = new JColorChooser();
105    JColorChooser dropColorChooser = new JColorChooser();
106    JColorChooser localColorChooser = new JColorChooser();
107    JColorChooser missingCarColorChooser = new JColorChooser();
108
109    // message formats
110    List<JComboBox<String>> enginePickupMessageList = new ArrayList<>();
111    List<JComboBox<String>> engineDropMessageList = new ArrayList<>();
112    List<JComboBox<String>> carPickupMessageList = new ArrayList<>();
113    List<JComboBox<String>> carDropMessageList = new ArrayList<>();
114    List<JComboBox<String>> localMessageList = new ArrayList<>();
115    List<JComboBox<String>> switchListCarPickupMessageList = new ArrayList<>();
116    List<JComboBox<String>> switchListCarDropMessageList = new ArrayList<>();
117    List<JComboBox<String>> switchListLocalMessageList = new ArrayList<>();
118
119    // manifest panels
120    JPanel pManifest = new JPanel();
121    JPanel pEngPickup = new JPanel();
122    JPanel pEngDrop = new JPanel();
123    JPanel pPickup = new JPanel();
124    JPanel pDrop = new JPanel();
125    JPanel pLocal = new JPanel();
126
127    // switch list panels
128    JPanel pSwitchListOrientation = new JPanel();
129    JPanel pSwPickup = new JPanel();
130    JPanel pSwDrop = new JPanel();
131    JPanel pSwLocal = new JPanel();
132
133    public PrintOptionPanel() {
134
135        // tool tips
136        saveButton.setToolTipText(Bundle.getMessage("SaveToolTip"));
137        addLogoButton.setToolTipText(Bundle.getMessage("AddLogoToolTip"));
138        removeLogoButton.setToolTipText(Bundle.getMessage("RemoveLogoToolTip"));
139        tabFormatCheckBox.setToolTipText(Bundle.getMessage("TabComment"));
140        printLocCommentsCheckBox.setToolTipText(Bundle.getMessage("AddLocationComments"));
141        printRouteCommentsCheckBox.setToolTipText(Bundle.getMessage("AddRouteComments"));
142        printLoadsEmptiesCheckBox.setToolTipText(Bundle.getMessage("LoadsEmptiesComment"));
143        printCabooseLoadCheckBox.setToolTipText(Bundle.getMessage("CabooseLoadTip"));
144        printPassengerLoadCheckBox.setToolTipText(Bundle.getMessage("PassengerLoadTip"));
145        printTrainScheduleNameCheckBox.setToolTipText(Bundle.getMessage("ShowTrainScheduleTip"));
146        use12hrFormatCheckBox.setToolTipText(Bundle.getMessage("Use12hrFormatTip"));
147        printValidCheckBox.setToolTipText(Bundle.getMessage("PrintValidTip"));
148        sortByTrackCheckBox.setToolTipText(Bundle.getMessage("SortByTrackTip"));
149        noPageBreaksCheckBox.setToolTipText(Bundle.getMessage("NoPageBreaksTip"));
150        printHeadersCheckBox.setToolTipText(Bundle.getMessage("PrintHeadersTip"));
151        printPageHeaderCheckBox.setToolTipText(Bundle.getMessage("PrintPageHeaderTip"));
152        truncateCheckBox.setToolTipText(Bundle.getMessage("TruncateTip"));
153        manifestDepartureTimeCheckBox.setToolTipText(Bundle.getMessage("DepartureTimeTip"));
154        switchListDepartureTimeCheckBox.setToolTipText(Bundle.getMessage("SwitchListDepartureTimeTip"));
155        routeLocationCheckBox.setToolTipText(Bundle.getMessage("RouteLocationTip"));
156        editManifestCheckBox.setToolTipText(Bundle.getMessage("UseTextEditorTip"));
157        trackSummaryCheckBox.setToolTipText(Bundle.getMessage("TrackSummaryTip"));
158        groupCarMovesCheckBox.setToolTipText(Bundle.getMessage("GroupCarsTip"));
159        printLocoLastCheckBox.setToolTipText(Bundle.getMessage("LocoLastTip"));
160
161        addEngPickupComboboxButton.setToolTipText(Bundle.getMessage("AddMessageComboboxTip"));
162        deleteEngPickupComboboxButton.setToolTipText(Bundle.getMessage("DeleteMessageComboboxTip"));
163        addEngDropComboboxButton.setToolTipText(Bundle.getMessage("AddMessageComboboxTip"));
164        deleteEngDropComboboxButton.setToolTipText(Bundle.getMessage("DeleteMessageComboboxTip"));
165
166        addCarPickupComboboxButton.setToolTipText(Bundle.getMessage("AddMessageComboboxTip"));
167        deleteCarPickupComboboxButton.setToolTipText(Bundle.getMessage("DeleteMessageComboboxTip"));
168        addCarDropComboboxButton.setToolTipText(Bundle.getMessage("AddMessageComboboxTip"));
169        deleteCarDropComboboxButton.setToolTipText(Bundle.getMessage("DeleteMessageComboboxTip"));
170        addLocalComboboxButton.setToolTipText(Bundle.getMessage("AddMessageComboboxTip"));
171        deleteLocalComboboxButton.setToolTipText(Bundle.getMessage("DeleteMessageComboboxTip"));
172
173        addSwitchListPickupComboboxButton.setToolTipText(Bundle.getMessage("AddMessageComboboxTip"));
174        deleteSwitchListPickupComboboxButton.setToolTipText(Bundle.getMessage("DeleteMessageComboboxTip"));
175        addSwitchListDropComboboxButton.setToolTipText(Bundle.getMessage("AddMessageComboboxTip"));
176        deleteSwitchListDropComboboxButton.setToolTipText(Bundle.getMessage("DeleteMessageComboboxTip"));
177        addSwitchListLocalComboboxButton.setToolTipText(Bundle.getMessage("AddMessageComboboxTip"));
178        deleteSwitchListLocalComboboxButton.setToolTipText(Bundle.getMessage("DeleteMessageComboboxTip"));
179
180        // Manifest panel
181        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
182        pManifest.setLayout(new BoxLayout(pManifest, BoxLayout.Y_AXIS));
183        JScrollPane pManifestPane = new JScrollPane(pManifest);
184        pManifestPane.setBorder(BorderFactory.createTitledBorder(""));
185
186        // row 1 font type, size, format, orientation, text colors
187        JPanel p1 = new JPanel();
188        p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS));
189
190        JPanel pFont = new JPanel();
191        pFont.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutFont")));
192        pFont.add(fontComboBox);
193
194        JPanel pFontSize = new JPanel();
195        pFontSize.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutFontSize")));
196        pFontSize.add(fontSizeComboBox);
197
198        JPanel pFormat = new JPanel();
199        pFormat.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutFormat")));
200        pFormat.add(tabFormatCheckBox);
201        pFormat.add(manifestFormatComboBox);
202
203        JPanel pOrientation = new JPanel();
204        pOrientation.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutOrientation")));
205        pOrientation.add(manifestOrientationComboBox);
206
207        JPanel pDuplex = new JPanel();
208        pDuplex.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutDuplex")));
209        pDuplex.add(printDuplexComboBox);
210
211        printDuplexComboBox.addItem(SidesType.ONE_SIDED);
212        printDuplexComboBox.addItem(SidesType.TWO_SIDED_LONG_EDGE);
213        printDuplexComboBox.addItem(SidesType.TWO_SIDED_SHORT_EDGE);
214
215        p1.add(pFont);
216        p1.add(pFontSize);
217        p1.add(pFormat);
218        p1.add(pOrientation);
219        p1.add(pDuplex);
220
221        JPanel pColor = new JPanel();
222        pColor.setLayout(new BoxLayout(pColor, BoxLayout.X_AXIS));
223        pColor.add(
224                getColorChooserPanel(Bundle.getMessage("BorderLayoutPickupEngineColor"), Setup.getPickupEngineColor(),
225                pickupEngineColorChooser));
226        pColor.add(getColorChooserPanel(Bundle.getMessage("BorderLayoutDropEngineColor"), Setup.getDropEngineColor(),
227                dropEngineColorChooser));
228        pColor.add(getColorChooserPanel(Bundle.getMessage("BorderLayoutPickupColor"), Setup.getPickupColor(),
229                pickupColorChooser));
230        pColor.add(getColorChooserPanel(Bundle.getMessage("BorderLayoutDropColor"), Setup.getDropColor(),
231                dropColorChooser));
232        pColor.add(getColorChooserPanel(Bundle.getMessage("BorderLayoutLocalColor"), Setup.getLocalColor(),
233                localColorChooser));
234
235        // load all of the message combo boxes, rows 2 through 5
236        loadFormatComboBox();
237
238        // Optional Switch List Panel
239        JPanel pSl = new JPanel();
240        pSl.setLayout(new BoxLayout(pSl, BoxLayout.X_AXIS));
241
242        JPanel pSwitchFormat = new JPanel();
243        pSwitchFormat.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutSwitchListFormat")));
244        pSwitchFormat.add(formatSwitchListCheckBox);
245
246        pSwitchListOrientation
247                .setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutSwitchListOrientation")));
248        pSwitchListOrientation.add(switchListOrientationComboBox);
249
250        pSl.add(pSwitchFormat);
251        pSl.add(pSwitchListOrientation);
252
253        JPanel pM = new JPanel();
254        pM.setLayout(new BoxLayout(pM, BoxLayout.X_AXIS));
255
256        // Switch List options
257        JPanel pSwitchOptions = new JPanel();
258        pSwitchOptions.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutSwitchListOptions")));
259        pSwitchOptions.add(trackSummaryCheckBox);
260        pSwitchOptions.add(routeLocationCheckBox);
261        pSwitchOptions.add(switchListDepartureTimeCheckBox);
262
263        // Manifest options
264        JPanel pManifestOptions = new JPanel();
265        pManifestOptions.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutManifestOptions")));
266        pManifestOptions.add(printLocCommentsCheckBox);
267        pManifestOptions.add(printRouteCommentsCheckBox);
268        pManifestOptions.add(manifestDepartureTimeCheckBox);
269        pManifestOptions.add(truncateCheckBox);
270
271        pM.add(pSwitchOptions);
272        pM.add(pManifestOptions);
273
274        // Manifest and Switch List options
275        JPanel pManifestSwtichListOptions = new JPanel();
276        pManifestSwtichListOptions.setLayout(new GridBagLayout());
277        pManifestSwtichListOptions.setBorder(
278                BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutManifestSwitchListOptions")));
279        addItemLeft(pManifestSwtichListOptions, printValidCheckBox, 0, 0);
280        addItemLeft(pManifestSwtichListOptions, printLoadsEmptiesCheckBox, 1, 0);
281        addItemLeft(pManifestSwtichListOptions, groupCarMovesCheckBox, 2, 0);
282        addItemLeft(pManifestSwtichListOptions, printLocoLastCheckBox, 3, 0);
283        addItemLeft(pManifestSwtichListOptions, printCabooseLoadCheckBox, 4, 0);
284        addItemLeft(pManifestSwtichListOptions, printPassengerLoadCheckBox, 5, 0);
285
286        addItemLeft(pManifestSwtichListOptions, use12hrFormatCheckBox, 0, 1);
287        addItemLeft(pManifestSwtichListOptions, printTrainScheduleNameCheckBox, 1, 1);
288        addItemLeft(pManifestSwtichListOptions, sortByTrackCheckBox, 2, 1);
289        addItemLeft(pManifestSwtichListOptions, noPageBreaksCheckBox, 3, 1);
290        addItemLeft(pManifestSwtichListOptions, printHeadersCheckBox, 4, 1);
291        addItemLeft(pManifestSwtichListOptions, printPageHeaderCheckBox, 5, 1);
292
293        JPanel p2 = new JPanel();
294        p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));
295
296        // Use text editor for manifest
297        JPanel pEdit = new JPanel();
298        pEdit.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutManifestPreview")));
299        pEdit.add(editManifestCheckBox);
300
301        // manifest logo
302        JPanel pLogo = new JPanel();
303        pLogo.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutLogo")));
304        pLogo.add(removeLogoButton);
305        pLogo.add(addLogoButton);
306        pLogo.add(logoURL);
307
308        // Hazardous comment
309        JPanel pHazardous = new JPanel();
310        pHazardous.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutHazardous")));
311        pHazardous.add(hazardousTextField);
312
313        p2.add(pEdit);
314        p2.add(pLogo);
315        p2.add(pHazardous);
316
317        // missing cars comment
318        JPanel pCommentMia = new JPanel();
319        pCommentMia.setLayout(new GridBagLayout());
320        pCommentMia.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutCommentOptions")));
321        addItem(pCommentMia, commentScroller, 0, 0);
322        addItem(pCommentMia, getColorChooserPanel(Setup.getMiaComment(), missingCarColorChooser), 2, 0);
323
324        pManifest.add(p1);
325        pManifest.add(pColor);
326        pManifest.add(pEngPickup);
327        pManifest.add(pEngDrop);
328        pManifest.add(pPickup);
329        pManifest.add(pDrop);
330        pManifest.add(pLocal);
331        pManifest.add(pSl);
332        pManifest.add(pSwPickup);
333        pManifest.add(pSwDrop);
334        pManifest.add(pSwLocal);
335        pManifest.add(pM);
336        pManifest.add(pManifestSwtichListOptions);
337        pManifest.add(p2);
338        pManifest.add(pCommentMia);
339
340        // row 11
341        JPanel pControl = new JPanel();
342        pControl.setBorder(BorderFactory.createTitledBorder(""));
343        pControl.setLayout(new GridBagLayout());
344        addItem(pControl, saveButton, 0, 0);
345
346        add(pManifestPane);
347        add(pControl);
348
349        manifestFormatComboBox.setSelectedItem(Setup.getManifestFormat());
350        manifestOrientationComboBox.setSelectedItem(Setup.getManifestOrientation());
351        switchListOrientationComboBox.setSelectedItem(Setup.getSwitchListOrientation());
352
353        tabFormatCheckBox.setSelected(Setup.isTabEnabled());
354        printDuplexComboBox.setSelectedItem(Setup.getPrintDuplexSides());
355
356        formatSwitchListCheckBox.setSelected(Setup.isSwitchListFormatSameAsManifest());
357        printLocCommentsCheckBox.setSelected(Setup.isPrintLocationCommentsEnabled());
358        printRouteCommentsCheckBox.setSelected(Setup.isPrintRouteCommentsEnabled());
359        printLoadsEmptiesCheckBox.setSelected(Setup.isPrintLoadsAndEmptiesEnabled());
360        printCabooseLoadCheckBox.setSelected(Setup.isPrintCabooseLoadEnabled());
361        printPassengerLoadCheckBox.setSelected(Setup.isPrintPassengerLoadEnabled());
362        printTrainScheduleNameCheckBox.setSelected(Setup.isPrintTrainScheduleNameEnabled());
363        use12hrFormatCheckBox.setSelected(Setup.is12hrFormatEnabled());
364        printValidCheckBox.setSelected(Setup.isPrintValidEnabled());
365        sortByTrackCheckBox.setSelected(Setup.isSortByTrackNameEnabled());
366        noPageBreaksCheckBox.setSelected(Setup.isPrintNoPageBreaksEnabled());
367        printPageHeaderCheckBox.setSelected(Setup.isPrintPageHeaderEnabled());
368        printHeadersCheckBox.setSelected(Setup.isPrintHeadersEnabled());
369        truncateCheckBox.setSelected(Setup.isPrintTruncateManifestEnabled());
370        manifestDepartureTimeCheckBox.setSelected(Setup.isUseDepartureTimeEnabled());
371        trackSummaryCheckBox.setSelected(Setup.isPrintTrackSummaryEnabled());
372        trackSummaryCheckBox.setEnabled(Setup.isSwitchListRealTime());
373        routeLocationCheckBox.setSelected(Setup.isSwitchListRouteLocationCommentEnabled());
374        switchListDepartureTimeCheckBox.setSelected(Setup.isUseSwitchListDepartureTimeEnabled());
375        editManifestCheckBox.setSelected(Setup.isManifestEditorEnabled());
376        groupCarMovesCheckBox.setSelected(Setup.isGroupCarMovesEnabled());
377        printLocoLastCheckBox.setSelected(Setup.isPrintLocoLastEnabled());
378
379        commentTextArea.setText(TrainCommon.getTextColorString(Setup.getMiaComment()));
380        hazardousTextField.setText(Setup.getHazardousMsg());
381
382        setSwitchListVisible(!formatSwitchListCheckBox.isSelected());
383
384        updateLogoButtons();
385
386        loadFontSizeComboBox();
387        loadFontComboBox();
388
389        // setup buttons
390        addButtonAction(addLogoButton);
391        addButtonAction(removeLogoButton);
392        addButtonAction(saveButton);
393
394        addButtonAction(addEngPickupComboboxButton);
395        addButtonAction(deleteEngPickupComboboxButton);
396        addButtonAction(addEngDropComboboxButton);
397        addButtonAction(deleteEngDropComboboxButton);
398
399        addButtonAction(addCarPickupComboboxButton);
400        addButtonAction(deleteCarPickupComboboxButton);
401        addButtonAction(addCarDropComboboxButton);
402        addButtonAction(deleteCarDropComboboxButton);
403        addButtonAction(addLocalComboboxButton);
404        addButtonAction(deleteLocalComboboxButton);
405
406        addButtonAction(addSwitchListPickupComboboxButton);
407        addButtonAction(deleteSwitchListPickupComboboxButton);
408        addButtonAction(addSwitchListDropComboboxButton);
409        addButtonAction(deleteSwitchListDropComboboxButton);
410        addButtonAction(addSwitchListLocalComboboxButton);
411        addButtonAction(deleteSwitchListLocalComboboxButton);
412
413        addCheckBoxAction(tabFormatCheckBox);
414        addCheckBoxAction(formatSwitchListCheckBox);
415        addCheckBoxAction(truncateCheckBox);
416
417        addComboBoxAction(manifestFormatComboBox);
418
419        Setup.getDefault().addPropertyChangeListener(this);
420    }
421
422    // Add Remove Logo and Save buttons
423    @Override
424    public void buttonActionPerformed(java.awt.event.ActionEvent ae) {
425        if (ae.getSource() == addLogoButton) {
426            log.debug("add logo button pressed");
427            File f = selectFile();
428            if (f != null) {
429                Setup.setManifestLogoURL(FileUtil.getPortableFilename(f));
430            }
431            updateLogoButtons();
432        }
433        if (ae.getSource() == removeLogoButton) {
434            log.debug("remove logo button pressed");
435            Setup.setManifestLogoURL("");
436            updateLogoButtons();
437        }
438        // add or delete message comboBox
439        if (ae.getSource() == addEngPickupComboboxButton) {
440            addComboBox(pEngPickup, enginePickupMessageList, Setup.getEngineMessageComboBox());
441        }
442        if (ae.getSource() == deleteEngPickupComboboxButton) {
443            removeComboBox(pEngPickup, enginePickupMessageList);
444        }
445        if (ae.getSource() == addEngDropComboboxButton) {
446            addComboBox(pEngDrop, engineDropMessageList, Setup.getEngineMessageComboBox());
447        }
448        if (ae.getSource() == deleteEngDropComboboxButton) {
449            removeComboBox(pEngDrop, engineDropMessageList);
450        }
451
452        if (ae.getSource() == addCarPickupComboboxButton) {
453            addComboBox(pPickup, carPickupMessageList, Setup.getCarMessageComboBox());
454        }
455        if (ae.getSource() == deleteCarPickupComboboxButton) {
456            removeComboBox(pPickup, carPickupMessageList);
457        }
458        if (ae.getSource() == addCarDropComboboxButton) {
459            addComboBox(pDrop, carDropMessageList, Setup.getCarMessageComboBox());
460        }
461        if (ae.getSource() == deleteCarDropComboboxButton) {
462            removeComboBox(pDrop, carDropMessageList);
463        }
464
465        if (ae.getSource() == addLocalComboboxButton) {
466            addComboBox(pLocal, localMessageList, Setup.getCarMessageComboBox());
467        }
468        if (ae.getSource() == deleteLocalComboboxButton) {
469            removeComboBox(pLocal, localMessageList);
470        }
471
472        if (ae.getSource() == addSwitchListPickupComboboxButton) {
473            addComboBox(pSwPickup, switchListCarPickupMessageList, Setup.getCarMessageComboBox());
474        }
475        if (ae.getSource() == deleteSwitchListPickupComboboxButton) {
476            removeComboBox(pSwPickup, switchListCarPickupMessageList);
477        }
478        if (ae.getSource() == addSwitchListDropComboboxButton) {
479            addComboBox(pSwDrop, switchListCarDropMessageList, Setup.getCarMessageComboBox());
480        }
481        if (ae.getSource() == deleteSwitchListDropComboboxButton) {
482            removeComboBox(pSwDrop, switchListCarDropMessageList);
483        }
484
485        if (ae.getSource() == addSwitchListLocalComboboxButton) {
486            addComboBox(pSwLocal, switchListLocalMessageList, Setup.getCarMessageComboBox());
487        }
488        if (ae.getSource() == deleteSwitchListLocalComboboxButton) {
489            removeComboBox(pSwLocal, switchListLocalMessageList);
490        }
491
492        if (ae.getSource() == saveButton) {
493            this.savePreferences();
494            var topLevelAncestor = getTopLevelAncestor();
495            if (Setup.isCloseWindowOnSaveEnabled() && topLevelAncestor instanceof PrintOptionFrame) {
496                ((PrintOptionFrame) topLevelAncestor).dispose();
497            }
498        }
499    }
500
501    @Override
502    public void checkBoxActionPerformed(ActionEvent ae) {
503        if (ae.getSource() == tabFormatCheckBox) {
504            loadFontComboBox();
505        }
506        if (ae.getSource() == formatSwitchListCheckBox) {
507            log.debug("Switch list check box activated");
508            setSwitchListVisible(!formatSwitchListCheckBox.isSelected());
509            setPreferredSize(null);
510            var topLevelAncestor = getTopLevelAncestor();
511            if (topLevelAncestor instanceof PrintOptionFrame) {
512                ((PrintOptionFrame) topLevelAncestor).pack();
513            }
514        }
515        if (ae.getSource() == truncateCheckBox && truncateCheckBox.isSelected()) {
516            if (JmriJOptionPane.showConfirmDialog(this, Bundle.getMessage("EnableTruncateWarning"),
517                    Bundle.getMessage("TruncateManifests?"),
518                    JmriJOptionPane.YES_NO_OPTION) == JmriJOptionPane.NO_OPTION) {
519                truncateCheckBox.setSelected(false);
520            }
521        }
522    }
523
524    @Override
525    public void comboBoxActionPerformed(ActionEvent ae) {
526        if (ae.getSource() == manifestFormatComboBox) {
527            loadFontComboBox();
528        }
529    }
530
531    private void setSwitchListVisible(boolean b) {
532        pSwitchListOrientation.setVisible(b);
533        pSwPickup.setVisible(b);
534        pSwDrop.setVisible(b);
535        pSwLocal.setVisible(b);
536    }
537
538    /**
539     * We always use the same file chooser in this class, so that the user's
540     * last-accessed directory remains available.
541     */
542    JFileChooser fc = jmri.jmrit.XmlFile.userFileChooser(Bundle.getMessage("Images"));
543
544    private File selectFile() {
545        if (fc == null) {
546            log.error("Could not find user directory");
547        } else {
548            fc.setDialogTitle(Bundle.getMessage("FindDesiredImage"));
549            // when reusing the chooser, make sure new files are included
550            fc.rescanCurrentDirectory();
551            int retVal = fc.showOpenDialog(null);
552            // handle selection or cancel
553            if (retVal == JFileChooser.APPROVE_OPTION) {
554                return fc.getSelectedFile();
555            }
556        }
557        return null;
558    }
559
560    private void updateLogoButtons() {
561        boolean flag = Setup.getManifestLogoURL().equals(Setup.NONE);
562        addLogoButton.setVisible(flag);
563        removeLogoButton.setVisible(!flag);
564        logoURL.setText(Setup.getManifestLogoURL());
565        var topLevelAncestor = getTopLevelAncestor();
566        if (topLevelAncestor instanceof PrintOptionFrame) {
567            ((PrintOptionFrame) topLevelAncestor).pack();
568        }
569    }
570
571    private void addComboBox(JPanel panel, List<JComboBox<String>> list, JComboBox<String> box) {
572        list.add(box);
573        panel.add(box, list.size());
574        panel.revalidate();
575        pManifest.revalidate();
576    }
577
578    private void removeComboBox(JPanel panel, List<JComboBox<String>> list) {
579        for (int i = 0; i < list.size(); i++) {
580            JComboBox<String> cb = list.get(i);
581            if (cb.getSelectedItem().equals(Setup.BLANK)) {
582                list.remove(i);
583                panel.remove(cb);
584                panel.revalidate();
585                pManifest.revalidate();
586                return;
587            }
588        }
589    }
590
591    private void loadFormatComboBox() {
592        // loco pick up message format
593        pEngPickup.removeAll();
594        enginePickupMessageList.clear();
595        pEngPickup.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutPickupEngine")));
596        pEngPickup.add(pickupEngPrefix);
597        pickupEngPrefix.setText(Setup.getPickupEnginePrefix());
598        String[] format = Setup.getPickupEngineMessageFormat();
599        for (String f : format) {
600            JComboBox<String> cb = Setup.getEngineMessageComboBox();
601            cb.setSelectedItem(f);
602            pEngPickup.add(cb);
603            enginePickupMessageList.add(cb);
604        }
605        pEngPickup.add(addEngPickupComboboxButton);
606        pEngPickup.add(deleteEngPickupComboboxButton);
607        pEngPickup.revalidate();
608
609        // loco set out message format
610        pEngDrop.removeAll();
611        engineDropMessageList.clear();
612        pEngDrop.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutDropEngine")));
613        pEngDrop.add(dropEngPrefix);
614        dropEngPrefix.setText(Setup.getDropEnginePrefix());
615        format = Setup.getDropEngineMessageFormat();
616        for (String f : format) {
617            JComboBox<String> cb = Setup.getEngineMessageComboBox();
618            cb.setSelectedItem(f);
619            pEngDrop.add(cb);
620            engineDropMessageList.add(cb);
621        }
622        pEngDrop.add(addEngDropComboboxButton);
623        pEngDrop.add(deleteEngDropComboboxButton);
624        pEngDrop.revalidate();
625
626        // car pickup message format
627        pPickup.removeAll();
628        carPickupMessageList.clear();
629        pPickup.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutPickupCar")));
630        pPickup.add(pickupCarPrefix);
631        pickupCarPrefix.setText(Setup.getPickupCarPrefix());
632        String[] pickFormat = Setup.getPickupManifestMessageFormat();
633        for (String pf : pickFormat) {
634            JComboBox<String> cb = Setup.getCarMessageComboBox();
635            cb.setSelectedItem(pf);
636            pPickup.add(cb);
637            carPickupMessageList.add(cb);
638        }
639        pPickup.add(addCarPickupComboboxButton);
640        pPickup.add(deleteCarPickupComboboxButton);
641        pPickup.revalidate();
642
643        // car drop message format
644        pDrop.removeAll();
645        carDropMessageList.clear();
646        pDrop.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutDropCar")));
647        pDrop.add(dropCarPrefix);
648        dropCarPrefix.setText(Setup.getDropCarPrefix());
649        String[] dropFormat = Setup.getDropManifestMessageFormat();
650        for (String lf : dropFormat) {
651            JComboBox<String> cb = Setup.getCarMessageComboBox();
652            cb.setSelectedItem(lf);
653            pDrop.add(cb);
654            carDropMessageList.add(cb);
655        }
656        pDrop.add(addCarDropComboboxButton);
657        pDrop.add(deleteCarDropComboboxButton);
658        pDrop.revalidate();
659
660        // local car move message format
661        pLocal.removeAll();
662        localMessageList.clear();
663        pLocal.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutLocal")));
664        pLocal.add(localPrefix);
665        localPrefix.setText(Setup.getLocalPrefix());
666        String[] localFormat = Setup.getLocalManifestMessageFormat();
667        for (String lf : localFormat) {
668            JComboBox<String> cb = Setup.getCarMessageComboBox();
669            cb.setSelectedItem(lf);
670            pLocal.add(cb);
671            localMessageList.add(cb);
672        }
673        pLocal.add(addLocalComboboxButton);
674        pLocal.add(deleteLocalComboboxButton);
675        pLocal.revalidate();
676
677        // switch list car pickup message format
678        pSwPickup.removeAll();
679        switchListCarPickupMessageList.clear();
680        pSwPickup.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutSwitchListPickupCar")));
681        pSwPickup.add(switchListPickupCarPrefix);
682        switchListPickupCarPrefix.setText(Setup.getSwitchListPickupCarPrefix());
683        pickFormat = Setup.getPickupSwitchListMessageFormat();
684        for (String pf : pickFormat) {
685            JComboBox<String> cb = Setup.getCarMessageComboBox();
686            cb.setSelectedItem(pf);
687            pSwPickup.add(cb);
688            switchListCarPickupMessageList.add(cb);
689        }
690        pSwPickup.add(addSwitchListPickupComboboxButton);
691        pSwPickup.add(deleteSwitchListPickupComboboxButton);
692
693        // switch list car drop message format
694        pSwDrop.removeAll();
695        switchListCarDropMessageList.clear();
696        pSwDrop.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutSwitchListDropCar")));
697        pSwDrop.add(switchListDropCarPrefix);
698        switchListDropCarPrefix.setText(Setup.getSwitchListDropCarPrefix());
699        dropFormat = Setup.getDropSwitchListMessageFormat();
700        for (String df : dropFormat) {
701            JComboBox<String> cb = Setup.getCarMessageComboBox();
702            cb.setSelectedItem(df);
703            pSwDrop.add(cb);
704            switchListCarDropMessageList.add(cb);
705        }
706        pSwDrop.add(addSwitchListDropComboboxButton);
707        pSwDrop.add(deleteSwitchListDropComboboxButton);
708
709        // switch list local car move message format
710        pSwLocal.removeAll();
711        switchListLocalMessageList.clear();
712        pSwLocal.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutSwitchListLocal")));
713        pSwLocal.add(switchListLocalPrefix);
714        switchListLocalPrefix.setText(Setup.getSwitchListLocalPrefix());
715        localFormat = Setup.getLocalSwitchListMessageFormat();
716        for (String lf : localFormat) {
717            JComboBox<String> cb = Setup.getCarMessageComboBox();
718            cb.setSelectedItem(lf);
719            pSwLocal.add(cb);
720            switchListLocalMessageList.add(cb);
721        }
722        pSwLocal.add(addSwitchListLocalComboboxButton);
723        pSwLocal.add(deleteSwitchListLocalComboboxButton);
724    }
725
726    private void loadFontSizeComboBox() {
727        loadFontSizeComboBox(fontSizeComboBox);
728        fontSizeComboBox.setSelectedItem(Setup.getManifestFontSize());
729    }
730
731    private void loadFontComboBox() {
732        fontComboBox.removeAllItems();
733        List<String> fonts = FontComboUtil.getFonts(FontComboUtil.ALL);
734        if (tabFormatCheckBox.isSelected() || !manifestFormatComboBox.getSelectedItem().equals(Setup.STANDARD_FORMAT)) {
735            fonts = FontComboUtil.getFonts(FontComboUtil.MONOSPACED);
736        }
737        for (String font : fonts) {
738            fontComboBox.addItem(font);
739        }
740        fontComboBox.setSelectedItem(Setup.getFontName());
741    }
742
743    @Override
744    public String getTabbedPreferencesTitle() {
745        return Bundle.getMessage("TitlePrintOptions");
746    }
747
748    @Override
749    public String getPreferencesTooltip() {
750        return null;
751    }
752
753    @Override
754    public void savePreferences() {
755        // font name
756        Setup.setFontName((String) fontComboBox.getSelectedItem());
757        // font size
758        Setup.setManifestFontSize((Integer) fontSizeComboBox.getSelectedItem());
759        // page orientation
760        Setup.setManifestOrientation((String) manifestOrientationComboBox.getSelectedItem());
761        Setup.setSwitchListOrientation((String) switchListOrientationComboBox.getSelectedItem());
762        Setup.setPrintDuplexSides((SidesType) printDuplexComboBox.getSelectedItem());
763        // format
764        Setup.setManifestFormat((String) manifestFormatComboBox.getSelectedItem());
765        // drop and pick up color option
766        Setup.setDropEngineColor(dropEngineColorChooser.getColor());
767        Setup.setPickupEngineColor(pickupEngineColorChooser.getColor());
768        Setup.setDropColor(dropColorChooser.getColor());
769        Setup.setPickupColor(pickupColorChooser.getColor());
770        Setup.setLocalColor(localColorChooser.getColor());
771        // save engine pick up message format
772        Setup.setPickupEnginePrefix(pickupEngPrefix.getText());
773        String[] format = new String[enginePickupMessageList.size()];
774        for (int i = 0; i < enginePickupMessageList.size(); i++) {
775            JComboBox<?> cb = enginePickupMessageList.get(i);
776            format[i] = (String) cb.getSelectedItem();
777        }
778        Setup.setPickupEngineMessageFormat(format);
779        // save engine drop message format
780        Setup.setDropEnginePrefix(dropEngPrefix.getText());
781        format = new String[engineDropMessageList.size()];
782        for (int i = 0; i < engineDropMessageList.size(); i++) {
783            JComboBox<?> cb = engineDropMessageList.get(i);
784            format[i] = (String) cb.getSelectedItem();
785        }
786        Setup.setDropEngineMessageFormat(format);
787        // save car pick up message format
788        Setup.setPickupCarPrefix(pickupCarPrefix.getText());
789        format = new String[carPickupMessageList.size()];
790        for (int i = 0; i < carPickupMessageList.size(); i++) {
791            JComboBox<?> cb = carPickupMessageList.get(i);
792            format[i] = (String) cb.getSelectedItem();
793        }
794        Setup.setPickupManifestMessageFormat(format);
795        // save car drop message format
796        Setup.setDropCarPrefix(dropCarPrefix.getText());
797        format = new String[carDropMessageList.size()];
798        for (int i = 0; i < carDropMessageList.size(); i++) {
799            JComboBox<?> cb = carDropMessageList.get(i);
800            format[i] = (String) cb.getSelectedItem();
801        }
802        Setup.setDropManifestMessageFormat(format);
803        // save local message format
804        Setup.setLocalPrefix(localPrefix.getText());
805        format = new String[localMessageList.size()];
806        for (int i = 0; i < localMessageList.size(); i++) {
807            JComboBox<?> cb = localMessageList.get(i);
808            format[i] = (String) cb.getSelectedItem();
809        }
810        Setup.setLocalManifestMessageFormat(format);
811        // save switch list car pick up message format
812        Setup.setSwitchListPickupCarPrefix(switchListPickupCarPrefix.getText());
813        format = new String[switchListCarPickupMessageList.size()];
814        for (int i = 0; i < switchListCarPickupMessageList.size(); i++) {
815            JComboBox<?> cb = switchListCarPickupMessageList.get(i);
816            format[i] = (String) cb.getSelectedItem();
817        }
818        Setup.setPickupSwitchListMessageFormat(format);
819        // save switch list car drop message format
820        Setup.setSwitchListDropCarPrefix(switchListDropCarPrefix.getText());
821        format = new String[switchListCarDropMessageList.size()];
822        for (int i = 0; i < switchListCarDropMessageList.size(); i++) {
823            JComboBox<?> cb = switchListCarDropMessageList.get(i);
824            format[i] = (String) cb.getSelectedItem();
825        }
826        Setup.setDropSwitchListMessageFormat(format);
827        // save switch list local message format
828        Setup.setSwitchListLocalPrefix(switchListLocalPrefix.getText());
829        format = new String[switchListLocalMessageList.size()];
830        for (int i = 0; i < switchListLocalMessageList.size(); i++) {
831            JComboBox<?> cb = switchListLocalMessageList.get(i);
832            format[i] = (String) cb.getSelectedItem();
833        }
834        Setup.setLocalSwitchListMessageFormat(format);
835        // hazardous comment
836        Setup.setHazardousMsg(hazardousTextField.getText());
837        // misplaced car comment
838        Setup.setMiaComment(
839                TrainCommon.formatColorString(commentTextArea.getText(), missingCarColorChooser.getColor()));
840        Setup.setSwitchListFormatSameAsManifest(formatSwitchListCheckBox.isSelected());
841        Setup.setPrintLocationCommentsEnabled(printLocCommentsCheckBox.isSelected());
842        Setup.setPrintRouteCommentsEnabled(printRouteCommentsCheckBox.isSelected());
843        Setup.setPrintLoadsAndEmptiesEnabled(printLoadsEmptiesCheckBox.isSelected());
844        Setup.setPrintCabooseLoadEnabled(printCabooseLoadCheckBox.isSelected());
845        Setup.setPrintPassengerLoadEnabled(printPassengerLoadCheckBox.isSelected());
846        Setup.set12hrFormatEnabled(use12hrFormatCheckBox.isSelected());
847        Setup.setPrintValidEnabled(printValidCheckBox.isSelected());
848        Setup.setSortByTrackNameEnabled(sortByTrackCheckBox.isSelected());
849        Setup.setPrintNoPageBreaksEnabled(noPageBreaksCheckBox.isSelected());
850        Setup.setPrintPageHeaderEnabled(printPageHeaderCheckBox.isSelected());
851        Setup.setPrintHeadersEnabled(printHeadersCheckBox.isSelected());
852        Setup.setPrintTrainScheduleNameEnabled(printTrainScheduleNameCheckBox.isSelected());
853        Setup.setPrintTruncateManifestEnabled(truncateCheckBox.isSelected());
854        Setup.setUseDepartureTimeEnabled(manifestDepartureTimeCheckBox.isSelected());
855        Setup.setManifestEditorEnabled(editManifestCheckBox.isSelected());
856        Setup.setPrintTrackSummaryEnabled(trackSummaryCheckBox.isSelected());
857        Setup.setUseSwitchListDepartureTimeEnabled(switchListDepartureTimeCheckBox.isSelected());
858        Setup.setSwitchListRouteLocationCommentEnabled(routeLocationCheckBox.isSelected());
859        Setup.setGroupCarMoves(groupCarMovesCheckBox.isSelected());
860        Setup.setPrintLocoLast(printLocoLastCheckBox.isSelected());
861
862        // reload combo boxes if tab changed
863        boolean oldTabEnabled = Setup.isTabEnabled();
864        Setup.setTabEnabled(tabFormatCheckBox.isSelected());
865        if (oldTabEnabled ^ Setup.isTabEnabled()) {
866            loadFormatComboBox();
867        }
868
869        // recreate all train manifests
870        InstanceManager.getDefault(TrainManager.class).setTrainsModified();
871
872        InstanceManager.getDefault(OperationsSetupXml.class).writeOperationsFile();
873    }
874
875    @Override
876    public boolean isDirty() {
877        if (!Setup.getFontName().equals(fontComboBox.getSelectedItem()) ||
878                Setup.getManifestFontSize() != (Integer) fontSizeComboBox.getSelectedItem() ||
879                Setup.getPrintDuplexSides() != printDuplexComboBox.getSelectedItem() ||
880                !Setup.getManifestOrientation().equals(manifestOrientationComboBox.getSelectedItem()) ||
881                !Setup.getSwitchListOrientation().equals(switchListOrientationComboBox.getSelectedItem()) ||
882                !Setup.getManifestFormat().equals(manifestFormatComboBox.getSelectedItem()) ||
883                !Setup.getDropEngineColor().equals(dropEngineColorChooser.getColor()) ||
884                !Setup.getPickupEngineColor().equals(pickupEngineColorChooser.getColor()) ||
885                !Setup.getDropColor().equals(dropColorChooser.getColor()) ||
886                !Setup.getPickupColor().equals(pickupColorChooser.getColor()) ||
887                !Setup.getLocalColor().equals(localColorChooser.getColor()) ||
888                !Setup.getHazardousMsg().equals(hazardousTextField.getText()) ||
889                !Setup.getMiaComment().equals(
890                        TrainCommon.formatColorString(commentTextArea.getText(), missingCarColorChooser.getColor())) ||
891                Setup.isSwitchListFormatSameAsManifest() != formatSwitchListCheckBox.isSelected() ||
892                Setup.isPrintLocationCommentsEnabled() != printLocCommentsCheckBox.isSelected() ||
893                Setup.isPrintRouteCommentsEnabled() != printRouteCommentsCheckBox.isSelected() ||
894                Setup.isPrintLoadsAndEmptiesEnabled() != printLoadsEmptiesCheckBox.isSelected() ||
895                Setup.isPrintCabooseLoadEnabled() != printCabooseLoadCheckBox.isSelected() ||
896                Setup.isPrintPassengerLoadEnabled() != printPassengerLoadCheckBox.isSelected() ||
897                Setup.is12hrFormatEnabled() != use12hrFormatCheckBox.isSelected() ||
898                Setup.isPrintValidEnabled() != printValidCheckBox.isSelected() ||
899                Setup.isSortByTrackNameEnabled() != sortByTrackCheckBox.isSelected() ||
900                Setup.isPrintNoPageBreaksEnabled() != noPageBreaksCheckBox.isSelected() ||
901                Setup.isPrintHeadersEnabled() != printHeadersCheckBox.isSelected() ||
902                Setup.isPrintPageHeaderEnabled() != printPageHeaderCheckBox.isSelected() ||
903                Setup.isPrintTrainScheduleNameEnabled() != printTrainScheduleNameCheckBox.isSelected() ||
904                Setup.isPrintTruncateManifestEnabled() != truncateCheckBox.isSelected() ||
905                Setup.isUseDepartureTimeEnabled() != manifestDepartureTimeCheckBox.isSelected() ||
906                Setup.isManifestEditorEnabled() != editManifestCheckBox.isSelected() ||
907                Setup.isSwitchListRouteLocationCommentEnabled() != routeLocationCheckBox.isSelected() ||
908                Setup.isPrintTrackSummaryEnabled() != trackSummaryCheckBox.isSelected() ||
909                Setup.isUseSwitchListDepartureTimeEnabled() != switchListDepartureTimeCheckBox.isSelected() ||
910                Setup.isGroupCarMovesEnabled() != groupCarMovesCheckBox.isSelected() ||
911                Setup.isPrintLocoLastEnabled() != printLocoLastCheckBox.isSelected() ||
912                Setup.isTabEnabled() != tabFormatCheckBox.isSelected()) {
913            return true;
914        }
915        // engine pick up message format
916        String[] format = new String[enginePickupMessageList.size()];
917        for (int i = 0; i < enginePickupMessageList.size(); i++) {
918            JComboBox<?> cb = enginePickupMessageList.get(i);
919            format[i] = (String) cb.getSelectedItem();
920        }
921        if (!Setup.getPickupEnginePrefix().equals(pickupEngPrefix.getText()) ||
922                !Arrays.equals(Setup.getPickupEngineMessageFormat(), format)) {
923            return true;
924        }
925        // engine drop message format
926        format = new String[engineDropMessageList.size()];
927        for (int i = 0; i < engineDropMessageList.size(); i++) {
928            JComboBox<?> cb = engineDropMessageList.get(i);
929            format[i] = (String) cb.getSelectedItem();
930        }
931        if (!Setup.getDropEnginePrefix().equals(dropEngPrefix.getText()) ||
932                !Arrays.equals(Setup.getDropEngineMessageFormat(), format)) {
933            return true;
934        }
935        // car pick up message format
936        format = new String[carPickupMessageList.size()];
937        for (int i = 0; i < carPickupMessageList.size(); i++) {
938            JComboBox<?> cb = carPickupMessageList.get(i);
939            format[i] = (String) cb.getSelectedItem();
940        }
941        if (!Setup.getPickupCarPrefix().equals(this.pickupCarPrefix.getText()) ||
942                !Arrays.equals(Setup.getPickupManifestMessageFormat(), format)) {
943            return true;
944        }
945        // car drop message format
946        format = new String[carDropMessageList.size()];
947        for (int i = 0; i < carDropMessageList.size(); i++) {
948            JComboBox<?> cb = carDropMessageList.get(i);
949            format[i] = (String) cb.getSelectedItem();
950        }
951        if (!Setup.getDropCarPrefix().equals(this.dropCarPrefix.getText()) ||
952                !Arrays.equals(Setup.getDropManifestMessageFormat(), format)) {
953            return true;
954        }
955        // local message format
956        format = new String[localMessageList.size()];
957        for (int i = 0; i < localMessageList.size(); i++) {
958            JComboBox<?> cb = localMessageList.get(i);
959            format[i] = (String) cb.getSelectedItem();
960        }
961        if (!Setup.getLocalPrefix().equals(this.localPrefix.getText()) ||
962                !Arrays.equals(Setup.getLocalManifestMessageFormat(), format)) {
963            return true;
964        }
965        // switch list car pick up message format
966        format = new String[switchListCarPickupMessageList.size()];
967        for (int i = 0; i < switchListCarPickupMessageList.size(); i++) {
968            JComboBox<?> cb = switchListCarPickupMessageList.get(i);
969            format[i] = (String) cb.getSelectedItem();
970        }
971        if (!Setup.getSwitchListPickupCarPrefix().equals(this.switchListPickupCarPrefix.getText()) ||
972                !Arrays.equals(Setup.getPickupSwitchListMessageFormat(), format)) {
973            return true;
974        }
975        // switch list car drop message format
976        format = new String[switchListCarDropMessageList.size()];
977        for (int i = 0; i < switchListCarDropMessageList.size(); i++) {
978            JComboBox<?> cb = switchListCarDropMessageList.get(i);
979            format[i] = (String) cb.getSelectedItem();
980        }
981        if (!Setup.getSwitchListDropCarPrefix().equals(this.switchListDropCarPrefix.getText()) ||
982                !Arrays.equals(Setup.getDropSwitchListMessageFormat(), format)) {
983            return true;
984        }
985        // switch list local message format
986        format = new String[switchListLocalMessageList.size()];
987        for (int i = 0; i < switchListLocalMessageList.size(); i++) {
988            JComboBox<?> cb = switchListLocalMessageList.get(i);
989            format[i] = (String) cb.getSelectedItem();
990        }
991        return !Setup.getSwitchListLocalPrefix().equals(this.switchListLocalPrefix.getText()) ||
992                !Arrays.equals(Setup.getLocalSwitchListMessageFormat(), format);
993    }
994
995    @Override
996    public void propertyChange(java.beans.PropertyChangeEvent e) {
997        if (Control.SHOW_PROPERTY) {
998            log.debug("Property change: ({}) old: ({}) new: ({})", e.getPropertyName(), e.getOldValue(),
999                    e.getNewValue());
1000        }
1001        if (e.getPropertyName().equals(Setup.REAL_TIME_PROPERTY_CHANGE)) {
1002            trackSummaryCheckBox.setEnabled(Setup.isSwitchListRealTime());
1003        }
1004    }
1005
1006    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(PrintOptionPanel.class);
1007
1008}