001package jmri.jmrit.operations.setup;
002
003import java.awt.Color;
004import java.io.IOException;
005import java.util.*;
006
007import javax.swing.JComboBox;
008
009import org.jdom2.Element;
010import org.slf4j.Logger;
011import org.slf4j.LoggerFactory;
012
013import jmri.*;
014import jmri.beans.PropertyChangeSupport;
015import jmri.jmris.AbstractOperationsServer;
016import jmri.jmrit.operations.rollingstock.RollingStockLogger;
017import jmri.jmrit.operations.trains.TrainLogger;
018import jmri.jmrit.operations.trains.TrainManagerXml;
019import jmri.util.ColorUtil;
020import jmri.util.swing.JmriColorChooser;
021import jmri.web.server.WebServerPreferences;
022
023/**
024 * Operations settings.
025 *
026 * @author Daniel Boudreau Copyright (C) 2008, 2010, 2012, 2014
027 */
028public class Setup extends PropertyChangeSupport implements InstanceManagerAutoDefault, Disposable {
029
030    public static final String NONE = "";
031
032    // scale ratios from NMRA
033    private static final int Z_RATIO = 220;
034    private static final int N_RATIO = 160;
035    private static final int TT_RATIO = 120;
036    private static final int OO_RATIO = 76; // actual ratio 76.2
037    private static final int HO_RATIO = 87;
038    private static final int S_RATIO = 64;
039    private static final int O_RATIO = 48;
040    private static final int G_RATIO = 32; // NMRA #1
041
042    // initial weight in milli ounces from NMRA
043    private static final int Z_INITIAL_WEIGHT = 364; // not specified by NMRA
044    private static final int N_INITIAL_WEIGHT = 500;
045    private static final int TT_INITIAL_WEIGHT = 750;
046    private static final int HOn3_INITIAL_WEIGHT = 750;
047    private static final int OO_INITIAL_WEIGHT = 750; // not specified by NMRA
048    private static final int HO_INITIAL_WEIGHT = 1000;
049    private static final int Sn3_INITIAL_WEIGHT = 1000;
050    private static final int S_INITIAL_WEIGHT = 2000;
051    private static final int On3_INITIAL_WEIGHT = 1500;
052    private static final int O_INITIAL_WEIGHT = 5000;
053    private static final int G_INITIAL_WEIGHT = 10000; // not specified by NMRA
054
055    // additional weight in milli ounces from NMRA
056    private static final int Z_ADD_WEIGHT = 100; // not specified by NMRA
057    private static final int N_ADD_WEIGHT = 150;
058    private static final int TT_ADD_WEIGHT = 375;
059    private static final int HOn3_ADD_WEIGHT = 375;
060    private static final int OO_ADD_WEIGHT = 500; // not specified by NMRA
061    private static final int HO_ADD_WEIGHT = 500;
062    private static final int Sn3_ADD_WEIGHT = 500;
063    private static final int S_ADD_WEIGHT = 500;
064    private static final int On3_ADD_WEIGHT = 750;
065    private static final int O_ADD_WEIGHT = 1000;
066    private static final int G_ADD_WEIGHT = 2000; // not specified by NMRA
067
068    // actual weight to tons conversion ratios (based on 40' boxcar at ~80 tons)
069    private static final int Z_RATIO_TONS = 130;
070    private static final int N_RATIO_TONS = 80;
071    private static final int TT_RATIO_TONS = 36;
072    private static final int HOn3_RATIO_TONS = 20;
073    private static final int OO_RATIO_TONS = 20;
074    private static final int HO_RATIO_TONS = 20; // 20 tons per ounce
075    private static final int Sn3_RATIO_TONS = 16;
076    private static final int S_RATIO_TONS = 14;
077    private static final int On3_RATIO_TONS = 8;
078    private static final int O_RATIO_TONS = 5;
079    private static final int G_RATIO_TONS = 2;
080
081    public static final int Z_SCALE = 1;
082    public static final int N_SCALE = 2;
083    public static final int TT_SCALE = 3;
084    public static final int HOn3_SCALE = 4;
085    public static final int OO_SCALE = 5;
086    public static final int HO_SCALE = 6;
087    public static final int Sn3_SCALE = 7;
088    public static final int S_SCALE = 8;
089    public static final int On3_SCALE = 9;
090    public static final int O_SCALE = 10;
091    public static final int G_SCALE = 11; // NMRA #1
092
093    public static final int EAST = 1; // train direction serviced by this location
094    public static final int WEST = 2;
095    public static final int NORTH = 4;
096    public static final int SOUTH = 8;
097
098    public static final String EAST_DIR = Bundle.getMessage("East");
099    public static final String WEST_DIR = Bundle.getMessage("West");
100    public static final String NORTH_DIR = Bundle.getMessage("North");
101    public static final String SOUTH_DIR = Bundle.getMessage("South");
102
103    public static final String DESCRIPTIVE = Bundle.getMessage("Descriptive"); // Car types
104    public static final String AAR = Bundle.getMessage("ArrCodes"); // Car types
105
106    public static final String MONOSPACED = Bundle.getMessage("Monospaced"); // default printer font
107
108    public static final String STANDARD_FORMAT = Bundle.getMessage("StandardFormat");
109    public static final String TWO_COLUMN_FORMAT = Bundle.getMessage("TwoColumnFormat");
110    public static final String TWO_COLUMN_TRACK_FORMAT = Bundle.getMessage("TwoColumnTrackFormat");
111
112    public static final String PORTRAIT = Bundle.getMessage("Portrait");
113    public static final String LANDSCAPE = Bundle.getMessage("Landscape");
114    public static final String HALFPAGE = Bundle.getMessage("HalfPage");
115    public static final String HANDHELD = Bundle.getMessage("HandHeld");
116
117    public static final String PAGE_NORMAL = Bundle.getMessage("PageNormal");
118    public static final String PAGE_PER_TRAIN = Bundle.getMessage("PagePerTrain");
119    public static final String PAGE_PER_VISIT = Bundle.getMessage("PagePerVisit");
120
121    public static final String BUILD_REPORT_MINIMAL = "1";
122    public static final String BUILD_REPORT_NORMAL = "3";
123    public static final String BUILD_REPORT_DETAILED = "5";
124    public static final String BUILD_REPORT_VERY_DETAILED = "7";
125
126    // the following are converted to English spelling when storing to file, see KEYS below
127    public static final String ROAD = Bundle.getMessage("Road"); // the supported message format options
128    public static final String NUMBER = Bundle.getMessage("Number");
129    public static final String TYPE = Bundle.getMessage("Type");
130    public static final String MODEL = Bundle.getMessage("Model");
131    public static final String LENGTH = Bundle.getMessage("Length");
132    public static final String WEIGHT = Bundle.getMessage("Weight");
133    public static final String LOAD = Bundle.getMessage("Load");
134    public static final String LOAD_TYPE = Bundle.getMessage("Load_Type");
135    public static final String COLOR = Bundle.getMessage("Color");
136    public static final String TRACK = Bundle.getMessage("Track");
137    public static final String DESTINATION = Bundle.getMessage("Destination");
138    public static final String DEST_TRACK = Bundle.getMessage("Dest&Track");
139    public static final String FINAL_DEST = Bundle.getMessage("Final_Dest");
140    public static final String FINAL_DEST_TRACK = Bundle.getMessage("FD&Track");
141    public static final String LOCATION = Bundle.getMessage("Location");
142    public static final String CONSIST = Bundle.getMessage("Consist");
143    public static final String DCC_ADDRESS = Bundle.getMessage("DCC_Address");
144    public static final String KERNEL = Bundle.getMessage("Kernel");
145    public static final String KERNEL_SIZE = Bundle.getMessage("Kernel_Size");
146    public static final String OWNER = Bundle.getMessage("Owner");
147    public static final String DIVISION = Bundle.getMessage("Division");
148    public static final String RWE = Bundle.getMessage("RWE");
149    public static final String COMMENT = Bundle.getMessage("Comment");
150    public static final String DROP_COMMENT = Bundle.getMessage("SetOut_Msg");
151    public static final String PICKUP_COMMENT = Bundle.getMessage("PickUp_Msg");
152    public static final String HAZARDOUS = Bundle.getMessage("Hazardous");
153    public static final String BLANK = " "; // blank has be a character or a space
154    public static final String TAB = Bundle.getMessage("Tab"); // used to tab out in tabular mode
155    public static final String TAB2 = Bundle.getMessage("Tab2");
156    public static final String TAB3 = Bundle.getMessage("Tab3");
157    
158    public static final String BOX = " [ ] "; // NOI18N
159
160    // these are for the utility printing when using tabs
161    public static final String NO_ROAD = "NO_ROAD"; // NOI18N
162    public static final String NO_NUMBER = "NO_NUMBER"; // NOI18N
163    public static final String NO_COLOR = "NO_COLOR"; // NOI18N
164
165    // truncated manifests
166    public static final String NO_DESTINATION = "NO_DESTINATION"; // NOI18N
167    public static final String NO_DEST_TRACK = "NO_DEST_TRACK"; // NOI18N
168    public static final String NO_LOCATION = "NO_LOCATION"; // NOI18N
169    public static final String NO_TRACK = "NO_TRACK"; // NOI18N
170
171    // Unit of Length
172    public static final String FEET = Bundle.getMessage("Feet");
173    public static final String METER = Bundle.getMessage("Meter");
174    public static final String FEET_ABV = Bundle.getMessage("FeetAbbreviation");
175    public static final String METER_ABV = Bundle.getMessage("MeterAbbreviation");
176
177    private static final String[] CAR_ATTRIBUTES = { ROAD, NUMBER, TYPE, LENGTH, WEIGHT, LOAD, LOAD_TYPE, HAZARDOUS,
178            COLOR, KERNEL, KERNEL_SIZE, OWNER, DIVISION, TRACK, LOCATION, DESTINATION, DEST_TRACK, FINAL_DEST, FINAL_DEST_TRACK,
179            COMMENT, DROP_COMMENT, PICKUP_COMMENT, RWE };
180    
181    private static final String[] ENGINE_ATTRIBUTES = { ROAD, NUMBER, TYPE, MODEL, LENGTH, WEIGHT, CONSIST, OWNER,
182            TRACK, LOCATION, DESTINATION, COMMENT, DCC_ADDRESS };
183    /*
184     * The print Manifest and switch list user selectable options are stored in the
185     * xml file using the English translations.
186     */
187    private static final String[] KEYS = {"Road", "Number", "Type", "Model", "Length", "Weight", "Load", "Load_Type",
188            "Color", "Track", "Destination", "Dest&Track", "Final_Dest", "FD&Track", "Location", "Consist",
189            "DCC_Address", "Kernel", "Kernel_Size", "Owner", "Division", "RWE", "Comment", "SetOut_Msg", "PickUp_Msg",
190            "Hazardous", "Tab", "Tab2", "Tab3"};
191
192    private int scale = HO_SCALE; // Default scale
193    private int ratio = HO_RATIO;
194    private int ratioTons = HO_RATIO_TONS;
195    private int initWeight = HO_INITIAL_WEIGHT;
196    private int addWeight = HO_ADD_WEIGHT;
197    private String railroadName = NONE;
198    private int traindir = EAST + WEST + NORTH + SOUTH;
199    private int maxTrainLength = 1000; // maximum train length
200    private int maxEngineSize = 6; // maximum number of engines that can be assigned to a train
201    private int horsePowerPerTon = 1; // Horsepower per ton
202    private int carMoves = 5; // default number of moves when creating a route
203    private String carTypes = DESCRIPTIVE;
204    private String ownerName = NONE;
205    private String fontName = MONOSPACED;
206    private int manifestFontSize = 10;
207    private int buildReportFontSize = 10;
208    private String manifestOrientation = PORTRAIT;
209    private String switchListOrientation = PORTRAIT;
210    private boolean printHeader = true;
211    private Color pickupColor = Color.black;
212    private Color dropColor = Color.black;
213    private Color localColor = Color.black;
214    private String[] pickupEngineMessageFormat = { ROAD, NUMBER, BLANK, MODEL, BLANK, BLANK, LOCATION, COMMENT };
215    private String[] dropEngineMessageFormat = { ROAD, NUMBER, BLANK, MODEL, BLANK, BLANK, DESTINATION, COMMENT };
216    private String[] pickupManifestMessageFormat = { ROAD, NUMBER, TYPE, LENGTH, COLOR, LOAD, HAZARDOUS, LOCATION,
217            COMMENT, PICKUP_COMMENT };
218    private String[] dropManifestMessageFormat = { ROAD, NUMBER, TYPE, LENGTH, COLOR, LOAD, HAZARDOUS, DESTINATION,
219            COMMENT, DROP_COMMENT };
220    private String[] localManifestMessageFormat = { ROAD, NUMBER, TYPE, LENGTH, COLOR, LOAD, HAZARDOUS, LOCATION,
221            DESTINATION, COMMENT };
222    private String[] pickupSwitchListMessageFormat = { ROAD, NUMBER, TYPE, LENGTH, COLOR, LOAD, HAZARDOUS, LOCATION,
223            COMMENT, PICKUP_COMMENT };
224    private String[] dropSwitchListMessageFormat = { ROAD, NUMBER, TYPE, LENGTH, COLOR, LOAD, HAZARDOUS, DESTINATION,
225            COMMENT, DROP_COMMENT };
226    private String[] localSwitchListMessageFormat = { ROAD, NUMBER, TYPE, LENGTH, COLOR, LOAD, HAZARDOUS, LOCATION,
227            DESTINATION, COMMENT };
228    private String[] missingCarMessageFormat = { ROAD, NUMBER, TYPE, LENGTH, COLOR, COMMENT };
229    private String pickupEnginePrefix = BOX + Bundle.getMessage("PickUpPrefix");
230    private String dropEnginePrefix = BOX + Bundle.getMessage("SetOutPrefix");
231    private String pickupCarPrefix = BOX + Bundle.getMessage("PickUpPrefix");
232    private String dropCarPrefix = BOX + Bundle.getMessage("SetOutPrefix");
233    private String localPrefix = BOX + Bundle.getMessage("LocalCarPrefix");
234    private String switchListPickupCarPrefix = BOX + Bundle.getMessage("PickUpPrefix");
235    private String switchListDropCarPrefix = BOX + Bundle.getMessage("SetOutPrefix");
236    private String switchListLocalPrefix = BOX + Bundle.getMessage("LocalCarPrefix");
237    private String miaComment = Bundle.getMessage("misplacedCars");
238    private String hazardousMsg = "(" + Bundle.getMessage("Hazardous") + ")";
239    private String logoURL = NONE;
240    private String panelName = "Panel"; // NOI18N
241    private String buildReportLevel = BUILD_REPORT_VERY_DETAILED;
242    private String routerBuildReportLevel = BUILD_REPORT_NORMAL;
243    private int carSwitchTime = 3; // how long it takes to move a car in minutes
244    private int travelTime = 4; // how long it takes a train to move from one location to another in minutes
245    private String yearModeled = NONE; // year being modeled
246    private String lengthUnit = FEET;
247    private String lengthUnitAbv = FEET_ABV;
248    private String iconNorthColor = NONE;
249    private String iconSouthColor = NONE;
250    private String iconEastColor = NONE;
251    private String iconWestColor = NONE;
252    private String iconLocalColor = NONE;
253    private String iconTerminateColor = NONE;
254
255    private boolean tab = false; // when true, tab out manifest and switch lists
256    private int tab1CharLength = Control.max_len_string_attibute;
257    private int tab2CharLength = 6; // arbitrary lengths
258    private int tab3CharLength = 8;
259
260    private String manifestFormat = STANDARD_FORMAT;
261    private boolean manifestEditorEnabled = false; // when true use text editor to view build report
262    private boolean switchListSameManifest = true; // when true switch list format is the same as the manifest
263    private boolean manifestTruncated = false; // when true, manifest is truncated if switch list is available
264    private boolean manifestDepartureTime = false; // when true, manifest shows train's departure time
265    private boolean switchListDepartureTime = false; // when true, switch list shows train's departure time
266    private boolean switchListRouteComment = true; // when true, switch list have route location comments
267    private boolean trackSummary = true; // when true, print switch list track summary
268
269    private boolean switchListRealTime = true; // when true switch list only show work for built trains
270    private boolean switchListAllTrains = true; // when true show all trains that visit the location
271    private String switchListPageFormat = PAGE_NORMAL; // how switch lists pages are printed
272
273    private boolean buildReportEditorEnabled = false; // when true use text editor to view build report
274    private boolean buildReportIndentEnabled = true; // when true use text editor to view build report
275    private boolean buildReportAlwaysPreviewEnabled = false; // when true use text editor to view build report
276
277    private boolean enableTrainIconXY = true;
278    private boolean appendTrainIcon = false; // when true, append engine number to train name
279    private String setupComment = NONE;
280
281    private boolean mainMenuEnabled = false; // when true add operations menu to main menu bar
282    private boolean closeWindowOnSave = false; // when true, close window when save button is activated
283    private boolean autoSave = true; // when true, automatically save files if modified
284    private boolean autoBackup = true; // when true, automatically backup files
285    private boolean enableValue = false; // when true show value fields for rolling stock
286    private String labelValue = Bundle.getMessage("Value");
287    private boolean enableRfid = false; // when true show RFID fields for rolling stock
288    private String labelRfid = Bundle.getMessage("RFID");
289
290    private boolean carRoutingEnabled = true; // when true enable car routing
291    private boolean carRoutingYards = true; // when true enable car routing via yard tracks
292    private boolean carRoutingStaging = false; // when true staging tracks can be used for car routing
293    private boolean forwardToYardEnabled = true; // when true forward car to yard if track is full
294    private boolean onlyActiveTrains = false; // when true only active trains are used for routing
295    private boolean checkCarDestination = false; // when true check car's track for valid destination
296
297    private boolean carLogger = false; // when true car logger is enabled
298    private boolean engineLogger = false; // when true engine logger is enabled
299    private boolean trainLogger = false; // when true train logger is enabled
300    private boolean saveTrainManifests = false; // when true save previous train manifest
301
302    private boolean aggressiveBuild = false; // when true subtract car length from track reserve length
303    private int numberPasses = 2; // the number of passes in train builder
304    private boolean allowLocalInterchangeMoves = false; // when true local C/I to C/I moves are allowed
305    private boolean allowLocalYardMoves = false; // when true local yard to yard moves are allowed
306    private boolean allowLocalSpurMoves = false; // when true local spur to spur moves are allowed
307
308    private boolean trainIntoStagingCheck = true; // staging track must accept train's rolling stock types and roads
309    private boolean trackImmediatelyAvail = false; // when true staging track is available for other trains
310    private boolean allowCarsReturnStaging = false; // allow cars on a turn to return to staging if necessary (prevent
311                                                    // build failure)
312    private boolean promptFromStaging = false; // prompt user to specify which departure staging track to use
313    private boolean promptToStaging = false; // prompt user to specify which arrival staging track to use
314    private boolean tryNormalModeStaging = true; // try normal build if route length failure using aggressive
315
316    private boolean generateCsvManifest = false; // when true generate csv manifest
317    private boolean generateCsvSwitchList = false; // when true generate csv switch list
318    private boolean enableVsdPhysicalLocations = false;
319
320    private boolean printLocationComments = false; // when true print location comments on the manifest
321    private boolean printRouteComments = false; // when true print route comments on the manifest
322    private boolean printLoadsAndEmpties = false; // when true print Loads and Empties on the manifest
323    private boolean printTrainScheduleName = false; // when true print train schedule name on manifests and switch lists
324    private boolean use12hrFormat = false; // when true use 12hr rather than 24hr format
325    private boolean printValid = true; // when true print out the valid time and date
326    private boolean sortByTrack = false; // when true manifest work is sorted by track names
327    private boolean printHeaders = false; // when true add headers to manifest and switch lists
328
329    private boolean printCabooseLoad = false; // when true print caboose load
330    private boolean printPassengerLoad = false; // when true print passenger car load
331    private boolean showTrackMoves = false; // when true show track moves in table
332
333    // property changes
334    public static final String SWITCH_LIST_CSV_PROPERTY_CHANGE = "setupSwitchListCSVChange"; // NOI18N
335    public static final String MANIFEST_CSV_PROPERTY_CHANGE = "setupManifestCSVChange"; // NOI18N
336    public static final String REAL_TIME_PROPERTY_CHANGE = "setupSwitchListRealTime"; // NOI18N
337    public static final String SHOW_TRACK_MOVES_PROPERTY_CHANGE = "setupShowTrackMoves"; // NOI18N
338    public static final String SAVE_TRAIN_MANIFEST_PROPERTY_CHANGE = "saveTrainManifestChange"; // NOI18N
339    public static final String ALLOW_CARS_TO_RETURN_PROPERTY_CHANGE = "allowCarsToReturnChange"; // NOI18N
340    public static final String TRAIN_DIRECTION_PROPERTY_CHANGE = "setupTrainDirectionChange"; // NOI18N
341    public static final String ROUTING_STAGING_PROPERTY_CHANGE = "setupRoutingStagingChange"; // NOI18N
342
343    public static boolean isMainMenuEnabled() {
344        InstanceManager.getDefault(OperationsSetupXml.class); // load file
345        return getDefault().mainMenuEnabled;
346    }
347
348    public static void setMainMenuEnabled(boolean enabled) {
349        getDefault().mainMenuEnabled = enabled;
350    }
351
352    public static boolean isCloseWindowOnSaveEnabled() {
353        return getDefault().closeWindowOnSave;
354    }
355
356    public static void setCloseWindowOnSaveEnabled(boolean enabled) {
357        getDefault().closeWindowOnSave = enabled;
358    }
359
360    public static boolean isAutoSaveEnabled() {
361        return getDefault().autoSave;
362    }
363
364    public static void setAutoSaveEnabled(boolean enabled) {
365        getDefault().autoSave = enabled;
366        if (enabled) {
367            AutoSave.start();
368        } else {
369            AutoSave.stop();
370        }
371    }
372
373    public static boolean isAutoBackupEnabled() {
374        return getDefault().autoBackup;
375    }
376
377    public static void setAutoBackupEnabled(boolean enabled) {
378        // Do an autoBackup only if we are changing the setting from false to
379        // true.
380        if (enabled && !getDefault().autoBackup) {
381            try {
382                new AutoBackup().autoBackup();
383            } catch (IOException ex) {
384                log.debug("Autobackup after setting AutoBackup flag true", ex);
385            }
386        }
387
388        getDefault().autoBackup = enabled;
389    }
390
391    public static boolean isValueEnabled() {
392        return getDefault().enableValue;
393    }
394
395    public static void setValueEnabled(boolean enabled) {
396        getDefault().enableValue = enabled;
397    }
398
399    public static String getValueLabel() {
400        return getDefault().labelValue;
401    }
402
403    public static void setValueLabel(String label) {
404        getDefault().labelValue = label;
405    }
406
407    public static boolean isRfidEnabled() {
408        return getDefault().enableRfid;
409    }
410
411    public static void setRfidEnabled(boolean enabled) {
412        getDefault().enableRfid = enabled;
413    }
414
415    public static String getRfidLabel() {
416        return getDefault().labelRfid;
417    }
418
419    public static void setRfidLabel(String label) {
420        getDefault().labelRfid = label;
421    }
422
423    public static boolean isCarRoutingEnabled() {
424        return getDefault().carRoutingEnabled;
425    }
426
427    public static void setCarRoutingEnabled(boolean enabled) {
428        getDefault().carRoutingEnabled = enabled;
429    }
430
431    public static boolean isCarRoutingViaYardsEnabled() {
432        return getDefault().carRoutingYards;
433    }
434
435    public static void setCarRoutingViaYardsEnabled(boolean enabled) {
436        getDefault().carRoutingYards = enabled;
437    }
438
439    public static boolean isCarRoutingViaStagingEnabled() {
440        return getDefault().carRoutingStaging;
441    }
442
443    public static void setCarRoutingViaStagingEnabled(boolean enabled) {
444        boolean old = isCarRoutingViaStagingEnabled();
445        getDefault().carRoutingStaging = enabled;
446        setDirtyAndFirePropertyChange(ROUTING_STAGING_PROPERTY_CHANGE, old, enabled);
447    }
448
449    public static boolean isForwardToYardEnabled() {
450        return getDefault().forwardToYardEnabled;
451    }
452
453    public static void setForwardToYardEnabled(boolean enabled) {
454        getDefault().forwardToYardEnabled = enabled;
455    }
456
457    public static boolean isOnlyActiveTrainsEnabled() {
458        return getDefault().onlyActiveTrains;
459    }
460
461    public static void setOnlyActiveTrainsEnabled(boolean enabled) {
462        getDefault().onlyActiveTrains = enabled;
463    }
464
465    /**
466     * When true, router checks that the car's destination is serviced by departure
467     * track. Very restrictive, not recommended.
468     * 
469     * @return true if enabled.
470     */
471    public static boolean isCheckCarDestinationEnabled() {
472        return getDefault().checkCarDestination;
473    }
474
475    public static void setCheckCarDestinationEnabled(boolean enabled) {
476        getDefault().checkCarDestination = enabled;
477    }
478
479    public static boolean isBuildAggressive() {
480        return getDefault().aggressiveBuild;
481    }
482
483    public static void setBuildAggressive(boolean enabled) {
484        getDefault().aggressiveBuild = enabled;
485    }
486
487    public static int getNumberPasses() {
488        return getDefault().numberPasses;
489    }
490
491    public static void setNumberPasses(int number) {
492        getDefault().numberPasses = number;
493    }
494
495    public static boolean isLocalInterchangeMovesEnabled() {
496        return getDefault().allowLocalInterchangeMoves;
497    }
498
499    public static void setLocalInterchangeMovesEnabled(boolean enabled) {
500        getDefault().allowLocalInterchangeMoves = enabled;
501    }
502
503    public static boolean isLocalYardMovesEnabled() {
504        return getDefault().allowLocalYardMoves;
505    }
506
507    public static void setLocalYardMovesEnabled(boolean enabled) {
508        getDefault().allowLocalYardMoves = enabled;
509    }
510
511    public static boolean isLocalSpurMovesEnabled() {
512        return getDefault().allowLocalSpurMoves;
513    }
514
515    public static void setLocalSpurMovesEnabled(boolean enabled) {
516        getDefault().allowLocalSpurMoves = enabled;
517    }
518
519    public static boolean isStagingTrainCheckEnabled() {
520        return getDefault().trainIntoStagingCheck;
521    }
522
523    /**
524     * Controls staging track selection, when true, the terminus staging track has
525     * to have the same characteristics as the train.
526     *
527     * @param enabled when true, the terminal staging track must service the same
528     *                car types, loads, etc. as the train
529     */
530    public static void setStagingTrainCheckEnabled(boolean enabled) {
531        getDefault().trainIntoStagingCheck = enabled;
532    }
533
534    public static boolean isStagingTrackImmediatelyAvail() {
535        return getDefault().trackImmediatelyAvail;
536    }
537
538    public static void setStagingTrackImmediatelyAvail(boolean enabled) {
539        getDefault().trackImmediatelyAvail = enabled;
540    }
541
542    /**
543     * allow cars to return to the same staging location if no other options
544     * (tracks) are available. Also available on a per train basis.
545     * 
546     * @return true if cars are allowed to depart and return to same staging
547     *         location
548     */
549    public static boolean isStagingAllowReturnEnabled() {
550        return getDefault().allowCarsReturnStaging;
551    }
552
553    public static void setStagingAllowReturnEnabled(boolean enabled) {
554        boolean old = getDefault().allowCarsReturnStaging;
555        getDefault().allowCarsReturnStaging = enabled;
556        setDirtyAndFirePropertyChange(ALLOW_CARS_TO_RETURN_PROPERTY_CHANGE, old, enabled);
557    }
558
559    public static boolean isStagingPromptFromEnabled() {
560        return getDefault().promptFromStaging;
561    }
562
563    public static void setStagingPromptFromEnabled(boolean enabled) {
564        getDefault().promptFromStaging = enabled;
565    }
566
567    public static boolean isStagingPromptToEnabled() {
568        return getDefault().promptToStaging;
569    }
570
571    public static void setStagingPromptToEnabled(boolean enabled) {
572        getDefault().promptToStaging = enabled;
573    }
574
575    public static boolean isStagingTryNormalBuildEnabled() {
576        return getDefault().tryNormalModeStaging;
577    }
578
579    public static void setStagingTryNormalBuildEnabled(boolean enabled) {
580        getDefault().tryNormalModeStaging = enabled;
581    }
582
583    public static boolean isGenerateCsvManifestEnabled() {
584        return getDefault().generateCsvManifest;
585    }
586
587    public static void setGenerateCsvManifestEnabled(boolean enabled) {
588        boolean old = getDefault().generateCsvManifest;
589        getDefault().generateCsvManifest = enabled;
590        if (enabled && !old) {
591            InstanceManager.getDefault(TrainManagerXml.class).createDefaultCsvManifestDirectory();
592        }
593        setDirtyAndFirePropertyChange(MANIFEST_CSV_PROPERTY_CHANGE, old, enabled);
594    }
595
596    public static boolean isGenerateCsvSwitchListEnabled() {
597        return getDefault().generateCsvSwitchList;
598    }
599
600    public static void setGenerateCsvSwitchListEnabled(boolean enabled) {
601        boolean old = getDefault().generateCsvSwitchList;
602        getDefault().generateCsvSwitchList = enabled;
603        if (enabled && !old) {
604            InstanceManager.getDefault(TrainManagerXml.class).createDefaultCsvSwitchListDirectory();
605        }
606        setDirtyAndFirePropertyChange(SWITCH_LIST_CSV_PROPERTY_CHANGE, old, enabled);
607    }
608
609    public static boolean isVsdPhysicalLocationEnabled() {
610        return getDefault().enableVsdPhysicalLocations;
611    }
612
613    public static void setVsdPhysicalLocationEnabled(boolean enabled) {
614        getDefault().enableVsdPhysicalLocations = enabled;
615    }
616
617    public static String getRailroadName() {
618        if (getDefault().railroadName.isEmpty()) {
619            return InstanceManager.getDefault(WebServerPreferences.class).getRailroadName();
620        }
621        return getDefault().railroadName;
622    }
623
624    public static void setRailroadName(String name) {
625        String old = getDefault().railroadName;
626        getDefault().railroadName = name;
627        if (old == null || !old.equals(name)) {
628            setDirtyAndFirePropertyChange("Railroad Name Change", old, name); // NOI18N
629        }
630    }
631
632    public static String getHazardousMsg() {
633        return getDefault().hazardousMsg;
634    }
635
636    public static void setHazardousMsg(String message) {
637        getDefault().hazardousMsg = message;
638    }
639
640    public static String getMiaComment() {
641        return getDefault().miaComment;
642    }
643
644    public static void setMiaComment(String comment) {
645        getDefault().miaComment = comment;
646    }
647
648    public static void setTrainDirection(int direction) {
649        int old = getDefault().traindir;
650        getDefault().traindir = direction;
651        if (old != direction) {
652            setDirtyAndFirePropertyChange(TRAIN_DIRECTION_PROPERTY_CHANGE, old, direction);
653        }
654    }
655
656    public static int getTrainDirection() {
657        return getDefault().traindir;
658    }
659
660    public static void setMaxTrainLength(int length) {
661        getDefault().maxTrainLength = length;
662    }
663
664    public static int getMaxTrainLength() {
665        return getDefault().maxTrainLength;
666    }
667
668    public static void setMaxNumberEngines(int value) {
669        getDefault().maxEngineSize = value;
670    }
671
672    public static int getMaxNumberEngines() {
673        return getDefault().maxEngineSize;
674    }
675
676    public static void setHorsePowerPerTon(int value) {
677        getDefault().horsePowerPerTon = value;
678    }
679
680    public static int getHorsePowerPerTon() {
681        return getDefault().horsePowerPerTon;
682    }
683
684    public static void setCarMoves(int moves) {
685        getDefault().carMoves = moves;
686    }
687
688    public static int getCarMoves() {
689        return getDefault().carMoves;
690    }
691
692    public static String getPanelName() {
693        return getDefault().panelName;
694    }
695
696    public static void setPanelName(String name) {
697        getDefault().panelName = name;
698    }
699
700    public static String getLengthUnit() {
701        return getDefault().lengthUnit;
702    }
703
704    /**
705     * Abbreviation unit of length
706     * 
707     * @return symbol for feet or meter
708     */
709    public static String getLengthUnitAbv() {
710        return getDefault().lengthUnitAbv;
711    }
712
713    public static void setLengthUnit(String unit) {
714        getDefault().lengthUnit = unit;
715        if (unit.equals(FEET)) {
716            getDefault().lengthUnitAbv = FEET_ABV;
717        } else {
718            getDefault().lengthUnitAbv = METER_ABV;
719        }
720    }
721
722    public static String getYearModeled() {
723        return getDefault().yearModeled;
724    }
725
726    public static void setYearModeled(String year) {
727        getDefault().yearModeled = year;
728    }
729
730    public static String getCarTypes() {
731        return getDefault().carTypes;
732    }
733
734    public static void setCarTypes(String types) {
735        getDefault().carTypes = types;
736    }
737
738    public static void setTrainIconCordEnabled(boolean enable) {
739        getDefault().enableTrainIconXY = enable;
740    }
741
742    public static boolean isTrainIconCordEnabled() {
743        return getDefault().enableTrainIconXY;
744    }
745
746    public static void setTrainIconAppendEnabled(boolean enable) {
747        getDefault().appendTrainIcon = enable;
748    }
749
750    public static boolean isTrainIconAppendEnabled() {
751        return getDefault().appendTrainIcon;
752    }
753
754    public static void setComment(String comment) {
755        getDefault().setupComment = comment;
756    }
757
758    public static String getComment() {
759        return getDefault().setupComment;
760    }
761
762    public static void setBuildReportLevel(String level) {
763        getDefault().buildReportLevel = level;
764    }
765
766    public static String getBuildReportLevel() {
767        return getDefault().buildReportLevel;
768    }
769
770    /**
771     * Sets the report level for the car router.
772     * 
773     * @param level BUILD_REPORT_NORMAL, BUILD_REPORT_DETAILED,
774     *              BUILD_REPORT_VERY_DETAILED
775     */
776    public static void setRouterBuildReportLevel(String level) {
777        getDefault().routerBuildReportLevel = level;
778    }
779
780    public static String getRouterBuildReportLevel() {
781        return getDefault().routerBuildReportLevel;
782    }
783
784    public static void setManifestEditorEnabled(boolean enable) {
785        getDefault().manifestEditorEnabled = enable;
786    }
787
788    public static boolean isManifestEditorEnabled() {
789        return getDefault().manifestEditorEnabled;
790    }
791
792    public static void setBuildReportEditorEnabled(boolean enable) {
793        getDefault().buildReportEditorEnabled = enable;
794    }
795
796    public static boolean isBuildReportEditorEnabled() {
797        return getDefault().buildReportEditorEnabled;
798    }
799
800    public static void setBuildReportIndentEnabled(boolean enable) {
801        getDefault().buildReportIndentEnabled = enable;
802    }
803
804    public static boolean isBuildReportIndentEnabled() {
805        return getDefault().buildReportIndentEnabled;
806    }
807
808    public static void setBuildReportAlwaysPreviewEnabled(boolean enable) {
809        getDefault().buildReportAlwaysPreviewEnabled = enable;
810    }
811
812    public static boolean isBuildReportAlwaysPreviewEnabled() {
813        return getDefault().buildReportAlwaysPreviewEnabled;
814    }
815
816    public static void setSwitchListFormatSameAsManifest(boolean b) {
817        getDefault().switchListSameManifest = b;
818    }
819
820    public static boolean isSwitchListFormatSameAsManifest() {
821        return getDefault().switchListSameManifest;
822    }
823
824    public static void setPrintTrackSummaryEnabled(boolean b) {
825        getDefault().trackSummary = b;
826    }
827
828    public static boolean isPrintTrackSummaryEnabled() {
829        return getDefault().trackSummary;
830    }
831
832    public static void setSwitchListRouteLocationCommentEnabled(boolean b) {
833        getDefault().switchListRouteComment = b;
834    }
835
836    public static boolean isSwitchListRouteLocationCommentEnabled() {
837        return getDefault().switchListRouteComment;
838    }
839
840    public static void setSwitchListRealTime(boolean b) {
841        boolean old = getDefault().switchListRealTime;
842        getDefault().switchListRealTime = b;
843        setDirtyAndFirePropertyChange(REAL_TIME_PROPERTY_CHANGE, old, b);
844    }
845
846    public static boolean isSwitchListRealTime() {
847        return getDefault().switchListRealTime;
848    }
849
850    public static void setSwitchListAllTrainsEnabled(boolean b) {
851        boolean old = getDefault().switchListAllTrains;
852        getDefault().switchListAllTrains = b;
853        setDirtyAndFirePropertyChange("Switch List All Trains", old, b); // NOI18N
854    }
855
856    /**
857     * When true switch list shows all trains visiting a location, even if the train
858     * doesn't have any work at that location. When false, switch lists only report
859     * a train if it has work at the location.
860     *
861     * @return When true show all trains visiting a location.
862     */
863    public static boolean isSwitchListAllTrainsEnabled() {
864        return getDefault().switchListAllTrains;
865    }
866
867    /**
868     * Used to determine if there's spaces or form feed between trains and locations
869     * when printing switch lists. see getSwitchListPageFormatComboBox()
870     *
871     * @param format PAGE_NORMAL, PAGE_PER_TRAIN, or PAGE_PER_VISIT
872     */
873    public static void setSwitchListPageFormat(String format) {
874        getDefault().switchListPageFormat = format;
875    }
876
877    public static String getSwitchListPageFormat() {
878        return getDefault().switchListPageFormat;
879    }
880
881    public static void setPrintTruncateManifestEnabled(boolean b) {
882        getDefault().manifestTruncated = b;
883    }
884
885    public static boolean isPrintTruncateManifestEnabled() {
886        return getDefault().manifestTruncated;
887    }
888
889    public static void setUseDepartureTimeEnabled(boolean b) {
890        getDefault().manifestDepartureTime = b;
891    }
892
893    public static boolean isUseDepartureTimeEnabled() {
894        return getDefault().manifestDepartureTime;
895    }
896
897    public static void setUseSwitchListDepartureTimeEnabled(boolean b) {
898        getDefault().switchListDepartureTime = b;
899    }
900
901    public static boolean isUseSwitchListDepartureTimeEnabled() {
902        return getDefault().switchListDepartureTime;
903    }
904
905    public static void setPrintLocationCommentsEnabled(boolean enable) {
906        getDefault().printLocationComments = enable;
907    }
908
909    public static boolean isPrintLocationCommentsEnabled() {
910        return getDefault().printLocationComments;
911    }
912
913    public static void setPrintRouteCommentsEnabled(boolean enable) {
914        getDefault().printRouteComments = enable;
915    }
916
917    public static boolean isPrintRouteCommentsEnabled() {
918        return getDefault().printRouteComments;
919    }
920
921    public static void setPrintLoadsAndEmptiesEnabled(boolean enable) {
922        getDefault().printLoadsAndEmpties = enable;
923    }
924
925    public static boolean isPrintLoadsAndEmptiesEnabled() {
926        return getDefault().printLoadsAndEmpties;
927    }
928
929    public static void setPrintTrainScheduleNameEnabled(boolean enable) {
930        getDefault().printTrainScheduleName = enable;
931    }
932
933    public static boolean isPrintTrainScheduleNameEnabled() {
934        return getDefault().printTrainScheduleName;
935    }
936
937    public static void set12hrFormatEnabled(boolean enable) {
938        getDefault().use12hrFormat = enable;
939    }
940
941    public static boolean is12hrFormatEnabled() {
942        return getDefault().use12hrFormat;
943    }
944
945    public static void setPrintValidEnabled(boolean enable) {
946        getDefault().printValid = enable;
947    }
948
949    public static boolean isPrintValidEnabled() {
950        return getDefault().printValid;
951    }
952
953    public static void setSortByTrackNameEnabled(boolean enable) {
954        getDefault().sortByTrack = enable;
955    }
956
957    /**
958     * when true manifest work is sorted by track names.
959     * 
960     * @return true if work at a location is to be sorted by track names.
961     */
962    public static boolean isSortByTrackNameEnabled() {
963        return getDefault().sortByTrack;
964    }
965
966    public static void setPrintHeadersEnabled(boolean enable) {
967        getDefault().printHeaders = enable;
968    }
969
970    public static boolean isPrintHeadersEnabled() {
971        return getDefault().printHeaders;
972    }
973
974    public static void setPrintCabooseLoadEnabled(boolean enable) {
975        getDefault().printCabooseLoad = enable;
976    }
977
978    public static boolean isPrintCabooseLoadEnabled() {
979        return getDefault().printCabooseLoad;
980    }
981
982    public static void setPrintPassengerLoadEnabled(boolean enable) {
983        getDefault().printPassengerLoad = enable;
984    }
985
986    public static boolean isPrintPassengerLoadEnabled() {
987        return getDefault().printPassengerLoad;
988    }
989
990    public static void setShowTrackMovesEnabled(boolean enable) {
991        boolean old = getDefault().showTrackMoves;
992        getDefault().showTrackMoves = enable;
993        setDirtyAndFirePropertyChange(SHOW_TRACK_MOVES_PROPERTY_CHANGE, old, enable);
994    }
995
996    public static boolean isShowTrackMovesEnabled() {
997        return getDefault().showTrackMoves;
998    }
999
1000    public static void setSwitchTime(int minutes) {
1001        getDefault().carSwitchTime = minutes;
1002    }
1003
1004    public static int getSwitchTime() {
1005        return getDefault().carSwitchTime;
1006    }
1007
1008    public static void setTravelTime(int minutes) {
1009        getDefault().travelTime = minutes;
1010    }
1011
1012    public static int getTravelTime() {
1013        return getDefault().travelTime;
1014    }
1015
1016    public static void setTrainIconColorNorth(String color) {
1017        getDefault().iconNorthColor = color;
1018    }
1019
1020    public static String getTrainIconColorNorth() {
1021        return getDefault().iconNorthColor;
1022    }
1023
1024    public static void setTrainIconColorSouth(String color) {
1025        getDefault().iconSouthColor = color;
1026    }
1027
1028    public static String getTrainIconColorSouth() {
1029        return getDefault().iconSouthColor;
1030    }
1031
1032    public static void setTrainIconColorEast(String color) {
1033        getDefault().iconEastColor = color;
1034    }
1035
1036    public static String getTrainIconColorEast() {
1037        return getDefault().iconEastColor;
1038    }
1039
1040    public static void setTrainIconColorWest(String color) {
1041        getDefault().iconWestColor = color;
1042    }
1043
1044    public static String getTrainIconColorWest() {
1045        return getDefault().iconWestColor;
1046    }
1047
1048    public static void setTrainIconColorLocal(String color) {
1049        getDefault().iconLocalColor = color;
1050    }
1051
1052    public static String getTrainIconColorLocal() {
1053        return getDefault().iconLocalColor;
1054    }
1055
1056    public static void setTrainIconColorTerminate(String color) {
1057        getDefault().iconTerminateColor = color;
1058    }
1059
1060    public static String getTrainIconColorTerminate() {
1061        return getDefault().iconTerminateColor;
1062    }
1063
1064    public static String getFontName() {
1065        return getDefault().fontName;
1066    }
1067
1068    public static void setFontName(String name) {
1069        getDefault().fontName = name;
1070    }
1071
1072    public static int getManifestFontSize() {
1073        return getDefault().manifestFontSize;
1074    }
1075
1076    public static void setManifestFontSize(int size) {
1077        getDefault().manifestFontSize = size;
1078    }
1079
1080    public static boolean isPrintPageHeaderEnabled() {
1081        return getDefault().printHeader;
1082    }
1083
1084    public static void setPrintPageHeaderEnabled(boolean enable) {
1085        getDefault().printHeader = enable;
1086    }
1087
1088    public static int getBuildReportFontSize() {
1089        return getDefault().buildReportFontSize;
1090    }
1091
1092    public static void setBuildReportFontSize(int size) {
1093        getDefault().buildReportFontSize = size;
1094    }
1095
1096    public static String getManifestOrientation() {
1097        return getDefault().manifestOrientation;
1098    }
1099
1100    public static void setManifestOrientation(String orientation) {
1101        getDefault().manifestOrientation = orientation;
1102    }
1103
1104    public static String getSwitchListOrientation() {
1105        if (isSwitchListFormatSameAsManifest()) {
1106            return getDefault().manifestOrientation;
1107        } else {
1108            return getDefault().switchListOrientation;
1109        }
1110    }
1111
1112    public static void setSwitchListOrientation(String orientation) {
1113        getDefault().switchListOrientation = orientation;
1114    }
1115
1116    public static boolean isTabEnabled() {
1117        return getDefault().tab;
1118    }
1119
1120    public static void setTabEnabled(boolean enable) {
1121        getDefault().tab = enable;
1122    }
1123
1124    public static int getTab1Length() {
1125        return getDefault().tab1CharLength;
1126    }
1127
1128    public static void setTab1length(int length) {
1129        getDefault().tab1CharLength = length;
1130    }
1131
1132    public static int getTab2Length() {
1133        return getDefault().tab2CharLength;
1134    }
1135
1136    public static void setTab2length(int length) {
1137        getDefault().tab2CharLength = length;
1138    }
1139
1140    public static int getTab3Length() {
1141        return getDefault().tab3CharLength;
1142    }
1143
1144    public static void setTab3length(int length) {
1145        getDefault().tab3CharLength = length;
1146    }
1147
1148    public static String getManifestFormat() {
1149        return getDefault().manifestFormat;
1150    }
1151
1152    /**
1153     * Sets the format for manifests
1154     * 
1155     * @param format STANDARD_FORMAT, TWO_COLUMN_FORMAT, or TWO_COLUMN_TRACK_FORMAT
1156     */
1157    public static void setManifestFormat(String format) {
1158        getDefault().manifestFormat = format;
1159    }
1160
1161    public static boolean isCarLoggerEnabled() {
1162        return getDefault().carLogger;
1163    }
1164
1165    public static void setCarLoggerEnabled(boolean enable) {
1166        getDefault().carLogger = enable;
1167        InstanceManager.getDefault(RollingStockLogger.class).enableCarLogging(enable);
1168    }
1169
1170    public static boolean isEngineLoggerEnabled() {
1171        return getDefault().engineLogger;
1172    }
1173
1174    public static void setEngineLoggerEnabled(boolean enable) {
1175        getDefault().engineLogger = enable;
1176        InstanceManager.getDefault(RollingStockLogger.class).enableEngineLogging(enable);
1177    }
1178
1179    public static boolean isTrainLoggerEnabled() {
1180        return getDefault().trainLogger;
1181    }
1182
1183    public static void setTrainLoggerEnabled(boolean enable) {
1184        getDefault().trainLogger = enable;
1185        InstanceManager.getDefault(TrainLogger.class).enableTrainLogging(enable);
1186    }
1187
1188    public static boolean isSaveTrainManifestsEnabled() {
1189        return getDefault().saveTrainManifests;
1190    }
1191
1192    public static void setSaveTrainManifestsEnabled(boolean enable) {
1193        boolean old = getDefault().saveTrainManifests;
1194        getDefault().saveTrainManifests = enable;
1195        setDirtyAndFirePropertyChange(SAVE_TRAIN_MANIFEST_PROPERTY_CHANGE, old, enable);
1196    }
1197
1198    public static String getPickupEnginePrefix() {
1199        return getDefault().pickupEnginePrefix;
1200    }
1201
1202    public static void setPickupEnginePrefix(String prefix) {
1203        getDefault().pickupEnginePrefix = prefix;
1204    }
1205
1206    public static String getDropEnginePrefix() {
1207        return getDefault().dropEnginePrefix;
1208    }
1209
1210    public static void setDropEnginePrefix(String prefix) {
1211        getDefault().dropEnginePrefix = prefix;
1212    }
1213
1214    public static String getPickupCarPrefix() {
1215        return getDefault().pickupCarPrefix;
1216    }
1217
1218    public static void setPickupCarPrefix(String prefix) {
1219        getDefault().pickupCarPrefix = prefix;
1220    }
1221
1222    public static String getDropCarPrefix() {
1223        return getDefault().dropCarPrefix;
1224    }
1225
1226    public static void setDropCarPrefix(String prefix) {
1227        getDefault().dropCarPrefix = prefix;
1228    }
1229
1230    public static String getLocalPrefix() {
1231        return getDefault().localPrefix;
1232    }
1233
1234    public static void setLocalPrefix(String prefix) {
1235        getDefault().localPrefix = prefix;
1236    }
1237
1238    public static int getManifestPrefixLength() {
1239        int maxLength = getPickupEnginePrefix().length();
1240        if (getDropEnginePrefix().length() > maxLength) {
1241            maxLength = getDropEnginePrefix().length();
1242        }
1243        if (getPickupCarPrefix().length() > maxLength) {
1244            maxLength = getPickupCarPrefix().length();
1245        }
1246        if (getDropCarPrefix().length() > maxLength) {
1247            maxLength = getDropCarPrefix().length();
1248        }
1249        if (getLocalPrefix().length() > maxLength) {
1250            maxLength = getLocalPrefix().length();
1251        }
1252        return maxLength;
1253    }
1254
1255    public static String getSwitchListPickupCarPrefix() {
1256        if (isSwitchListFormatSameAsManifest()) {
1257            return getDefault().pickupCarPrefix;
1258        } else {
1259            return getDefault().switchListPickupCarPrefix;
1260        }
1261    }
1262
1263    public static void setSwitchListPickupCarPrefix(String prefix) {
1264        getDefault().switchListPickupCarPrefix = prefix;
1265    }
1266
1267    public static String getSwitchListDropCarPrefix() {
1268        if (isSwitchListFormatSameAsManifest()) {
1269            return getDefault().dropCarPrefix;
1270        } else {
1271            return getDefault().switchListDropCarPrefix;
1272        }
1273    }
1274
1275    public static void setSwitchListDropCarPrefix(String prefix) {
1276        getDefault().switchListDropCarPrefix = prefix;
1277    }
1278
1279    public static String getSwitchListLocalPrefix() {
1280        if (isSwitchListFormatSameAsManifest()) {
1281            return getDefault().localPrefix;
1282        } else {
1283            return getDefault().switchListLocalPrefix;
1284        }
1285    }
1286
1287    public static void setSwitchListLocalPrefix(String prefix) {
1288        getDefault().switchListLocalPrefix = prefix;
1289    }
1290
1291    public static int getSwitchListPrefixLength() {
1292        int maxLength = getPickupEnginePrefix().length();
1293        if (getDropEnginePrefix().length() > maxLength) {
1294            maxLength = getDropEnginePrefix().length();
1295        }
1296        if (getSwitchListPickupCarPrefix().length() > maxLength) {
1297            maxLength = getSwitchListPickupCarPrefix().length();
1298        }
1299        if (getSwitchListDropCarPrefix().length() > maxLength) {
1300            maxLength = getSwitchListDropCarPrefix().length();
1301        }
1302        if (getSwitchListLocalPrefix().length() > maxLength) {
1303            maxLength = getSwitchListLocalPrefix().length();
1304        }
1305        return maxLength;
1306    }
1307
1308    public static String[] getEngineAttributes() {
1309        return ENGINE_ATTRIBUTES.clone();
1310    }
1311
1312    public static String[] getPickupEngineMessageFormat() {
1313        return getDefault().pickupEngineMessageFormat.clone();
1314    }
1315
1316    public static void setPickupEngineMessageFormat(String[] format) {
1317        getDefault().pickupEngineMessageFormat = format;
1318    }
1319
1320    public static String[] getDropEngineMessageFormat() {
1321        return getDefault().dropEngineMessageFormat.clone();
1322    }
1323
1324    public static void setDropEngineMessageFormat(String[] format) {
1325        getDefault().dropEngineMessageFormat = format;
1326    }
1327
1328    public static String[] getCarAttributes() {
1329        return CAR_ATTRIBUTES.clone();
1330    }
1331
1332    public static String[] getPickupManifestMessageFormat() {
1333        return getDefault().pickupManifestMessageFormat.clone();
1334    }
1335
1336    public static void setPickupManifestMessageFormat(String[] format) {
1337        getDefault().pickupManifestMessageFormat = format;
1338    }
1339
1340    public static String[] getDropManifestMessageFormat() {
1341        return getDefault().dropManifestMessageFormat.clone();
1342    }
1343
1344    public static void setDropManifestMessageFormat(String[] format) {
1345        getDefault().dropManifestMessageFormat = format;
1346    }
1347
1348    public static String[] getLocalManifestMessageFormat() {
1349        return getDefault().localManifestMessageFormat.clone();
1350    }
1351
1352    public static void setLocalManifestMessageFormat(String[] format) {
1353        getDefault().localManifestMessageFormat = format;
1354    }
1355
1356    public static String[] getMissingCarMessageFormat() {
1357        return getDefault().missingCarMessageFormat.clone();
1358    }
1359
1360    public static void setMissingCarMessageFormat(String[] format) {
1361        getDefault().missingCarMessageFormat = format;
1362    }
1363
1364    public static String[] getPickupSwitchListMessageFormat() {
1365        if (isSwitchListFormatSameAsManifest()) {
1366            return getDefault().pickupManifestMessageFormat.clone();
1367        } else {
1368            return getDefault().pickupSwitchListMessageFormat.clone();
1369        }
1370    }
1371
1372    public static void setPickupSwitchListMessageFormat(String[] format) {
1373        getDefault().pickupSwitchListMessageFormat = format;
1374    }
1375
1376    public static String[] getDropSwitchListMessageFormat() {
1377        if (isSwitchListFormatSameAsManifest()) {
1378            return getDefault().dropManifestMessageFormat.clone();
1379        } else {
1380            return getDefault().dropSwitchListMessageFormat.clone();
1381        }
1382    }
1383
1384    public static void setDropSwitchListMessageFormat(String[] format) {
1385        getDefault().dropSwitchListMessageFormat = format;
1386    }
1387
1388    public static String[] getLocalSwitchListMessageFormat() {
1389        if (isSwitchListFormatSameAsManifest()) {
1390            return getDefault().localManifestMessageFormat.clone();
1391        } else {
1392            return getDefault().localSwitchListMessageFormat.clone();
1393        }
1394    }
1395
1396    public static void setLocalSwitchListMessageFormat(String[] format) {
1397        getDefault().localSwitchListMessageFormat = format;
1398    }
1399
1400    /**
1401     * Gets the manifest format for utility cars. The car's road, number, and color
1402     * are not printed.
1403     *
1404     * @return Utility car format
1405     */
1406    public static String[] getPickupUtilityManifestMessageFormat() {
1407        return createUitlityCarMessageFormat(getPickupManifestMessageFormat());
1408    }
1409
1410    public static String[] getDropUtilityManifestMessageFormat() {
1411        return createUitlityCarMessageFormat(getDropManifestMessageFormat());
1412    }
1413
1414    public static String[] getLocalUtilityManifestMessageFormat() {
1415        return createUitlityCarMessageFormat(getLocalManifestMessageFormat());
1416    }
1417
1418    public static String[] getPickupUtilitySwitchListMessageFormat() {
1419        return createUitlityCarMessageFormat(getPickupSwitchListMessageFormat());
1420    }
1421
1422    public static String[] getDropUtilitySwitchListMessageFormat() {
1423        return createUitlityCarMessageFormat(getDropSwitchListMessageFormat());
1424    }
1425
1426    public static String[] getLocalUtilitySwitchListMessageFormat() {
1427        return createUitlityCarMessageFormat(getLocalSwitchListMessageFormat());
1428    }
1429
1430    private static String[] createUitlityCarMessageFormat(String[] format) {
1431        // remove car's road, number, color
1432        for (int i = 0; i < format.length; i++) {
1433            if (format[i].equals(ROAD)) {
1434                format[i] = NO_ROAD;
1435            } else if (format[i].equals(NUMBER)) {
1436                format[i] = NO_NUMBER;
1437            } else if (format[i].equals(COLOR)) {
1438                format[i] = NO_COLOR;
1439            }
1440        }
1441        return format;
1442    }
1443
1444    public static String[] getPickupTruncatedManifestMessageFormat() {
1445        return createTruncatedManifestMessageFormat(getPickupManifestMessageFormat());
1446    }
1447
1448    public static String[] getDropTruncatedManifestMessageFormat() {
1449        return createTruncatedManifestMessageFormat(getDropManifestMessageFormat());
1450    }
1451
1452    public static String[] createTruncatedManifestMessageFormat(String[] format) {
1453        // remove car's destination and location
1454        for (int i = 0; i < format.length; i++) {
1455            if (format[i].equals(DESTINATION)) {
1456                format[i] = NO_DESTINATION;
1457            } else if (format[i].equals(DEST_TRACK)) {
1458                format[i] = NO_DEST_TRACK;
1459            } else if (format[i].equals(LOCATION)) {
1460                format[i] = NO_LOCATION;
1461            } else if (format[i].equals(TRACK)) {
1462                format[i] = NO_TRACK;
1463            }
1464        }
1465        return format;
1466    }
1467
1468    public static String[] getPickupTwoColumnByTrackManifestMessageFormat() {
1469        return createTwoColumnByTrackPickupMessageFormat(getPickupManifestMessageFormat());
1470    }
1471
1472    public static String[] getPickupTwoColumnByTrackSwitchListMessageFormat() {
1473        return createTwoColumnByTrackPickupMessageFormat(getPickupSwitchListMessageFormat());
1474    }
1475
1476    public static String[] getPickupTwoColumnByTrackUtilityManifestMessageFormat() {
1477        return createTwoColumnByTrackPickupMessageFormat(getPickupUtilityManifestMessageFormat());
1478    }
1479
1480    public static String[] getPickupTwoColumnByTrackUtilitySwitchListMessageFormat() {
1481        return createTwoColumnByTrackPickupMessageFormat(getPickupUtilitySwitchListMessageFormat());
1482    }
1483
1484    private static String[] createTwoColumnByTrackPickupMessageFormat(String[] format) {
1485        for (int i = 0; i < format.length; i++) {
1486            if (format[i].equals(LOCATION)) {
1487                format[i] = BLANK;
1488            } else if (format[i].equals(TRACK)) {
1489                format[i] = BLANK;
1490            }
1491        }
1492        return format;
1493    }
1494
1495    public static String[] getDropTwoColumnByTrackManifestMessageFormat() {
1496        return createTwoColumnByTrackDropMessageFormat(getDropManifestMessageFormat());
1497    }
1498
1499    public static String[] getDropTwoColumnByTrackSwitchListMessageFormat() {
1500        return createTwoColumnByTrackDropMessageFormat(getDropSwitchListMessageFormat());
1501    }
1502
1503    public static String[] getDropTwoColumnByTrackUtilityManifestMessageFormat() {
1504        return createTwoColumnByTrackDropMessageFormat(getDropUtilityManifestMessageFormat());
1505    }
1506
1507    public static String[] getDropTwoColumnByTrackUtilitySwitchListMessageFormat() {
1508        return createTwoColumnByTrackDropMessageFormat(getDropUtilitySwitchListMessageFormat());
1509    }
1510
1511    private static String[] createTwoColumnByTrackDropMessageFormat(String[] format) {
1512        for (int i = 0; i < format.length; i++) {
1513            if (format[i].equals(DESTINATION)) {
1514                format[i] = BLANK;
1515            } else if (format[i].equals(TRACK)) {
1516                format[i] = BLANK;
1517            }
1518        }
1519        return format;
1520    }
1521
1522    public static String getDropTextColor() {
1523        return ColorUtil.colorToColorName(getDefault().dropColor);
1524    }
1525
1526    public static void setDropTextColor(String color) {
1527        setDropColor(ColorUtil.stringToColor(color));
1528    }
1529
1530    public static void setDropColor(Color c) {
1531        getDefault().dropColor = c;
1532        JmriColorChooser.addRecentColor(c);
1533    }
1534
1535    public static String getPickupTextColor() {
1536        return ColorUtil.colorToColorName(getDefault().pickupColor);
1537    }
1538
1539    public static void setPickupTextColor(String color) {
1540        setPickupColor(ColorUtil.stringToColor(color));
1541    }
1542
1543    public static void setPickupColor(Color c) {
1544        getDefault().pickupColor = c;
1545        JmriColorChooser.addRecentColor(c);
1546    }
1547
1548    public static String getLocalTextColor() {
1549        return ColorUtil.colorToColorName(getDefault().localColor);
1550    }
1551
1552    public static void setLocalTextColor(String color) {
1553        setLocalColor(ColorUtil.stringToColor(color));
1554    }
1555
1556    public static void setLocalColor(Color c) {
1557        getDefault().localColor = c;
1558        JmriColorChooser.addRecentColor(c);
1559    }
1560
1561    public static Color getPickupColor() {
1562        return getDefault().pickupColor;
1563    }
1564
1565    public static Color getDropColor() {
1566        return getDefault().dropColor;
1567    }
1568
1569    public static Color getLocalColor() {
1570        return getDefault().localColor;
1571    }
1572
1573    public static Color getColor(String colorName) {
1574        return ColorUtil.stringToColor(colorName);
1575    }
1576
1577    public static String getManifestLogoURL() {
1578        return getDefault().logoURL;
1579    }
1580
1581    public static void setManifestLogoURL(String pathName) {
1582        getDefault().logoURL = pathName;
1583    }
1584
1585    public static String getOwnerName() {
1586        return getDefault().ownerName;
1587    }
1588
1589    public static void setOwnerName(String name) {
1590        getDefault().ownerName = name;
1591    }
1592
1593    public static int getScaleRatio() {
1594        if (getDefault().scale == 0) {
1595            log.error("Scale not set");
1596        }
1597        return getDefault().ratio;
1598    }
1599
1600    public static int getScaleTonRatio() {
1601        if (getDefault().scale == 0) {
1602            log.error("Scale not set");
1603        }
1604        return getDefault().ratioTons;
1605    }
1606
1607    public static int getInitalWeight() {
1608        if (getDefault().scale == 0) {
1609            log.error("Scale not set");
1610        }
1611        return getDefault().initWeight;
1612    }
1613
1614    public static int getAddWeight() {
1615        if (getDefault().scale == 0) {
1616            log.error("Scale not set");
1617        }
1618        return getDefault().addWeight;
1619    }
1620
1621    public static int getScale() {
1622        return getDefault().scale;
1623    }
1624
1625    public static void setScale(int s) {
1626        getDefault().scale = s;
1627        switch (getDefault().scale) {
1628            case Z_SCALE:
1629                getDefault().ratio = Z_RATIO;
1630                getDefault().initWeight = Z_INITIAL_WEIGHT;
1631                getDefault().addWeight = Z_ADD_WEIGHT;
1632                getDefault().ratioTons = Z_RATIO_TONS;
1633                break;
1634            case N_SCALE:
1635                getDefault().ratio = N_RATIO;
1636                getDefault().initWeight = N_INITIAL_WEIGHT;
1637                getDefault().addWeight = N_ADD_WEIGHT;
1638                getDefault().ratioTons = N_RATIO_TONS;
1639                break;
1640            case TT_SCALE:
1641                getDefault().ratio = TT_RATIO;
1642                getDefault().initWeight = TT_INITIAL_WEIGHT;
1643                getDefault().addWeight = TT_ADD_WEIGHT;
1644                getDefault().ratioTons = TT_RATIO_TONS;
1645                break;
1646            case HOn3_SCALE:
1647                getDefault().ratio = HO_RATIO;
1648                getDefault().initWeight = HOn3_INITIAL_WEIGHT;
1649                getDefault().addWeight = HOn3_ADD_WEIGHT;
1650                getDefault().ratioTons = HOn3_RATIO_TONS;
1651                break;
1652            case OO_SCALE:
1653                getDefault().ratio = OO_RATIO;
1654                getDefault().initWeight = OO_INITIAL_WEIGHT;
1655                getDefault().addWeight = OO_ADD_WEIGHT;
1656                getDefault().ratioTons = OO_RATIO_TONS;
1657                break;
1658            case HO_SCALE:
1659                getDefault().ratio = HO_RATIO;
1660                getDefault().initWeight = HO_INITIAL_WEIGHT;
1661                getDefault().addWeight = HO_ADD_WEIGHT;
1662                getDefault().ratioTons = HO_RATIO_TONS;
1663                break;
1664            case Sn3_SCALE:
1665                getDefault().ratio = S_RATIO;
1666                getDefault().initWeight = Sn3_INITIAL_WEIGHT;
1667                getDefault().addWeight = Sn3_ADD_WEIGHT;
1668                getDefault().ratioTons = Sn3_RATIO_TONS;
1669                break;
1670            case S_SCALE:
1671                getDefault().ratio = S_RATIO;
1672                getDefault().initWeight = S_INITIAL_WEIGHT;
1673                getDefault().addWeight = S_ADD_WEIGHT;
1674                getDefault().ratioTons = S_RATIO_TONS;
1675                break;
1676            case On3_SCALE:
1677                getDefault().ratio = O_RATIO;
1678                getDefault().initWeight = On3_INITIAL_WEIGHT;
1679                getDefault().addWeight = On3_ADD_WEIGHT;
1680                getDefault().ratioTons = On3_RATIO_TONS;
1681                break;
1682            case O_SCALE:
1683                getDefault().ratio = O_RATIO;
1684                getDefault().initWeight = O_INITIAL_WEIGHT;
1685                getDefault().addWeight = O_ADD_WEIGHT;
1686                getDefault().ratioTons = O_RATIO_TONS;
1687                break;
1688            case G_SCALE:
1689                getDefault().ratio = G_RATIO;
1690                getDefault().initWeight = G_INITIAL_WEIGHT;
1691                getDefault().addWeight = G_ADD_WEIGHT;
1692                getDefault().ratioTons = G_RATIO_TONS;
1693                break;
1694            default:
1695                log.error("Unknown scale");
1696        }
1697    }
1698
1699    public static JComboBox<String> getManifestFormatComboBox() {
1700        JComboBox<String> box = new JComboBox<>();
1701        box.addItem(STANDARD_FORMAT);
1702        box.addItem(TWO_COLUMN_FORMAT);
1703        box.addItem(TWO_COLUMN_TRACK_FORMAT);
1704        return box;
1705    }
1706
1707    public static JComboBox<String> getOrientationComboBox() {
1708        JComboBox<String> box = new JComboBox<>();
1709        box.addItem(PORTRAIT);
1710        box.addItem(LANDSCAPE);
1711        box.addItem(HALFPAGE);
1712        box.addItem(HANDHELD);
1713        return box;
1714    }
1715
1716    public static JComboBox<String> getSwitchListPageFormatComboBox() {
1717        JComboBox<String> box = new JComboBox<>();
1718        box.addItem(PAGE_NORMAL);
1719        box.addItem(PAGE_PER_TRAIN);
1720        box.addItem(PAGE_PER_VISIT);
1721        return box;
1722    }
1723
1724    public static JComboBox<String> getEngineMessageComboBox() {
1725        JComboBox<String> box = new JComboBox<>();
1726        box.addItem(BLANK);
1727        for (String attribute : getEngineAttributes()) {
1728            box.addItem(attribute);
1729        }
1730        if (isTabEnabled()) {
1731            box.addItem(TAB);
1732            box.addItem(TAB2);
1733            box.addItem(TAB3);
1734        }
1735        return box;
1736    }
1737
1738    public static JComboBox<String> getCarMessageComboBox() {
1739        JComboBox<String> box = new JComboBox<>();
1740        box.addItem(BLANK);
1741        for (String attribute : getCarAttributes()) {
1742            box.addItem(attribute);
1743        }
1744        if (isTabEnabled()) {
1745            box.addItem(TAB);
1746            box.addItem(TAB2);
1747            box.addItem(TAB3);
1748        }
1749        return box;
1750    }
1751
1752    /**
1753     *
1754     * @return JComboBox loaded with the strings (North, South, East, West) showing
1755     *         the available train directions for this railroad
1756     */
1757    public static JComboBox<String> getTrainDirectionComboBox() {
1758        JComboBox<String> box = new JComboBox<>();
1759        for (String direction : getTrainDirectionList()) {
1760            box.addItem(direction);
1761        }
1762        return box;
1763    }
1764
1765    /**
1766     * Get train directions String format
1767     *
1768     * @return List of valid train directions
1769     */
1770    public static List<String> getTrainDirectionList() {
1771        List<String> directions = new ArrayList<>();
1772        if ((getDefault().traindir & EAST) == EAST) {
1773            directions.add(EAST_DIR);
1774        }
1775        if ((getDefault().traindir & WEST) == WEST) {
1776            directions.add(WEST_DIR);
1777        }
1778        if ((getDefault().traindir & NORTH) == NORTH) {
1779            directions.add(NORTH_DIR);
1780        }
1781        if ((getDefault().traindir & SOUTH) == SOUTH) {
1782            directions.add(SOUTH_DIR);
1783        }
1784        return directions;
1785    }
1786
1787    /**
1788     * Converts binary direction to String direction
1789     *
1790     * @param direction EAST, WEST, NORTH, SOUTH
1791     * @return String representation of a direction
1792     */
1793    public static String getDirectionString(int direction) {
1794        switch (direction) {
1795            case EAST:
1796                return EAST_DIR;
1797            case WEST:
1798                return WEST_DIR;
1799            case NORTH:
1800                return NORTH_DIR;
1801            case SOUTH:
1802                return SOUTH_DIR;
1803            default:
1804                return "unknown"; // NOI18N
1805        }
1806    }
1807
1808    /**
1809     * Converts binary direction to a set of String directions
1810     *
1811     * @param directions EAST, WEST, NORTH, SOUTH
1812     * @return String[] representation of a set of directions
1813     */
1814    public static String[] getDirectionStrings(int directions) {
1815        String[] dir = new String[4];
1816        int i = 0;
1817        if ((directions & EAST) == EAST) {
1818            dir[i++] = EAST_DIR;
1819        }
1820        if ((directions & WEST) == WEST) {
1821            dir[i++] = WEST_DIR;
1822        }
1823        if ((directions & NORTH) == NORTH) {
1824            dir[i++] = NORTH_DIR;
1825        }
1826        if ((directions & SOUTH) == SOUTH) {
1827            dir[i++] = SOUTH_DIR;
1828        }
1829        return dir;
1830    }
1831
1832    /**
1833     * Converts String direction to binary direction
1834     *
1835     * @param direction EAST_DIR WEST_DIR NORTH_DIR SOUTH_DIR
1836     * @return integer representation of a direction
1837     */
1838    public static int getDirectionInt(String direction) {
1839        if (direction.equals(EAST_DIR)) {
1840            return EAST;
1841        } else if (direction.equals(WEST_DIR)) {
1842            return WEST;
1843        } else if (direction.equals(NORTH_DIR)) {
1844            return NORTH;
1845        } else if (direction.equals(SOUTH_DIR)) {
1846            return SOUTH;
1847        } else {
1848            return 0; // return unknown
1849        }
1850    }
1851
1852    // must synchronize changes with operation-config.dtd
1853    public static Element store() {
1854        Element values;
1855        Element e = new Element(Xml.OPERATIONS);
1856
1857        // only store railroad name if it doesn't match the preferences railroad name
1858        if (!InstanceManager.getDefault(WebServerPreferences.class).getRailroadName().equals(getRailroadName())) {
1859            e.addContent(values = new Element(Xml.RAIL_ROAD));
1860            values.setAttribute(Xml.NAME, getRailroadName());
1861        }
1862
1863        e.addContent(values = new Element(Xml.SETUP));
1864        values.setAttribute(Xml.COMMENT, getComment());
1865
1866        e.addContent(values = new Element(Xml.SETTINGS));
1867        values.setAttribute(Xml.MAIN_MENU, isMainMenuEnabled() ? Xml.TRUE : Xml.FALSE);
1868        values.setAttribute(Xml.CLOSE_ON_SAVE, isCloseWindowOnSaveEnabled() ? Xml.TRUE : Xml.FALSE);
1869        values.setAttribute(Xml.AUTO_SAVE, isAutoSaveEnabled() ? Xml.TRUE : Xml.FALSE);
1870        values.setAttribute(Xml.AUTO_BACKUP, isAutoBackupEnabled() ? Xml.TRUE : Xml.FALSE);
1871        values.setAttribute(Xml.TRAIN_DIRECTION, Integer.toString(getTrainDirection()));
1872        values.setAttribute(Xml.TRAIN_LENGTH, Integer.toString(getMaxTrainLength()));
1873        values.setAttribute(Xml.MAX_ENGINES, Integer.toString(getMaxNumberEngines()));
1874        values.setAttribute(Xml.HPT, Integer.toString(getHorsePowerPerTon()));
1875        values.setAttribute(Xml.SCALE, Integer.toString(getScale()));
1876        values.setAttribute(Xml.CAR_TYPES, getCarTypes());
1877        values.setAttribute(Xml.SWITCH_TIME, Integer.toString(getSwitchTime()));
1878        values.setAttribute(Xml.TRAVEL_TIME, Integer.toString(getTravelTime()));
1879        values.setAttribute(Xml.SHOW_VALUE, isValueEnabled() ? Xml.TRUE : Xml.FALSE);
1880        values.setAttribute(Xml.VALUE_LABEL, getValueLabel());
1881        values.setAttribute(Xml.SHOW_RFID, isRfidEnabled() ? Xml.TRUE : Xml.FALSE);
1882        values.setAttribute(Xml.RFID_LABEL, getRfidLabel());
1883        values.setAttribute(Xml.LENGTH_UNIT, getLengthUnit());
1884        values.setAttribute(Xml.YEAR_MODELED, getYearModeled());
1885
1886        e.addContent(values = new Element(Xml.PICKUP_ENG_FORMAT));
1887        storeXmlMessageFormat(values, getPickupEnginePrefix(), getPickupEngineMessageFormat());
1888
1889        e.addContent(values = new Element(Xml.DROP_ENG_FORMAT));
1890        storeXmlMessageFormat(values, getDropEnginePrefix(), getDropEngineMessageFormat());
1891
1892        e.addContent(values = new Element(Xml.PICKUP_CAR_FORMAT));
1893        storeXmlMessageFormat(values, getPickupCarPrefix(), getPickupManifestMessageFormat());
1894
1895        e.addContent(values = new Element(Xml.DROP_CAR_FORMAT));
1896        storeXmlMessageFormat(values, getDropCarPrefix(), getDropManifestMessageFormat());
1897
1898        e.addContent(values = new Element(Xml.LOCAL_FORMAT));
1899        storeXmlMessageFormat(values, getLocalPrefix(), getLocalManifestMessageFormat());
1900
1901        e.addContent(values = new Element(Xml.MISSING_CAR_FORMAT));
1902        storeXmlMessageFormat(values, NONE, getMissingCarMessageFormat());
1903
1904        e.addContent(values = new Element(Xml.SWITCH_LIST));
1905        values.setAttribute(Xml.SAME_AS_MANIFEST, isSwitchListFormatSameAsManifest() ? Xml.TRUE : Xml.FALSE);
1906        values.setAttribute(Xml.REAL_TIME, isSwitchListRealTime() ? Xml.TRUE : Xml.FALSE);
1907        values.setAttribute(Xml.ALL_TRAINS, isSwitchListAllTrainsEnabled() ? Xml.TRUE : Xml.FALSE);
1908
1909        // save switch list format
1910        String format = Xml.PAGE_NORMAL;
1911        if (getSwitchListPageFormat().equals(PAGE_PER_TRAIN)) {
1912            format = Xml.PAGE_PER_TRAIN;
1913            values.setAttribute(Xml.PAGE_MODE, Xml.TRUE); // backwards compatible for versions before 3.11
1914        } else if (getSwitchListPageFormat().equals(PAGE_PER_VISIT)) {
1915            format = Xml.PAGE_PER_VISIT;
1916        }
1917        values.setAttribute(Xml.PAGE_FORMAT, format);
1918
1919        values.setAttribute(Xml.PRINT_ROUTE_LOCATION, isSwitchListRouteLocationCommentEnabled() ? Xml.TRUE : Xml.FALSE);
1920        values.setAttribute(Xml.TRACK_SUMMARY, isPrintTrackSummaryEnabled() ? Xml.TRUE : Xml.FALSE);
1921        values.setAttribute(Xml.USE_DEPARTURE_TIME, isUseSwitchListDepartureTimeEnabled() ? Xml.TRUE : Xml.FALSE);
1922
1923        e.addContent(values = new Element(Xml.SWITCH_LIST_PICKUP_CAR_FORMAT));
1924        storeXmlMessageFormat(values, getSwitchListPickupCarPrefix(), getPickupSwitchListMessageFormat());
1925
1926        e.addContent(values = new Element(Xml.SWITCH_LIST_DROP_CAR_FORMAT));
1927        storeXmlMessageFormat(values, getSwitchListDropCarPrefix(), getDropSwitchListMessageFormat());
1928
1929        e.addContent(values = new Element(Xml.SWITCH_LIST_LOCAL_FORMAT));
1930        storeXmlMessageFormat(values, getSwitchListLocalPrefix(), getLocalSwitchListMessageFormat());
1931
1932        e.addContent(values = new Element(Xml.PANEL));
1933        values.setAttribute(Xml.NAME, getPanelName());
1934        values.setAttribute(Xml.TRAIN_ICONXY, isTrainIconCordEnabled() ? Xml.TRUE : Xml.FALSE);
1935        values.setAttribute(Xml.TRAIN_ICON_APPEND, isTrainIconAppendEnabled() ? Xml.TRUE : Xml.FALSE);
1936
1937        e.addContent(values = new Element(Xml.FONT_NAME));
1938        values.setAttribute(Xml.NAME, getFontName());
1939
1940        e.addContent(values = new Element(Xml.FONT_SIZE));
1941        values.setAttribute(Xml.SIZE, Integer.toString(getManifestFontSize()));
1942
1943        e.addContent(values = new Element(Xml.PAGE_ORIENTATION));
1944        values.setAttribute(Xml.MANIFEST, getManifestOrientation());
1945        values.setAttribute(Xml.SWITCH_LIST, getSwitchListOrientation());
1946
1947        e.addContent(values = new Element(Xml.MANIFEST_COLORS));
1948        values.setAttribute(Xml.DROP_COLOR, getDropTextColor());
1949        values.setAttribute(Xml.PICKUP_COLOR, getPickupTextColor());
1950        values.setAttribute(Xml.LOCAL_COLOR, getLocalTextColor());
1951
1952        e.addContent(values = new Element(Xml.TAB));
1953        values.setAttribute(Xml.ENABLED, isTabEnabled() ? Xml.TRUE : Xml.FALSE);
1954        values.setAttribute(Xml.LENGTH, Integer.toString(getTab1Length()));
1955        values.setAttribute(Xml.TAB2_LENGTH, Integer.toString(getTab2Length()));
1956        values.setAttribute(Xml.TAB3_LENGTH, Integer.toString(getTab3Length()));
1957
1958        e.addContent(values = new Element(Xml.MANIFEST));
1959        values.setAttribute(Xml.PRINT_LOC_COMMENTS, isPrintLocationCommentsEnabled() ? Xml.TRUE : Xml.FALSE);
1960        values.setAttribute(Xml.PRINT_ROUTE_COMMENTS, isPrintRouteCommentsEnabled() ? Xml.TRUE : Xml.FALSE);
1961        values.setAttribute(Xml.PRINT_LOADS_EMPTIES, isPrintLoadsAndEmptiesEnabled() ? Xml.TRUE : Xml.FALSE);
1962        values.setAttribute(Xml.PRINT_TRAIN_SCHEDULE, isPrintTrainScheduleNameEnabled() ? Xml.TRUE : Xml.FALSE);
1963        values.setAttribute(Xml.USE12HR_FORMAT, is12hrFormatEnabled() ? Xml.TRUE : Xml.FALSE);
1964        values.setAttribute(Xml.PRINT_VALID, isPrintValidEnabled() ? Xml.TRUE : Xml.FALSE);
1965        values.setAttribute(Xml.SORT_BY_TRACK, isSortByTrackNameEnabled() ? Xml.TRUE : Xml.FALSE);
1966        values.setAttribute(Xml.PRINT_PAGE_HEADER, isPrintPageHeaderEnabled() ? Xml.TRUE : Xml.FALSE);
1967        values.setAttribute(Xml.PRINT_HEADERS, isPrintHeadersEnabled() ? Xml.TRUE : Xml.FALSE);
1968        values.setAttribute(Xml.TRUNCATE, isPrintTruncateManifestEnabled() ? Xml.TRUE : Xml.FALSE);
1969        values.setAttribute(Xml.USE_DEPARTURE_TIME, isUseDepartureTimeEnabled() ? Xml.TRUE : Xml.FALSE);
1970        values.setAttribute(Xml.USE_EDITOR, isManifestEditorEnabled() ? Xml.TRUE : Xml.FALSE);
1971        values.setAttribute(Xml.PRINT_CABOOSE_LOAD, isPrintCabooseLoadEnabled() ? Xml.TRUE : Xml.FALSE);
1972        values.setAttribute(Xml.PRINT_PASSENGER_LOAD, isPrintPassengerLoadEnabled() ? Xml.TRUE : Xml.FALSE);
1973        values.setAttribute(Xml.HAZARDOUS_MSG, getHazardousMsg());
1974
1975        // new format June 2014
1976        e.addContent(values = new Element(Xml.MANIFEST_FORMAT));
1977
1978        // save manifest format
1979        String value = Xml.STANDARD;
1980        if (getManifestFormat().equals(TWO_COLUMN_FORMAT)) {
1981            value = Xml.TWO_COLUMN;
1982        } else if (getManifestFormat().equals(TWO_COLUMN_TRACK_FORMAT)) {
1983            value = Xml.TWO_COLUMN_TRACK;
1984        }
1985        values.setAttribute(Xml.VALUE, value);
1986
1987        if (!getManifestLogoURL().equals(NONE)) {
1988            values = new Element(Xml.MANIFEST_LOGO);
1989            values.setAttribute(Xml.NAME, getManifestLogoURL());
1990            e.addContent(values);
1991        }
1992
1993        // manifest save file options
1994        e.addContent(values = new Element(Xml.MANIFEST_FILE_OPTIONS));
1995        values.setAttribute(Xml.MANIFEST_SAVE, isSaveTrainManifestsEnabled() ? Xml.TRUE : Xml.FALSE);
1996
1997        e.addContent(values = new Element(Xml.BUILD_OPTIONS));
1998        values.setAttribute(Xml.AGGRESSIVE, isBuildAggressive() ? Xml.TRUE : Xml.FALSE);
1999        values.setAttribute(Xml.NUMBER_PASSES, Integer.toString(getNumberPasses()));
2000
2001        values.setAttribute(Xml.ALLOW_LOCAL_INTERCHANGE, isLocalInterchangeMovesEnabled() ? Xml.TRUE : Xml.FALSE);
2002        values.setAttribute(Xml.ALLOW_LOCAL_SPUR, isLocalSpurMovesEnabled() ? Xml.TRUE : Xml.FALSE);
2003        values.setAttribute(Xml.ALLOW_LOCAL_YARD, isLocalYardMovesEnabled() ? Xml.TRUE : Xml.FALSE);
2004
2005        values.setAttribute(Xml.STAGING_RESTRICTION_ENABLED, isStagingTrainCheckEnabled() ? Xml.TRUE : Xml.FALSE);
2006        values.setAttribute(Xml.STAGING_TRACK_AVAIL, isStagingTrackImmediatelyAvail() ? Xml.TRUE : Xml.FALSE);
2007        values.setAttribute(Xml.ALLOW_RETURN_STAGING, isStagingAllowReturnEnabled() ? Xml.TRUE : Xml.FALSE);
2008        values.setAttribute(Xml.PROMPT_STAGING_ENABLED, isStagingPromptFromEnabled() ? Xml.TRUE : Xml.FALSE);
2009        values.setAttribute(Xml.PROMPT_TO_STAGING_ENABLED, isStagingPromptToEnabled() ? Xml.TRUE : Xml.FALSE);
2010        values.setAttribute(Xml.STAGING_TRY_NORMAL, isStagingTryNormalBuildEnabled() ? Xml.TRUE : Xml.FALSE);
2011
2012        values.setAttribute(Xml.GENERATE_CSV_MANIFEST, isGenerateCsvManifestEnabled() ? Xml.TRUE : Xml.FALSE);
2013        values.setAttribute(Xml.GENERATE_CSV_SWITCH_LIST, isGenerateCsvSwitchListEnabled() ? Xml.TRUE : Xml.FALSE);
2014
2015        e.addContent(values = new Element(Xml.BUILD_REPORT));
2016        values.setAttribute(Xml.LEVEL, getBuildReportLevel());
2017        values.setAttribute(Xml.ROUTER_LEVEL, getRouterBuildReportLevel());
2018        values.setAttribute(Xml.USE_EDITOR, isBuildReportEditorEnabled() ? Xml.TRUE : Xml.FALSE);
2019        values.setAttribute(Xml.INDENT, isBuildReportIndentEnabled() ? Xml.TRUE : Xml.FALSE);
2020        values.setAttribute(Xml.ALWAYS_PREVIEW, isBuildReportAlwaysPreviewEnabled() ? Xml.TRUE : Xml.FALSE);
2021        values.setAttribute(Xml.FONT_SIZE, Integer.toString(getBuildReportFontSize()));
2022
2023        // new format for router options
2024        e.addContent(values = new Element(Xml.ROUTER));
2025        values.setAttribute(Xml.CAR_ROUTING_ENABLED, isCarRoutingEnabled() ? Xml.TRUE : Xml.FALSE);
2026        values.setAttribute(Xml.CAR_ROUTING_VIA_YARDS, isCarRoutingViaYardsEnabled() ? Xml.TRUE : Xml.FALSE);
2027        values.setAttribute(Xml.CAR_ROUTING_VIA_STAGING, isCarRoutingViaStagingEnabled() ? Xml.TRUE : Xml.FALSE);
2028        values.setAttribute(Xml.FORWARD_TO_YARD, isForwardToYardEnabled() ? Xml.TRUE : Xml.FALSE);
2029        values.setAttribute(Xml.ONLY_ACTIVE_TRAINS, isOnlyActiveTrainsEnabled() ? Xml.TRUE : Xml.FALSE);
2030        values.setAttribute(Xml.CHECK_CAR_DESTINATION, isCheckCarDestinationEnabled() ? Xml.TRUE : Xml.FALSE);
2031
2032        // new format for logger options
2033        e.addContent(values = new Element(Xml.LOGGER));
2034        values.setAttribute(Xml.CAR_LOGGER, isCarLoggerEnabled() ? Xml.TRUE : Xml.FALSE);
2035        values.setAttribute(Xml.ENGINE_LOGGER, isEngineLoggerEnabled() ? Xml.TRUE : Xml.FALSE);
2036        values.setAttribute(Xml.TRAIN_LOGGER, isTrainLoggerEnabled() ? Xml.TRUE : Xml.FALSE);
2037
2038        e.addContent(values = new Element(Xml.OWNER));
2039        values.setAttribute(Xml.NAME, getOwnerName());
2040
2041        e.addContent(values = new Element(Xml.ICON_COLOR));
2042        values.setAttribute(Xml.NORTH, getTrainIconColorNorth());
2043        values.setAttribute(Xml.SOUTH, getTrainIconColorSouth());
2044        values.setAttribute(Xml.EAST, getTrainIconColorEast());
2045        values.setAttribute(Xml.WEST, getTrainIconColorWest());
2046        values.setAttribute(Xml.LOCAL, getTrainIconColorLocal());
2047        values.setAttribute(Xml.TERMINATE, getTrainIconColorTerminate());
2048
2049        e.addContent(values = new Element(Xml.COMMENTS));
2050        values.setAttribute(Xml.MISPLACED_CARS, getMiaComment());
2051
2052        e.addContent(values = new Element(Xml.DISPLAY));
2053        values.setAttribute(Xml.SHOW_TRACK_MOVES, isShowTrackMovesEnabled() ? Xml.TRUE : Xml.FALSE);
2054
2055        if (isVsdPhysicalLocationEnabled()) {
2056            e.addContent(values = new Element(Xml.VSD));
2057            values.setAttribute(Xml.ENABLE_PHYSICAL_LOCATIONS, isVsdPhysicalLocationEnabled() ? Xml.TRUE : Xml.FALSE);
2058        }
2059
2060        // Save CATS setting
2061        e.addContent(values = new Element(Xml.CATS));
2062        values.setAttribute(Xml.EXACT_LOCATION_NAME,
2063                AbstractOperationsServer.isExactLoationNameEnabled() ? Xml.TRUE : Xml.FALSE);
2064        return e;
2065    }
2066
2067    private static void storeXmlMessageFormat(Element values, String prefix, String[] messageFormat) {
2068        values.setAttribute(Xml.PREFIX, prefix);
2069        StringBuilder buf = new StringBuilder();
2070        stringToTagConversion(messageFormat);
2071        for (String attibute : messageFormat) {
2072            buf.append(attibute).append(",");
2073        }
2074        values.setAttribute(Xml.SETTING, buf.toString());
2075    }
2076
2077    public static void load(Element e) {
2078        if (e.getChild(Xml.OPERATIONS) == null) {
2079            log.warn("OperationsPro settings values not found");
2080            return;
2081        }
2082        Element operations = e.getChild(Xml.OPERATIONS);
2083        org.jdom2.Attribute a;
2084
2085        if ((operations.getChild(Xml.RAIL_ROAD) != null) &&
2086                (a = operations.getChild(Xml.RAIL_ROAD).getAttribute(Xml.NAME)) != null) {
2087            String name = a.getValue();
2088            log.debug("railroadName: {}", name);
2089            // code before 4.11 "useJmriRailroadName" when using the preferences railroad
2090            // name.
2091            // here for backwards compatibility
2092            if (!name.equals(Xml.USE_JMRI_RAILROAD_NAME)) {
2093                getDefault().railroadName = name; // don't set the dirty bit
2094            }
2095        }
2096
2097        if ((operations.getChild(Xml.SETUP) != null) &&
2098                (a = operations.getChild(Xml.SETUP).getAttribute(Xml.COMMENT)) != null) {
2099            String comment = a.getValue();
2100            log.debug("setup comment: {}", comment);
2101            getDefault().setupComment = comment;
2102        }
2103
2104        if (operations.getChild(Xml.SETTINGS) != null) {
2105            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.MAIN_MENU)) != null) {
2106                String enabled = a.getValue();
2107                log.debug("mainMenu: {}", enabled);
2108                setMainMenuEnabled(enabled.equals(Xml.TRUE));
2109            }
2110            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.CLOSE_ON_SAVE)) != null) {
2111                String enabled = a.getValue();
2112                log.debug("closeOnSave: {}", enabled);
2113                setCloseWindowOnSaveEnabled(enabled.equals(Xml.TRUE));
2114            }
2115            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.TRAIN_DIRECTION)) != null) {
2116                String dir = a.getValue();
2117                log.debug("direction: {}", dir);
2118                try {
2119                    getDefault().traindir = Integer.parseInt(dir);
2120                } catch (NumberFormatException ee) {
2121                    log.error("Train direction ({}) isn't a valid number", a.getValue());
2122                }
2123            }
2124            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.TRAIN_LENGTH)) != null) {
2125                String length = a.getValue();
2126                log.debug("Max train length: {}", length);
2127                try {
2128                    setMaxTrainLength(Integer.parseInt(length));
2129                } catch (NumberFormatException ee) {
2130                    log.error("Train maximum length ({}) isn't a valid number", a.getValue());
2131                }
2132            }
2133            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.MAX_ENGINES)) != null) {
2134                String size = a.getValue();
2135                log.debug("Max number of engines: {}", size);
2136                try {
2137                    setMaxNumberEngines(Integer.parseInt(size));
2138                } catch (NumberFormatException ee) {
2139                    log.error("Maximum number of engines ({}) isn't a valid number", a.getValue());
2140                }
2141            }
2142            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.HPT)) != null) {
2143                String value = a.getValue();
2144                log.debug("HPT: {}", value);
2145                try {
2146                    setHorsePowerPerTon(Integer.parseInt(value));
2147                } catch (NumberFormatException ee) {
2148                    log.error("Train HPT ({}) isn't a valid number", a.getValue());
2149                }
2150            }
2151            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.SCALE)) != null) {
2152                String scale = a.getValue();
2153                log.debug("scale: {}", scale);
2154                try {
2155                    setScale(Integer.parseInt(scale));
2156                } catch (NumberFormatException ee) {
2157                    log.error("Scale ({}) isn't a valid number", a.getValue());
2158                }
2159            }
2160            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.CAR_TYPES)) != null) {
2161                String types = a.getValue();
2162                log.debug("CarTypes: {}", types);
2163                setCarTypes(types);
2164            }
2165            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.SWITCH_TIME)) != null) {
2166                String minutes = a.getValue();
2167                log.debug("switchTime: {}", minutes);
2168                try {
2169                    setSwitchTime(Integer.parseInt(minutes));
2170                } catch (NumberFormatException ee) {
2171                    log.error("Switch time ({}) isn't a valid number", a.getValue());
2172                }
2173            }
2174            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.TRAVEL_TIME)) != null) {
2175                String minutes = a.getValue();
2176                log.debug("travelTime: {}", minutes);
2177                try {
2178                    setTravelTime(Integer.parseInt(minutes));
2179                } catch (NumberFormatException ee) {
2180                    log.error("Travel time ({}) isn't a valid number", a.getValue());
2181                }
2182            }
2183            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.SHOW_VALUE)) != null) {
2184                String enable = a.getValue();
2185                log.debug("showValue: {}", enable);
2186                setValueEnabled(enable.equals(Xml.TRUE));
2187            }
2188            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.VALUE_LABEL)) != null) {
2189                String label = a.getValue();
2190                log.debug("valueLabel: {}", label);
2191                setValueLabel(label);
2192            }
2193            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.SHOW_RFID)) != null) {
2194                String enable = a.getValue();
2195                log.debug("showRfid: {}", enable);
2196                setRfidEnabled(enable.equals(Xml.TRUE));
2197            }
2198            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.RFID_LABEL)) != null) {
2199                String label = a.getValue();
2200                log.debug("rfidLabel: {}", label);
2201                setRfidLabel(label);
2202            }
2203            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.LENGTH_UNIT)) != null) {
2204                String unit = a.getValue();
2205                log.debug("lengthUnit: {}", unit);
2206                setLengthUnit(unit);
2207            }
2208            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.YEAR_MODELED)) != null) {
2209                String year = a.getValue();
2210                log.debug("yearModeled: {}", year);
2211                setYearModeled(year);
2212            }
2213            // next eight attributes are here for backward compatibility
2214            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.PRINT_LOC_COMMENTS)) != null) {
2215                String enable = a.getValue();
2216                log.debug("printLocComments: {}", enable);
2217                setPrintLocationCommentsEnabled(enable.equals(Xml.TRUE));
2218            }
2219            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.PRINT_ROUTE_COMMENTS)) != null) {
2220                String enable = a.getValue();
2221                log.debug("printRouteComments: {}", enable);
2222                setPrintRouteCommentsEnabled(enable.equals(Xml.TRUE));
2223            }
2224            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.PRINT_LOADS_EMPTIES)) != null) {
2225                String enable = a.getValue();
2226                log.debug("printLoadsEmpties: {}", enable);
2227                setPrintLoadsAndEmptiesEnabled(enable.equals(Xml.TRUE));
2228            }
2229            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.PRINT_TRAIN_SCHEDULE)) != null) {
2230                String enable = a.getValue();
2231                log.debug("printTrainSchedule: {}", enable);
2232                setPrintTrainScheduleNameEnabled(enable.equals(Xml.TRUE));
2233            }
2234            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.USE12HR_FORMAT)) != null) {
2235                String enable = a.getValue();
2236                log.debug("use12hrFormat: {}", enable);
2237                set12hrFormatEnabled(enable.equals(Xml.TRUE));
2238            }
2239            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.PRINT_VALID)) != null) {
2240                String enable = a.getValue();
2241                log.debug("printValid: {}", enable);
2242                setPrintValidEnabled(enable.equals(Xml.TRUE));
2243            }
2244            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.SORT_BY_TRACK)) != null) {
2245                String enable = a.getValue();
2246                log.debug("sortByTrack: {}", enable);
2247                setSortByTrackNameEnabled(enable.equals(Xml.TRUE));
2248            }
2249            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.PRINT_HEADERS)) != null) {
2250                String enable = a.getValue();
2251                log.debug("printHeaders: {}", enable);
2252                setPrintHeadersEnabled(enable.equals(Xml.TRUE));
2253            }
2254        }
2255        if (operations.getChild(Xml.PICKUP_ENG_FORMAT) != null) {
2256            if ((a = operations.getChild(Xml.PICKUP_ENG_FORMAT).getAttribute(Xml.PREFIX)) != null) {
2257                setPickupEnginePrefix(a.getValue());
2258            }
2259            if ((a = operations.getChild(Xml.PICKUP_ENG_FORMAT).getAttribute(Xml.SETTING)) != null) {
2260                String setting = a.getValue();
2261                log.debug("pickupEngFormat: {}", setting);
2262                String[] keys = setting.split(",");
2263                xmlAttributeToKeyConversion(keys);
2264                keyToStringConversion(keys);
2265                setPickupEngineMessageFormat(keys);
2266            }
2267        }
2268        if (operations.getChild(Xml.DROP_ENG_FORMAT) != null) {
2269            if ((a = operations.getChild(Xml.DROP_ENG_FORMAT).getAttribute(Xml.PREFIX)) != null) {
2270                setDropEnginePrefix(a.getValue());
2271            }
2272            if ((a = operations.getChild(Xml.DROP_ENG_FORMAT).getAttribute(Xml.SETTING)) != null) {
2273                String setting = a.getValue();
2274                log.debug("dropEngFormat: {}", setting);
2275                String[] keys = setting.split(",");
2276                xmlAttributeToKeyConversion(keys);
2277                keyToStringConversion(keys);
2278                setDropEngineMessageFormat(keys);
2279            }
2280        }
2281        if (operations.getChild(Xml.PICKUP_CAR_FORMAT) != null) {
2282            if ((a = operations.getChild(Xml.PICKUP_CAR_FORMAT).getAttribute(Xml.PREFIX)) != null) {
2283                setPickupCarPrefix(a.getValue());
2284            }
2285            if ((a = operations.getChild(Xml.PICKUP_CAR_FORMAT).getAttribute(Xml.SETTING)) != null) {
2286                String setting = a.getValue();
2287                log.debug("pickupCarFormat: {}", setting);
2288                String[] keys = setting.split(",");
2289                replaceOldFormat(keys);
2290                xmlAttributeToKeyConversion(keys);
2291                keyToStringConversion(keys);
2292                setPickupManifestMessageFormat(keys);
2293            }
2294        }
2295        if (operations.getChild(Xml.DROP_CAR_FORMAT) != null) {
2296            if ((a = operations.getChild(Xml.DROP_CAR_FORMAT).getAttribute(Xml.PREFIX)) != null) {
2297                setDropCarPrefix(a.getValue());
2298            }
2299            if ((a = operations.getChild(Xml.DROP_CAR_FORMAT).getAttribute(Xml.SETTING)) != null) {
2300                String setting = a.getValue();
2301                log.debug("dropCarFormat: {}", setting);
2302                String[] keys = setting.split(",");
2303                replaceOldFormat(keys);
2304                xmlAttributeToKeyConversion(keys);
2305                keyToStringConversion(keys);
2306                setDropManifestMessageFormat(keys);
2307            }
2308        }
2309        if (operations.getChild(Xml.LOCAL_FORMAT) != null) {
2310            if ((a = operations.getChild(Xml.LOCAL_FORMAT).getAttribute(Xml.PREFIX)) != null) {
2311                setLocalPrefix(a.getValue());
2312            }
2313            if ((a = operations.getChild(Xml.LOCAL_FORMAT).getAttribute(Xml.SETTING)) != null) {
2314                String setting = a.getValue();
2315                log.debug("localFormat: {}", setting);
2316                String[] keys = setting.split(",");
2317                replaceOldFormat(keys);
2318                xmlAttributeToKeyConversion(keys);
2319                keyToStringConversion(keys);
2320                setLocalManifestMessageFormat(keys);
2321            }
2322        }
2323        if (operations.getChild(Xml.MISSING_CAR_FORMAT) != null) {
2324            if ((a = operations.getChild(Xml.MISSING_CAR_FORMAT).getAttribute(Xml.SETTING)) != null) {
2325                String setting = a.getValue();
2326                log.debug("missingCarFormat: {}", setting);
2327                String[] keys = setting.split(",");
2328                keyToStringConversion(keys);
2329                setMissingCarMessageFormat(keys);
2330            }
2331        }
2332        if (operations.getChild(Xml.SWITCH_LIST) != null) {
2333            if ((a = operations.getChild(Xml.SWITCH_LIST).getAttribute(Xml.SAME_AS_MANIFEST)) != null) {
2334                String b = a.getValue();
2335                log.debug("sameAsManifest: {}", b);
2336                setSwitchListFormatSameAsManifest(b.equals(Xml.TRUE));
2337            }
2338            if ((a = operations.getChild(Xml.SWITCH_LIST).getAttribute(Xml.REAL_TIME)) != null) {
2339                String b = a.getValue();
2340                log.debug("realTime: {}", b);
2341                getDefault().switchListRealTime = b.equals(Xml.TRUE);
2342            }
2343            if ((a = operations.getChild(Xml.SWITCH_LIST).getAttribute(Xml.ALL_TRAINS)) != null) {
2344                String b = a.getValue();
2345                log.debug("allTrains: {}", b);
2346                getDefault().switchListAllTrains = b.equals(Xml.TRUE);
2347            }
2348            if ((a = operations.getChild(Xml.SWITCH_LIST).getAttribute(Xml.PAGE_FORMAT)) != null) {
2349                switch (a.getValue()) {
2350                    case Xml.PAGE_NORMAL:
2351                        getDefault().switchListPageFormat = PAGE_NORMAL;
2352                        break;
2353                    case Xml.PAGE_PER_TRAIN:
2354                        getDefault().switchListPageFormat = PAGE_PER_TRAIN;
2355                        break;
2356                    case Xml.PAGE_PER_VISIT:
2357                        getDefault().switchListPageFormat = PAGE_PER_VISIT;
2358                        break;
2359                    default:
2360                        log.error("Unknown switch list page format {}", a.getValue());
2361                }
2362            } // old way to save switch list page format pre 3.11
2363            else if ((a = operations.getChild(Xml.SWITCH_LIST).getAttribute(Xml.PAGE_MODE)) != null) {
2364                String b = a.getValue();
2365                log.debug("old style pageMode: {}", b);
2366                if (b.equals(Xml.TRUE)) {
2367                    getDefault().switchListPageFormat = PAGE_PER_TRAIN;
2368                }
2369            }
2370            if ((a = operations.getChild(Xml.SWITCH_LIST).getAttribute(Xml.PRINT_ROUTE_LOCATION)) != null) {
2371                String b = a.getValue();
2372                log.debug("print route location comment: {}", b);
2373                setSwitchListRouteLocationCommentEnabled(b.equals(Xml.TRUE));
2374            }
2375            if ((a = operations.getChild(Xml.SWITCH_LIST).getAttribute(Xml.TRACK_SUMMARY)) != null) {
2376                String b = a.getValue();
2377                log.debug("track summary: {}", b);
2378                setPrintTrackSummaryEnabled(b.equals(Xml.TRUE));
2379            }
2380            if ((a = operations.getChild(Xml.SWITCH_LIST).getAttribute(Xml.USE_DEPARTURE_TIME)) != null) {
2381                String b = a.getValue();
2382                log.debug("switch list departure time: {}", b);
2383                setUseSwitchListDepartureTimeEnabled(b.equals(Xml.TRUE));
2384            }
2385        }
2386        if (operations.getChild(Xml.SWITCH_LIST_PICKUP_CAR_FORMAT) != null) {
2387            if ((a = operations.getChild(Xml.SWITCH_LIST_PICKUP_CAR_FORMAT).getAttribute(Xml.PREFIX)) != null) {
2388                setSwitchListPickupCarPrefix(a.getValue());
2389            }
2390            if ((a = operations.getChild(Xml.SWITCH_LIST_PICKUP_CAR_FORMAT).getAttribute(Xml.SETTING)) != null) {
2391                String setting = a.getValue();
2392                log.debug("switchListpickupCarFormat: {}", setting);
2393                String[] keys = setting.split(",");
2394                replaceOldFormat(keys);
2395                xmlAttributeToKeyConversion(keys);
2396                keyToStringConversion(keys);
2397                setPickupSwitchListMessageFormat(keys);
2398            }
2399        }
2400        if (operations.getChild(Xml.SWITCH_LIST_DROP_CAR_FORMAT) != null) {
2401            if ((a = operations.getChild(Xml.SWITCH_LIST_DROP_CAR_FORMAT).getAttribute(Xml.PREFIX)) != null) {
2402                setSwitchListDropCarPrefix(a.getValue());
2403            }
2404            if ((a = operations.getChild(Xml.SWITCH_LIST_DROP_CAR_FORMAT).getAttribute(Xml.SETTING)) != null) {
2405                String setting = a.getValue();
2406                log.debug("switchListDropCarFormat: {}", setting);
2407                String[] keys = setting.split(",");
2408                replaceOldFormat(keys);
2409                xmlAttributeToKeyConversion(keys);
2410                keyToStringConversion(keys);
2411                setDropSwitchListMessageFormat(keys);
2412            }
2413        }
2414        if (operations.getChild(Xml.SWITCH_LIST_LOCAL_FORMAT) != null) {
2415            if ((a = operations.getChild(Xml.SWITCH_LIST_LOCAL_FORMAT).getAttribute(Xml.PREFIX)) != null) {
2416                setSwitchListLocalPrefix(a.getValue());
2417            }
2418            if ((a = operations.getChild(Xml.SWITCH_LIST_LOCAL_FORMAT).getAttribute(Xml.SETTING)) != null) {
2419                String setting = a.getValue();
2420                log.debug("switchListLocalFormat: {}", setting);
2421                String[] keys = setting.split(",");
2422                replaceOldFormat(keys);
2423                xmlAttributeToKeyConversion(keys);
2424                keyToStringConversion(keys);
2425                setLocalSwitchListMessageFormat(keys);
2426            }
2427        }
2428        if (operations.getChild(Xml.PANEL) != null) {
2429            if ((a = operations.getChild(Xml.PANEL).getAttribute(Xml.NAME)) != null) {
2430                String panel = a.getValue();
2431                log.debug("panel: {}", panel);
2432                setPanelName(panel);
2433            }
2434            if ((a = operations.getChild(Xml.PANEL).getAttribute(Xml.TRAIN_ICONXY)) != null) {
2435                String enable = a.getValue();
2436                log.debug("TrainIconXY: {}", enable);
2437                setTrainIconCordEnabled(enable.equals(Xml.TRUE));
2438            }
2439            if ((a = operations.getChild(Xml.PANEL).getAttribute(Xml.TRAIN_ICON_APPEND)) != null) {
2440                String enable = a.getValue();
2441                log.debug("TrainIconAppend: {}", enable);
2442                setTrainIconAppendEnabled(enable.equals(Xml.TRUE));
2443            }
2444        }
2445        if ((operations.getChild(Xml.FONT_NAME) != null) &&
2446                (a = operations.getChild(Xml.FONT_NAME).getAttribute(Xml.NAME)) != null) {
2447            String font = a.getValue();
2448            log.debug("fontName: {}", font);
2449            setFontName(font);
2450        }
2451        if ((operations.getChild(Xml.FONT_SIZE) != null) &&
2452                (a = operations.getChild(Xml.FONT_SIZE).getAttribute(Xml.SIZE)) != null) {
2453            String size = a.getValue();
2454            log.debug("fontsize: {}", size);
2455            try {
2456                setManifestFontSize(Integer.parseInt(size));
2457            } catch (NumberFormatException ee) {
2458                log.error("Manifest font size ({}) isn't a valid number", a.getValue());
2459            }
2460        }
2461        if ((operations.getChild(Xml.PAGE_ORIENTATION) != null)) {
2462            if ((a = operations.getChild(Xml.PAGE_ORIENTATION).getAttribute(Xml.MANIFEST)) != null) {
2463                String orientation = a.getValue();
2464                log.debug("manifestOrientation: {}", orientation);
2465                setManifestOrientation(orientation);
2466            }
2467            if ((a = operations.getChild(Xml.PAGE_ORIENTATION).getAttribute(Xml.SWITCH_LIST)) != null) {
2468                String orientation = a.getValue();
2469                log.debug("switchListOrientation: {}", orientation);
2470                setSwitchListOrientation(orientation);
2471            }
2472        }
2473        if ((operations.getChild(Xml.MANIFEST_COLORS) != null)) {
2474            if ((a = operations.getChild(Xml.MANIFEST_COLORS).getAttribute(Xml.DROP_COLOR)) != null) {
2475                String dropColor = a.getValue();
2476                log.debug("dropColor: {}", dropColor);
2477                setDropTextColor(dropColor);
2478            }
2479            if ((a = operations.getChild(Xml.MANIFEST_COLORS).getAttribute(Xml.PICKUP_COLOR)) != null) {
2480                String pickupColor = a.getValue();
2481                log.debug("pickupColor: {}", pickupColor);
2482                setPickupTextColor(pickupColor);
2483            }
2484            if ((a = operations.getChild(Xml.MANIFEST_COLORS).getAttribute(Xml.LOCAL_COLOR)) != null) {
2485                String localColor = a.getValue();
2486                log.debug("localColor: {}", localColor);
2487                setLocalTextColor(localColor);
2488            }
2489        }
2490        if ((operations.getChild(Xml.TAB) != null)) {
2491            if ((a = operations.getChild(Xml.TAB).getAttribute(Xml.ENABLED)) != null) {
2492                String enable = a.getValue();
2493                log.debug("tab: {}", enable);
2494                setTabEnabled(enable.equals(Xml.TRUE));
2495            }
2496            if ((a = operations.getChild(Xml.TAB).getAttribute(Xml.LENGTH)) != null) {
2497                String length = a.getValue();
2498                log.debug("tab 1 length: {}", length);
2499                try {
2500                    setTab1length(Integer.parseInt(length));
2501                } catch (NumberFormatException ee) {
2502                    log.error("Tab 1 length ({}) isn't a valid number", a.getValue());
2503                }
2504            }
2505            if ((a = operations.getChild(Xml.TAB).getAttribute(Xml.TAB2_LENGTH)) != null) {
2506                String length = a.getValue();
2507                log.debug("tab 2 length: {}", length);
2508                try {
2509                    setTab2length(Integer.parseInt(length));
2510                } catch (NumberFormatException ee) {
2511                    log.error("Tab 2 length ({}) isn't a valid number", a.getValue());
2512                }
2513            }
2514            if ((a = operations.getChild(Xml.TAB).getAttribute(Xml.TAB3_LENGTH)) != null) {
2515                String length = a.getValue();
2516                log.debug("tab 3 length: {}", length);
2517                try {
2518                    setTab3length(Integer.parseInt(length));
2519                } catch (NumberFormatException ee) {
2520                    log.error("Tab 3 length ({}) isn't a valid number", a.getValue());
2521                }
2522            }
2523        }
2524        if ((operations.getChild(Xml.MANIFEST) != null)) {
2525            if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.PRINT_LOC_COMMENTS)) != null) {
2526                String enable = a.getValue();
2527                log.debug("manifest printLocComments: {}", enable);
2528                setPrintLocationCommentsEnabled(enable.equals(Xml.TRUE));
2529            }
2530            if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.PRINT_ROUTE_COMMENTS)) != null) {
2531                String enable = a.getValue();
2532                log.debug("manifest printRouteComments: {}", enable);
2533                setPrintRouteCommentsEnabled(enable.equals(Xml.TRUE));
2534            }
2535            if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.PRINT_LOADS_EMPTIES)) != null) {
2536                String enable = a.getValue();
2537                log.debug("manifest printLoadsEmpties: {}", enable);
2538                setPrintLoadsAndEmptiesEnabled(enable.equals(Xml.TRUE));
2539            }
2540            if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.PRINT_TRAIN_SCHEDULE)) != null) {
2541                String enable = a.getValue();
2542                log.debug("manifest printTrainSchedule: {}", enable);
2543                setPrintTrainScheduleNameEnabled(enable.equals(Xml.TRUE));
2544            }
2545            if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.USE12HR_FORMAT)) != null) {
2546                String enable = a.getValue();
2547                log.debug("manifest use12hrFormat: {}", enable);
2548                set12hrFormatEnabled(enable.equals(Xml.TRUE));
2549            }
2550            if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.PRINT_VALID)) != null) {
2551                String enable = a.getValue();
2552                log.debug("manifest printValid: {}", enable);
2553                setPrintValidEnabled(enable.equals(Xml.TRUE));
2554            }
2555            if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.SORT_BY_TRACK)) != null) {
2556                String enable = a.getValue();
2557                log.debug("manifest sortByTrack: {}", enable);
2558                setSortByTrackNameEnabled(enable.equals(Xml.TRUE));
2559            }
2560            if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.PRINT_PAGE_HEADER)) != null) {
2561                String enable = a.getValue();
2562                log.debug("manifest printPageHeader: {}", enable);
2563                setPrintPageHeaderEnabled(enable.equals(Xml.TRUE));
2564            }
2565            if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.PRINT_HEADERS)) != null) {
2566                String enable = a.getValue();
2567                log.debug("manifest print headers: {}", enable);
2568                setPrintHeadersEnabled(enable.equals(Xml.TRUE));
2569            }
2570            if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.TRUNCATE)) != null) {
2571                String enable = a.getValue();
2572                log.debug("manifest truncate: {}", enable);
2573                setPrintTruncateManifestEnabled(enable.equals(Xml.TRUE));
2574            }
2575            if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.USE_DEPARTURE_TIME)) != null) {
2576                String enable = a.getValue();
2577                log.debug("manifest use departure time: {}", enable);
2578                setUseDepartureTimeEnabled(enable.equals(Xml.TRUE));
2579            }
2580            if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.USE_EDITOR)) != null) {
2581                String enable = a.getValue();
2582                log.debug("manifest useEditor: {}", enable);
2583                setManifestEditorEnabled(enable.equals(Xml.TRUE));
2584            }
2585            if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.PRINT_CABOOSE_LOAD)) != null) {
2586                String enable = a.getValue();
2587                log.debug("manifest print caboose load: {}", enable);
2588                setPrintCabooseLoadEnabled(enable.equals(Xml.TRUE));
2589            }
2590            if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.PRINT_PASSENGER_LOAD)) != null) {
2591                String enable = a.getValue();
2592                log.debug("manifest print passenger load: {}", enable);
2593                setPrintPassengerLoadEnabled(enable.equals(Xml.TRUE));
2594            }
2595            if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.HAZARDOUS_MSG)) != null) {
2596                String message = a.getValue();
2597                log.debug("manifest hazardousMsg: {}", message);
2598                setHazardousMsg(message);
2599            }
2600        }
2601        if ((operations.getChild(Xml.MANIFEST_FORMAT) != null)) {
2602            if ((a = operations.getChild(Xml.MANIFEST_FORMAT).getAttribute(Xml.VALUE)) != null) {
2603                switch (a.getValue()) {
2604                    case Xml.STANDARD:
2605                        getDefault().manifestFormat = STANDARD_FORMAT;
2606                        break;
2607                    case Xml.TWO_COLUMN:
2608                        getDefault().manifestFormat = TWO_COLUMN_FORMAT;
2609                        break;
2610                    case Xml.TWO_COLUMN_TRACK:
2611                        getDefault().manifestFormat = TWO_COLUMN_TRACK_FORMAT;
2612                        break;
2613                    default:
2614                        log.debug("Unknown manifest format");
2615                }
2616            }
2617        } else if ((operations.getChild(Xml.COLUMN_FORMAT) != null)) {
2618            if ((a = operations.getChild(Xml.COLUMN_FORMAT).getAttribute(Xml.TWO_COLUMNS)) != null) {
2619                String enable = a.getValue();
2620                log.debug("two columns: {}", enable);
2621                if (enable.equals(Xml.TRUE)) {
2622                    setManifestFormat(TWO_COLUMN_FORMAT);
2623                }
2624            }
2625        }
2626        // get manifest logo
2627        if ((operations.getChild(Xml.MANIFEST_LOGO) != null)) {
2628            if ((a = operations.getChild(Xml.MANIFEST_LOGO).getAttribute(Xml.NAME)) != null) {
2629                setManifestLogoURL(a.getValue());
2630            }
2631        }
2632        // manifest file options
2633        if ((operations.getChild(Xml.MANIFEST_FILE_OPTIONS) != null)) {
2634            if ((a = operations.getChild(Xml.MANIFEST_FILE_OPTIONS).getAttribute(Xml.MANIFEST_SAVE)) != null) {
2635                String enable = a.getValue();
2636                log.debug("manifest file save option: {}", enable);
2637                getDefault().saveTrainManifests = enable.equals(Xml.TRUE);
2638            }
2639        }
2640        if ((operations.getChild(Xml.BUILD_OPTIONS) != null)) {
2641            if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.AGGRESSIVE)) != null) {
2642                String enable = a.getValue();
2643                log.debug("aggressive: {}", enable);
2644                setBuildAggressive(enable.equals(Xml.TRUE));
2645            }
2646            if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.NUMBER_PASSES)) != null) {
2647                String number = a.getValue();
2648                log.debug("number of passes: {}", number);
2649                try {
2650                    setNumberPasses(Integer.parseInt(number));
2651                } catch (NumberFormatException ne) {
2652                    log.debug("Number of passes isn't a number");
2653                }
2654            }
2655            if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.ALLOW_LOCAL_INTERCHANGE)) != null) {
2656                String enable = a.getValue();
2657                log.debug("allowLocalInterchangeMoves: {}", enable);
2658                setLocalInterchangeMovesEnabled(enable.equals(Xml.TRUE));
2659            }
2660            if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.ALLOW_LOCAL_SPUR)) != null) {
2661                String enable = a.getValue();
2662                log.debug("allowLocalSpurMoves: {}", enable);
2663                setLocalSpurMovesEnabled(enable.equals(Xml.TRUE));
2664            } else if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.ALLOW_LOCAL_SIDING)) != null) {
2665                String enable = a.getValue();
2666                log.debug("allowLocalSidingMoves: {}", enable);
2667                setLocalSpurMovesEnabled(enable.equals(Xml.TRUE));
2668            }
2669            if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.ALLOW_LOCAL_YARD)) != null) {
2670                String enable = a.getValue();
2671                log.debug("allowLocalYardMoves: {}", enable);
2672                setLocalYardMovesEnabled(enable.equals(Xml.TRUE));
2673            }
2674            if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.STAGING_RESTRICTION_ENABLED)) != null) {
2675                String enable = a.getValue();
2676                log.debug("stagingRestrictionEnabled: {}", enable);
2677                setStagingTrainCheckEnabled(enable.equals(Xml.TRUE));
2678            }
2679            if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.STAGING_TRACK_AVAIL)) != null) {
2680                String enable = a.getValue();
2681                log.debug("stagingTrackAvail: {}", enable);
2682                setStagingTrackImmediatelyAvail(enable.equals(Xml.TRUE));
2683            }
2684            if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.ALLOW_RETURN_STAGING)) != null) {
2685                String enable = a.getValue();
2686                log.debug("allowReturnStaging: {}", enable);
2687                getDefault().allowCarsReturnStaging = enable.equals(Xml.TRUE);
2688            }
2689            if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.PROMPT_STAGING_ENABLED)) != null) {
2690                String enable = a.getValue();
2691                log.debug("promptStagingEnabled: {}", enable);
2692                setStagingPromptFromEnabled(enable.equals(Xml.TRUE));
2693            }
2694            if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.PROMPT_TO_STAGING_ENABLED)) != null) {
2695                String enable = a.getValue();
2696                log.debug("promptToStagingEnabled: {}", enable);
2697                setStagingPromptToEnabled(enable.equals(Xml.TRUE));
2698            }
2699            if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.STAGING_TRY_NORMAL)) != null) {
2700                String enable = a.getValue();
2701                log.debug("stagingTryNormalEnabled: {}", enable);
2702                setStagingTryNormalBuildEnabled(enable.equals(Xml.TRUE));
2703            }
2704            if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.GENERATE_CSV_MANIFEST)) != null) {
2705                String enable = a.getValue();
2706                log.debug("generateCvsManifest: {}", enable);
2707                getDefault().generateCsvManifest = enable.equals(Xml.TRUE);
2708            }
2709            if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.GENERATE_CSV_SWITCH_LIST)) != null) {
2710                String enable = a.getValue();
2711                log.debug("generateCvsSwitchList: {}", enable);
2712                getDefault().generateCsvSwitchList = enable.equals(Xml.TRUE);
2713            }
2714        }
2715        if (operations.getChild(Xml.BUILD_REPORT) != null) {
2716            if ((a = operations.getChild(Xml.BUILD_REPORT).getAttribute(Xml.LEVEL)) != null) {
2717                String level = a.getValue();
2718                log.debug("buildReportLevel: {}", level);
2719                setBuildReportLevel(level);
2720            }
2721            if ((a = operations.getChild(Xml.BUILD_REPORT).getAttribute(Xml.ROUTER_LEVEL)) != null) {
2722                String level = a.getValue();
2723                log.debug("routerBuildReportLevel: {}", level);
2724                setRouterBuildReportLevel(level);
2725            }
2726            if ((a = operations.getChild(Xml.BUILD_REPORT).getAttribute(Xml.USE_EDITOR)) != null) {
2727                String enable = a.getValue();
2728                log.debug("build report useEditor: {}", enable);
2729                setBuildReportEditorEnabled(enable.equals(Xml.TRUE));
2730            }
2731            if ((a = operations.getChild(Xml.BUILD_REPORT).getAttribute(Xml.INDENT)) != null) {
2732                String enable = a.getValue();
2733                log.debug("build report indent: {}", enable);
2734                setBuildReportIndentEnabled(enable.equals(Xml.TRUE));
2735            }
2736            if ((a = operations.getChild(Xml.BUILD_REPORT).getAttribute(Xml.FONT_SIZE)) != null) {
2737                String size = a.getValue();
2738                log.debug("build font size: {}", size);
2739                try {
2740                    setBuildReportFontSize(Integer.parseInt(size));
2741                } catch (NumberFormatException ee) {
2742                    log.error("Build report font size ({}) isn't a valid number", a.getValue());
2743                }
2744            }
2745            if ((a = operations.getChild(Xml.BUILD_REPORT).getAttribute(Xml.ALWAYS_PREVIEW)) != null) {
2746                String enable = a.getValue();
2747                log.debug("build report always preview: {}", enable);
2748                setBuildReportAlwaysPreviewEnabled(enable.equals(Xml.TRUE));
2749            }
2750        }
2751
2752        if (operations.getChild(Xml.ROUTER) != null) {
2753            if ((a = operations.getChild(Xml.ROUTER).getAttribute(Xml.CAR_ROUTING_ENABLED)) != null) {
2754                String enable = a.getValue();
2755                log.debug("carRoutingEnabled: {}", enable);
2756                setCarRoutingEnabled(enable.equals(Xml.TRUE));
2757            }
2758            if ((a = operations.getChild(Xml.ROUTER).getAttribute(Xml.CAR_ROUTING_VIA_YARDS)) != null) {
2759                String enable = a.getValue();
2760                log.debug("carRoutingViaYards: {}", enable);
2761                setCarRoutingViaYardsEnabled(enable.equals(Xml.TRUE));
2762            }
2763            if ((a = operations.getChild(Xml.ROUTER).getAttribute(Xml.CAR_ROUTING_VIA_STAGING)) != null) {
2764                String enable = a.getValue();
2765                log.debug("carRoutingViaStaging: {}", enable);
2766                setCarRoutingViaStagingEnabled(enable.equals(Xml.TRUE));
2767            }
2768            if ((a = operations.getChild(Xml.ROUTER).getAttribute(Xml.FORWARD_TO_YARD)) != null) {
2769                String enable = a.getValue();
2770                log.debug("forwardToYard: {}", enable);
2771                setForwardToYardEnabled(enable.equals(Xml.TRUE));
2772            }
2773            if ((a = operations.getChild(Xml.ROUTER).getAttribute(Xml.ONLY_ACTIVE_TRAINS)) != null) {
2774                String enable = a.getValue();
2775                log.debug("onlyActiveTrains: {}", enable);
2776                setOnlyActiveTrainsEnabled(enable.equals(Xml.TRUE));
2777            }
2778            if ((a = operations.getChild(Xml.ROUTER).getAttribute(Xml.CHECK_CAR_DESTINATION)) != null) {
2779                String enable = a.getValue();
2780                log.debug("checkCarDestination: {}", enable);
2781                setCheckCarDestinationEnabled(enable.equals(Xml.TRUE));
2782            }
2783        } else if (operations.getChild(Xml.SETTINGS) != null) {
2784            // the next four items are for backwards compatibility
2785            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.CAR_ROUTING_ENABLED)) != null) {
2786                String enable = a.getValue();
2787                log.debug("carRoutingEnabled: {}", enable);
2788                setCarRoutingEnabled(enable.equals(Xml.TRUE));
2789            }
2790            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.CAR_ROUTING_VIA_YARDS)) != null) {
2791                String enable = a.getValue();
2792                log.debug("carRoutingViaYards: {}", enable);
2793                setCarRoutingViaYardsEnabled(enable.equals(Xml.TRUE));
2794            }
2795            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.CAR_ROUTING_VIA_STAGING)) != null) {
2796                String enable = a.getValue();
2797                log.debug("carRoutingViaStaging: {}", enable);
2798                setCarRoutingViaStagingEnabled(enable.equals(Xml.TRUE));
2799            }
2800            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.FORWARD_TO_YARD)) != null) {
2801                String enable = a.getValue();
2802                log.debug("forwardToYard: {}", enable);
2803                setForwardToYardEnabled(enable.equals(Xml.TRUE));
2804            }
2805        }
2806
2807        if ((operations.getChild(Xml.OWNER) != null) &&
2808                (a = operations.getChild(Xml.OWNER).getAttribute(Xml.NAME)) != null) {
2809            String owner = a.getValue();
2810            log.debug("owner: {}", owner);
2811            setOwnerName(owner);
2812        }
2813        if (operations.getChild(Xml.ICON_COLOR) != null) {
2814            if ((a = operations.getChild(Xml.ICON_COLOR).getAttribute(Xml.NORTH)) != null) {
2815                String color = a.getValue();
2816                log.debug("north color: {}", color);
2817                setTrainIconColorNorth(color);
2818            }
2819            if ((a = operations.getChild(Xml.ICON_COLOR).getAttribute(Xml.SOUTH)) != null) {
2820                String color = a.getValue();
2821                log.debug("south color: {}", color);
2822                setTrainIconColorSouth(color);
2823            }
2824            if ((a = operations.getChild(Xml.ICON_COLOR).getAttribute(Xml.EAST)) != null) {
2825                String color = a.getValue();
2826                log.debug("east color: {}", color);
2827                setTrainIconColorEast(color);
2828            }
2829            if ((a = operations.getChild(Xml.ICON_COLOR).getAttribute(Xml.WEST)) != null) {
2830                String color = a.getValue();
2831                log.debug("west color: {}", color);
2832                setTrainIconColorWest(color);
2833            }
2834            if ((a = operations.getChild(Xml.ICON_COLOR).getAttribute(Xml.LOCAL)) != null) {
2835                String color = a.getValue();
2836                log.debug("local color: {}", color);
2837                setTrainIconColorLocal(color);
2838            }
2839            if ((a = operations.getChild(Xml.ICON_COLOR).getAttribute(Xml.TERMINATE)) != null) {
2840                String color = a.getValue();
2841                log.debug("terminate color: {}", color);
2842                setTrainIconColorTerminate(color);
2843            }
2844        }
2845        if (operations.getChild(Xml.COMMENTS) != null) {
2846            if ((a = operations.getChild(Xml.COMMENTS).getAttribute(Xml.MISPLACED_CARS)) != null) {
2847                String comment = a.getValue();
2848                log.debug("Misplaced comment: {}", comment);
2849                setMiaComment(comment);
2850            }
2851        }
2852
2853        if (operations.getChild(Xml.DISPLAY) != null) {
2854            if ((a = operations.getChild(Xml.DISPLAY).getAttribute(Xml.SHOW_TRACK_MOVES)) != null) {
2855                String enable = a.getValue();
2856                log.debug("show track moves: {}", enable);
2857                getDefault().showTrackMoves = enable.equals(Xml.TRUE);
2858            }
2859        }
2860
2861        if (operations.getChild(Xml.VSD) != null) {
2862            if ((a = operations.getChild(Xml.VSD).getAttribute(Xml.ENABLE_PHYSICAL_LOCATIONS)) != null) {
2863                String enable = a.getValue();
2864                setVsdPhysicalLocationEnabled(enable.equals(Xml.TRUE));
2865            }
2866        }
2867        if (operations.getChild(Xml.CATS) != null) {
2868            if ((a = operations.getChild(Xml.CATS).getAttribute(Xml.EXACT_LOCATION_NAME)) != null) {
2869                String enable = a.getValue();
2870                AbstractOperationsServer.setExactLocationName(enable.equals(Xml.TRUE));
2871            }
2872        }
2873
2874        if (operations.getChild(Xml.SETTINGS) != null) {
2875            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.AUTO_SAVE)) != null) {
2876                String enabled = a.getValue();
2877                log.debug("autoSave: {}", enabled);
2878                setAutoSaveEnabled(enabled.equals(Xml.TRUE));
2879            }
2880            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.AUTO_BACKUP)) != null) {
2881                String enabled = a.getValue();
2882                log.debug("autoBackup: {}", enabled);
2883                setAutoBackupEnabled(enabled.equals(Xml.TRUE));
2884            }
2885        }
2886
2887        if (operations.getChild(Xml.LOGGER) != null) {
2888            if ((a = operations.getChild(Xml.LOGGER).getAttribute(Xml.CAR_LOGGER)) != null) {
2889                String enable = a.getValue();
2890                log.debug("carLogger: {}", enable);
2891                getDefault().carLogger = enable.equals(Xml.TRUE);
2892            }
2893            if ((a = operations.getChild(Xml.LOGGER).getAttribute(Xml.ENGINE_LOGGER)) != null) {
2894                String enable = a.getValue();
2895                log.debug("engineLogger: {}", enable);
2896                getDefault().engineLogger = enable.equals(Xml.TRUE);
2897            }
2898            if ((a = operations.getChild(Xml.LOGGER).getAttribute(Xml.TRAIN_LOGGER)) != null) {
2899                String enable = a.getValue();
2900                log.debug("trainLogger: {}", enable);
2901                getDefault().trainLogger = enable.equals(Xml.TRUE);
2902            }
2903        } else if (operations.getChild(Xml.SETTINGS) != null) {
2904            // for backward compatibility
2905            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.CAR_LOGGER)) != null) {
2906                String enable = a.getValue();
2907                log.debug("carLogger: {}", enable);
2908                getDefault().carLogger = enable.equals(Xml.TRUE);
2909            }
2910            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.ENGINE_LOGGER)) != null) {
2911                String enable = a.getValue();
2912                log.debug("engineLogger: {}", enable);
2913                getDefault().engineLogger = enable.equals(Xml.TRUE);
2914            }
2915            if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.TRAIN_LOGGER)) != null) {
2916                String enable = a.getValue();
2917                log.debug("trainLogger: {}", enable);
2918                getDefault().trainLogger = enable.equals(Xml.TRUE);
2919            }
2920        }
2921    }
2922
2923    // replace old pickup and drop message keys
2924    // Change happened from 2.11.3 to 2.11.4
2925    // 4/16/2014
2926    private static void replaceOldFormat(String[] format) {
2927        for (int i = 0; i < format.length; i++) {
2928            if (format[i].equals("Pickup Msg")) // NOI18N
2929            {
2930                format[i] = PICKUP_COMMENT;
2931            } else if (format[i].equals("Drop Msg")) // NOI18N
2932            {
2933                format[i] = DROP_COMMENT;
2934            }
2935        }
2936    }
2937
2938    /**
2939     * Converts the xml key to the proper locale text
2940     *
2941     */
2942    private static void keyToStringConversion(String[] keys) {
2943        for (int i = 0; i < keys.length; i++) {
2944            if (keys[i].equals(BLANK)) {
2945                continue;
2946            }
2947            try {
2948                keys[i] = Bundle.getMessage(keys[i]);
2949            } catch (Exception e) {
2950                log.warn("Key {}: ({}) not found", i, keys[i]);
2951            }
2952        }
2953    }
2954
2955    /*
2956     * Converts the strings into English tags for xml storage
2957     *
2958     */
2959    private static void stringToTagConversion(String[] strings) {
2960        for (int i = 0; i < strings.length; i++) {
2961            if (strings[i].equals(BLANK)) {
2962                continue;
2963            }
2964            for (String key : KEYS) {
2965                if (strings[i].equals(Bundle.getMessage(key))) {
2966                    strings[i] = Bundle.getMessage(Locale.ROOT, key);
2967                    break;
2968                }
2969            }
2970            // log.debug("Converted {} to {}", old, strings[i]);
2971        }
2972    }
2973
2974    /*
2975     * The xml attributes stored using the English translation. This converts the
2976     * attribute to the appropriate key for language conversion.
2977     */
2978    private static void xmlAttributeToKeyConversion(String[] format) {
2979        for (int i = 0; i < format.length; i++) {
2980            for (String key : KEYS) {
2981                if (format[i].equals(Bundle.getMessage(Locale.ROOT, key))) {
2982                    format[i] = key;
2983                }
2984            }
2985        }
2986    }
2987
2988    protected static void setDirtyAndFirePropertyChange(String p, Object old, Object n) {
2989        InstanceManager.getDefault(OperationsSetupXml.class).setDirty(true);
2990        getDefault().firePropertyChange(p, old, n);
2991    }
2992
2993    public static Setup getDefault() {
2994        return InstanceManager.getDefault(Setup.class);
2995    }
2996
2997    private static final Logger log = LoggerFactory.getLogger(Setup.class);
2998
2999    @Override
3000    public void dispose() {
3001        AutoSave.stop();
3002    }
3003
3004}