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