001package jmri.jmrit.operations.setup; 002 003import java.awt.GridBagLayout; 004import java.util.ResourceBundle; 005 006import javax.swing.*; 007 008import jmri.InstanceManager; 009import jmri.jmrit.operations.trains.TrainSwitchListText; 010 011/** 012 * Frame for user edit of switch list text strings 013 * 014 * @author Dan Boudreau Copyright (C) 2013 015 * 016 */ 017public class EditSwitchListTextPanel extends OperationsPreferencesPanel { 018 019// private static final Logger log = LoggerFactory.getLogger(EditSwitchListTextPanel.class); 020 021 protected static final ResourceBundle rb = ResourceBundle 022 .getBundle("jmri.jmrit.operations.trains.JmritOperationsTrainsBundle"); 023 024 // major buttons 025 JButton saveButton = new JButton(Bundle.getMessage("ButtonSave")); 026 JButton resetButton = new JButton(rb.getString("Reset")); 027 028 // text fields 029 JTextField switchListForTextField = new JTextField(60); 030 JTextField scheduledWorkTextField = new JTextField(60); 031 032 JTextField departsAtTextField = new JTextField(60); 033 JTextField departsAtExpectedArrivalTextField = new JTextField(60); 034 JTextField departedExpectedTextField = new JTextField(60); 035 036 JTextField visitNumberTextField = new JTextField(60); 037 JTextField visitNumberDepartedTextField = new JTextField(60); 038 JTextField visitNumberTerminatesTextField = new JTextField(60); 039 JTextField visitNumberTerminatesDepartedTextField = new JTextField(60); 040 JTextField visitNumberDoneTextField = new JTextField(60); 041 042 JTextField trainDirectionChangeTextField = new JTextField(60); 043 JTextField noCarPickUpsTextField = new JTextField(60); 044 JTextField noCarDropsTextField = new JTextField(60); 045 JTextField trainDoneTextField = new JTextField(60); 046 JTextField trainDepartsCarsTextField = new JTextField(60); 047 JTextField trainDepartsLoadsTextField = new JTextField(60); 048 049 JTextField switchListByTrackTextField = new JTextField(60); 050 JTextField holdCarTextField = new JTextField(60); 051 052 public EditSwitchListTextPanel() { 053 054 // the following code sets the frame's initial state 055 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 056 057 // text fields 058 JPanel pSwitchList = new JPanel(); 059 JScrollPane pSwitchListPane = new JScrollPane(pSwitchList); 060 pSwitchListPane.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutSwitchList"))); 061 pSwitchList.setLayout(new BoxLayout(pSwitchList, BoxLayout.Y_AXIS)); 062 063 JPanel pSwitchListForTextField = new JPanel(); 064 pSwitchListForTextField.setBorder(BorderFactory.createTitledBorder(rb 065 .getString("SwitchListFor"))); 066 pSwitchListForTextField.add(switchListForTextField); 067 switchListForTextField.setText(TrainSwitchListText.getStringSwitchListFor()); 068 switchListForTextField.setToolTipText(rb.getString("ToolTipSwitchListFor")); 069 pSwitchList.add(pSwitchListForTextField); 070 071 JPanel pScheduledWorkTextField = new JPanel(); 072 pScheduledWorkTextField.setBorder(BorderFactory.createTitledBorder(rb.getString("ScheduledWork"))); 073 pScheduledWorkTextField.add(scheduledWorkTextField); 074 scheduledWorkTextField.setText(TrainSwitchListText.getStringScheduledWork()); 075 scheduledWorkTextField.setToolTipText(rb.getString("ToolTipManifestForTrain")); 076 pSwitchList.add(pScheduledWorkTextField); 077 078 JPanel pDepartsAtTextField = new JPanel(); 079 pDepartsAtTextField.setBorder(BorderFactory.createTitledBorder(rb 080 .getString("DepartsAt"))); 081 pDepartsAtTextField.add(departsAtTextField); 082 departsAtTextField.setText(TrainSwitchListText.getStringDepartsAt()); 083 departsAtTextField.setToolTipText(rb.getString("ToolTipDepartsAt")); 084 pSwitchList.add(pDepartsAtTextField); 085 086 JPanel pDepartsAtExpectedArrivalTextField = new JPanel(); 087 pDepartsAtExpectedArrivalTextField 088 .setBorder(BorderFactory.createTitledBorder(rb.getString("DepartsAtExpectedArrival"))); 089 pDepartsAtExpectedArrivalTextField.add(departsAtExpectedArrivalTextField); 090 departsAtExpectedArrivalTextField.setText(TrainSwitchListText.getStringDepartsAtExpectedArrival()); 091 departsAtExpectedArrivalTextField.setToolTipText(rb.getString("ToolTipArrives")); 092 pSwitchList.add(pDepartsAtExpectedArrivalTextField); 093 094 JPanel pDepartedExpectedTextField = new JPanel(); 095 pDepartedExpectedTextField.setBorder(BorderFactory.createTitledBorder(rb 096 .getString("DepartedExpected"))); 097 pDepartedExpectedTextField.add(departedExpectedTextField); 098 departedExpectedTextField.setText(TrainSwitchListText.getStringDepartedExpected()); 099 departedExpectedTextField.setToolTipText(rb.getString("ToolTipDeparted")); 100 pSwitchList.add(pDepartedExpectedTextField); 101 102 JPanel pVisitNumber = new JPanel(); 103 pVisitNumber.setBorder(BorderFactory.createTitledBorder(rb.getString("VisitNumber"))); 104 pVisitNumber.add(visitNumberTextField); 105 visitNumberTextField.setText(TrainSwitchListText.getStringVisitNumber()); 106 visitNumberTextField.setToolTipText(rb.getString("ToolTipVisitNumber")); 107 pSwitchList.add(pVisitNumber); 108 109 JPanel pVisitNumberDeparted = new JPanel(); 110 pVisitNumberDeparted.setBorder(BorderFactory.createTitledBorder(rb.getString("VisitNumberDeparted"))); 111 pVisitNumberDeparted.add(visitNumberDepartedTextField); 112 visitNumberDepartedTextField.setText(TrainSwitchListText.getStringVisitNumberDeparted()); 113 visitNumberDepartedTextField.setToolTipText(rb.getString("ToolTipVisitNumber")); 114 pSwitchList.add(pVisitNumberDeparted); 115 116 JPanel pVisitNumberTerminates = new JPanel(); 117 pVisitNumberTerminates.setBorder(BorderFactory.createTitledBorder(rb.getString("VisitNumberTerminates"))); 118 pVisitNumberTerminates.add(visitNumberTerminatesTextField); 119 visitNumberTerminatesTextField.setText(TrainSwitchListText.getStringVisitNumberTerminates()); 120 visitNumberTerminatesTextField.setToolTipText(rb.getString("ToolTipVisitNumberTerminates")); 121 pSwitchList.add(pVisitNumberTerminates); 122 123 JPanel pVisitNumberTerminatesDepartedTextField = new JPanel(); 124 pVisitNumberTerminatesDepartedTextField.setBorder(BorderFactory.createTitledBorder(rb 125 .getString("VisitNumberTerminatesDeparted"))); 126 pVisitNumberTerminatesDepartedTextField.add(visitNumberTerminatesDepartedTextField); 127 visitNumberTerminatesDepartedTextField.setText(TrainSwitchListText.getStringVisitNumberTerminatesDeparted()); 128 visitNumberTerminatesDepartedTextField.setToolTipText(rb.getString("ToolTipVisitNumberTerminates")); 129 pSwitchList.add(pVisitNumberTerminatesDepartedTextField); 130 131 JPanel pVisitNumberDone = new JPanel(); 132 pVisitNumberDone.setBorder(BorderFactory.createTitledBorder(rb.getString("VisitNumberDone"))); 133 pVisitNumberDone.add(visitNumberDoneTextField); 134 visitNumberDoneTextField.setText(TrainSwitchListText.getStringVisitNumberDone()); 135 visitNumberDoneTextField.setToolTipText(rb.getString("ToolTipVisitNumberDone")); 136 pSwitchList.add(pVisitNumberDone); 137 138 JPanel pTrainDirectionChange = new JPanel(); 139 pTrainDirectionChange.setBorder(BorderFactory.createTitledBorder(rb.getString("TrainDirectionChange"))); 140 pTrainDirectionChange.add(trainDirectionChangeTextField); 141 trainDirectionChangeTextField.setText(TrainSwitchListText.getStringTrainDirectionChange()); 142 trainDirectionChangeTextField.setToolTipText(rb.getString("ToolTipDirectionChange")); 143 pSwitchList.add(pTrainDirectionChange); 144 145 JPanel pNoCarPickUps = new JPanel(); 146 pNoCarPickUps.setBorder(BorderFactory.createTitledBorder(rb.getString("NoCarPickUps"))); 147 pNoCarPickUps.add(noCarPickUpsTextField); 148 noCarPickUpsTextField.setText(TrainSwitchListText.getStringNoCarPickUps()); 149 noCarPickUpsTextField.setToolTipText(rb.getString("ToolTipTrainDone")); 150 pSwitchList.add(pNoCarPickUps); 151 152 JPanel pNoCarDrops = new JPanel(); 153 pNoCarDrops.setBorder(BorderFactory.createTitledBorder(rb.getString("NoCarDrops"))); 154 pNoCarDrops.add(noCarDropsTextField); 155 noCarDropsTextField.setText(TrainSwitchListText.getStringNoCarDrops()); 156 noCarDropsTextField.setToolTipText(rb.getString("ToolTipTrainDone")); 157 pSwitchList.add(pNoCarDrops); 158 159 JPanel pTrainDone = new JPanel(); 160 pTrainDone.setBorder(BorderFactory.createTitledBorder(rb.getString("TrainDone"))); 161 pTrainDone.add(trainDoneTextField); 162 trainDoneTextField.setText(TrainSwitchListText.getStringTrainDone()); 163 trainDoneTextField.setToolTipText(rb.getString("ToolTipTrainDone")); 164 pSwitchList.add(pTrainDone); 165 166 JPanel pTrainDepartsCars = new JPanel(); 167 pTrainDepartsCars.setBorder(BorderFactory.createTitledBorder(rb.getString("TrainDepartsCars"))); 168 pTrainDepartsCars.add(trainDepartsCarsTextField); 169 trainDepartsCarsTextField.setText(TrainSwitchListText.getStringTrainDepartsCars()); 170 trainDepartsCarsTextField.setToolTipText(rb.getString("ToolTipTrainDepartsCars")); 171 pSwitchList.add(pTrainDepartsCars); 172 173 JPanel pTrainDepartsLoadsTextField = new JPanel(); 174 pTrainDepartsLoadsTextField.setBorder(BorderFactory.createTitledBorder(rb.getString("TrainDepartsLoads"))); 175 pTrainDepartsLoadsTextField.add(trainDepartsLoadsTextField); 176 trainDepartsLoadsTextField.setText(TrainSwitchListText.getStringTrainDepartsLoads()); 177 trainDepartsLoadsTextField.setToolTipText(rb.getString("ToolTipTrainDepartsLoads")); 178 pSwitchList.add(pTrainDepartsLoadsTextField); 179 180 JPanel pSwitchListByTrackTextField = new JPanel(); 181 pSwitchListByTrackTextField.setBorder(BorderFactory.createTitledBorder(rb.getString("SwitchListByTrack"))); 182 pSwitchListByTrackTextField.add(switchListByTrackTextField); 183 switchListByTrackTextField.setText(TrainSwitchListText.getStringSwitchListByTrack()); 184 switchListByTrackTextField.setToolTipText(rb.getString("ToolTipSwitchListFor")); 185 pSwitchList.add(pSwitchListByTrackTextField); 186 187 JPanel pHoldCarTextField = new JPanel(); 188 pHoldCarTextField.setBorder(BorderFactory.createTitledBorder(rb.getString("HoldCar"))); 189 pHoldCarTextField.add(holdCarTextField); 190 holdCarTextField.setText(TrainSwitchListText.getStringHoldCar()); 191 holdCarTextField.setToolTipText(rb.getString("ToolTipHoldCar")); 192 pSwitchList.add(pHoldCarTextField); 193 194 // add tool tips 195 saveButton.setToolTipText(Bundle.getMessage("SaveToolTip")); 196 197 // row 11 198 JPanel pControl = new JPanel(); 199 pControl.setBorder(BorderFactory.createTitledBorder("")); 200 pControl.setLayout(new GridBagLayout()); 201 addItem(pControl, resetButton, 0, 0); 202 addItem(pControl, saveButton, 1, 0); 203 204 add(pSwitchListPane); 205 add(pControl); 206 207 // setup buttons 208 addButtonAction(resetButton); 209 addButtonAction(saveButton); 210 } 211 212 // Save buttons 213 @Override 214 public void buttonActionPerformed(java.awt.event.ActionEvent ae) { 215 if (ae.getSource() == resetButton) { 216 switchListForTextField.setText(rb.getString("SwitchListFor")); 217 scheduledWorkTextField.setText(rb.getString("ScheduledWork")); 218 219 departsAtTextField.setText(rb.getString("DepartsAt")); 220 departsAtExpectedArrivalTextField.setText(rb.getString("DepartsAtExpectedArrival")); 221 departedExpectedTextField.setText(rb.getString("DepartedExpected")); 222 223 visitNumberTextField.setText(rb.getString("VisitNumber")); 224 visitNumberDepartedTextField.setText(rb.getString("VisitNumberDeparted")); 225 visitNumberTerminatesTextField.setText(rb.getString("VisitNumberTerminates")); 226 visitNumberTerminatesDepartedTextField.setText(rb.getString("VisitNumberTerminatesDeparted")); 227 visitNumberDoneTextField.setText(rb.getString("VisitNumberDone")); 228 229 trainDirectionChangeTextField.setText(rb.getString("TrainDirectionChange")); 230 noCarPickUpsTextField.setText(rb.getString("NoCarPickUps")); 231 noCarDropsTextField.setText(rb.getString("NoCarDrops")); 232 trainDoneTextField.setText(rb.getString("TrainDone")); 233 trainDepartsCarsTextField.setText(rb.getString("TrainDepartsCars")); 234 trainDepartsLoadsTextField.setText(rb.getString("TrainDepartsLoads")); 235 236 switchListByTrackTextField.setText(rb.getString("SwitchListByTrack")); 237 holdCarTextField.setText(rb.getString("HoldCar")); 238 } 239 if (ae.getSource() == saveButton) { 240 this.savePreferences(); 241 var topLevelAncestor = getTopLevelAncestor(); 242 if (Setup.isCloseWindowOnSaveEnabled() && topLevelAncestor instanceof EditSwitchListTextFrame) { 243 ((EditSwitchListTextFrame) topLevelAncestor).dispose(); 244 } 245 } 246 } 247 248 @Override 249 public String getTabbedPreferencesTitle() { 250 return Bundle.getMessage("TitleSwitchListText"); 251 } 252 253 @Override 254 public String getPreferencesTooltip() { 255 return null; 256 } 257 258 @Override 259 public void savePreferences() { 260 TrainSwitchListText.setStringSwitchListFor(switchListForTextField.getText()); 261 TrainSwitchListText.setStringScheduledWork(scheduledWorkTextField.getText()); 262 263 TrainSwitchListText.setStringDepartsAt(departsAtTextField.getText()); 264 TrainSwitchListText.setStringDepartsAtExpectedArrival(departsAtExpectedArrivalTextField.getText()); 265 TrainSwitchListText.setStringDepartedExpected(departedExpectedTextField.getText()); 266 267 TrainSwitchListText.setStringVisitNumber(visitNumberTextField.getText()); 268 TrainSwitchListText.setStringVisitNumberDeparted(visitNumberDepartedTextField.getText()); 269 TrainSwitchListText.setStringVisitNumberTerminates(visitNumberTerminatesTextField.getText()); 270 TrainSwitchListText.setStringVisitNumberTerminatesDeparted(visitNumberTerminatesDepartedTextField.getText()); 271 TrainSwitchListText.setStringVisitNumberDone(visitNumberDoneTextField.getText()); 272 273 TrainSwitchListText.setStringTrainDirectionChange(trainDirectionChangeTextField.getText()); 274 TrainSwitchListText.setStringNoCarPickUps(noCarPickUpsTextField.getText()); 275 TrainSwitchListText.setStringNoCarDrops(noCarDropsTextField.getText()); 276 TrainSwitchListText.setStringTrainDone(trainDoneTextField.getText()); 277 TrainSwitchListText.setStringTrainDepartsCars(trainDepartsCarsTextField.getText()); 278 TrainSwitchListText.setStringTrainDepartsLoads(trainDepartsLoadsTextField.getText()); 279 280 TrainSwitchListText.setStringSwitchListByTrack(switchListByTrackTextField.getText()); 281 TrainSwitchListText.setStringHoldCar(holdCarTextField.getText()); 282 283 InstanceManager.getDefault(OperationsSetupXml.class).writeOperationsFile(); 284 } 285 286 @Override 287 public boolean isDirty() { 288 return !(TrainSwitchListText.getStringSwitchListFor().equals(switchListForTextField.getText()) 289 && TrainSwitchListText.getStringScheduledWork().equals(scheduledWorkTextField.getText()) 290 && TrainSwitchListText.getStringDepartsAt().equals(departsAtTextField.getText()) 291 && TrainSwitchListText.getStringDepartsAtExpectedArrival().equals(departsAtExpectedArrivalTextField.getText()) 292 && TrainSwitchListText.getStringDepartedExpected().equals(departedExpectedTextField.getText()) 293 && TrainSwitchListText.getStringVisitNumber().equals(visitNumberTextField.getText()) 294 && TrainSwitchListText.getStringVisitNumberDeparted().equals(visitNumberDepartedTextField.getText()) 295 && TrainSwitchListText.getStringVisitNumberTerminates().equals(visitNumberTerminatesTextField.getText()) 296 && TrainSwitchListText.getStringVisitNumberTerminatesDeparted().equals(visitNumberTerminatesDepartedTextField.getText()) 297 && TrainSwitchListText.getStringVisitNumberDone().equals(visitNumberDoneTextField.getText()) 298 && TrainSwitchListText.getStringTrainDirectionChange().equals(trainDirectionChangeTextField.getText()) 299 && TrainSwitchListText.getStringNoCarPickUps().equals(noCarPickUpsTextField.getText()) 300 && TrainSwitchListText.getStringNoCarDrops().equals(noCarDropsTextField.getText()) 301 && TrainSwitchListText.getStringTrainDone().equals(trainDoneTextField.getText())) 302 && TrainSwitchListText.getStringTrainDepartsCars().equals(trainDepartsCarsTextField.getText()) 303 && TrainSwitchListText.getStringTrainDepartsLoads().equals(trainDepartsLoadsTextField.getText()) 304 && TrainSwitchListText.getStringSwitchListByTrack().equals(switchListByTrackTextField.getText()) 305 && TrainSwitchListText.getStringHoldCar().equals(holdCarTextField.getText()) 306 ; 307 } 308}