001package jmri.jmrit.operations.trains;
002
003import org.jdom2.Attribute;
004import org.jdom2.Element;
005
006/**
007 * Loads and stores the switch list text strings.
008 *
009 * @author Daniel Boudreau Copyright (C) 2013
010 * 
011 *
012 */
013public class TrainSwitchListText {
014
015    private static String switchListFor = Bundle.getMessage("SwitchListFor");
016    private static String scheduledWork = Bundle.getMessage("ScheduledWork");
017
018    private static String departsAt = Bundle.getMessage("DepartsAt");
019    private static String departsAtExpectedArrival = Bundle.getMessage("DepartsAtExpectedArrival");
020    private static String departedExpected = Bundle.getMessage("DepartedExpected");
021
022    private static String visitNumber = Bundle.getMessage("VisitNumber");
023    private static String visitNumberDeparted = Bundle.getMessage("VisitNumberDeparted"); // this get's appended to "no
024                                                                                          // scheduled work at"
025    private static String visitNumberTerminates = Bundle.getMessage("VisitNumberTerminates");
026    private static String visitNumberTerminatesDeparted = Bundle.getMessage("VisitNumberTerminatesDeparted");
027    private static String visitNumberDone = Bundle.getMessage("VisitNumberDone");
028
029    private static String trainDirectionChange = Bundle.getMessage("TrainDirectionChange");
030    private static String noCarPickUps = Bundle.getMessage("NoCarPickUps");
031    private static String noCarDrops = Bundle.getMessage("NoCarDrops");
032    private static String trainDone = Bundle.getMessage("TrainDone");
033
034    private static String trainDepartsCars = Bundle.getMessage("TrainDepartsCars");
035    private static String trainDepartsLoads = Bundle.getMessage("TrainDepartsLoads");
036
037    private static String switchListByTrack = Bundle.getMessage("SwitchListByTrack");
038    private static String holdCar = Bundle.getMessage("HoldCar");
039
040    public static String getStringSwitchListFor() {
041        return switchListFor;
042    }
043
044    public static void setStringSwitchListFor(String s) {
045        switchListFor = s;
046    }
047
048    public static String getStringScheduledWork() {
049        return scheduledWork;
050    }
051
052    public static void setStringScheduledWork(String s) {
053        scheduledWork = s;
054    }
055
056    public static String getStringDepartsAt() {
057        return departsAt;
058    }
059
060    public static void setStringDepartsAt(String s) {
061        departsAt = s;
062    }
063
064    public static String getStringDepartsAtExpectedArrival() {
065        return departsAtExpectedArrival;
066    }
067
068    public static void setStringDepartsAtExpectedArrival(String s) {
069        departsAtExpectedArrival = s;
070    }
071
072    public static String getStringDepartedExpected() {
073        return departedExpected;
074    }
075
076    public static void setStringDepartedExpected(String s) {
077        departedExpected = s;
078    }
079
080    public static String getStringVisitNumber() {
081        return visitNumber;
082    }
083
084    public static void setStringVisitNumber(String s) {
085        visitNumber = s;
086    }
087
088    public static String getStringVisitNumberDeparted() {
089        return visitNumberDeparted;
090    }
091
092    public static void setStringVisitNumberDeparted(String s) {
093        visitNumberDeparted = s;
094    }
095
096    public static String getStringVisitNumberTerminates() {
097        return visitNumberTerminates;
098    }
099
100    public static void setStringVisitNumberTerminates(String s) {
101        visitNumberTerminates = s;
102    }
103
104    public static String getStringVisitNumberTerminatesDeparted() {
105        return visitNumberTerminatesDeparted;
106    }
107
108    public static void setStringVisitNumberTerminatesDeparted(String s) {
109        visitNumberTerminatesDeparted = s;
110    }
111
112    public static String getStringVisitNumberDone() {
113        return visitNumberDone;
114    }
115
116    public static void setStringVisitNumberDone(String s) {
117        visitNumberDone = s;
118    }
119
120    public static String getStringTrainDirectionChange() {
121        return trainDirectionChange;
122    }
123
124    public static void setStringTrainDirectionChange(String s) {
125        trainDirectionChange = s;
126    }
127
128    public static String getStringNoCarPickUps() {
129        return noCarPickUps;
130    }
131
132    public static void setStringNoCarPickUps(String s) {
133        noCarPickUps = s;
134    }
135
136    public static String getStringNoCarDrops() {
137        return noCarDrops;
138    }
139
140    public static void setStringNoCarDrops(String s) {
141        noCarDrops = s;
142    }
143
144    public static String getStringTrainDone() {
145        return trainDone;
146    }
147
148    public static void setStringTrainDone(String s) {
149        trainDone = s;
150    }
151
152    public static String getStringTrainDepartsCars() {
153        return trainDepartsCars;
154    }
155
156    public static void setStringTrainDepartsCars(String s) {
157        trainDepartsCars = s;
158    }
159
160    public static String getStringTrainDepartsLoads() {
161        return trainDepartsLoads;
162    }
163
164    public static void setStringTrainDepartsLoads(String s) {
165        trainDepartsLoads = s;
166    }
167
168    public static String getStringSwitchListByTrack() {
169        return switchListByTrack;
170    }
171
172    public static void setStringSwitchListByTrack(String s) {
173        switchListByTrack = s;
174    }
175
176    public static String getStringHoldCar() {
177        return holdCar;
178    }
179
180    public static void setStringHoldCar(String s) {
181        holdCar = s;
182    }
183
184    // must synchronize changes with operation-config.dtd
185    public static Element store() {
186        Element values;
187        Element e = new Element(Xml.SWITCH_LIST_TEXT_STRINGS);
188        // only save strings that have been modified
189        if (!getStringSwitchListFor().equals(Bundle.getMessage("SwitchListFor"))) {
190            e.addContent(values = new Element(Xml.SWICH_LIST_FOR));
191            values.setAttribute(Xml.TEXT, getStringSwitchListFor());
192        }
193        if (!getStringScheduledWork().equals(Bundle.getMessage("ScheduledWork"))) {
194            e.addContent(values = new Element(Xml.SCHEDULED_WORK_TRAIN));
195            values.setAttribute(Xml.TEXT, getStringScheduledWork());
196        }
197
198        if (!getStringDepartsAt().equals(Bundle.getMessage("DepartsAt"))) {
199            e.addContent(values = new Element(Xml.DEPARTS_AT));
200            values.setAttribute(Xml.TEXT, getStringDepartsAt());
201        }
202        if (!getStringDepartsAtExpectedArrival().equals(Bundle.getMessage("DepartsAtExpectedArrival"))) {
203            e.addContent(values = new Element(Xml.DEPARTS_EXPECTED_ARRIVAL));
204            values.setAttribute(Xml.TEXT, getStringDepartsAtExpectedArrival());
205        }
206        if (!getStringDepartedExpected().equals(Bundle.getMessage("DepartedExpected"))) {
207            e.addContent(values = new Element(Xml.DEPARTED_EXPECTED));
208            values.setAttribute(Xml.TEXT, getStringDepartedExpected());
209        }
210
211        if (!getStringVisitNumber().equals(Bundle.getMessage("VisitNumber"))) {
212            e.addContent(values = new Element(Xml.VISIT_NUMBER));
213            values.setAttribute(Xml.TEXT, getStringVisitNumber());
214        }
215        if (!getStringVisitNumberDeparted().equals(Bundle.getMessage("VisitNumberDeparted"))) {
216            e.addContent(values = new Element(Xml.VISIT_NUMBER_DEPARTED));
217            values.setAttribute(Xml.TEXT, getStringVisitNumberDeparted());
218        }
219        if (!getStringVisitNumberTerminates().equals(Bundle.getMessage("VisitNumberTerminates"))) {
220            e.addContent(values = new Element(Xml.VISIT_NUMBER_TERMINATES));
221            values.setAttribute(Xml.TEXT, getStringVisitNumberTerminates());
222        }
223        if (!getStringVisitNumberTerminatesDeparted().equals(Bundle.getMessage("VisitNumberTerminatesDeparted"))) {
224            e.addContent(values = new Element(Xml.VISIT_NUMBER_TERMINATES_DEPARTED));
225            values.setAttribute(Xml.TEXT, getStringVisitNumberTerminatesDeparted());
226        }
227        if (!getStringVisitNumberDone().equals(Bundle.getMessage("VisitNumberDone"))) {
228            e.addContent(values = new Element(Xml.VISIT_NUMBER_DONE));
229            values.setAttribute(Xml.TEXT, getStringVisitNumberDone());
230        }
231
232        if (!getStringTrainDirectionChange().equals(Bundle.getMessage("TrainDirectionChange"))) {
233            e.addContent(values = new Element(Xml.TRAIN_DIRECTION_CHANGE));
234            values.setAttribute(Xml.TEXT, getStringTrainDirectionChange());
235        }
236        if (!getStringNoCarPickUps().equals(Bundle.getMessage("NoCarPickUps"))) {
237            e.addContent(values = new Element(Xml.NO_CAR_PICK_UPS));
238            values.setAttribute(Xml.TEXT, getStringNoCarPickUps());
239        }
240        if (!getStringNoCarDrops().equals(Bundle.getMessage("NoCarDrops"))) {
241            e.addContent(values = new Element(Xml.NO_CAR_SET_OUTS));
242            values.setAttribute(Xml.TEXT, getStringNoCarDrops());
243        }
244        if (!getStringTrainDone().equals(Bundle.getMessage("TrainDone"))) {
245            e.addContent(values = new Element(Xml.TRAIN_DONE));
246            values.setAttribute(Xml.TEXT, getStringTrainDone());
247        }
248        if (!getStringTrainDepartsCars().equals(Bundle.getMessage("TrainDepartsCars"))) {
249            e.addContent(values = new Element(Xml.TRAIN_DEPARTS_CARS));
250            values.setAttribute(Xml.TEXT, getStringTrainDepartsCars());
251        }
252        if (!getStringTrainDepartsLoads().equals(Bundle.getMessage("TrainDepartsLoads"))) {
253            e.addContent(values = new Element(Xml.TRAIN_DEPARTS_LOADS));
254            values.setAttribute(Xml.TEXT, getStringTrainDepartsLoads());
255        }
256        if (!getStringSwitchListByTrack().equals(Bundle.getMessage("SwitchListByTrack"))) {
257            e.addContent(values = new Element(Xml.SWITCH_LIST_TRACK));
258            values.setAttribute(Xml.TEXT, getStringSwitchListByTrack());
259        }
260        if (!getStringHoldCar().equals(Bundle.getMessage("HoldCar"))) {
261            e.addContent(values = new Element(Xml.HOLD_CAR));
262            values.setAttribute(Xml.TEXT, getStringHoldCar());
263        }
264
265        return e;
266    }
267
268    // must synchronize changes with operation-config.dtd
269    public static void load(Element e) {
270        Element emts = e.getChild(Xml.SWITCH_LIST_TEXT_STRINGS);
271        if (emts == null) {
272            return;
273        }
274        Attribute a;
275        if (emts.getChild(Xml.SWICH_LIST_FOR) != null) {
276            if ((a = emts.getChild(Xml.SWICH_LIST_FOR).getAttribute(Xml.TEXT)) != null) {
277                setStringSwitchListFor(a.getValue());
278            }
279        }
280        if (emts.getChild(Xml.SCHEDULED_WORK_TRAIN) != null) {
281            if ((a = emts.getChild(Xml.SCHEDULED_WORK_TRAIN).getAttribute(Xml.TEXT)) != null) {
282                setStringScheduledWork(a.getValue());
283            }
284        }
285
286        if (emts.getChild(Xml.DEPARTS_AT) != null) {
287            if ((a = emts.getChild(Xml.DEPARTS_AT).getAttribute(Xml.TEXT)) != null) {
288                setStringDepartsAt(a.getValue());
289            }
290        }
291        if (emts.getChild(Xml.DEPARTS_EXPECTED_ARRIVAL) != null) {
292            if ((a = emts.getChild(Xml.DEPARTS_EXPECTED_ARRIVAL).getAttribute(Xml.TEXT)) != null) {
293                setStringDepartsAtExpectedArrival(a.getValue());
294            }
295        }
296        if (emts.getChild(Xml.DEPARTED_EXPECTED) != null) {
297            if ((a = emts.getChild(Xml.DEPARTED_EXPECTED).getAttribute(Xml.TEXT)) != null) {
298                setStringDepartedExpected(a.getValue());
299            }
300        }
301
302        if (emts.getChild(Xml.VISIT_NUMBER) != null) {
303            if ((a = emts.getChild(Xml.VISIT_NUMBER).getAttribute(Xml.TEXT)) != null) {
304                setStringVisitNumber(a.getValue());
305            }
306        }
307        if (emts.getChild(Xml.VISIT_NUMBER_DEPARTED) != null) {
308            if ((a = emts.getChild(Xml.VISIT_NUMBER_DEPARTED).getAttribute(Xml.TEXT)) != null) {
309                setStringVisitNumberDeparted(a.getValue());
310            }
311        }
312        if (emts.getChild(Xml.VISIT_NUMBER_TERMINATES) != null) {
313            if ((a = emts.getChild(Xml.VISIT_NUMBER_TERMINATES).getAttribute(Xml.TEXT)) != null) {
314                setStringVisitNumberTerminates(a.getValue());
315            }
316        }
317        if (emts.getChild(Xml.VISIT_NUMBER_TERMINATES_DEPARTED) != null) {
318            if ((a = emts.getChild(Xml.VISIT_NUMBER_TERMINATES_DEPARTED).getAttribute(Xml.TEXT)) != null) {
319                setStringVisitNumberTerminatesDeparted(a.getValue());
320            }
321        }
322        if (emts.getChild(Xml.VISIT_NUMBER_DONE) != null) {
323            if ((a = emts.getChild(Xml.VISIT_NUMBER_DONE).getAttribute(Xml.TEXT)) != null) {
324                setStringVisitNumberDone(a.getValue());
325            }
326        }
327
328        if (emts.getChild(Xml.TRAIN_DIRECTION_CHANGE) != null) {
329            if ((a = emts.getChild(Xml.TRAIN_DIRECTION_CHANGE).getAttribute(Xml.TEXT)) != null) {
330                setStringTrainDirectionChange(a.getValue());
331            }
332        }
333        if (emts.getChild(Xml.NO_CAR_PICK_UPS) != null) {
334            if ((a = emts.getChild(Xml.NO_CAR_PICK_UPS).getAttribute(Xml.TEXT)) != null) {
335                setStringNoCarPickUps(a.getValue());
336            }
337        }
338        if (emts.getChild(Xml.NO_CAR_SET_OUTS) != null) {
339            if ((a = emts.getChild(Xml.NO_CAR_SET_OUTS).getAttribute(Xml.TEXT)) != null) {
340                setStringNoCarDrops(a.getValue());
341            }
342        }
343        if (emts.getChild(Xml.TRAIN_DONE) != null) {
344            if ((a = emts.getChild(Xml.TRAIN_DONE).getAttribute(Xml.TEXT)) != null) {
345                setStringTrainDone(a.getValue());
346            }
347        }
348        if (emts.getChild(Xml.TRAIN_DEPARTS_CARS) != null) {
349            if ((a = emts.getChild(Xml.TRAIN_DEPARTS_CARS).getAttribute(Xml.TEXT)) != null) {
350                setStringTrainDepartsCars(a.getValue());
351            }
352        }
353        if (emts.getChild(Xml.TRAIN_DEPARTS_LOADS) != null) {
354            if ((a = emts.getChild(Xml.TRAIN_DEPARTS_LOADS).getAttribute(Xml.TEXT)) != null) {
355                setStringTrainDepartsLoads(a.getValue());
356            }
357        }
358        if (emts.getChild(Xml.SWITCH_LIST_TRACK) != null) {
359            if ((a = emts.getChild(Xml.SWITCH_LIST_TRACK).getAttribute(Xml.TEXT)) != null) {
360                setStringSwitchListByTrack(a.getValue());
361            }
362        }
363        if (emts.getChild(Xml.HOLD_CAR) != null) {
364            if ((a = emts.getChild(Xml.HOLD_CAR).getAttribute(Xml.TEXT)) != null) {
365                setStringHoldCar(a.getValue());
366            }
367        }
368    }
369}