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