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