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