001package jmri.jmrit.operations.locations.gui; 002 003import java.awt.*; 004import java.util.ArrayList; 005import java.util.List; 006 007import javax.swing.*; 008 009import jmri.*; 010import jmri.jmrit.operations.OperationsFrame; 011import jmri.jmrit.operations.OperationsXml; 012import jmri.jmrit.operations.locations.*; 013import jmri.jmrit.operations.locations.tools.*; 014import jmri.jmrit.operations.rollingstock.cars.*; 015import jmri.jmrit.operations.rollingstock.engines.EngineTypes; 016import jmri.jmrit.operations.routes.Route; 017import jmri.jmrit.operations.routes.RouteManager; 018import jmri.jmrit.operations.setup.Control; 019import jmri.jmrit.operations.setup.Setup; 020import jmri.jmrit.operations.trains.*; 021import jmri.swing.NamedBeanComboBox; 022import jmri.util.swing.JmriJOptionPane; 023 024/** 025 * Frame for user edit of tracks. Base for edit of all track types. 026 * 027 * @author Dan Boudreau Copyright (C) 2008, 2010, 2011, 2012, 2013, 2023 028 */ 029public abstract class TrackEditFrame extends OperationsFrame implements java.beans.PropertyChangeListener { 030 031 // where in the tool menu new items are inserted 032 protected static final int TOOL_MENU_OFFSET = 6; 033 034 // Managers 035 TrainManager trainManager = InstanceManager.getDefault(TrainManager.class); 036 RouteManager routeManager = InstanceManager.getDefault(RouteManager.class); 037 038 public Location _location = null; 039 public Track _track = null; 040 String _type = ""; 041 JMenu _toolMenu = new JMenu(Bundle.getMessage("MenuTools")); 042 043 List<JCheckBox> checkBoxes = new ArrayList<>(); 044 045 // panels 046 JPanel panelCheckBoxes = new JPanel(); 047 JScrollPane paneCheckBoxes = new JScrollPane(panelCheckBoxes); 048 JPanel panelTrainDir = new JPanel(); 049 JPanel pShipLoadOption = new JPanel(); 050 JPanel pDestinationOption = new JPanel(); 051 JPanel panelOrder = new JPanel(); 052 053 // Alternate tool buttons 054 JButton loadOptionButton = new JButton(Bundle.getMessage("AcceptsAllLoads")); 055 JButton shipLoadOptionButton = new JButton(Bundle.getMessage("ShipsAllLoads")); 056 JButton roadOptionButton = new JButton(Bundle.getMessage("AcceptsAllRoads")); 057 JButton destinationOptionButton = new JButton(); 058 059 // major buttons 060 JButton clearButton = new JButton(Bundle.getMessage("ClearAll")); 061 JButton setButton = new JButton(Bundle.getMessage("SelectAll")); 062 JButton autoSelectButton = new JButton(Bundle.getMessage("AutoSelect")); 063 064 JButton saveTrackButton = new JButton(Bundle.getMessage("SaveTrack")); 065 JButton deleteTrackButton = new JButton(Bundle.getMessage("DeleteTrack")); 066 JButton addTrackButton = new JButton(Bundle.getMessage("AddTrack")); 067 068 JButton deleteDropButton = new JButton(Bundle.getMessage("ButtonDelete")); 069 JButton addDropButton = new JButton(Bundle.getMessage("Add")); 070 JButton deletePickupButton = new JButton(Bundle.getMessage("ButtonDelete")); 071 JButton addPickupButton = new JButton(Bundle.getMessage("Add")); 072 073 // check boxes 074 JCheckBox northCheckBox = new JCheckBox(Bundle.getMessage("North")); 075 JCheckBox southCheckBox = new JCheckBox(Bundle.getMessage("South")); 076 JCheckBox eastCheckBox = new JCheckBox(Bundle.getMessage("East")); 077 JCheckBox westCheckBox = new JCheckBox(Bundle.getMessage("West")); 078 JCheckBox autoDropCheckBox = new JCheckBox(Bundle.getMessage("Auto")); 079 JCheckBox autoPickupCheckBox = new JCheckBox(Bundle.getMessage("Auto")); 080 081 // car pick up order controls 082 JRadioButton orderNormal = new JRadioButton(Bundle.getMessage("Normal")); 083 JRadioButton orderFIFO = new JRadioButton(Bundle.getMessage("DescriptiveFIFO")); 084 JRadioButton orderLIFO = new JRadioButton(Bundle.getMessage("DescriptiveLIFO")); 085 086 JRadioButton anyDrops = new JRadioButton(Bundle.getMessage("Any")); 087 JRadioButton trainDrop = new JRadioButton(Bundle.getMessage("Trains")); 088 JRadioButton routeDrop = new JRadioButton(Bundle.getMessage("Routes")); 089 JRadioButton excludeTrainDrop = new JRadioButton(Bundle.getMessage("ExcludeTrains")); 090 JRadioButton excludeRouteDrop = new JRadioButton(Bundle.getMessage("ExcludeRoutes")); 091 092 JRadioButton anyPickups = new JRadioButton(Bundle.getMessage("Any")); 093 JRadioButton trainPickup = new JRadioButton(Bundle.getMessage("Trains")); 094 JRadioButton routePickup = new JRadioButton(Bundle.getMessage("Routes")); 095 JRadioButton excludeTrainPickup = new JRadioButton(Bundle.getMessage("ExcludeTrains")); 096 JRadioButton excludeRoutePickup = new JRadioButton(Bundle.getMessage("ExcludeRoutes")); 097 098 JComboBox<Train> comboBoxDropTrains = trainManager.getTrainComboBox(); 099 JComboBox<Route> comboBoxDropRoutes = routeManager.getComboBox(); 100 JComboBox<Train> comboBoxPickupTrains = trainManager.getTrainComboBox(); 101 JComboBox<Route> comboBoxPickupRoutes = routeManager.getComboBox(); 102 103 // text field 104 JTextField trackNameTextField = new JTextField(Control.max_len_string_track_name); 105 JTextField trackLengthTextField = new JTextField(Control.max_len_string_track_length_name); 106 107 // text area 108 JTextArea commentTextArea = new JTextArea(2, 60); 109 JScrollPane commentScroller = new JScrollPane(commentTextArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, 110 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 111 112 // optional panel for spurs, staging, and interchanges 113 JPanel dropPanel = new JPanel(); 114 JPanel pickupPanel = new JPanel(); 115 JPanel panelOpt3 = new JPanel(); // not currently used 116 JPanel panelOpt4 = new JPanel(); 117 118 // Reader selection dropdown. 119 NamedBeanComboBox<Reporter> readerSelector; 120 121 public static final String DISPOSE = "dispose"; // NOI18N 122 public static final int MAX_NAME_LENGTH = Control.max_len_string_track_name; 123 124 public TrackEditFrame(String title) { 125 super(title); 126 } 127 128 protected abstract void initComponents(Track track); 129 130 public void initComponents(Location location, Track track) { 131 _location = location; 132 _track = track; 133 134 // tool tips 135 autoDropCheckBox.setToolTipText(Bundle.getMessage("TipAutoTrack")); 136 autoPickupCheckBox.setToolTipText(Bundle.getMessage("TipAutoTrack")); 137 trackLengthTextField.setToolTipText(Bundle.getMessage("TipTrackLength", 138 Setup.getLengthUnit().toLowerCase())); 139 140 // property changes 141 _location.addPropertyChangeListener(this); 142 // listen for car road name and type changes 143 InstanceManager.getDefault(CarRoads.class).addPropertyChangeListener(this); 144 InstanceManager.getDefault(CarLoads.class).addPropertyChangeListener(this); 145 InstanceManager.getDefault(CarTypes.class).addPropertyChangeListener(this); 146 InstanceManager.getDefault(Setup.class).addPropertyChangeListener(this); 147 trainManager.addPropertyChangeListener(this); 148 routeManager.addPropertyChangeListener(this); 149 150 // the following code sets the frame's initial state 151 getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); 152 153 // place all panels in a scroll pane. 154 JPanel panels = new JPanel(); 155 panels.setLayout(new BoxLayout(panels, BoxLayout.Y_AXIS)); 156 JScrollPane pane = new JScrollPane(panels); 157 158 // row 1 159 JPanel p1 = new JPanel(); 160 p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS)); 161 JScrollPane p1Pane = new JScrollPane(p1); 162 p1Pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); 163 p1Pane.setMinimumSize(new Dimension(300, 3 * trackNameTextField.getPreferredSize().height)); 164 p1Pane.setBorder(BorderFactory.createTitledBorder("")); 165 166 // row 1a 167 JPanel pName = new JPanel(); 168 pName.setLayout(new GridBagLayout()); 169 pName.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Name"))); 170 addItem(pName, trackNameTextField, 0, 0); 171 172 // row 1b 173 JPanel pLength = new JPanel(); 174 pLength.setLayout(new GridBagLayout()); 175 pLength.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Length"))); 176 pLength.setMinimumSize(new Dimension(60, 1)); 177 addItem(pLength, trackLengthTextField, 0, 0); 178 179 // row 1c 180 panelTrainDir.setLayout(new GridBagLayout()); 181 panelTrainDir.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("TrainTrack"))); 182 panelTrainDir.setPreferredSize(new Dimension(200, 10)); 183 addItem(panelTrainDir, northCheckBox, 1, 1); 184 addItem(panelTrainDir, southCheckBox, 2, 1); 185 addItem(panelTrainDir, eastCheckBox, 3, 1); 186 addItem(panelTrainDir, westCheckBox, 4, 1); 187 188 p1.add(pName); 189 p1.add(pLength); 190 p1.add(panelTrainDir); 191 192 // row 2 193 paneCheckBoxes.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("TypesTrack"))); 194 panelCheckBoxes.setLayout(new GridBagLayout()); 195 196 // status panel for roads and loads 197 JPanel panelRoadAndLoadStatus = new JPanel(); 198 panelRoadAndLoadStatus.setLayout(new BoxLayout(panelRoadAndLoadStatus, BoxLayout.X_AXIS)); 199 200 // row 3 201 JPanel pRoadOption = new JPanel(); 202 pRoadOption.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("RoadOption"))); 203 pRoadOption.add(roadOptionButton); 204 roadOptionButton.addActionListener(new TrackRoadEditAction(this)); 205 206 JPanel pLoadOption = new JPanel(); 207 pLoadOption.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("LoadOption"))); 208 pLoadOption.add(loadOptionButton); 209 loadOptionButton.addActionListener(new TrackLoadEditAction(this)); 210 211 pShipLoadOption.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("ShipLoadOption"))); 212 pShipLoadOption.add(shipLoadOptionButton); 213 shipLoadOptionButton.addActionListener(new TrackLoadEditAction(this)); 214 215 pDestinationOption.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Destinations"))); 216 pDestinationOption.add(destinationOptionButton); 217 destinationOptionButton.addActionListener(new TrackDestinationEditAction(this)); 218 219 panelRoadAndLoadStatus.add(pRoadOption); 220 panelRoadAndLoadStatus.add(pLoadOption); 221 panelRoadAndLoadStatus.add(pShipLoadOption); 222 panelRoadAndLoadStatus.add(pDestinationOption); 223 224 // only staging uses the ship load option 225 pShipLoadOption.setVisible(false); 226 // only classification/interchange tracks use the destination option 227 pDestinationOption.setVisible(false); 228 229 // row 4, order panel 230 panelOrder.setLayout(new GridBagLayout()); 231 panelOrder.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("PickupOrder"))); 232 panelOrder.add(orderNormal); 233 panelOrder.add(orderFIFO); 234 panelOrder.add(orderLIFO); 235 236 ButtonGroup orderGroup = new ButtonGroup(); 237 orderGroup.add(orderNormal); 238 orderGroup.add(orderFIFO); 239 orderGroup.add(orderLIFO); 240 241 // row 5, drop panel 242 dropPanel.setLayout(new GridBagLayout()); 243 dropPanel.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("TrainsOrRoutesDrops"))); 244 245 // row 6, pickup panel 246 pickupPanel.setLayout(new GridBagLayout()); 247 pickupPanel.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("TrainsOrRoutesPickups"))); 248 249 // row 9 250 JPanel panelComment = new JPanel(); 251 panelComment.setLayout(new GridBagLayout()); 252 panelComment.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Comment"))); 253 addItem(panelComment, commentScroller, 0, 0); 254 255 // adjust text area width based on window size 256 adjustTextAreaColumnWidth(commentScroller, commentTextArea); 257 258 // row 10, reader row 259 JPanel readerPanel = new JPanel(); 260 if (Setup.isRfidEnabled()) { 261 readerPanel.setLayout(new GridBagLayout()); 262 readerPanel.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("idReporter"))); 263 ReporterManager reporterManager = InstanceManager.getDefault(ReporterManager.class); 264 readerSelector = new NamedBeanComboBox<>(reporterManager); 265 readerSelector.setAllowNull(true); 266 addItem(readerPanel, readerSelector, 0, 0); 267 } else { 268 readerPanel.setVisible(false); 269 } 270 271 // row 11 272 JPanel panelButtons = new JPanel(); 273 panelButtons.setLayout(new GridBagLayout()); 274 275 addItem(panelButtons, deleteTrackButton, 0, 0); 276 addItem(panelButtons, addTrackButton, 1, 0); 277 addItem(panelButtons, saveTrackButton, 2, 0); 278 279 panels.add(p1Pane); 280 panels.add(paneCheckBoxes); 281 panels.add(panelRoadAndLoadStatus); 282 panels.add(panelOrder); 283 panels.add(dropPanel); 284 panels.add(pickupPanel); 285 286 // add optional panels 287 panels.add(panelOpt3); 288 panels.add(panelOpt4); 289 290 panels.add(panelComment); 291 panels.add(readerPanel); 292 panels.add(panelButtons); 293 294 getContentPane().add(pane); 295 296 // setup buttons 297 addButtonAction(setButton); 298 addButtonAction(clearButton); 299 300 addButtonAction(deleteTrackButton); 301 addButtonAction(addTrackButton); 302 addButtonAction(saveTrackButton); 303 304 addButtonAction(deleteDropButton); 305 addButtonAction(addDropButton); 306 addButtonAction(deletePickupButton); 307 addButtonAction(addPickupButton); 308 309 addRadioButtonAction(orderNormal); 310 addRadioButtonAction(orderFIFO); 311 addRadioButtonAction(orderLIFO); 312 313 addRadioButtonAction(anyDrops); 314 addRadioButtonAction(trainDrop); 315 addRadioButtonAction(routeDrop); 316 addRadioButtonAction(excludeTrainDrop); 317 addRadioButtonAction(excludeRouteDrop); 318 319 addRadioButtonAction(anyPickups); 320 addRadioButtonAction(trainPickup); 321 addRadioButtonAction(routePickup); 322 addRadioButtonAction(excludeTrainPickup); 323 addRadioButtonAction(excludeRoutePickup); 324 325 // addComboBoxAction(comboBoxTypes); 326 addCheckBoxAction(autoDropCheckBox); 327 addCheckBoxAction(autoPickupCheckBox); 328 329 autoDropCheckBox.setSelected(true); 330 autoPickupCheckBox.setSelected(true); 331 332 // load fields and enable buttons 333 if (_track != null) { 334 _track.addPropertyChangeListener(this); 335 trackNameTextField.setText(_track.getName()); 336 commentTextArea.setText(_track.getComment()); 337 trackLengthTextField.setText(Integer.toString(_track.getLength())); 338 enableButtons(true); 339 if (Setup.isRfidEnabled()) { 340 readerSelector.setSelectedItem(_track.getReporter()); 341 } 342 } else { 343 enableButtons(false); 344 } 345 346 // build menu 347 JMenuBar menuBar = new JMenuBar(); 348 // spurs, interchanges, and staging insert menu items here 349 _toolMenu.add(new TrackLoadEditAction(this)); 350 _toolMenu.add(new TrackRoadEditAction(this)); 351 _toolMenu.add(new PoolTrackAction(this)); 352 _toolMenu.add(new IgnoreUsedTrackAction(this)); 353 _toolMenu.add(new TrackEditCommentsAction(this)); 354 _toolMenu.addSeparator(); 355 // spurs, interchanges, and yards insert menu items here 356 _toolMenu.add(new TrackCopyAction(_track, _location)); 357 _toolMenu.addSeparator(); 358 _toolMenu.add(new ShowCarsByLocationAction(false, _location, _track)); 359 _toolMenu.add(new ShowTrainsServingLocationAction(_location, _track)); 360 361 menuBar.add(_toolMenu); 362 setJMenuBar(menuBar); 363 364 // load 365 updateCheckboxes(); 366 updateTrainDir(); 367 updateCarOrder(); 368 updateDropOptions(); 369 updatePickupOptions(); 370 updateRoadOption(); 371 updateLoadOption(); 372 updateDestinationOption(); 373 updateTrainComboBox(); 374 updateRouteComboBox(); 375 376 setMinimumSize(new Dimension(Control.panelWidth500, Control.panelHeight600)); 377 } 378 379 // Save, Delete, Add 380 @Override 381 public void buttonActionPerformed(java.awt.event.ActionEvent ae) { 382 if (ae.getSource() == addTrackButton) { 383 addNewTrack(); 384 } 385 if (_track == null) { 386 return; // not possible 387 } 388 if (ae.getSource() == saveTrackButton) { 389 if (!checkUserInputs(_track)) { 390 return; 391 } 392 saveTrack(_track); 393 checkTrackPickups(_track); // warn user if there are car types that 394 // will be stranded 395 if (Setup.isCloseWindowOnSaveEnabled()) { 396 dispose(); 397 } 398 } 399 if (ae.getSource() == deleteTrackButton) { 400 deleteTrack(); 401 } 402 if (ae.getSource() == setButton) { 403 selectCheckboxes(true); 404 } 405 if (ae.getSource() == clearButton) { 406 selectCheckboxes(false); 407 } 408 if (ae.getSource() == addDropButton) { 409 addDropId(); 410 } 411 if (ae.getSource() == deleteDropButton) { 412 deleteDropId(); 413 } 414 if (ae.getSource() == addPickupButton) { 415 addPickupId(); 416 } 417 if (ae.getSource() == deletePickupButton) { 418 deletePickupId(); 419 } 420 } 421 422 private void addDropId() { 423 String id = ""; 424 if (trainDrop.isSelected() || excludeTrainDrop.isSelected()) { 425 if (comboBoxDropTrains.getSelectedItem() == null) { 426 return; 427 } 428 Train train = ((Train) comboBoxDropTrains.getSelectedItem()); 429 Route route = train.getRoute(); 430 id = train.getId(); 431 if (!checkRoute(route)) { 432 JmriJOptionPane.showMessageDialog(this, 433 Bundle.getMessage("TrackNotByTrain", train.getName()), 434 Bundle.getMessage("ErrorTitle"), JmriJOptionPane.ERROR_MESSAGE); 435 return; 436 } 437 selectNextItemComboBox(comboBoxDropTrains); 438 } else { 439 if (comboBoxDropRoutes.getSelectedItem() == null) { 440 return; 441 } 442 Route route = ((Route) comboBoxDropRoutes.getSelectedItem()); 443 id = route.getId(); 444 if (!checkRoute(route)) { 445 JmriJOptionPane.showMessageDialog(this, 446 Bundle.getMessage("TrackNotByRoute", route.getName()), 447 Bundle.getMessage("ErrorTitle"), JmriJOptionPane.ERROR_MESSAGE); 448 return; 449 } 450 selectNextItemComboBox(comboBoxDropRoutes); 451 } 452 _track.addDropId(id); 453 } 454 455 private void deleteDropId() { 456 String id = ""; 457 if (trainDrop.isSelected() || excludeTrainDrop.isSelected()) { 458 if (comboBoxDropTrains.getSelectedItem() == null) { 459 return; 460 } 461 id = ((Train) comboBoxDropTrains.getSelectedItem()).getId(); 462 selectNextItemComboBox(comboBoxDropTrains); 463 } else { 464 if (comboBoxDropRoutes.getSelectedItem() == null) { 465 return; 466 } 467 id = ((Route) comboBoxDropRoutes.getSelectedItem()).getId(); 468 selectNextItemComboBox(comboBoxDropRoutes); 469 } 470 _track.deleteDropId(id); 471 } 472 473 private void addPickupId() { 474 String id = ""; 475 if (trainPickup.isSelected() || excludeTrainPickup.isSelected()) { 476 if (comboBoxPickupTrains.getSelectedItem() == null) { 477 return; 478 } 479 Train train = ((Train) comboBoxPickupTrains.getSelectedItem()); 480 Route route = train.getRoute(); 481 id = train.getId(); 482 if (!checkRoute(route)) { 483 JmriJOptionPane.showMessageDialog(this, 484 Bundle.getMessage("TrackNotByTrain", train.getName()), 485 Bundle.getMessage("ErrorTitle"), JmriJOptionPane.ERROR_MESSAGE); 486 return; 487 } 488 selectNextItemComboBox(comboBoxPickupTrains); 489 } else { 490 if (comboBoxPickupRoutes.getSelectedItem() == null) { 491 return; 492 } 493 Route route = ((Route) comboBoxPickupRoutes.getSelectedItem()); 494 id = route.getId(); 495 if (!checkRoute(route)) { 496 JmriJOptionPane.showMessageDialog(this, 497 Bundle.getMessage("TrackNotByRoute", route.getName()), 498 Bundle.getMessage("ErrorTitle"), JmriJOptionPane.ERROR_MESSAGE); 499 return; 500 } 501 selectNextItemComboBox(comboBoxPickupRoutes); 502 } 503 _track.addPickupId(id); 504 } 505 506 private void deletePickupId() { 507 String id = ""; 508 if (trainPickup.isSelected() || excludeTrainPickup.isSelected()) { 509 if (comboBoxPickupTrains.getSelectedItem() == null) { 510 return; 511 } 512 id = ((Train) comboBoxPickupTrains.getSelectedItem()).getId(); 513 selectNextItemComboBox(comboBoxPickupTrains); 514 } else { 515 if (comboBoxPickupRoutes.getSelectedItem() == null) { 516 return; 517 } 518 id = ((Route) comboBoxPickupRoutes.getSelectedItem()).getId(); 519 selectNextItemComboBox(comboBoxPickupRoutes); 520 } 521 _track.deletePickupId(id); 522 } 523 524 protected void addNewTrack() { 525 // check that track name is valid 526 if (!checkName(Bundle.getMessage("add"))) { 527 return; 528 } 529 // check to see if track already exists 530 Track check = _location.getTrackByName(trackNameTextField.getText(), null); 531 if (check != null) { 532 reportTrackExists(Bundle.getMessage("add")); 533 return; 534 } 535 // add track to this location 536 _track = _location.addTrack(trackNameTextField.getText(), _type); 537 // check track length 538 checkLength(_track); 539 540 // save window size so it doesn't change during the following updates 541 setPreferredSize(getSize()); 542 543 // reset all of the track's attributes 544 updateTrainDir(); 545 updateCheckboxes(); 546 updateDropOptions(); 547 updatePickupOptions(); 548 updateRoadOption(); 549 updateLoadOption(); 550 updateDestinationOption(); 551 552 _track.addPropertyChangeListener(this); 553 554 // setup check boxes 555 selectCheckboxes(true); 556 // store comment 557 _track.setComment(commentTextArea.getText()); 558 // enable 559 enableButtons(true); 560 // save location file 561 OperationsXml.save(); 562 } 563 564 protected void deleteTrack() { 565 if (_track != null) { 566 int rs = _track.getNumberRS(); 567 if (rs > 0) { 568 if (JmriJOptionPane.showConfirmDialog(this, 569 Bundle.getMessage("ThereAreCars", Integer.toString(rs)), 570 Bundle.getMessage("deleteTrack?"), 571 JmriJOptionPane.YES_NO_OPTION) != JmriJOptionPane.YES_OPTION) { 572 return; 573 } 574 } 575 selectCheckboxes(false); 576 _location.deleteTrack(_track); 577 _track = null; 578 enableButtons(false); 579 // save location file 580 OperationsXml.save(); 581 } 582 } 583 584 // check to see if the route services this location 585 private boolean checkRoute(Route route) { 586 if (route == null) { 587 return false; 588 } 589 return route.getLastLocationByName(_location.getName()) != null; 590 } 591 592 protected void saveTrack(Track track) { 593 saveTrackDirections(track); 594 track.setName(trackNameTextField.getText()); 595 track.setComment(commentTextArea.getText()); 596 597 if (Setup.isRfidEnabled()) { 598 _track.setReporter(readerSelector.getSelectedItem()); 599 } 600 601 // save current window size so it doesn't change during updates 602 setPreferredSize(getSize()); 603 604 // enable 605 enableButtons(true); 606 // save location file 607 OperationsXml.save(); 608 } 609 610 private void saveTrackDirections(Track track) { 611 // save train directions serviced by this location 612 int direction = 0; 613 if (northCheckBox.isSelected()) { 614 direction += Track.NORTH; 615 } 616 if (southCheckBox.isSelected()) { 617 direction += Track.SOUTH; 618 } 619 if (eastCheckBox.isSelected()) { 620 direction += Track.EAST; 621 } 622 if (westCheckBox.isSelected()) { 623 direction += Track.WEST; 624 } 625 track.setTrainDirections(direction); 626 } 627 628 private boolean checkUserInputs(Track track) { 629 // check that track name is valid 630 if (!checkName(Bundle.getMessage("save"))) { 631 return false; 632 } 633 // check to see if track already exists 634 Track check = _location.getTrackByName(trackNameTextField.getText(), null); 635 if (check != null && check != track) { 636 reportTrackExists(Bundle.getMessage("save")); 637 return false; 638 } 639 // check track length 640 if (!checkLength(track)) { 641 return false; 642 } 643 // check trains and route option 644 if (!checkService(track)) { 645 return false; 646 } 647 648 return true; 649 } 650 651 /** 652 * @return true if name is less than 26 characters 653 */ 654 private boolean checkName(String s) { 655 String trackName = trackNameTextField.getText().trim(); 656 if (trackName.isEmpty()) { 657 log.debug("Must enter a track name"); 658 JmriJOptionPane.showMessageDialog(this, Bundle.getMessage("MustEnterName"), 659 Bundle.getMessage("CanNotTrack", s), 660 JmriJOptionPane.ERROR_MESSAGE); 661 return false; 662 } 663 String[] check = trackName.split(TrainCommon.HYPHEN); 664 if (check.length == 0) { 665 JmriJOptionPane.showMessageDialog(this, Bundle.getMessage("HyphenFeature"), 666 Bundle.getMessage("CanNotTrack", s), 667 JmriJOptionPane.ERROR_MESSAGE); 668 669 return false; 670 } 671 if (TrainCommon.splitString(trackName).length() > MAX_NAME_LENGTH) { 672 JmriJOptionPane.showMessageDialog(this, 673 Bundle.getMessage("TrackNameLengthMax", Integer.toString(MAX_NAME_LENGTH + 1)), 674 Bundle.getMessage("CanNotTrack", s), 675 JmriJOptionPane.ERROR_MESSAGE); 676 return false; 677 } 678 return true; 679 } 680 681 private boolean checkLength(Track track) { 682 // convert track length if in inches 683 String length = trackLengthTextField.getText(); 684 if (length.endsWith("\"")) { // NOI18N 685 length = length.substring(0, length.length() - 1); 686 try { 687 double inches = Double.parseDouble(length); 688 int feet = (int) (inches * Setup.getScaleRatio() / 12); 689 length = Integer.toString(feet); 690 } catch (NumberFormatException e) { 691 JmriJOptionPane.showMessageDialog(this, Bundle.getMessage("CanNotConvertFeet"), 692 Bundle.getMessage("ErrorTrackLength"), JmriJOptionPane.ERROR_MESSAGE); 693 return false; 694 } 695 } 696 if (length.endsWith("cm")) { // NOI18N 697 length = length.substring(0, length.length() - 2); 698 try { 699 double cm = Double.parseDouble(length); 700 int meter = (int) (cm * Setup.getScaleRatio() / 100); 701 length = Integer.toString(meter); 702 } catch (NumberFormatException e) { 703 // log.error("Can not convert from cm to meters"); 704 JmriJOptionPane.showMessageDialog(this, Bundle.getMessage("CanNotConvertMeter"), 705 Bundle.getMessage("ErrorTrackLength"), JmriJOptionPane.ERROR_MESSAGE); 706 return false; 707 } 708 } 709 // confirm that length is a number and less than 10000 feet 710 int trackLength = 0; 711 try { 712 trackLength = Integer.parseInt(length); 713 if (length.length() > Control.max_len_string_track_length_name) { 714 JmriJOptionPane.showMessageDialog(this, 715 Bundle.getMessage("TrackMustBeLessThan", 716 Math.pow(10, Control.max_len_string_track_length_name), 717 Setup.getLengthUnit().toLowerCase()), 718 Bundle.getMessage("ErrorTrackLength"), JmriJOptionPane.ERROR_MESSAGE); 719 return false; 720 } 721 } catch (NumberFormatException e) { 722 // log.error("Track length not an integer"); 723 JmriJOptionPane.showMessageDialog(this, Bundle.getMessage("TrackMustBeNumber"), 724 Bundle.getMessage("ErrorTrackLength"), JmriJOptionPane.ERROR_MESSAGE); 725 return false; 726 } 727 // track length can not be less than than the sum of used and reserved 728 // length 729 if (trackLength != track.getLength() && trackLength < track.getUsedLength() + track.getReserved()) { 730 // log.warn("Track length should not be less than used and 731 // reserved"); 732 JmriJOptionPane.showMessageDialog(this, Bundle.getMessage("TrackMustBeGreater"), 733 Bundle.getMessage("ErrorTrackLength"), JmriJOptionPane.ERROR_MESSAGE); 734 // does the user want to force the track length? 735 if (JmriJOptionPane.showConfirmDialog(this, 736 Bundle.getMessage("TrackForceLength", track.getLength(), trackLength, 737 Setup.getLengthUnit().toLowerCase()), 738 Bundle.getMessage("ErrorTrackLength"), 739 JmriJOptionPane.YES_NO_OPTION) != JmriJOptionPane.YES_OPTION) { 740 return false; 741 } 742 } 743 // if everything is okay, save length 744 track.setLength(trackLength); 745 return true; 746 } 747 748 private boolean checkService(Track track) { 749 // check train and route restrictions 750 if ((trainDrop.isSelected() || routeDrop.isSelected()) && track.getDropIds().length == 0) { 751 log.debug("Must enter trains or routes for this track"); 752 JmriJOptionPane.showMessageDialog(this, Bundle.getMessage("UseAddTrainsOrRoutes"), 753 Bundle.getMessage("SetOutDisabled"), JmriJOptionPane.ERROR_MESSAGE); 754 return false; 755 } 756 if ((trainPickup.isSelected() || routePickup.isSelected()) && track.getPickupIds().length == 0) { 757 log.debug("Must enter trains or routes for this track"); 758 JmriJOptionPane.showMessageDialog(this, Bundle.getMessage("UseAddTrainsOrRoutes"), 759 Bundle.getMessage("PickUpsDisabled"), JmriJOptionPane.ERROR_MESSAGE); 760 return false; 761 } 762 return true; 763 } 764 765 private boolean checkTrackPickups(Track track) { 766 // check to see if all car types can be pulled from this track 767 String status = track.checkPickups(); 768 if (!status.equals(Track.PICKUP_OKAY) && !track.getPickupOption().equals(Track.ANY)) { 769 JmriJOptionPane.showMessageDialog(this, status, Bundle.getMessage("ErrorStrandedCar"), 770 JmriJOptionPane.ERROR_MESSAGE); 771 return false; 772 } 773 return true; 774 } 775 776 private void reportTrackExists(String s) { 777 JmriJOptionPane.showMessageDialog(this, Bundle.getMessage("TrackAlreadyExists"), 778 Bundle.getMessage("CanNotTrack", s), JmriJOptionPane.ERROR_MESSAGE); 779 } 780 781 protected void enableButtons(boolean enabled) { 782 _toolMenu.setEnabled(enabled); 783 northCheckBox.setEnabled(enabled); 784 southCheckBox.setEnabled(enabled); 785 eastCheckBox.setEnabled(enabled); 786 westCheckBox.setEnabled(enabled); 787 clearButton.setEnabled(enabled); 788 setButton.setEnabled(enabled); 789 deleteTrackButton.setEnabled(enabled); 790 saveTrackButton.setEnabled(enabled); 791 roadOptionButton.setEnabled(enabled); 792 loadOptionButton.setEnabled(enabled); 793 shipLoadOptionButton.setEnabled(enabled); 794 destinationOptionButton.setEnabled(enabled); 795 anyDrops.setEnabled(enabled); 796 trainDrop.setEnabled(enabled); 797 routeDrop.setEnabled(enabled); 798 excludeTrainDrop.setEnabled(enabled); 799 excludeRouteDrop.setEnabled(enabled); 800 anyPickups.setEnabled(enabled); 801 trainPickup.setEnabled(enabled); 802 routePickup.setEnabled(enabled); 803 excludeTrainPickup.setEnabled(enabled); 804 excludeRoutePickup.setEnabled(enabled); 805 orderNormal.setEnabled(enabled); 806 orderFIFO.setEnabled(enabled); 807 orderLIFO.setEnabled(enabled); 808 enableCheckboxes(enabled); 809 if (readerSelector != null) { 810 // enable readerSelect. 811 readerSelector.setEnabled(enabled && Setup.isRfidEnabled()); 812 } 813 } 814 815 @Override 816 public void radioButtonActionPerformed(java.awt.event.ActionEvent ae) { 817 log.debug("radio button activated"); 818 if (ae.getSource() == orderNormal) { 819 _track.setServiceOrder(Track.NORMAL); 820 } 821 if (ae.getSource() == orderFIFO) { 822 _track.setServiceOrder(Track.FIFO); 823 } 824 if (ae.getSource() == orderLIFO) { 825 _track.setServiceOrder(Track.LIFO); 826 } 827 if (ae.getSource() == anyDrops) { 828 _track.setDropOption(Track.ANY); 829 updateDropOptions(); 830 } 831 if (ae.getSource() == trainDrop) { 832 _track.setDropOption(Track.TRAINS); 833 updateDropOptions(); 834 } 835 if (ae.getSource() == routeDrop) { 836 _track.setDropOption(Track.ROUTES); 837 updateDropOptions(); 838 } 839 if (ae.getSource() == excludeTrainDrop) { 840 _track.setDropOption(Track.EXCLUDE_TRAINS); 841 updateDropOptions(); 842 } 843 if (ae.getSource() == excludeRouteDrop) { 844 _track.setDropOption(Track.EXCLUDE_ROUTES); 845 updateDropOptions(); 846 } 847 if (ae.getSource() == anyPickups) { 848 _track.setPickupOption(Track.ANY); 849 updatePickupOptions(); 850 } 851 if (ae.getSource() == trainPickup) { 852 _track.setPickupOption(Track.TRAINS); 853 updatePickupOptions(); 854 } 855 if (ae.getSource() == routePickup) { 856 _track.setPickupOption(Track.ROUTES); 857 updatePickupOptions(); 858 } 859 if (ae.getSource() == excludeTrainPickup) { 860 _track.setPickupOption(Track.EXCLUDE_TRAINS); 861 updatePickupOptions(); 862 } 863 if (ae.getSource() == excludeRoutePickup) { 864 _track.setPickupOption(Track.EXCLUDE_ROUTES); 865 updatePickupOptions(); 866 } 867 } 868 869 // TODO only update comboBox when train or route list changes. 870 private void updateDropOptions() { 871 dropPanel.removeAll(); 872 int numberOfItems = getNumberOfCheckboxesPerLine(); 873 874 JPanel p = new JPanel(); 875 p.setLayout(new GridBagLayout()); 876 p.add(anyDrops); 877 p.add(trainDrop); 878 p.add(routeDrop); 879 p.add(excludeTrainDrop); 880 p.add(excludeRouteDrop); 881 GridBagConstraints gc = new GridBagConstraints(); 882 gc.gridwidth = numberOfItems + 1; 883 dropPanel.add(p, gc); 884 885 int y = 1; // vertical position in panel 886 887 if (_track != null) { 888 // set radio button 889 anyDrops.setSelected(_track.getDropOption().equals(Track.ANY)); 890 trainDrop.setSelected(_track.getDropOption().equals(Track.TRAINS)); 891 routeDrop.setSelected(_track.getDropOption().equals(Track.ROUTES)); 892 excludeTrainDrop.setSelected(_track.getDropOption().equals(Track.EXCLUDE_TRAINS)); 893 excludeRouteDrop.setSelected(_track.getDropOption().equals(Track.EXCLUDE_ROUTES)); 894 895 if (!anyDrops.isSelected()) { 896 p = new JPanel(); 897 p.setLayout(new FlowLayout()); 898 if (trainDrop.isSelected() || excludeTrainDrop.isSelected()) { 899 p.add(comboBoxDropTrains); 900 } else { 901 p.add(comboBoxDropRoutes); 902 } 903 p.add(addDropButton); 904 p.add(deleteDropButton); 905 p.add(autoDropCheckBox); 906 gc.gridy = y++; 907 dropPanel.add(p, gc); 908 y++; 909 910 String[] dropIds = _track.getDropIds(); 911 int x = 0; 912 for (String id : dropIds) { 913 JLabel names = new JLabel(); 914 String name = "<deleted>"; // NOI18N 915 if (trainDrop.isSelected() || excludeTrainDrop.isSelected()) { 916 Train train = trainManager.getTrainById(id); 917 if (train != null) { 918 name = train.getName(); 919 } 920 } else { 921 Route route = routeManager.getRouteById(id); 922 if (route != null) { 923 name = route.getName(); 924 } 925 } 926 if (name.equals("<deleted>")) // NOI18N 927 { 928 _track.deleteDropId(id); 929 } 930 names.setText(name); 931 addItem(dropPanel, names, x++, y); 932 if (x > numberOfItems) { 933 y++; 934 x = 0; 935 } 936 } 937 } 938 } else { 939 anyDrops.setSelected(true); 940 } 941 dropPanel.revalidate(); 942 dropPanel.repaint(); 943 revalidate(); 944 } 945 946 private void updatePickupOptions() { 947 log.debug("update pick up options"); 948 pickupPanel.removeAll(); 949 int numberOfCheckboxes = getNumberOfCheckboxesPerLine(); 950 951 JPanel p = new JPanel(); 952 p.setLayout(new GridBagLayout()); 953 p.add(anyPickups); 954 p.add(trainPickup); 955 p.add(routePickup); 956 p.add(excludeTrainPickup); 957 p.add(excludeRoutePickup); 958 GridBagConstraints gc = new GridBagConstraints(); 959 gc.gridwidth = numberOfCheckboxes + 1; 960 pickupPanel.add(p, gc); 961 962 int y = 1; // vertical position in panel 963 964 if (_track != null) { 965 // set radio button 966 anyPickups.setSelected(_track.getPickupOption().equals(Track.ANY)); 967 trainPickup.setSelected(_track.getPickupOption().equals(Track.TRAINS)); 968 routePickup.setSelected(_track.getPickupOption().equals(Track.ROUTES)); 969 excludeTrainPickup.setSelected(_track.getPickupOption().equals(Track.EXCLUDE_TRAINS)); 970 excludeRoutePickup.setSelected(_track.getPickupOption().equals(Track.EXCLUDE_ROUTES)); 971 972 if (!anyPickups.isSelected()) { 973 p = new JPanel(); 974 p.setLayout(new FlowLayout()); 975 if (trainPickup.isSelected() || excludeTrainPickup.isSelected()) { 976 p.add(comboBoxPickupTrains); 977 } else { 978 p.add(comboBoxPickupRoutes); 979 } 980 p.add(addPickupButton); 981 p.add(deletePickupButton); 982 p.add(autoPickupCheckBox); 983 gc.gridy = y++; 984 pickupPanel.add(p, gc); 985 y++; 986 987 int x = 0; 988 for (String id : _track.getPickupIds()) { 989 JLabel names = new JLabel(); 990 String name = "<deleted>"; // NOI18N 991 if (trainPickup.isSelected() || excludeTrainPickup.isSelected()) { 992 Train train = trainManager.getTrainById(id); 993 if (train != null) { 994 name = train.getName(); 995 } 996 } else { 997 Route route = routeManager.getRouteById(id); 998 if (route != null) { 999 name = route.getName(); 1000 } 1001 } 1002 if (name.equals("<deleted>")) // NOI18N 1003 { 1004 _track.deletePickupId(id); 1005 } 1006 names.setText(name); 1007 addItem(pickupPanel, names, x++, y); 1008 if (x > numberOfCheckboxes) { 1009 y++; 1010 x = 0; 1011 } 1012 } 1013 } 1014 } else { 1015 anyPickups.setSelected(true); 1016 } 1017 pickupPanel.revalidate(); 1018 pickupPanel.repaint(); 1019 revalidate(); 1020 } 1021 1022 protected void updateTrainComboBox() { 1023 trainManager.updateTrainComboBox(comboBoxPickupTrains); 1024 if (autoPickupCheckBox.isSelected()) { 1025 autoTrainComboBox(comboBoxPickupTrains); 1026 } 1027 trainManager.updateTrainComboBox(comboBoxDropTrains); 1028 if (autoDropCheckBox.isSelected()) { 1029 autoTrainComboBox(comboBoxDropTrains); 1030 } 1031 } 1032 1033 // filter all trains not serviced by this track 1034 private void autoTrainComboBox(JComboBox<Train> box) { 1035 for (int i = 0; i < box.getItemCount(); i++) { 1036 Train train = box.getItemAt(i); 1037 if (train == null || !checkRoute(train.getRoute())) { 1038 box.removeItemAt(i--); 1039 } 1040 } 1041 } 1042 1043 protected void updateRouteComboBox() { 1044 routeManager.updateComboBox(comboBoxPickupRoutes); 1045 if (autoPickupCheckBox.isSelected()) { 1046 autoRouteComboBox(comboBoxPickupRoutes); 1047 } 1048 routeManager.updateComboBox(comboBoxDropRoutes); 1049 if (autoDropCheckBox.isSelected()) { 1050 autoRouteComboBox(comboBoxDropRoutes); 1051 } 1052 } 1053 1054 // filter out all routes not serviced by this track 1055 private void autoRouteComboBox(JComboBox<Route> box) { 1056 for (int i = 0; i < box.getItemCount(); i++) { 1057 Route route = box.getItemAt(i); 1058 if (!checkRoute(route)) { 1059 box.removeItemAt(i--); 1060 } 1061 } 1062 } 1063 1064 private void enableCheckboxes(boolean enable) { 1065 for (int i = 0; i < checkBoxes.size(); i++) { 1066 checkBoxes.get(i).setEnabled(enable); 1067 } 1068 } 1069 1070 private void selectCheckboxes(boolean enable) { 1071 for (int i = 0; i < checkBoxes.size(); i++) { 1072 JCheckBox checkBox = checkBoxes.get(i); 1073 checkBox.setSelected(enable); 1074 if (_track != null) { 1075 if (enable) { 1076 _track.addTypeName(checkBox.getText()); 1077 } else { 1078 _track.deleteTypeName(checkBox.getText()); 1079 } 1080 } 1081 } 1082 } 1083 1084 // car and loco types 1085 private void updateCheckboxes() { 1086 // log.debug("Update all checkboxes"); 1087 checkBoxes.clear(); 1088 panelCheckBoxes.removeAll(); 1089 numberOfCheckBoxes = getNumberOfCheckboxesPerLine(); 1090 x = 0; 1091 y = 0; // vertical position in panel 1092 loadTypes(InstanceManager.getDefault(CarTypes.class).getNames()); 1093 1094 // add space between car and loco types 1095 checkNewLine(); 1096 1097 loadTypes(InstanceManager.getDefault(EngineTypes.class).getNames()); 1098 enableCheckboxes(_track != null); 1099 1100 JPanel p = new JPanel(); 1101 p.add(clearButton); 1102 p.add(setButton); 1103 if (_track != null && _track.isSpur()) { 1104 p.add(autoSelectButton); 1105 } 1106 GridBagConstraints gc = new GridBagConstraints(); 1107 gc.gridwidth = getNumberOfCheckboxesPerLine() + 1; 1108 gc.gridy = ++y; 1109 panelCheckBoxes.add(p, gc); 1110 1111 panelCheckBoxes.revalidate(); 1112 panelCheckBoxes.repaint(); 1113 } 1114 1115 int x = 0; 1116 int y = 0; // vertical position in panel 1117 1118 private void loadTypes(String[] types) { 1119 for (String type : types) { 1120 if (_location.acceptsTypeName(type)) { 1121 JCheckBox checkBox = new JCheckBox(); 1122 checkBoxes.add(checkBox); 1123 checkBox.setText(type); 1124 addCheckBoxAction(checkBox); 1125 addItemLeft(panelCheckBoxes, checkBox, x, y); 1126 if (_track != null && _track.isTypeNameAccepted(type)) { 1127 checkBox.setSelected(true); 1128 } 1129 checkNewLine(); 1130 } 1131 } 1132 } 1133 1134 int numberOfCheckBoxes; 1135 1136 private void checkNewLine() { 1137 if (++x > numberOfCheckBoxes) { 1138 y++; 1139 x = 0; 1140 } 1141 } 1142 1143 private void updateRoadOption() { 1144 if (_track != null) { 1145 roadOptionButton.setText(_track.getRoadOptionString()); 1146 } 1147 } 1148 1149 private void updateLoadOption() { 1150 if (_track != null) { 1151 loadOptionButton.setText(_track.getLoadOptionString()); 1152 shipLoadOptionButton.setText(_track.getShipLoadOptionString()); 1153 } 1154 } 1155 1156 private void updateTrainDir() { 1157 northCheckBox.setVisible(((Setup.getTrainDirection() & Setup.NORTH) & 1158 (_location.getTrainDirections() & Location.NORTH)) == Location.NORTH); 1159 southCheckBox.setVisible(((Setup.getTrainDirection() & Setup.SOUTH) & 1160 (_location.getTrainDirections() & Location.SOUTH)) == Location.SOUTH); 1161 eastCheckBox.setVisible(((Setup.getTrainDirection() & Setup.EAST) & 1162 (_location.getTrainDirections() & Location.EAST)) == Location.EAST); 1163 westCheckBox.setVisible(((Setup.getTrainDirection() & Setup.WEST) & 1164 (_location.getTrainDirections() & Location.WEST)) == Location.WEST); 1165 1166 if (_track != null) { 1167 northCheckBox.setSelected((_track.getTrainDirections() & Track.NORTH) == Track.NORTH); 1168 southCheckBox.setSelected((_track.getTrainDirections() & Track.SOUTH) == Track.SOUTH); 1169 eastCheckBox.setSelected((_track.getTrainDirections() & Track.EAST) == Track.EAST); 1170 westCheckBox.setSelected((_track.getTrainDirections() & Track.WEST) == Track.WEST); 1171 } 1172 panelTrainDir.revalidate(); 1173 revalidate(); 1174 } 1175 1176 @Override 1177 public void checkBoxActionPerformed(java.awt.event.ActionEvent ae) { 1178 if (ae.getSource() == autoDropCheckBox || ae.getSource() == autoPickupCheckBox) { 1179 updateTrainComboBox(); 1180 updateRouteComboBox(); 1181 return; 1182 } 1183 JCheckBox b = (JCheckBox) ae.getSource(); 1184 log.debug("checkbox change {}", b.getText()); 1185 if (b.isSelected()) { 1186 _track.addTypeName(b.getText()); 1187 } else { 1188 _track.deleteTypeName(b.getText()); 1189 } 1190 } 1191 1192 // set the service order 1193 private void updateCarOrder() { 1194 if (_track != null) { 1195 orderNormal.setSelected(_track.getServiceOrder().equals(Track.NORMAL)); 1196 orderFIFO.setSelected(_track.getServiceOrder().equals(Track.FIFO)); 1197 orderLIFO.setSelected(_track.getServiceOrder().equals(Track.LIFO)); 1198 } 1199 } 1200 1201 protected void updateDestinationOption() { 1202 if (_track != null) { 1203 if (_track.getDestinationOption().equals(Track.INCLUDE_DESTINATIONS)) { 1204 pDestinationOption.setVisible(true); 1205 destinationOptionButton.setText(Bundle.getMessage("AcceptOnly") + 1206 " " + 1207 _track.getDestinationListSize() + 1208 " " + 1209 Bundle.getMessage("Destinations")); 1210 } else if (_track.getDestinationOption().equals(Track.EXCLUDE_DESTINATIONS)) { 1211 pDestinationOption.setVisible(true); 1212 destinationOptionButton.setText(Bundle.getMessage("Exclude") + 1213 " " + 1214 (InstanceManager.getDefault(LocationManager.class).getNumberOfLocations() - 1215 _track.getDestinationListSize()) + 1216 " " + 1217 Bundle.getMessage("Destinations")); 1218 } else { 1219 destinationOptionButton.setText(Bundle.getMessage("AcceptAll")); 1220 } 1221 } 1222 } 1223 1224 @Override 1225 public void dispose() { 1226 if (_track != null) { 1227 _track.removePropertyChangeListener(this); 1228 } 1229 if (_location != null) { 1230 _location.removePropertyChangeListener(this); 1231 } 1232 InstanceManager.getDefault(CarRoads.class).removePropertyChangeListener(this); 1233 InstanceManager.getDefault(CarLoads.class).removePropertyChangeListener(this); 1234 InstanceManager.getDefault(CarTypes.class).removePropertyChangeListener(this); 1235 trainManager.removePropertyChangeListener(this); 1236 routeManager.removePropertyChangeListener(this); 1237 super.dispose(); 1238 } 1239 1240 @Override 1241 public void propertyChange(java.beans.PropertyChangeEvent e) { 1242 if (Control.SHOW_PROPERTY) { 1243 log.debug("Property change: ({}) old: ({}) new: ({})", e.getPropertyName(), e.getOldValue(), 1244 e.getNewValue()); 1245 } 1246 if (e.getPropertyName().equals(Location.TYPES_CHANGED_PROPERTY) || 1247 e.getPropertyName().equals(CarTypes.CARTYPES_CHANGED_PROPERTY) || 1248 e.getPropertyName().equals(Track.TYPES_CHANGED_PROPERTY)) { 1249 updateCheckboxes(); 1250 } 1251 if (e.getPropertyName().equals(Location.TRAIN_DIRECTION_CHANGED_PROPERTY) || 1252 e.getPropertyName().equals(Track.TRAIN_DIRECTION_CHANGED_PROPERTY) || 1253 e.getPropertyName().equals(Setup.TRAIN_DIRECTION_PROPERTY_CHANGE)) { 1254 updateTrainDir(); 1255 } 1256 if (e.getPropertyName().equals(TrainManager.LISTLENGTH_CHANGED_PROPERTY)) { 1257 updateTrainComboBox(); 1258 updateDropOptions(); 1259 updatePickupOptions(); 1260 } 1261 if (e.getPropertyName().equals(RouteManager.LISTLENGTH_CHANGED_PROPERTY)) { 1262 updateRouteComboBox(); 1263 updateDropOptions(); 1264 updatePickupOptions(); 1265 } 1266 if (e.getPropertyName().equals(Track.ROADS_CHANGED_PROPERTY)) { 1267 updateRoadOption(); 1268 } 1269 if (e.getPropertyName().equals(Track.LOADS_CHANGED_PROPERTY)) { 1270 updateLoadOption(); 1271 } 1272 if (e.getPropertyName().equals(Track.DROP_CHANGED_PROPERTY)) { 1273 updateDropOptions(); 1274 } 1275 if (e.getPropertyName().equals(Track.PICKUP_CHANGED_PROPERTY)) { 1276 updatePickupOptions(); 1277 } 1278 if (e.getPropertyName().equals(Track.SERVICE_ORDER_CHANGED_PROPERTY)) { 1279 updateCarOrder(); 1280 } 1281 if (e.getPropertyName().equals(Track.DESTINATIONS_CHANGED_PROPERTY) || 1282 e.getPropertyName().equals(Track.DESTINATION_OPTIONS_CHANGED_PROPERTY)) { 1283 updateDestinationOption(); 1284 } 1285 if (e.getPropertyName().equals(Track.LENGTH_CHANGED_PROPERTY)) { 1286 trackLengthTextField.setText(Integer.toString(_track.getLength())); 1287 } 1288 } 1289 1290 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(TrackEditFrame.class); 1291}