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