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