001package jmri.jmrit.operations.setup.gui; 002 003import java.awt.GridBagLayout; 004import java.util.ResourceBundle; 005 006import javax.swing.*; 007 008import jmri.InstanceManager; 009import jmri.jmrit.operations.setup.OperationsSetupXml; 010import jmri.jmrit.operations.setup.Setup; 011import jmri.jmrit.operations.trains.TrainManager; 012import jmri.jmrit.operations.trains.TrainManifestText; 013 014/** 015 * Frame for user edit of manifest text strings 016 * 017 * @author Dan Boudreau Copyright (C) 2013 018 * 019 */ 020public class EditManifestTextPanel extends OperationsPreferencesPanel { 021 022 protected static final ResourceBundle rb = ResourceBundle 023 .getBundle("jmri.jmrit.operations.trains.JmritOperationsTrainsBundle"); 024 025 // major buttons 026 JButton saveButton = new JButton(Bundle.getMessage("ButtonSave")); 027 JButton resetButton = new JButton(Bundle.getMessage("Reset")); 028 029 // text field 030 JTextField manifestForTrainTextField = new JTextField(60); 031 JTextField validTextField = new JTextField(60); 032 JTextField scheduledWorkAtTextField = new JTextField(60); 033 JTextField scheduledWorkDepartureTextField = new JTextField(60); 034 JTextField scheduledWorkArrivalTextField = new JTextField(60); 035 JTextField noScheduledWorkAtTextField = new JTextField(60); 036 JTextField noScheduledWorkAtWithRouteCommentTextField = new JTextField(60); 037 JTextField departTimeTextField = new JTextField(60); 038 JTextField trainDepartsCarsTextField = new JTextField(60); 039 JTextField trainDepartsLoadsTextField = new JTextField(60); 040 JTextField trainTerminatesInTextField = new JTextField(60); 041 042 JTextField destinationTextField = new JTextField(60); 043 JTextField toTextField = new JTextField(25); 044 JTextField fromTextField = new JTextField(25); 045 JTextField destTextField = new JTextField(25); 046 JTextField finalDestinationTextField = new JTextField(25); 047 048 JTextField addHelpersAtTextField = new JTextField(60); 049 JTextField removeHelpersAtTextField = new JTextField(60); 050 JTextField locoChangeAtTextField = new JTextField(60); 051 JTextField cabooseChangeAtTextField = new JTextField(60); 052 JTextField locoAndCabooseChangeAtTextField = new JTextField(60); 053 054 public EditManifestTextPanel() { 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("BorderLayoutManifest"))); 063 pManifest.setLayout(new BoxLayout(pManifest, BoxLayout.Y_AXIS)); 064 065 JPanel pManifestForTrainTextField = new JPanel(); 066 pManifestForTrainTextField.setBorder(BorderFactory.createTitledBorder(rb.getString("ManifestForTrain"))); 067 pManifestForTrainTextField.add(manifestForTrainTextField); 068 manifestForTrainTextField.setText(TrainManifestText.getStringManifestForTrain()); 069 manifestForTrainTextField.setToolTipText(rb.getString("ToolTipManifestForTrain")); 070 pManifest.add(pManifestForTrainTextField); 071 072 JPanel pValidTextField = new JPanel(); 073 pValidTextField.setBorder(BorderFactory.createTitledBorder(rb.getString("Valid"))); 074 pValidTextField.add(validTextField); 075 validTextField.setText(TrainManifestText.getStringValid()); 076 validTextField.setToolTipText(rb.getString("ToolTipValid")); 077 pManifest.add(pValidTextField); 078 079 JPanel pScheduledWorkAtTextField = new JPanel(); 080 pScheduledWorkAtTextField.setBorder(BorderFactory.createTitledBorder(rb.getString("ScheduledWorkAt"))); 081 pScheduledWorkAtTextField.add(scheduledWorkAtTextField); 082 scheduledWorkAtTextField.setText(TrainManifestText.getStringScheduledWork()); 083 scheduledWorkAtTextField.setToolTipText(rb.getString("ToolTipScheduledWorkAt")); 084 pManifest.add(pScheduledWorkAtTextField); 085 086 JPanel pScheduledWorkDepartureTextField = new JPanel(); 087 pScheduledWorkDepartureTextField.setBorder(BorderFactory.createTitledBorder(rb.getString("WorkDepartureTime"))); 088 pScheduledWorkDepartureTextField.add(scheduledWorkDepartureTextField); 089 scheduledWorkDepartureTextField.setText(TrainManifestText.getStringWorkDepartureTime()); 090 scheduledWorkDepartureTextField.setToolTipText(rb.getString("ToolTipWorkDepartureTime")); 091 pManifest.add(pScheduledWorkDepartureTextField); 092 093 JPanel pScheduledWorkArrivalTextField = new JPanel(); 094 pScheduledWorkArrivalTextField.setBorder(BorderFactory.createTitledBorder(rb.getString("WorkArrivalTime"))); 095 pScheduledWorkArrivalTextField.add(scheduledWorkArrivalTextField); 096 scheduledWorkArrivalTextField.setText(TrainManifestText.getStringWorkArrivalTime()); 097 scheduledWorkArrivalTextField.setToolTipText(rb.getString("ToolTipWorkDepartureTime")); 098 pManifest.add(pScheduledWorkArrivalTextField); 099 100 JPanel pNoScheduledWorkAt = new JPanel(); 101 pNoScheduledWorkAt.setBorder(BorderFactory.createTitledBorder(rb.getString("NoScheduledWorkAt"))); 102 pNoScheduledWorkAt.add(noScheduledWorkAtTextField); 103 noScheduledWorkAtTextField.setText(TrainManifestText.getStringNoScheduledWork()); 104 noScheduledWorkAtTextField.setToolTipText(rb.getString("ToolTipScheduledWorkAt")); 105 pManifest.add(pNoScheduledWorkAt); 106 107 JPanel pNoScheduledWorkAtWithRouteComment = new JPanel(); 108 pNoScheduledWorkAtWithRouteComment.setBorder(BorderFactory.createTitledBorder(rb 109 .getString("NoScheduledWorkAtWithRouteComment"))); 110 pNoScheduledWorkAtWithRouteComment.add(noScheduledWorkAtWithRouteCommentTextField); 111 noScheduledWorkAtWithRouteCommentTextField 112 .setText(TrainManifestText.getStringNoScheduledWorkWithRouteComment()); 113 noScheduledWorkAtWithRouteCommentTextField.setToolTipText(rb 114 .getString("ToolTipNoScheduledWorkAtWithRouteComment")); 115 pManifest.add(pNoScheduledWorkAtWithRouteComment); 116 117 JPanel pDepartTime = new JPanel(); 118 pDepartTime.setBorder(BorderFactory.createTitledBorder(rb.getString("departureTime"))); 119 pDepartTime.add(departTimeTextField); 120 departTimeTextField.setText(TrainManifestText.getStringDepartTime()); 121 departTimeTextField.setToolTipText(rb.getString("ToolTipNoScheduledWorkShowTime")); 122 pManifest.add(pDepartTime); 123 124 JPanel pTrainDepartsCars = new JPanel(); 125 pTrainDepartsCars.setBorder(BorderFactory.createTitledBorder(rb.getString("TrainDepartsCars"))); 126 pTrainDepartsCars.add(trainDepartsCarsTextField); 127 trainDepartsCarsTextField.setText(TrainManifestText.getStringTrainDepartsCars()); 128 trainDepartsCarsTextField.setToolTipText(rb.getString("ToolTipTrainDepartsCars")); 129 pManifest.add(pTrainDepartsCars); 130 131 JPanel pTrainDepartsLoadsTextField = new JPanel(); 132 pTrainDepartsLoadsTextField.setBorder(BorderFactory.createTitledBorder(rb.getString("TrainDepartsLoads"))); 133 pTrainDepartsLoadsTextField.add(trainDepartsLoadsTextField); 134 trainDepartsLoadsTextField.setText(TrainManifestText.getStringTrainDepartsLoads()); 135 trainDepartsLoadsTextField.setToolTipText(rb.getString("ToolTipTrainDepartsLoads")); 136 pManifest.add(pTrainDepartsLoadsTextField); 137 138 JPanel pTrainTerminatesIn = new JPanel(); 139 pTrainTerminatesIn.setBorder(BorderFactory.createTitledBorder(rb.getString("TrainTerminatesIn"))); 140 pTrainTerminatesIn.add(trainTerminatesInTextField); 141 trainTerminatesInTextField.setText(TrainManifestText.getStringTrainTerminates()); 142 trainTerminatesInTextField.setToolTipText(rb.getString("ToolTipScheduledWorkAt")); 143 pManifest.add(pTrainTerminatesIn); 144 145 JPanel pDestination = new JPanel(); 146 pDestination.setBorder(BorderFactory.createTitledBorder(rb.getString("destination"))); 147 pDestination.add(destinationTextField); 148 destinationTextField.setText(TrainManifestText.getStringDestination()); 149 pManifest.add(pDestination); 150 151 JPanel pToFrom = new JPanel(); 152 pToFrom.setLayout(new BoxLayout(pToFrom, BoxLayout.X_AXIS)); 153 154 JPanel pTo = new JPanel(); 155 pTo.setBorder(BorderFactory.createTitledBorder(rb.getString("to"))); 156 pTo.add(toTextField); 157 toTextField.setText(TrainManifestText.getStringTo()); 158 pToFrom.add(pTo); 159 160 JPanel pFrom = new JPanel(); 161 pFrom.setBorder(BorderFactory.createTitledBorder(rb.getString("from"))); 162 pFrom.add(fromTextField); 163 fromTextField.setText(TrainManifestText.getStringFrom()); 164 pToFrom.add(pFrom); 165 166 pManifest.add(pToFrom); 167 168 JPanel pDestFinalDest = new JPanel(); 169 pDestFinalDest.setLayout(new BoxLayout(pDestFinalDest, BoxLayout.X_AXIS)); 170 171 JPanel pDest = new JPanel(); 172 pDest.setBorder(BorderFactory.createTitledBorder(rb.getString("dest"))); 173 pDest.add(destTextField); 174 destTextField.setText(TrainManifestText.getStringDest()); 175 pDestFinalDest.add(pDest); 176 177 JPanel pFinalDestination = new JPanel(); 178 pFinalDestination.setBorder(BorderFactory.createTitledBorder(rb.getString("FD") + " (" 179 + Bundle.getMessage("FinalDestination") + ")")); 180 pFinalDestination.add(finalDestinationTextField); 181 finalDestinationTextField.setText(TrainManifestText.getStringFinalDestination()); 182 pDestFinalDest.add(pFinalDestination); 183 184 pManifest.add(pDestFinalDest); 185 186 JPanel pAddHelpersAt = new JPanel(); 187 pAddHelpersAt.setBorder(BorderFactory.createTitledBorder(rb.getString("AddHelpersAt"))); 188 pAddHelpersAt.add(addHelpersAtTextField); 189 addHelpersAtTextField.setText(TrainManifestText.getStringAddHelpers()); 190 addHelpersAtTextField.setToolTipText(rb.getString("ToolTipAddHelpers")); 191 pManifest.add(pAddHelpersAt); 192 193 JPanel pRemoveHelpersAt = new JPanel(); 194 pRemoveHelpersAt.setBorder(BorderFactory.createTitledBorder(rb.getString("RemoveHelpersAt"))); 195 pRemoveHelpersAt.add(removeHelpersAtTextField); 196 removeHelpersAtTextField.setText(TrainManifestText.getStringRemoveHelpers()); 197 removeHelpersAtTextField.setToolTipText(rb.getString("ToolTipRemoveHelpers")); 198 pManifest.add(pRemoveHelpersAt); 199 200 JPanel pLocoChangeAt = new JPanel(); 201 pLocoChangeAt.setBorder(BorderFactory.createTitledBorder(rb.getString("LocoChangeAt"))); 202 pLocoChangeAt.add(locoChangeAtTextField); 203 locoChangeAtTextField.setText(TrainManifestText.getStringLocoChange()); 204 locoChangeAtTextField.setToolTipText(rb.getString("ToolTipScheduledWorkAt")); 205 pManifest.add(pLocoChangeAt); 206 207 JPanel pCabooseChangeAt = new JPanel(); 208 pCabooseChangeAt.setBorder(BorderFactory.createTitledBorder(rb.getString("CabooseChangeAt"))); 209 pCabooseChangeAt.add(cabooseChangeAtTextField); 210 cabooseChangeAtTextField.setText(TrainManifestText.getStringCabooseChange()); 211 cabooseChangeAtTextField.setToolTipText(rb.getString("ToolTipScheduledWorkAt")); 212 pManifest.add(pCabooseChangeAt); 213 214 JPanel pLocoAndCabooseChangeAt = new JPanel(); 215 pLocoAndCabooseChangeAt.setBorder(BorderFactory.createTitledBorder(rb.getString("LocoAndCabooseChangeAt"))); 216 pLocoAndCabooseChangeAt.add(locoAndCabooseChangeAtTextField); 217 locoAndCabooseChangeAtTextField.setText(TrainManifestText.getStringLocoAndCabooseChange()); 218 locoAndCabooseChangeAtTextField.setToolTipText(rb.getString("ToolTipScheduledWorkAt")); 219 pManifest.add(pLocoAndCabooseChangeAt); 220 221 // add tool tips 222 saveButton.setToolTipText(Bundle.getMessage("SaveToolTip")); 223 224 // row 11 225 JPanel pControl = new JPanel(); 226 pControl.setBorder(BorderFactory.createTitledBorder("")); 227 pControl.setLayout(new GridBagLayout()); 228 addItem(pControl, resetButton, 0, 0); 229 addItem(pControl, saveButton, 1, 0); 230 231 add(pManifestPane); 232 add(pControl); 233 234 // setup buttons 235 addButtonAction(resetButton); 236 addButtonAction(saveButton); 237 } 238 239 // Save buttons 240 @Override 241 public void buttonActionPerformed(java.awt.event.ActionEvent ae) { 242 if (ae.getSource() == resetButton) { 243 manifestForTrainTextField.setText(rb.getString("ManifestForTrain")); 244 validTextField.setText(rb.getString("Valid")); 245 scheduledWorkAtTextField.setText(rb.getString("ScheduledWorkAt")); 246 scheduledWorkDepartureTextField.setText(rb.getString("WorkDepartureTime")); 247 scheduledWorkArrivalTextField.setText(rb.getString("WorkArrivalTime")); 248 noScheduledWorkAtTextField.setText(rb.getString("NoScheduledWorkAt")); 249 noScheduledWorkAtWithRouteCommentTextField.setText(rb.getString("NoScheduledWorkAtWithRouteComment")); 250 departTimeTextField.setText(rb.getString("departureTime")); 251 trainDepartsCarsTextField.setText(rb.getString("TrainDepartsCars")); 252 trainDepartsLoadsTextField.setText(rb.getString("TrainDepartsLoads")); 253 trainTerminatesInTextField.setText(rb.getString("TrainTerminatesIn")); 254 255 destinationTextField.setText(rb.getString("destination")); 256 toTextField.setText(rb.getString("to")); 257 fromTextField.setText(rb.getString("from")); 258 destTextField.setText(rb.getString("dest")); 259 finalDestinationTextField.setText(rb.getString("FD")); 260 261 addHelpersAtTextField.setText(rb.getString("AddHelpersAt")); 262 removeHelpersAtTextField.setText(rb.getString("RemoveHelpersAt")); 263 locoChangeAtTextField.setText(rb.getString("LocoChangeAt")); 264 cabooseChangeAtTextField.setText(rb.getString("CabooseChangeAt")); 265 locoAndCabooseChangeAtTextField.setText(rb.getString("LocoAndCabooseChangeAt")); 266 } 267 if (ae.getSource() == saveButton) { 268 this.savePreferences(); 269 var topLevelAncestor = getTopLevelAncestor(); 270 if (Setup.isCloseWindowOnSaveEnabled() && topLevelAncestor instanceof EditManifestTextFrame) { 271 ((EditManifestTextFrame) topLevelAncestor).dispose(); 272 } 273 } 274 } 275 276 @Override 277 public String getTabbedPreferencesTitle() { 278 return Bundle.getMessage("TitleManifestText"); 279 } 280 281 @Override 282 public String getPreferencesTooltip() { 283 return null; 284 } 285 286 @Override 287 public void savePreferences() { 288 TrainManifestText.setStringManifestForTrain(manifestForTrainTextField.getText()); 289 TrainManifestText.setStringValid(validTextField.getText()); 290 TrainManifestText.setStringScheduledWork(scheduledWorkAtTextField.getText()); 291 TrainManifestText.setStringWorkDepartureTime(scheduledWorkDepartureTextField.getText()); 292 TrainManifestText.setStringWorkArrivalTime(scheduledWorkArrivalTextField.getText()); 293 TrainManifestText.setStringNoScheduledWork(noScheduledWorkAtTextField.getText()); 294 TrainManifestText.setStringNoScheduledWorkWithRouteComment(noScheduledWorkAtWithRouteCommentTextField.getText()); 295 TrainManifestText.setStringDepartTime(departTimeTextField.getText()); 296 TrainManifestText.setStringTrainDepartsCars(trainDepartsCarsTextField.getText()); 297 TrainManifestText.setStringTrainDepartsLoads(trainDepartsLoadsTextField.getText()); 298 TrainManifestText.setStringTrainTerminates(trainTerminatesInTextField.getText()); 299 300 TrainManifestText.setStringDestination(destinationTextField.getText()); 301 TrainManifestText.setStringTo(toTextField.getText()); 302 TrainManifestText.setStringFrom(fromTextField.getText()); 303 TrainManifestText.setStringDest(destTextField.getText()); 304 TrainManifestText.setStringFinalDestination(finalDestinationTextField.getText()); 305 306 TrainManifestText.setStringAddHelpers(addHelpersAtTextField.getText()); 307 TrainManifestText.setStringRemoveHelpers(removeHelpersAtTextField.getText()); 308 TrainManifestText.setStringLocoChange(locoChangeAtTextField.getText()); 309 TrainManifestText.setStringCabooseChange(cabooseChangeAtTextField.getText()); 310 TrainManifestText.setStringLocoAndCabooseChange(locoAndCabooseChangeAtTextField.getText()); 311 312 InstanceManager.getDefault(OperationsSetupXml.class).writeOperationsFile(); 313 314 // recreate all train manifests 315 InstanceManager.getDefault(TrainManager.class).setTrainsModified(); 316 } 317 318 @Override 319 public boolean isDirty() { 320 return !(TrainManifestText.getStringManifestForTrain().equals(manifestForTrainTextField.getText()) 321 && TrainManifestText.getStringValid().equals(validTextField.getText()) 322 && TrainManifestText.getStringScheduledWork().equals(scheduledWorkAtTextField.getText()) 323 && TrainManifestText.getStringWorkDepartureTime().equals(scheduledWorkDepartureTextField.getText()) 324 && TrainManifestText.getStringWorkArrivalTime().equals(scheduledWorkArrivalTextField.getText()) 325 && TrainManifestText.getStringNoScheduledWork().equals(noScheduledWorkAtTextField.getText()) 326 && TrainManifestText.getStringNoScheduledWorkWithRouteComment().equals(noScheduledWorkAtWithRouteCommentTextField.getText()) 327 && TrainManifestText.getStringDepartTime().equals(departTimeTextField.getText()) 328 && TrainManifestText.getStringTrainDepartsCars().equals(trainDepartsCarsTextField.getText()) 329 && TrainManifestText.getStringTrainDepartsLoads().equals(trainDepartsLoadsTextField.getText()) 330 && TrainManifestText.getStringTrainTerminates().equals(trainTerminatesInTextField.getText()) 331 && TrainManifestText.getStringDestination().equals(destinationTextField.getText()) 332 && TrainManifestText.getStringTo().equals(toTextField.getText()) 333 && TrainManifestText.getStringFrom().equals(fromTextField.getText()) 334 && TrainManifestText.getStringDest().equals(destTextField.getText()) 335 && TrainManifestText.getStringFinalDestination().equals(finalDestinationTextField.getText()) 336 && TrainManifestText.getStringAddHelpers().equals(addHelpersAtTextField.getText()) 337 && TrainManifestText.getStringRemoveHelpers().equals(removeHelpersAtTextField.getText()) 338 && TrainManifestText.getStringLocoChange().equals(locoChangeAtTextField.getText()) 339 && TrainManifestText.getStringCabooseChange().equals(cabooseChangeAtTextField.getText()) 340 && TrainManifestText.getStringLocoAndCabooseChange().equals(locoAndCabooseChangeAtTextField.getText())); 341 } 342}