001package jmri.jmrit.operations.setup;
002
003import java.awt.GridBagLayout;
004
005import javax.swing.*;
006
007import jmri.InstanceManager;
008import jmri.jmrit.operations.trains.TrainManager;
009import jmri.jmrit.operations.trains.TrainManifestHeaderText;
010
011/**
012 * Frame for user edit of manifest header text strings
013 *
014 * @author Dan Boudreau Copyright (C) 2014
015 * 
016 */
017public class EditManifestHeaderTextPanel extends OperationsPreferencesPanel {
018
019    // major buttons
020    JButton saveButton = new JButton(Bundle.getMessage("ButtonSave"));
021    JButton resetButton = new JButton(Bundle.getMessage("Reset"));
022
023    // car and engine attributes
024    JTextField road_TextField = new JTextField(25);
025    JTextField number_TextField = new JTextField(25);
026    JTextField engineNumber_TextField = new JTextField(25);
027    JTextField type_TextField = new JTextField(25);
028    JTextField length_TextField = new JTextField(25);
029    JTextField weight_TextField = new JTextField(25);
030    JTextField owner_TextField = new JTextField(25);
031    JTextField division_TextField = new JTextField(25);
032    JTextField track_TextField = new JTextField(25);
033    JTextField location_TextField = new JTextField(25);
034    JTextField destination_TextField = new JTextField(25);
035    JTextField dest_track_TextField = new JTextField(25);
036    JTextField comment_TextField = new JTextField(25);
037    // car attributes
038    JTextField load_TextField = new JTextField(25);
039    JTextField load_type_TextField = new JTextField(25);
040    JTextField hazardous_TextField = new JTextField(25);
041    JTextField color_TextField = new JTextField(25);
042    JTextField kernel_TextField = new JTextField(25);
043    JTextField final_dest_TextField = new JTextField(25);
044    JTextField final_dest_track_TextField = new JTextField(25);
045    JTextField drop_comment_TextField = new JTextField(25);
046    JTextField pickup_comment_TextField = new JTextField(25);
047    JTextField rwe_TextField = new JTextField(25);
048    // engine attributes
049    JTextField model_TextField = new JTextField(25);
050    JTextField consist_TextField = new JTextField(25);
051    JTextField dcc_address_TextField = new JTextField(25);
052
053    public EditManifestHeaderTextPanel() {
054
055        // the following code sets the frame's initial state
056        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
057
058        // manifest text fields
059        JPanel pManifest = new JPanel();
060        JScrollPane pManifestPane = new JScrollPane(pManifest);
061        pManifestPane.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutManifestHeader")));
062        pManifest.setLayout(new BoxLayout(pManifest, BoxLayout.Y_AXIS));
063
064        JPanel pRoad_TextField = new JPanel();
065        pRoad_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Road")));
066        pRoad_TextField.add(road_TextField);
067        road_TextField.setText(TrainManifestHeaderText.getStringHeader_Road());
068        pManifest.add(pRoad_TextField);
069
070        JPanel pNumber_TextField = new JPanel();
071        pNumber_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Number") + " ("
072                + Bundle.getMessage("Car") + ")"));
073        pNumber_TextField.add(number_TextField);
074        number_TextField.setText(TrainManifestHeaderText.getStringHeader_Number());
075        pManifest.add(pNumber_TextField);
076
077        JPanel pEngineNumber_TextField = new JPanel();
078        pEngineNumber_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Number") + " ("
079                + Bundle.getMessage("Loco") + ")"));
080        pEngineNumber_TextField.add(engineNumber_TextField);
081        engineNumber_TextField.setText(TrainManifestHeaderText.getStringHeader_EngineNumber());
082        pManifest.add(pEngineNumber_TextField);
083
084        JPanel pType_TextField = new JPanel();
085        pType_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Type")));
086        pType_TextField.add(type_TextField);
087        type_TextField.setText(TrainManifestHeaderText.getStringHeader_Type());
088        pManifest.add(pType_TextField);
089
090        JPanel pLength_TextField = new JPanel();
091        pLength_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Length")));
092        pLength_TextField.add(length_TextField);
093        length_TextField.setText(TrainManifestHeaderText.getStringHeader_Length());
094        pManifest.add(pLength_TextField);
095        
096        JPanel pWeight_TextField = new JPanel();
097        pWeight_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Weight")));
098        pWeight_TextField.add(weight_TextField);
099        weight_TextField.setText(TrainManifestHeaderText.getStringHeader_Weight());
100        pManifest.add(pWeight_TextField);
101
102        JPanel pOwner_TextField = new JPanel();
103        pOwner_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Owner")));
104        pOwner_TextField.add(owner_TextField);
105        owner_TextField.setText(TrainManifestHeaderText.getStringHeader_Owner());
106        pManifest.add(pOwner_TextField);
107
108        JPanel pTrack_TextField = new JPanel();
109        pTrack_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Track")));
110        pTrack_TextField.add(track_TextField);
111        track_TextField.setText(TrainManifestHeaderText.getStringHeader_Track());
112        pManifest.add(pTrack_TextField);
113
114        JPanel pLocation_TextField = new JPanel();
115        pLocation_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Location")));
116        pLocation_TextField.add(location_TextField);
117        location_TextField.setText(TrainManifestHeaderText.getStringHeader_Location());
118        pManifest.add(pLocation_TextField);
119
120        JPanel pDestination_TextField = new JPanel();
121        pDestination_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Destination")));
122        pDestination_TextField.add(destination_TextField);
123        destination_TextField.setText(TrainManifestHeaderText.getStringHeader_Destination());
124        pManifest.add(pDestination_TextField);
125
126        JPanel pDest_Track_TextField = new JPanel();
127        pDest_Track_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Dest&Track")));
128        pDest_Track_TextField.add(dest_track_TextField);
129        dest_track_TextField.setText(TrainManifestHeaderText.getStringHeader_Dest_Track());
130        pManifest.add(pDest_Track_TextField);
131
132        JPanel pComment_TextField = new JPanel();
133        pComment_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Comment")));
134        pComment_TextField.add(comment_TextField);
135        comment_TextField.setText(TrainManifestHeaderText.getStringHeader_Comment());
136        pManifest.add(pComment_TextField);
137
138        // car attributes
139        JPanel pLoad_TextField = new JPanel();
140        pLoad_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Load")));
141        pLoad_TextField.add(load_TextField);
142        load_TextField.setText(TrainManifestHeaderText.getStringHeader_Load());
143        pManifest.add(pLoad_TextField);
144        
145        JPanel pLoad_Type_TextField = new JPanel();
146        pLoad_Type_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Load_Type")));
147        pLoad_Type_TextField.add(load_type_TextField);
148        load_type_TextField.setText(TrainManifestHeaderText.getStringHeader_Load_Type());
149        pManifest.add(pLoad_Type_TextField);
150
151        JPanel pHazardous_TextField = new JPanel();
152        pHazardous_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Hazardous")));
153        pHazardous_TextField.add(hazardous_TextField);
154        hazardous_TextField.setText(TrainManifestHeaderText.getStringHeader_Hazardous());
155        pManifest.add(pHazardous_TextField);
156
157        JPanel pColor_TextField = new JPanel();
158        pColor_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Color")));
159        pColor_TextField.add(color_TextField);
160        color_TextField.setText(TrainManifestHeaderText.getStringHeader_Color());
161        pManifest.add(pColor_TextField);
162
163        JPanel pKernel_TextField = new JPanel();
164        pKernel_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Kernel")));
165        pKernel_TextField.add(kernel_TextField);
166        kernel_TextField.setText(TrainManifestHeaderText.getStringHeader_Kernel());
167        pManifest.add(pKernel_TextField);
168
169        JPanel pFinal_Dest_TextField = new JPanel();
170        pFinal_Dest_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Final_Dest")));
171        pFinal_Dest_TextField.add(final_dest_TextField);
172        final_dest_TextField.setText(TrainManifestHeaderText.getStringHeader_Final_Dest());
173        pManifest.add(pFinal_Dest_TextField);
174
175        JPanel pFinal_Dest_Track_TextField = new JPanel();
176        pFinal_Dest_Track_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("FD&Track")));
177        pFinal_Dest_Track_TextField.add(final_dest_track_TextField);
178        final_dest_track_TextField.setText(TrainManifestHeaderText.getStringHeader_Final_Dest_Track());
179        pManifest.add(pFinal_Dest_Track_TextField);
180
181        JPanel pDrop_Comment_TextField = new JPanel();
182        pDrop_Comment_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("SetOut_Msg")));
183        pDrop_Comment_TextField.add(drop_comment_TextField);
184        drop_comment_TextField.setText(TrainManifestHeaderText.getStringHeader_Drop_Comment());
185        pManifest.add(pDrop_Comment_TextField);
186
187        JPanel pPickup_Comment_TextField = new JPanel();
188        pPickup_Comment_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("PickUp_Msg")));
189        pPickup_Comment_TextField.add(pickup_comment_TextField);
190        pickup_comment_TextField.setText(TrainManifestHeaderText.getStringHeader_Pickup_Comment());
191        pManifest.add(pPickup_Comment_TextField);
192
193        JPanel pRWE_TextField = new JPanel();
194        pRWE_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("RWELabel")));
195        pRWE_TextField.add(rwe_TextField);
196        rwe_TextField.setText(TrainManifestHeaderText.getStringHeader_RWE());
197        pManifest.add(pRWE_TextField);   
198        
199        JPanel pDivision_TextField = new JPanel();
200        pDivision_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Division")));
201        pDivision_TextField.add(division_TextField);
202        division_TextField.setText(TrainManifestHeaderText.getStringHeader_Division());
203        pManifest.add(pDivision_TextField);
204
205        // engine attributes
206        JPanel pModel_TextField = new JPanel();
207        pModel_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Model")));
208        pModel_TextField.add(model_TextField);
209        model_TextField.setText(TrainManifestHeaderText.getStringHeader_Model());
210        pManifest.add(pModel_TextField);
211
212        JPanel pConsist_TextField = new JPanel();
213        pConsist_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Consist")));
214        pConsist_TextField.add(consist_TextField);
215        consist_TextField.setText(TrainManifestHeaderText.getStringHeader_Consist());
216        pManifest.add(pConsist_TextField);
217        
218        JPanel pDccAddress_TextField = new JPanel();
219        pDccAddress_TextField.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("DCC_Address")));
220        pDccAddress_TextField.add(dcc_address_TextField);
221        dcc_address_TextField.setText(TrainManifestHeaderText.getStringHeader_DCC_Address());
222        pManifest.add(pDccAddress_TextField);
223
224        // add tool tips
225        saveButton.setToolTipText(Bundle.getMessage("SaveToolTip"));
226
227        // row 11
228        JPanel pControl = new JPanel();
229        pControl.setBorder(BorderFactory.createTitledBorder(""));
230        pControl.setLayout(new GridBagLayout());
231        addItem(pControl, resetButton, 0, 0);
232        addItem(pControl, saveButton, 1, 0);
233
234        add(pManifestPane);
235        add(pControl);
236
237        // set up buttons
238        addButtonAction(resetButton);
239        addButtonAction(saveButton);
240    }
241
242    // Save buttons
243    @Override
244    public void buttonActionPerformed(java.awt.event.ActionEvent ae) {
245        if (ae.getSource() == resetButton) {
246            road_TextField.setText(Bundle.getMessage("Road"));
247            number_TextField.setText(Bundle.getMessage("Number"));
248            engineNumber_TextField.setText(Bundle.getMessage("Number"));
249            type_TextField.setText(Bundle.getMessage("Type"));
250            length_TextField.setText(Bundle.getMessage("Length"));
251            weight_TextField.setText(Bundle.getMessage("Weight"));
252            owner_TextField.setText(Bundle.getMessage("Owner"));
253            division_TextField.setText(Bundle.getMessage("Division"));
254            track_TextField.setText(Bundle.getMessage("Track"));
255            location_TextField.setText(Bundle.getMessage("Location"));
256            destination_TextField.setText(Bundle.getMessage("Destination"));
257            dest_track_TextField.setText(Bundle.getMessage("Dest&Track"));
258            comment_TextField.setText(Bundle.getMessage("Comment"));
259            // car attributes
260            load_TextField.setText(Bundle.getMessage("Load"));
261            load_type_TextField.setText(Bundle.getMessage("Load_Type"));
262            hazardous_TextField.setText(Bundle.getMessage("Hazardous"));
263            color_TextField.setText(Bundle.getMessage("Color"));
264            final_dest_TextField.setText(Bundle.getMessage("Final_Dest"));
265            final_dest_track_TextField.setText(Bundle.getMessage("FD&Track"));
266            drop_comment_TextField.setText(Bundle.getMessage("SetOut_Msg"));
267            pickup_comment_TextField.setText(Bundle.getMessage("PickUp_Msg"));
268            kernel_TextField.setText(Bundle.getMessage("Kernel"));
269            rwe_TextField.setText(Bundle.getMessage("RWELabel"));
270            // engine attributes
271            model_TextField.setText(Bundle.getMessage("Model"));
272            consist_TextField.setText(Bundle.getMessage("Consist"));
273            dcc_address_TextField.setText(Bundle.getMessage("DCC_Address"));
274        }
275        if (ae.getSource() == saveButton) {
276            this.savePreferences();
277            if (Setup.isCloseWindowOnSaveEnabled()) {
278                dispose();
279            }
280        }
281    }
282
283    @Override
284    public String getTabbedPreferencesTitle() {
285        return Bundle.getMessage("TitleManifestHeaderText");
286    }
287
288    @Override
289    public String getPreferencesTooltip() {
290        return null;
291    }
292
293    @Override
294    public void savePreferences() {
295        // car and engine attributes
296        TrainManifestHeaderText.setStringHeader_Road(road_TextField.getText());
297        TrainManifestHeaderText.setStringHeader_Number(number_TextField.getText());
298        TrainManifestHeaderText.setStringHeader_EngineNumber(engineNumber_TextField.getText());
299        TrainManifestHeaderText.setStringHeader_Type(type_TextField.getText());
300        TrainManifestHeaderText.setStringHeader_Length(length_TextField.getText());
301        TrainManifestHeaderText.setStringHeader_Weight(weight_TextField.getText());
302        TrainManifestHeaderText.setStringHeader_Owner(owner_TextField.getText());
303        TrainManifestHeaderText.setStringHeader_Track(track_TextField.getText());
304        TrainManifestHeaderText.setStringHeader_Location(location_TextField.getText());
305        TrainManifestHeaderText.setStringHeader_Destination(destination_TextField.getText());
306        TrainManifestHeaderText.setStringHeader_Dest_Track(dest_track_TextField.getText());
307        TrainManifestHeaderText.setStringHeader_Comment(comment_TextField.getText());
308        // car attributes
309        TrainManifestHeaderText.setStringHeader_Load(load_TextField.getText());
310        TrainManifestHeaderText.setStringHeader_Load_Type(load_type_TextField.getText());
311        TrainManifestHeaderText.setStringHeader_Hazardous(hazardous_TextField.getText());
312        TrainManifestHeaderText.setStringHeader_Color(color_TextField.getText());
313        TrainManifestHeaderText.setStringHeader_Final_Dest(final_dest_TextField.getText());
314        TrainManifestHeaderText.setStringHeader_Final_Dest_Track(final_dest_track_TextField.getText());
315        TrainManifestHeaderText.setStringHeader_Drop_Comment(drop_comment_TextField.getText());
316        TrainManifestHeaderText.setStringHeader_Pickup_Comment(pickup_comment_TextField.getText());
317        TrainManifestHeaderText.setStringHeader_Kernel(kernel_TextField.getText());
318        TrainManifestHeaderText.setStringHeader_RWE(rwe_TextField.getText());
319        TrainManifestHeaderText.setStringHeader_Division(division_TextField.getText());
320        // engine attributes
321        TrainManifestHeaderText.setStringHeader_Model(model_TextField.getText());
322        TrainManifestHeaderText.setStringHeader_Consist(consist_TextField.getText());
323        TrainManifestHeaderText.setStringHeader_DCC_Address(dcc_address_TextField.getText());
324
325        InstanceManager.getDefault(OperationsSetupXml.class).writeOperationsFile();
326
327        // recreate all train manifests
328        InstanceManager.getDefault(TrainManager.class).setTrainsModified();
329    }
330
331    @Override
332    public boolean isDirty() {
333        return !(TrainManifestHeaderText.getStringHeader_Road().equals(road_TextField.getText())
334                && TrainManifestHeaderText.getStringHeader_Number().equals(number_TextField.getText())
335                && TrainManifestHeaderText.getStringHeader_EngineNumber().equals(engineNumber_TextField.getText())
336                && TrainManifestHeaderText.getStringHeader_Type().equals(type_TextField.getText())
337                && TrainManifestHeaderText.getStringHeader_Length().equals(length_TextField.getText())
338                && TrainManifestHeaderText.getStringHeader_Weight().equals(weight_TextField.getText())
339                && TrainManifestHeaderText.getStringHeader_Owner().equals(owner_TextField.getText())
340                && TrainManifestHeaderText.getStringHeader_Division().equals(division_TextField.getText())
341                && TrainManifestHeaderText.getStringHeader_Track().equals(track_TextField.getText())
342                && TrainManifestHeaderText.getStringHeader_Location().equals(location_TextField.getText())
343                && TrainManifestHeaderText.getStringHeader_Destination().equals(destination_TextField.getText())
344                && TrainManifestHeaderText.getStringHeader_Dest_Track().equals(dest_track_TextField.getText())
345                && TrainManifestHeaderText.getStringHeader_Comment().equals(comment_TextField.getText())
346                && TrainManifestHeaderText.getStringHeader_Load().equals(load_TextField.getText())
347                && TrainManifestHeaderText.getStringHeader_Load_Type().equals(load_type_TextField.getText())
348                && TrainManifestHeaderText.getStringHeader_Hazardous().equals(hazardous_TextField.getText())
349                && TrainManifestHeaderText.getStringHeader_Color().equals(color_TextField.getText())
350                && TrainManifestHeaderText.getStringHeader_Final_Dest().equals(final_dest_TextField.getText())
351                && TrainManifestHeaderText.getStringHeader_Final_Dest_Track().equals(final_dest_track_TextField.getText())
352                && TrainManifestHeaderText.getStringHeader_Drop_Comment().equals(drop_comment_TextField.getText())
353                && TrainManifestHeaderText.getStringHeader_Pickup_Comment().equals(pickup_comment_TextField.getText())
354                && TrainManifestHeaderText.getStringHeader_Kernel().equals(kernel_TextField.getText())
355                && TrainManifestHeaderText.getStringHeader_RWE().equals(rwe_TextField.getText())
356                && TrainManifestHeaderText.getStringHeader_Model().equals(model_TextField.getText())
357                && TrainManifestHeaderText.getStringHeader_Consist().equals(consist_TextField.getText())
358                && TrainManifestHeaderText.getStringHeader_DCC_Address().equals(dcc_address_TextField.getText()));
359    }
360}