001package jmri.jmrit.operations.rollingstock.cars; 002 003import java.awt.GridBagLayout; 004import java.text.*; 005import java.util.List; 006import java.util.ResourceBundle; 007 008import javax.swing.*; 009 010import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 011import jmri.InstanceManager; 012import jmri.jmrit.operations.rollingstock.*; 013import jmri.jmrit.operations.rollingstock.cars.tools.CarAttributeEditFrame; 014import jmri.jmrit.operations.rollingstock.cars.tools.CarLoadEditFrame; 015import jmri.jmrit.operations.setup.Setup; 016import jmri.util.swing.JmriJOptionPane; 017 018/** 019 * Frame for user edit of car 020 * 021 * @author Dan Boudreau Copyright (C) 2008, 2010, 2011, 2014, 2018 022 */ 023public class CarEditFrame extends RollingStockEditFrame { 024 025 protected static final ResourceBundle rb = ResourceBundle 026 .getBundle("jmri.jmrit.operations.rollingstock.cars.JmritOperationsCarsBundle"); 027 028 CarManager carManager = InstanceManager.getDefault(CarManager.class); 029 CarManagerXml managerXml = InstanceManager.getDefault(CarManagerXml.class); 030 031 // labels 032 JLabel textWeightOz = new JLabel(Bundle.getMessage("WeightOz")); 033 034 JButton editColorButton = new JButton(Bundle.getMessage("ButtonEdit")); 035 JButton editLoadButton = new JButton(Bundle.getMessage("ButtonEdit")); 036 JButton fillWeightButton = new JButton(Bundle.getMessage("Calculate")); 037 038 JCheckBox passengerCheckBox = new JCheckBox(Bundle.getMessage("Passenger")); 039 JCheckBox cabooseCheckBox = new JCheckBox(Bundle.getMessage("Caboose")); 040 JCheckBox fredCheckBox = new JCheckBox(Bundle.getMessage("Fred")); 041 JCheckBox utilityCheckBox = new JCheckBox(Bundle.getMessage("Utility")); 042 JCheckBox hazardousCheckBox = new JCheckBox(Bundle.getMessage("Hazardous")); 043 JCheckBox autoWeightCheckBox = new JCheckBox(Bundle.getMessage("Auto")); 044 045 JComboBox<String> colorComboBox = InstanceManager.getDefault(CarColors.class).getComboBox(); 046 JComboBox<String> loadComboBox = InstanceManager.getDefault(CarLoads.class).getComboBox(null); 047 048 CarLoadEditFrame carLoadEditFrame; 049 050 public CarEditFrame() { 051 super(Bundle.getMessage("TitleCarAdd")); 052 } 053 054 @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "Checks for null") 055 @Override 056 public void initComponents() { 057 058 groupComboBox = InstanceManager.getDefault(KernelManager.class).getComboBox(); 059 060 super.initComponents(); 061 062 addButton.setText(Bundle.getMessage("TitleCarAdd")); 063 064 // type options for cars 065 addItem(pTypeOptions, passengerCheckBox, 0, 1); 066 addItem(pTypeOptions, cabooseCheckBox, 1, 1); 067 addItem(pTypeOptions, fredCheckBox, 2, 1); 068 addItem(pTypeOptions, utilityCheckBox, 3, 1); 069 addItem(pTypeOptions, hazardousCheckBox, 4, 1); 070 071 // default check box selections 072 autoWeightCheckBox.setSelected(true); 073 074 // load tool tips 075 weightTextField.setToolTipText(Bundle.getMessage("TipCarWeightOz")); 076 weightTonsTextField.setToolTipText(Bundle.getMessage("TipCarWeightTons")); 077 autoWeightCheckBox.setToolTipText(Bundle.getMessage("TipCarAutoCalculate")); 078 passengerCheckBox.setToolTipText(Bundle.getMessage("TipCarPassenger")); 079 cabooseCheckBox.setToolTipText(Bundle.getMessage("TipCarCaboose")); 080 fredCheckBox.setToolTipText(Bundle.getMessage("TipCarFred")); 081 utilityCheckBox.setToolTipText(Bundle.getMessage("TipCarUtility")); 082 hazardousCheckBox.setToolTipText(Bundle.getMessage("TipCarHazardous")); 083 blockingTextField.setToolTipText(Bundle.getMessage("TipPassengerCarBlocking")); 084 fillWeightButton.setToolTipText(Bundle.getMessage("TipCalculateCarWeight")); 085 builtTextField.setToolTipText(Bundle.getMessage("TipBuildDate")); 086 valueTextArea.setToolTipText(Bundle.getMessage("TipValue")); 087 088 editColorButton.setToolTipText(Bundle.getMessage("TipAddDeleteReplace", 089 Bundle.getMessage("Color").toLowerCase())); 090 editLoadButton.setToolTipText(Bundle.getMessage("TipAddDeleteReplace", 091 Bundle.getMessage("load"))); // initial caps for some languages i.e. German 092 editGroupButton.setToolTipText(Bundle.getMessage("TipAddDeleteReplace", 093 Bundle.getMessage("Kernel").toLowerCase())); 094 095 deleteButton.setToolTipText(Bundle.getMessage("TipDeleteButton")); 096 addButton.setToolTipText(Bundle.getMessage("TipAddButton")); 097 saveButton.setToolTipText(Bundle.getMessage("TipSaveButton")); 098 099 // row 7 100 pWeightOz.setLayout(new GridBagLayout()); 101 addItem(pWeightOz, textWeightOz, 0, 0); 102 addItem(pWeightOz, weightTextField, 1, 0); 103 addItem(pWeightOz, fillWeightButton, 2, 0); 104 addItem(pWeightOz, autoWeightCheckBox, 3, 0); 105 106 // row 8 107 pColor.setLayout(new GridBagLayout()); 108 pColor.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Color"))); 109 addItem(pColor, colorComboBox, 1, 0); 110 addItem(pColor, editColorButton, 2, 0); 111 pColor.setVisible(true); 112 113 // row 9 114 pLoad.setLayout(new GridBagLayout()); 115 pLoad.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Load"))); 116 addItem(pLoad, loadComboBox, 1, 0); 117 addItem(pLoad, editLoadButton, 2, 0); 118 pLoad.setVisible(true); 119 120 // select first item so load combobox will update 121 typeComboBox.setSelectedIndex(0); 122 123 // row 10 124 pGroup.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Kernel"))); 125 126 addEditButtonAction(editColorButton); 127 addButtonAction(fillWeightButton); 128 addButtonAction(editLoadButton); 129 130 // setup check boxes 131 addCheckBoxAction(cabooseCheckBox); 132 addCheckBoxAction(fredCheckBox); 133 addCheckBoxAction(passengerCheckBox); 134 135 addHelpMenu("package.jmri.jmrit.operations.Operations_CarsEdit", true); // NOI18N 136 } 137 138 @Override 139 protected ResourceBundle getRb() { 140 return rb; 141 } 142 143 @Override 144 protected RollingStockAttribute getTypeManager() { 145 return InstanceManager.getDefault(CarTypes.class); 146 } 147 148 @Override 149 protected RollingStockAttribute getLengthManager() { 150 return InstanceManager.getDefault(CarLengths.class); 151 } 152 153 public void load(Car car) { 154 setTitle(Bundle.getMessage("TitleCarEdit")); 155 super.load(car); 156 157 passengerCheckBox.setSelected(car.isPassenger()); 158 cabooseCheckBox.setSelected(car.isCaboose()); 159 utilityCheckBox.setSelected(car.isUtility()); 160 fredCheckBox.setSelected(car.hasFred()); 161 hazardousCheckBox.setSelected(car.isCarHazardous()); 162 163 pBlocking.setVisible(car.isPassenger() || car.getKernel() != null); 164 165 if (!InstanceManager.getDefault(CarLoads.class).containsName(car.getTypeName(), car.getLoadName())) { 166 if (JmriJOptionPane.showConfirmDialog(this, Bundle.getMessage("loadNameNotExist", 167 car.getLoadName()), Bundle.getMessage("addLoad"), 168 JmriJOptionPane.YES_NO_OPTION) == JmriJOptionPane.YES_OPTION) { 169 InstanceManager.getDefault(CarLoads.class).addName(car.getTypeName(), car.getLoadName()); 170 } 171 } 172 InstanceManager.getDefault(CarLoads.class).updateComboBox(car.getTypeName(), loadComboBox); 173 loadComboBox.setSelectedItem(car.getLoadName()); 174 175 // listen for changes in car load 176 car.addPropertyChangeListener(this); 177 178 // only cars have color attribute 179 if (!InstanceManager.getDefault(CarColors.class).containsName(car.getColor())) { 180 if (JmriJOptionPane.showConfirmDialog(this, Bundle.getMessage("colorNameNotExist", 181 car.getColor()), Bundle.getMessage("carAddColor"), 182 JmriJOptionPane.YES_NO_OPTION) == JmriJOptionPane.YES_OPTION) { 183 InstanceManager.getDefault(CarColors.class).addName(car.getColor()); 184 } 185 } 186 colorComboBox.setSelectedItem(car.getColor()); 187 groupComboBox.setSelectedItem(car.getKernelName()); 188 } 189 190 @Override 191 public void comboBoxActionPerformed(java.awt.event.ActionEvent ae) { 192 if (ae.getSource() == typeComboBox && typeComboBox.getSelectedItem() != null) { 193 log.debug("Type comboBox sees change, update car loads"); 194 InstanceManager.getDefault(CarLoads.class).updateComboBox((String) typeComboBox.getSelectedItem(), 195 loadComboBox); 196 if (_rs != null) { 197 loadComboBox.setSelectedItem(((Car)_rs).getLoadName()); 198 } 199 } 200 if (ae.getSource() == lengthComboBox && autoWeightCheckBox.isSelected()) { 201 calculateWeight(); 202 } 203 super.comboBoxActionPerformed(ae); 204 } 205 206 @Override 207 public void checkBoxActionPerformed(java.awt.event.ActionEvent ae) { 208 if (ae.getSource() == cabooseCheckBox && cabooseCheckBox.isSelected()) { 209 fredCheckBox.setSelected(false); 210 } 211 if (ae.getSource() == fredCheckBox && fredCheckBox.isSelected()) { 212 cabooseCheckBox.setSelected(false); 213 } 214 if (ae.getSource() == passengerCheckBox) { 215 pBlocking.setVisible(passengerCheckBox.isSelected() || (_rs != null && ((Car) _rs).getKernel() != null)); 216 } 217 super.checkBoxActionPerformed(ae); 218 } 219 220 // Save, Delete, Add, Clear, Calculate, Edit Load buttons 221 @Override 222 public void buttonActionPerformed(java.awt.event.ActionEvent ae) { 223 super.buttonActionPerformed(ae); 224 if (ae.getSource() == fillWeightButton) { 225 calculateWeight(); 226 } 227 if (ae.getSource() == editLoadButton) { 228 if (carLoadEditFrame != null) { 229 carLoadEditFrame.dispose(); 230 } 231 carLoadEditFrame = new CarLoadEditFrame(); 232 carLoadEditFrame.initComponents((String) typeComboBox.getSelectedItem(), 233 (String) loadComboBox.getSelectedItem()); 234 } 235 } 236 237 @Override 238 protected boolean check(RollingStock car) { 239 // check to see if car with road and number already exists 240 Car existingCar = carManager.getByRoadAndNumber((String) roadComboBox.getSelectedItem(), roadNumberTextField 241 .getText()); 242 if (existingCar != null) { 243 if (car == null) { 244 JmriJOptionPane.showMessageDialog(this, Bundle.getMessage("carRoadExists"), Bundle 245 .getMessage("carCanNotAdd"), JmriJOptionPane.ERROR_MESSAGE); 246 return false; 247 } 248 // old car with new road or number? 249 if (!existingCar.getId().equals(car.getId())) { 250 JmriJOptionPane.showMessageDialog(this, Bundle.getMessage("carRoadExists"), Bundle 251 .getMessage("carCanNotUpdate"), JmriJOptionPane.ERROR_MESSAGE); 252 return false; 253 } 254 } 255 // check car's weight has proper format 256 try { 257 Number number = NumberFormat.getNumberInstance().parse(weightTextField.getText()); 258 log.debug("Car weight in oz: {}", number); 259 } catch (Exception e) { 260 JmriJOptionPane.showMessageDialog(this, Bundle.getMessage("carWeightFormat"), Bundle 261 .getMessage("carActualWeight"), JmriJOptionPane.ERROR_MESSAGE); 262 return false; 263 } 264 265 return super.check(car); 266 } 267 268 private void calculateWeight() { 269 if (lengthComboBox.getSelectedItem() != null) { 270 String length = (String) lengthComboBox.getSelectedItem(); 271 try { 272 String carWeight = CarManager.calculateCarWeight(length); 273 weightTextField.setText(carWeight); // car weight in ounces. 274 int tons = (int) (NumberFormat.getNumberInstance().parse(carWeight).doubleValue() * Setup.getScaleTonRatio()); 275 // adjust weight for caboose 276 if (cabooseCheckBox.isSelected() || passengerCheckBox.isSelected()) { 277 tons = (int) (Double.parseDouble(length) * .9); // .9 tons/foot 278 } 279 weightTonsTextField.setText(Integer.toString(tons)); 280 } catch (NumberFormatException e) { 281 JmriJOptionPane.showMessageDialog(this, Bundle.getMessage("carLengthMustBe"), Bundle 282 .getMessage("carWeigthCanNot"), JmriJOptionPane.ERROR_MESSAGE); 283 } catch (ParseException ex) { 284 JmriJOptionPane.showMessageDialog(this, Bundle.getMessage("carWeightFormat"), Bundle 285 .getMessage("carWeigthCanNot"), JmriJOptionPane.ERROR_MESSAGE); 286 } 287 } 288 } 289 290 @Override 291 protected void save(boolean isSave) { 292 if (roadComboBox.getSelectedItem() == null) { 293 return; 294 } 295 super.save(carManager, isSave); 296 Car car = (Car) _rs; 297 298 if (colorComboBox.getSelectedItem() != null) { 299 car.setColor((String) colorComboBox.getSelectedItem()); 300 } 301 302 // ask if all cars of this type should be passenger 303 if (isSave && car.isPassenger() ^ passengerCheckBox.isSelected()) { 304 if (JmriJOptionPane.showConfirmDialog(this, MessageFormat.format(passengerCheckBox.isSelected() ? Bundle 305 .getMessage("carModifyTypePassenger") : Bundle.getMessage("carRemoveTypePassenger"), 306 new Object[]{car.getTypeName()}), 307 Bundle.getMessage("carModifyAllType", 308 car.getTypeName()), 309 JmriJOptionPane.YES_NO_OPTION) == JmriJOptionPane.YES_OPTION) { 310 // go through the entire list and change the passenger setting 311 // for all cars of this type 312 for (Car c : carManager.getList()) { 313 if (c.getTypeName().equals(car.getTypeName())) { 314 c.setPassenger(passengerCheckBox.isSelected()); 315 } 316 } 317 } 318 } 319 car.setPassenger(passengerCheckBox.isSelected()); 320 int blocking = Integer.parseInt(blockingTextField.getText()); 321 // ask if blocking order should be the same 322 if (isSave && car.getKernel() == null && passengerCheckBox.isSelected() && car.getBlocking() != blocking) { 323 if (JmriJOptionPane.showConfirmDialog(this, Bundle.getMessage("carChangeBlocking", 324 blocking, car.getTypeName()), 325 Bundle.getMessage("carModifyAllType", car.getTypeName()), 326 JmriJOptionPane.YES_NO_OPTION) == JmriJOptionPane.YES_OPTION) { 327 // go through the entire list and change the passenger setting 328 // for all cars of this type 329 for (Car c : carManager.getList()) { 330 if (c.isPassenger() && c.getTypeName().equals(car.getTypeName())) { 331 c.setBlocking(blocking); 332 } 333 } 334 } 335 } 336 car.setBlocking(blocking); 337 // ask if all cars of this type should be caboose 338 if (isSave && car.isCaboose() ^ cabooseCheckBox.isSelected()) { 339 if (JmriJOptionPane.showConfirmDialog(this, MessageFormat.format(cabooseCheckBox.isSelected() ? Bundle 340 .getMessage("carModifyTypeCaboose") : Bundle.getMessage("carRemoveTypeCaboose"), 341 new Object[]{car.getTypeName()}), 342 Bundle.getMessage("carModifyAllType", 343 car.getTypeName()), 344 JmriJOptionPane.YES_NO_OPTION) == JmriJOptionPane.YES_OPTION) { 345 // go through the entire list and change the caboose setting for all cars of this type 346 for (Car c : carManager.getList()) { 347 if (c.getTypeName().equals(car.getTypeName())) { 348 c.setCaboose(cabooseCheckBox.isSelected()); 349 } 350 } 351 } 352 } 353 car.setCaboose(cabooseCheckBox.isSelected()); 354 // ask if all cars of this type should be utility 355 if (isSave && car.isUtility() ^ utilityCheckBox.isSelected()) { 356 if (JmriJOptionPane.showConfirmDialog(this, MessageFormat.format(utilityCheckBox.isSelected() ? Bundle 357 .getMessage("carModifyTypeUtility") : Bundle.getMessage("carRemoveTypeUtility"), 358 new Object[]{car.getTypeName()}), 359 Bundle.getMessage("carModifyAllType", 360 car.getTypeName()), 361 JmriJOptionPane.YES_NO_OPTION) == JmriJOptionPane.YES_OPTION) { 362 // go through the entire list and change the utility for all cars of this type 363 for (Car c : carManager.getList()) { 364 if (c.getTypeName().equals(car.getTypeName())) { 365 c.setUtility(utilityCheckBox.isSelected()); 366 } 367 } 368 } 369 } 370 car.setUtility(utilityCheckBox.isSelected()); 371 // ask if all cars of this type should be hazardous 372 if (isSave && car.isCarHazardous() ^ hazardousCheckBox.isSelected()) { 373 if (JmriJOptionPane.showConfirmDialog(this, MessageFormat.format(hazardousCheckBox.isSelected() ? Bundle 374 .getMessage("carModifyTypeHazardous") : Bundle.getMessage("carRemoveTypeHazardous"), 375 new Object[]{car.getTypeName()}), 376 Bundle.getMessage("carModifyAllType", 377 car.getTypeName()), 378 JmriJOptionPane.YES_NO_OPTION) == JmriJOptionPane.YES_OPTION) { 379 // go through the entire list and change the hazardous setting for all cars of this type 380 for (Car c : carManager.getList()) { 381 if (c.getTypeName().equals(car.getTypeName())) { 382 c.setCarHazardous(hazardousCheckBox.isSelected()); 383 } 384 } 385 } 386 } 387 car.setCarHazardous(hazardousCheckBox.isSelected()); 388 car.setFred(fredCheckBox.isSelected()); 389 if (groupComboBox.getSelectedItem() != null) { 390 if (groupComboBox.getSelectedItem().equals(CarManager.NONE)) { 391 car.setKernel(null); 392 if (!car.isPassenger()) { 393 car.setBlocking(Car.DEFAULT_BLOCKING_ORDER); 394 } 395 } else if (!car.getKernelName().equals(groupComboBox.getSelectedItem())) { 396 car.setKernel(InstanceManager.getDefault(KernelManager.class).getKernelByName((String) groupComboBox.getSelectedItem())); 397 // if car has FRED or caboose make lead 398 if (car.hasFred() || car.isCaboose()) { 399 car.getKernel().setLead(car); 400 } 401 car.setBlocking(car.getKernel().getSize()); 402 } 403 } 404 if (loadComboBox.getSelectedItem() != null && !car.getLoadName().equals(loadComboBox.getSelectedItem())) { 405 car.setLoadName((String) loadComboBox.getSelectedItem()); 406 car.setWait(0); // car could be at spur with schedule 407 car.setScheduleItemId(Car.NONE); 408 // check to see if car is part of kernel, and ask if all the other cars in the kernel should be changed 409 if (car.getKernel() != null) { 410 List<Car> cars = car.getKernel().getCars(); 411 if (cars.size() > 1) { 412 if (JmriJOptionPane.showConfirmDialog(this, Bundle.getMessage("carInKernelLoad", 413 car.toString(), car.getLoadName()), 414 Bundle.getMessage("carPartKernel", 415 car.getKernelName()), 416 JmriJOptionPane.YES_NO_OPTION) == JmriJOptionPane.YES_OPTION) { 417 // go through the entire list and change the loads for all cars 418 for (Car c : cars) { 419 if (InstanceManager.getDefault(CarLoads.class).containsName(c.getTypeName(), 420 car.getLoadName())) { 421 c.setLoadName(car.getLoadName()); 422 c.setWait(0); // car could be at spur with schedule 423 c.setScheduleItemId(Car.NONE); 424 } 425 } 426 } 427 } 428 } 429 } 430 431 // place car on track after setting load name 432 checkAndSetLocationAndTrack(car); 433 434 // update blocking 435 pBlocking.setVisible(passengerCheckBox.isSelected() || car.getKernel() != null); 436 blockingTextField.setText(Integer.toString(car.getBlocking())); 437 438 // is this car part of a kernel? Ask if all cars should have the same location and track 439 if (car.getKernel() != null) { 440 List<Car> cars = car.getKernel().getCars(); 441 for (Car kcar : cars) { 442 if (kcar != car) { 443 if (kcar.getLocation() != car.getLocation() || kcar.getTrack() != car.getTrack()) { 444 int results = JmriJOptionPane.showConfirmDialog(this, Bundle 445 .getMessage("carInKernelLocation", 446 car.toString(), car.getLocationName(), car.getTrackName()), 447 Bundle.getMessage("carPartKernel", 448 car.getKernelName()), 449 JmriJOptionPane.YES_NO_OPTION); 450 if (results == JmriJOptionPane.YES_OPTION) { 451 // change the location for all cars in kernel 452 for (Car kcar2 : cars) { 453 if (kcar2 != car) { 454 setLocationAndTrack(kcar2); 455 } 456 } 457 } 458 break; // done 459 } 460 } 461 } 462 } 463 } 464 465 @Override 466 protected void delete() { 467 Car car = carManager.getByRoadAndNumber((String) roadComboBox.getSelectedItem(), roadNumberTextField 468 .getText()); 469 if (car != null) { 470 carManager.deregister(car); 471 } 472 } 473 474 CarAttributeEditFrame carAttributeEditFrame; 475 476 // edit buttons only one frame active at a time 477 @Override 478 public void buttonEditActionPerformed(java.awt.event.ActionEvent ae) { 479 if (carAttributeEditFrame != null) { 480 carAttributeEditFrame.dispose(); 481 } 482 carAttributeEditFrame = new CarAttributeEditFrame(); 483 carAttributeEditFrame.addPropertyChangeListener(this); 484 485 if (ae.getSource() == editRoadButton) { 486 carAttributeEditFrame.initComponents(CarAttributeEditFrame.ROAD, (String) roadComboBox.getSelectedItem()); 487 } 488 if (ae.getSource() == editTypeButton) { 489 carAttributeEditFrame.initComponents(CarAttributeEditFrame.TYPE, (String) typeComboBox.getSelectedItem()); 490 } 491 if (ae.getSource() == editColorButton) { 492 carAttributeEditFrame.initComponents(CarAttributeEditFrame.COLOR, (String) colorComboBox.getSelectedItem()); 493 } 494 if (ae.getSource() == editLengthButton) { 495 carAttributeEditFrame.initComponents(CarAttributeEditFrame.LENGTH, 496 (String) lengthComboBox.getSelectedItem()); 497 } 498 if (ae.getSource() == editOwnerButton) { 499 carAttributeEditFrame.initComponents(CarAttributeEditFrame.OWNER, (String) ownerComboBox.getSelectedItem()); 500 } 501 if (ae.getSource() == editGroupButton) { 502 carAttributeEditFrame.initComponents(CarAttributeEditFrame.KERNEL, 503 (String) groupComboBox.getSelectedItem()); 504 } 505 } 506 507 @Override 508 protected void addPropertyChangeListeners() { 509 InstanceManager.getDefault(CarLoads.class).addPropertyChangeListener(this); 510 InstanceManager.getDefault(CarColors.class).addPropertyChangeListener(this); 511 InstanceManager.getDefault(KernelManager.class).addPropertyChangeListener(this); 512 carManager.addPropertyChangeListener(this); 513 super.addPropertyChangeListeners(); 514 } 515 516 @Override 517 protected void removePropertyChangeListeners() { 518 InstanceManager.getDefault(CarLoads.class).removePropertyChangeListener(this); 519 InstanceManager.getDefault(CarColors.class).removePropertyChangeListener(this); 520 InstanceManager.getDefault(KernelManager.class).removePropertyChangeListener(this); 521 carManager.removePropertyChangeListener(this); 522 if (_rs != null) { 523 _rs.removePropertyChangeListener(this); 524 } 525 super.removePropertyChangeListeners(); 526 } 527 528 @Override 529 public void dispose() { 530 if (carLoadEditFrame != null) { 531 carLoadEditFrame.dispose(); 532 } 533 if (carAttributeEditFrame != null) { 534 carAttributeEditFrame.dispose(); 535 } 536 super.dispose(); 537 } 538 539 @Override 540 public void propertyChange(java.beans.PropertyChangeEvent e) { 541 // if (Control.SHOW_PROPERTY) { 542 log.debug("Property change: ({}) old: ({}) new: ({})", e.getPropertyName(), e.getOldValue(), e 543 .getNewValue()); 544 // } 545 super.propertyChange(e); 546 547 if (e.getPropertyName().equals(CarLengths.CARLENGTHS_CHANGED_PROPERTY)) { 548 InstanceManager.getDefault(CarLengths.class).updateComboBox(lengthComboBox); 549 if (_rs != null) { 550 lengthComboBox.setSelectedItem(_rs.getLength()); 551 } 552 } 553 if (e.getPropertyName().equals(CarColors.CARCOLORS_CHANGED_PROPERTY)) { 554 InstanceManager.getDefault(CarColors.class).updateComboBox(colorComboBox); 555 if (_rs != null) { 556 colorComboBox.setSelectedItem(_rs.getColor()); 557 } 558 } 559 if (e.getPropertyName().equals(KernelManager.LISTLENGTH_CHANGED_PROPERTY) || 560 e.getPropertyName().equals(Car.KERNEL_NAME_CHANGED_PROPERTY)) { 561 InstanceManager.getDefault(KernelManager.class).updateComboBox(groupComboBox); 562 if (_rs != null) { 563 groupComboBox.setSelectedItem(((Car) _rs).getKernelName()); 564 } 565 } 566 if (e.getPropertyName().equals(CarLoads.LOAD_CHANGED_PROPERTY)) { 567 InstanceManager.getDefault(CarLoads.class).updateComboBox((String) typeComboBox.getSelectedItem(), 568 loadComboBox); 569 } 570 if (e.getPropertyName().equals(Car.LOAD_CHANGED_PROPERTY) || 571 e.getPropertyName().equals(CarLoads.LOAD_CHANGED_PROPERTY)) { 572 if (_rs != null) { 573 loadComboBox.setSelectedItem(((Car) _rs).getLoadName()); 574 } 575 } 576 if (e.getPropertyName().equals(CarAttributeEditFrame.DISPOSE)) { 577 carAttributeEditFrame = null; 578 } 579 } 580 581 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(CarEditFrame.class); 582}