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 if (!super.save(carManager, isSave)) { 299 return; 300 } 301 Car car = (Car) _rs; 302 303 if (colorComboBox.getSelectedItem() != null) { 304 car.setColor((String) colorComboBox.getSelectedItem()); 305 } 306 307 // ask if all cars of this type should be passenger 308 if (isSave && car.isPassenger() ^ passengerCheckBox.isSelected()) { 309 if (JmriJOptionPane.showConfirmDialog(this, MessageFormat.format(passengerCheckBox.isSelected() ? Bundle 310 .getMessage("carModifyTypePassenger") : Bundle.getMessage("carRemoveTypePassenger"), 311 new Object[]{car.getTypeName()}), 312 Bundle.getMessage("carModifyAllType", 313 car.getTypeName()), 314 JmriJOptionPane.YES_NO_OPTION) == JmriJOptionPane.YES_OPTION) { 315 // go through the entire list and change the passenger setting 316 // for all cars of this type 317 for (Car c : carManager.getList()) { 318 if (c.getTypeName().equals(car.getTypeName())) { 319 c.setPassenger(passengerCheckBox.isSelected()); 320 } 321 } 322 } 323 } 324 car.setPassenger(passengerCheckBox.isSelected()); 325 int blocking = Integer.parseInt(blockingTextField.getText()); 326 // ask if blocking order should be the same 327 if (isSave && car.getKernel() == null && passengerCheckBox.isSelected() && car.getBlocking() != blocking) { 328 if (JmriJOptionPane.showConfirmDialog(this, Bundle.getMessage("carChangeBlocking", 329 blocking, car.getTypeName()), 330 Bundle.getMessage("carModifyAllType", car.getTypeName()), 331 JmriJOptionPane.YES_NO_OPTION) == JmriJOptionPane.YES_OPTION) { 332 // go through the entire list and change the passenger setting 333 // for all cars of this type 334 for (Car c : carManager.getList()) { 335 if (c.isPassenger() && c.getTypeName().equals(car.getTypeName())) { 336 c.setBlocking(blocking); 337 } 338 } 339 } 340 } 341 car.setBlocking(blocking); 342 // ask if all cars of this type should be caboose 343 if (isSave && car.isCaboose() ^ cabooseCheckBox.isSelected()) { 344 if (JmriJOptionPane.showConfirmDialog(this, MessageFormat.format(cabooseCheckBox.isSelected() ? Bundle 345 .getMessage("carModifyTypeCaboose") : Bundle.getMessage("carRemoveTypeCaboose"), 346 new Object[]{car.getTypeName()}), 347 Bundle.getMessage("carModifyAllType", 348 car.getTypeName()), 349 JmriJOptionPane.YES_NO_OPTION) == JmriJOptionPane.YES_OPTION) { 350 // go through the entire list and change the caboose setting for all cars of this type 351 for (Car c : carManager.getList()) { 352 if (c.getTypeName().equals(car.getTypeName())) { 353 c.setCaboose(cabooseCheckBox.isSelected()); 354 } 355 } 356 } 357 } 358 car.setCaboose(cabooseCheckBox.isSelected()); 359 // ask if all cars of this type should be utility 360 if (isSave && car.isUtility() ^ utilityCheckBox.isSelected()) { 361 if (JmriJOptionPane.showConfirmDialog(this, MessageFormat.format(utilityCheckBox.isSelected() ? Bundle 362 .getMessage("carModifyTypeUtility") : Bundle.getMessage("carRemoveTypeUtility"), 363 new Object[]{car.getTypeName()}), 364 Bundle.getMessage("carModifyAllType", 365 car.getTypeName()), 366 JmriJOptionPane.YES_NO_OPTION) == JmriJOptionPane.YES_OPTION) { 367 // go through the entire list and change the utility for all cars of this type 368 for (Car c : carManager.getList()) { 369 if (c.getTypeName().equals(car.getTypeName())) { 370 c.setUtility(utilityCheckBox.isSelected()); 371 } 372 } 373 } 374 } 375 car.setUtility(utilityCheckBox.isSelected()); 376 // ask if all cars of this type should be hazardous 377 if (isSave && car.isCarHazardous() ^ hazardousCheckBox.isSelected()) { 378 if (JmriJOptionPane.showConfirmDialog(this, MessageFormat.format(hazardousCheckBox.isSelected() ? Bundle 379 .getMessage("carModifyTypeHazardous") : Bundle.getMessage("carRemoveTypeHazardous"), 380 new Object[]{car.getTypeName()}), 381 Bundle.getMessage("carModifyAllType", 382 car.getTypeName()), 383 JmriJOptionPane.YES_NO_OPTION) == JmriJOptionPane.YES_OPTION) { 384 // go through the entire list and change the hazardous setting for all cars of this type 385 for (Car c : carManager.getList()) { 386 if (c.getTypeName().equals(car.getTypeName())) { 387 c.setCarHazardous(hazardousCheckBox.isSelected()); 388 } 389 } 390 } 391 } 392 car.setCarHazardous(hazardousCheckBox.isSelected()); 393 car.setFred(fredCheckBox.isSelected()); 394 if (groupComboBox.getSelectedItem() != null) { 395 if (groupComboBox.getSelectedItem().equals(CarManager.NONE)) { 396 car.setKernel(null); 397 if (!car.isPassenger()) { 398 car.setBlocking(Car.DEFAULT_BLOCKING_ORDER); 399 } 400 } else if (!car.getKernelName().equals(groupComboBox.getSelectedItem())) { 401 car.setKernel(InstanceManager.getDefault(KernelManager.class).getKernelByName((String) groupComboBox.getSelectedItem())); 402 // if car has FRED or caboose make lead 403 if (car.hasFred() || car.isCaboose()) { 404 car.getKernel().setLead(car); 405 } 406 car.setBlocking(car.getKernel().getSize()); 407 } 408 } 409 if (loadComboBox.getSelectedItem() != null && !car.getLoadName().equals(loadComboBox.getSelectedItem())) { 410 car.setLoadName((String) loadComboBox.getSelectedItem()); 411 car.setWait(0); // car could be at spur with schedule 412 car.setScheduleItemId(Car.NONE); 413 // check to see if car is part of kernel, and ask if all the other cars in the kernel should be changed 414 if (car.getKernel() != null) { 415 List<Car> cars = car.getKernel().getCars(); 416 if (cars.size() > 1) { 417 if (JmriJOptionPane.showConfirmDialog(this, Bundle.getMessage("carInKernelLoad", 418 car.toString(), car.getLoadName()), 419 Bundle.getMessage("carPartKernel", 420 car.getKernelName()), 421 JmriJOptionPane.YES_NO_OPTION) == JmriJOptionPane.YES_OPTION) { 422 // go through the entire list and change the loads for all cars 423 for (Car c : cars) { 424 if (InstanceManager.getDefault(CarLoads.class).containsName(c.getTypeName(), 425 car.getLoadName())) { 426 c.setLoadName(car.getLoadName()); 427 c.setWait(0); // car could be at spur with schedule 428 c.setScheduleItemId(Car.NONE); 429 } 430 } 431 } 432 } 433 } 434 } 435 436 // place car on track after setting load name 437 checkAndSetLocationAndTrack(car); 438 439 // update blocking 440 pBlocking.setVisible(passengerCheckBox.isSelected() || car.getKernel() != null); 441 blockingTextField.setText(Integer.toString(car.getBlocking())); 442 443 // is this car part of a kernel? Ask if all cars should have the same location and track 444 if (car.getKernel() != null) { 445 List<Car> cars = car.getKernel().getCars(); 446 for (Car kcar : cars) { 447 if (kcar != car) { 448 if (kcar.getLocation() != car.getLocation() || kcar.getTrack() != car.getTrack()) { 449 int results = JmriJOptionPane.showConfirmDialog(this, Bundle 450 .getMessage("carInKernelLocation", 451 car.toString(), car.getLocationName(), car.getTrackName()), 452 Bundle.getMessage("carPartKernel", 453 car.getKernelName()), 454 JmriJOptionPane.YES_NO_OPTION); 455 if (results == JmriJOptionPane.YES_OPTION) { 456 // change the location for all cars in kernel 457 for (Car kcar2 : cars) { 458 if (kcar2 != car) { 459 setLocationAndTrack(kcar2); 460 } 461 } 462 } 463 break; // done 464 } 465 } 466 } 467 } 468 } 469 470 @Override 471 protected void delete() { 472 Car car = carManager.getByRoadAndNumber((String) roadComboBox.getSelectedItem(), roadNumberTextField 473 .getText()); 474 if (car != null) { 475 carManager.deregister(car); 476 } 477 } 478 479 CarAttributeEditFrame carAttributeEditFrame; 480 481 // edit buttons only one frame active at a time 482 @Override 483 public void buttonEditActionPerformed(java.awt.event.ActionEvent ae) { 484 if (carAttributeEditFrame != null) { 485 carAttributeEditFrame.dispose(); 486 } 487 carAttributeEditFrame = new CarAttributeEditFrame(); 488 carAttributeEditFrame.addPropertyChangeListener(this); 489 490 if (ae.getSource() == editRoadButton) { 491 carAttributeEditFrame.initComponents(CarAttributeEditFrame.ROAD, (String) roadComboBox.getSelectedItem()); 492 } 493 if (ae.getSource() == editTypeButton) { 494 carAttributeEditFrame.initComponents(CarAttributeEditFrame.TYPE, (String) typeComboBox.getSelectedItem()); 495 } 496 if (ae.getSource() == editColorButton) { 497 carAttributeEditFrame.initComponents(CarAttributeEditFrame.COLOR, (String) colorComboBox.getSelectedItem()); 498 } 499 if (ae.getSource() == editLengthButton) { 500 carAttributeEditFrame.initComponents(CarAttributeEditFrame.LENGTH, 501 (String) lengthComboBox.getSelectedItem()); 502 } 503 if (ae.getSource() == editOwnerButton) { 504 carAttributeEditFrame.initComponents(CarAttributeEditFrame.OWNER, (String) ownerComboBox.getSelectedItem()); 505 } 506 if (ae.getSource() == editGroupButton) { 507 carAttributeEditFrame.initComponents(CarAttributeEditFrame.KERNEL, 508 (String) groupComboBox.getSelectedItem()); 509 } 510 } 511 512 @Override 513 protected void addPropertyChangeListeners() { 514 InstanceManager.getDefault(CarLoads.class).addPropertyChangeListener(this); 515 InstanceManager.getDefault(CarColors.class).addPropertyChangeListener(this); 516 InstanceManager.getDefault(KernelManager.class).addPropertyChangeListener(this); 517 carManager.addPropertyChangeListener(this); 518 super.addPropertyChangeListeners(); 519 } 520 521 @Override 522 protected void removePropertyChangeListeners() { 523 InstanceManager.getDefault(CarLoads.class).removePropertyChangeListener(this); 524 InstanceManager.getDefault(CarColors.class).removePropertyChangeListener(this); 525 InstanceManager.getDefault(KernelManager.class).removePropertyChangeListener(this); 526 carManager.removePropertyChangeListener(this); 527 if (_rs != null) { 528 _rs.removePropertyChangeListener(this); 529 } 530 super.removePropertyChangeListeners(); 531 } 532 533 @Override 534 public void dispose() { 535 if (carLoadEditFrame != null) { 536 carLoadEditFrame.dispose(); 537 } 538 if (carAttributeEditFrame != null) { 539 carAttributeEditFrame.dispose(); 540 } 541 super.dispose(); 542 } 543 544 @Override 545 public void propertyChange(java.beans.PropertyChangeEvent e) { 546 // if (Control.SHOW_PROPERTY) { 547 log.debug("Property change: ({}) old: ({}) new: ({})", e.getPropertyName(), e.getOldValue(), e 548 .getNewValue()); 549 // } 550 super.propertyChange(e); 551 552 if (e.getPropertyName().equals(CarLengths.CARLENGTHS_CHANGED_PROPERTY)) { 553 InstanceManager.getDefault(CarLengths.class).updateComboBox(lengthComboBox); 554 if (_rs != null) { 555 lengthComboBox.setSelectedItem(_rs.getLength()); 556 } 557 } 558 if (e.getPropertyName().equals(CarColors.CARCOLORS_CHANGED_PROPERTY)) { 559 InstanceManager.getDefault(CarColors.class).updateComboBox(colorComboBox); 560 if (_rs != null) { 561 colorComboBox.setSelectedItem(_rs.getColor()); 562 } 563 } 564 if (e.getPropertyName().equals(KernelManager.LISTLENGTH_CHANGED_PROPERTY) || 565 e.getPropertyName().equals(Car.KERNEL_NAME_CHANGED_PROPERTY)) { 566 InstanceManager.getDefault(KernelManager.class).updateComboBox(groupComboBox); 567 if (_rs != null) { 568 groupComboBox.setSelectedItem(((Car) _rs).getKernelName()); 569 } 570 } 571 if (e.getPropertyName().equals(CarLoads.LOAD_CHANGED_PROPERTY)) { 572 InstanceManager.getDefault(CarLoads.class).updateComboBox((String) typeComboBox.getSelectedItem(), 573 loadComboBox); 574 } 575 if (e.getPropertyName().equals(Car.LOAD_CHANGED_PROPERTY) || 576 e.getPropertyName().equals(CarLoads.LOAD_CHANGED_PROPERTY)) { 577 if (_rs != null) { 578 loadComboBox.setSelectedItem(((Car) _rs).getLoadName()); 579 } 580 } 581 if (e.getPropertyName().equals(CarAttributeEditFrame.DISPOSE)) { 582 carAttributeEditFrame = null; 583 } 584 } 585 586 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(CarEditFrame.class); 587}