/
CarEditFrame.java
599 lines (542 loc) · 27.7 KB
/
CarEditFrame.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
package jmri.jmrit.operations.rollingstock.cars;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.awt.GridBagLayout;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.util.List;
import java.util.ResourceBundle;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import jmri.InstanceManager;
import jmri.jmrit.operations.OperationsXml;
import jmri.jmrit.operations.rollingstock.RollingStock;
import jmri.jmrit.operations.rollingstock.RollingStockAttribute;
import jmri.jmrit.operations.rollingstock.RollingStockEditFrame;
import jmri.jmrit.operations.rollingstock.cars.tools.CarAttributeEditFrame;
import jmri.jmrit.operations.rollingstock.cars.tools.CarLoadEditFrame;
import jmri.jmrit.operations.setup.Setup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Frame for user edit of car
*
* @author Dan Boudreau Copyright (C) 2008, 2010, 2011, 2014, 2018
*/
public class CarEditFrame extends RollingStockEditFrame implements java.beans.PropertyChangeListener {
protected static final ResourceBundle rb = ResourceBundle
.getBundle("jmri.jmrit.operations.rollingstock.cars.JmritOperationsCarsBundle");
CarManager carManager = InstanceManager.getDefault(CarManager.class);
CarManagerXml managerXml = InstanceManager.getDefault(CarManagerXml.class);
// labels
JLabel textWeightOz = new JLabel(Bundle.getMessage("WeightOz"));
JButton editColorButton = new JButton(Bundle.getMessage("ButtonEdit"));
JButton editLoadButton = new JButton(Bundle.getMessage("ButtonEdit"));
JButton fillWeightButton = new JButton(Bundle.getMessage("Calculate"));
JCheckBox passengerCheckBox = new JCheckBox(Bundle.getMessage("Passenger"));
JCheckBox cabooseCheckBox = new JCheckBox(Bundle.getMessage("Caboose"));
JCheckBox fredCheckBox = new JCheckBox(Bundle.getMessage("Fred"));
JCheckBox utilityCheckBox = new JCheckBox(Bundle.getMessage("Utility"));
JCheckBox hazardousCheckBox = new JCheckBox(Bundle.getMessage("Hazardous"));
JCheckBox autoWeightCheckBox = new JCheckBox(Bundle.getMessage("Auto"));
JComboBox<String> colorComboBox = InstanceManager.getDefault(CarColors.class).getComboBox();
JComboBox<String> loadComboBox = InstanceManager.getDefault(CarLoads.class).getComboBox(null);
JTextField blockingTextField = new JTextField(4);
CarLoadEditFrame carLoadEditFrame;
public CarEditFrame() {
super(Bundle.getMessage("TitleCarAdd"));
}
@SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "Checks for null")
@Override
public void initComponents() {
groupComboBox = InstanceManager.getDefault(CarManager.class).getKernelComboBox();
super.initComponents();
addButton.setText(Bundle.getMessage("TitleCarAdd"));
// type options for cars
addItem(pTypeOptions, passengerCheckBox, 0, 1);
addItem(pTypeOptions, cabooseCheckBox, 1, 1);
addItem(pTypeOptions, fredCheckBox, 2, 1);
addItem(pTypeOptions, utilityCheckBox, 3, 1);
addItem(pTypeOptions, hazardousCheckBox, 4, 1);
// default check box selections
autoWeightCheckBox.setSelected(true);
passengerCheckBox.setSelected(false);
cabooseCheckBox.setSelected(false);
fredCheckBox.setSelected(false);
hazardousCheckBox.setSelected(false);
// load tool tips
weightTextField.setToolTipText(Bundle.getMessage("TipCarWeightOz"));
weightTonsTextField.setToolTipText(Bundle.getMessage("TipCarWeightTons"));
autoWeightCheckBox.setToolTipText(Bundle.getMessage("TipCarAutoCalculate"));
passengerCheckBox.setToolTipText(Bundle.getMessage("TipCarPassenger"));
cabooseCheckBox.setToolTipText(Bundle.getMessage("TipCarCaboose"));
fredCheckBox.setToolTipText(Bundle.getMessage("TipCarFred"));
utilityCheckBox.setToolTipText(Bundle.getMessage("TipCarUtility"));
hazardousCheckBox.setToolTipText(Bundle.getMessage("TipCarHazardous"));
blockingTextField.setToolTipText(Bundle.getMessage("TipPassengerCarBlocking"));
fillWeightButton.setToolTipText(Bundle.getMessage("TipCalculateCarWeight"));
builtTextField.setToolTipText(Bundle.getMessage("TipBuildDate"));
valueTextArea.setToolTipText(Bundle.getMessage("TipValue"));
editColorButton.setToolTipText(MessageFormat.format(Bundle.getMessage("TipAddDeleteReplace"),
new Object[]{Bundle.getMessage("Color").toLowerCase()}));
editLoadButton.setToolTipText(MessageFormat.format(Bundle.getMessage("TipAddDeleteReplace"),
new Object[]{Bundle.getMessage("load")})); // initial caps for some languages i.e. German
editGroupButton.setToolTipText(MessageFormat.format(Bundle.getMessage("TipAddDeleteReplace"),
new Object[]{Bundle.getMessage("Kernel").toLowerCase()}));
deleteButton.setToolTipText(Bundle.getMessage("TipDeleteButton"));
addButton.setToolTipText(Bundle.getMessage("TipAddButton"));
saveButton.setToolTipText(Bundle.getMessage("TipSaveButton"));
// row 4
pBlocking.setLayout(new GridBagLayout());
pBlocking.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BorderLayoutPassengerBlocking")));
addItem(pBlocking, blockingTextField, 0, 0);
blockingTextField.setText("0");
// row 7
pWeightOz.setLayout(new GridBagLayout());
addItem(pWeightOz, textWeightOz, 0, 0);
addItem(pWeightOz, weightTextField, 1, 0);
addItem(pWeightOz, fillWeightButton, 2, 0);
addItem(pWeightOz, autoWeightCheckBox, 3, 0);
// row 8
pColor.setLayout(new GridBagLayout());
pColor.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Color")));
addItem(pColor, colorComboBox, 1, 0);
addItem(pColor, editColorButton, 2, 0);
pColor.setVisible(true);
// row 9
pLoad.setLayout(new GridBagLayout());
pLoad.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Load")));
addItem(pLoad, loadComboBox, 1, 0);
addItem(pLoad, editLoadButton, 2, 0);
pLoad.setVisible(true);
// row 10
pGroup.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Kernel")));
addEditButtonAction(editColorButton);
addButtonAction(fillWeightButton);
addButtonAction(editLoadButton);
// setup check boxes
addCheckBoxAction(cabooseCheckBox);
addCheckBoxAction(fredCheckBox);
addCheckBoxAction(passengerCheckBox);
addHelpMenu("package.jmri.jmrit.operations.Operations_CarsEdit", true); // NOI18N
}
@Override
protected ResourceBundle getRb() {
return rb;
}
@Override
protected RollingStockAttribute getTypeManager() {
return InstanceManager.getDefault(CarTypes.class);
}
@Override
protected RollingStockAttribute getLengthManager() {
return InstanceManager.getDefault(CarLengths.class);
}
public void load(Car car) {
super.load(car);
passengerCheckBox.setSelected(car.isPassenger());
cabooseCheckBox.setSelected(car.isCaboose());
utilityCheckBox.setSelected(car.isUtility());
fredCheckBox.setSelected(car.hasFred());
hazardousCheckBox.setSelected(car.isHazardous());
pBlocking.setVisible(car.isPassenger() || car.getKernel() != null);
blockingTextField.setText(Integer.toString(car.getBlocking()));
if (!InstanceManager.getDefault(CarLoads.class).containsName(car.getTypeName(), car.getLoadName())) {
if (JOptionPane.showConfirmDialog(this, MessageFormat.format(Bundle.getMessage("loadNameNotExist"),
new Object[]{car.getLoadName()}), Bundle.getMessage("addLoad"),
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
InstanceManager.getDefault(CarLoads.class).addName(car.getTypeName(), car.getLoadName());
}
}
InstanceManager.getDefault(CarLoads.class).updateComboBox(car.getTypeName(), loadComboBox);
loadComboBox.setSelectedItem(car.getLoadName());
// listen for changes in car load
car.addPropertyChangeListener(this);
// only cars have color attribute
if (!InstanceManager.getDefault(CarColors.class).containsName(car.getColor())) {
if (JOptionPane.showConfirmDialog(this, MessageFormat.format(Bundle.getMessage("colorNameNotExist"),
new Object[]{car.getColor()}), Bundle.getMessage("carAddColor"),
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
InstanceManager.getDefault(CarColors.class).addName(car.getColor());
}
}
colorComboBox.setSelectedItem(car.getColor());
groupComboBox.setSelectedItem(car.getKernelName());
setTitle(Bundle.getMessage("TitleCarEdit"));
}
@Override
public void comboBoxActionPerformed(java.awt.event.ActionEvent ae) {
if (ae.getSource() == typeComboBox && typeComboBox.getSelectedItem() != null) {
log.debug("Type comboBox sees change, update car loads");
InstanceManager.getDefault(CarLoads.class).updateComboBox((String) typeComboBox.getSelectedItem(),
loadComboBox);
}
if (ae.getSource() == lengthComboBox && autoWeightCheckBox.isSelected()) {
calculateWeight();
}
super.comboBoxActionPerformed(ae);
}
@Override
public void checkBoxActionPerformed(java.awt.event.ActionEvent ae) {
if (ae.getSource() == cabooseCheckBox && cabooseCheckBox.isSelected()) {
fredCheckBox.setSelected(false);
}
if (ae.getSource() == fredCheckBox && fredCheckBox.isSelected()) {
cabooseCheckBox.setSelected(false);
}
if (ae.getSource() == passengerCheckBox) {
pBlocking.setVisible(passengerCheckBox.isSelected() || (_rs != null && ((Car) _rs).getKernel() != null));
}
super.checkBoxActionPerformed(ae);
}
// Save, Delete, Add, Clear, Calculate, Edit Load buttons
@Override
public void buttonActionPerformed(java.awt.event.ActionEvent ae) {
super.buttonActionPerformed(ae);
if (ae.getSource() == deleteButton) {
log.debug("car delete button activated");
// disable delete and save buttons
deleteButton.setEnabled(false);
saveButton.setEnabled(false);
if (_rs != null) {
_rs.removePropertyChangeListener(this);
}
Car car = carManager.getByRoadAndNumber((String) roadComboBox.getSelectedItem(), roadNumberTextField
.getText());
if (car != null) {
carManager.deregister(car);
}
_rs = null;
OperationsXml.save();
}
if (ae.getSource() == fillWeightButton) {
calculateWeight();
}
if (ae.getSource() == editLoadButton) {
if (carLoadEditFrame != null) {
carLoadEditFrame.dispose();
}
carLoadEditFrame = new CarLoadEditFrame();
carLoadEditFrame.setLocationRelativeTo(this);
carLoadEditFrame.initComponents((String) typeComboBox.getSelectedItem(),
(String) loadComboBox.getSelectedItem());
}
}
@Override
protected boolean check(RollingStock car) {
// check to see if car with road and number already exists
Car existingCar = carManager.getByRoadAndNumber((String) roadComboBox.getSelectedItem(), roadNumberTextField
.getText());
if (existingCar != null) {
if (car == null) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("carRoadExists"), Bundle
.getMessage("carCanNotAdd"), JOptionPane.ERROR_MESSAGE);
return false;
}
// old car with new road or number?
if (!existingCar.getId().equals(car.getId())) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("carRoadExists"), Bundle
.getMessage("carCanNotUpdate"), JOptionPane.ERROR_MESSAGE);
return false;
}
}
// check car's weight has proper format
try {
Number number = NumberFormat.getNumberInstance().parse(weightTextField.getText());
log.debug("Car weight in oz: {}", number);
} catch (Exception e) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("carWeightFormat"), Bundle
.getMessage("carActualWeight"), JOptionPane.ERROR_MESSAGE);
return false;
}
return super.check(car);
}
private void calculateWeight() {
if (lengthComboBox.getSelectedItem() != null) {
String length = (String) lengthComboBox.getSelectedItem();
try {
double carLength = Double.parseDouble(length) * 12 / Setup.getScaleRatio();
double carWeight = (Setup.getInitalWeight() + carLength * Setup.getAddWeight()) / 1000;
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(1);
weightTextField.setText((nf.format(carWeight))); // car weight in ounces.
int tons = (int) (carWeight * Setup.getScaleTonRatio());
// adjust weight for caboose
if (cabooseCheckBox.isSelected() || passengerCheckBox.isSelected()) {
tons = (int) (Double.parseDouble(length) * .9); // .9 tons/foot
}
weightTonsTextField.setText(Integer.toString(tons));
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("carLengthMustBe"), Bundle
.getMessage("carWeigthCanNot"), JOptionPane.ERROR_MESSAGE);
}
}
}
@Override
protected void save(boolean isSave) {
if (roadComboBox.getSelectedItem() == null) {
return;
}
super.save(carManager, isSave);
Car car = (Car) _rs;
if (colorComboBox.getSelectedItem() != null) {
car.setColor((String) colorComboBox.getSelectedItem());
}
// ask if all cars of this type should be passenger
if (isSave && car.isPassenger() ^ passengerCheckBox.isSelected()) {
if (JOptionPane.showConfirmDialog(this, MessageFormat.format(passengerCheckBox.isSelected() ? Bundle
.getMessage("carModifyTypePassenger") : Bundle.getMessage("carRemoveTypePassenger"),
new Object[]{car.getTypeName()}),
MessageFormat.format(Bundle.getMessage("carModifyAllType"),
new Object[]{car.getTypeName()}),
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
// go through the entire list and change the passenger setting
// for all cars of this type
for (Car c : carManager.getList()) {
if (c.getTypeName().equals(car.getTypeName())) {
c.setPassenger(passengerCheckBox.isSelected());
}
}
}
}
car.setPassenger(passengerCheckBox.isSelected());
int blocking = 0;
try {
blocking = Integer.parseInt(blockingTextField.getText());
// only allow numbers between 0 and 100
if (blocking < 0 || blocking > 100) {
blocking = 0;
}
} catch (Exception e) {
log.warn("Blocking must be a number between 0 and 100");
}
// ask if blocking order should be the same
if (isSave && car.getKernel() == null && passengerCheckBox.isSelected() && car.getBlocking() != blocking) {
if (JOptionPane.showConfirmDialog(this, MessageFormat.format(Bundle.getMessage("carChangeBlocking"),
new Object[]{blocking, car.getTypeName()}),
MessageFormat.format(Bundle
.getMessage("carModifyAllType"), new Object[]{car.getTypeName()}),
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
// go through the entire list and change the passenger setting
// for all cars of this type
for (Car c : carManager.getList()) {
if (c.isPassenger() && c.getTypeName().equals(car.getTypeName())) {
c.setBlocking(blocking);
}
}
}
}
car.setBlocking(blocking);
// ask if all cars of this type should be caboose
if (isSave && car.isCaboose() ^ cabooseCheckBox.isSelected()) {
if (JOptionPane.showConfirmDialog(this, MessageFormat.format(cabooseCheckBox.isSelected() ? Bundle
.getMessage("carModifyTypeCaboose") : Bundle.getMessage("carRemoveTypeCaboose"),
new Object[]{car.getTypeName()}),
MessageFormat.format(Bundle.getMessage("carModifyAllType"),
new Object[]{car.getTypeName()}),
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
// go through the entire list and change the caboose setting for all cars of this type
for (Car c : carManager.getList()) {
if (c.getTypeName().equals(car.getTypeName())) {
c.setCaboose(cabooseCheckBox.isSelected());
}
}
}
}
car.setCaboose(cabooseCheckBox.isSelected());
// ask if all cars of this type should be utility
if (isSave && car.isUtility() ^ utilityCheckBox.isSelected()) {
if (JOptionPane.showConfirmDialog(this, MessageFormat.format(utilityCheckBox.isSelected() ? Bundle
.getMessage("carModifyTypeUtility") : Bundle.getMessage("carRemoveTypeUtility"),
new Object[]{car.getTypeName()}),
MessageFormat.format(Bundle.getMessage("carModifyAllType"),
new Object[]{car.getTypeName()}),
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
// go through the entire list and change the utility for all cars of this type
for (Car c : carManager.getList()) {
if (c.getTypeName().equals(car.getTypeName())) {
c.setUtility(utilityCheckBox.isSelected());
}
}
}
}
car.setUtility(utilityCheckBox.isSelected());
// ask if all cars of this type should be hazardous
if (isSave && car.isHazardous() ^ hazardousCheckBox.isSelected()) {
if (JOptionPane.showConfirmDialog(this, MessageFormat.format(hazardousCheckBox.isSelected() ? Bundle
.getMessage("carModifyTypeHazardous") : Bundle.getMessage("carRemoveTypeHazardous"),
new Object[]{car.getTypeName()}),
MessageFormat.format(Bundle.getMessage("carModifyAllType"),
new Object[]{car.getTypeName()}),
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
// go through the entire list and change the hazardous setting for all cars of this type
for (Car c : carManager.getList()) {
if (c.getTypeName().equals(car.getTypeName())) {
c.setHazardous(hazardousCheckBox.isSelected());
}
}
}
}
car.setHazardous(hazardousCheckBox.isSelected());
car.setFred(fredCheckBox.isSelected());
if (groupComboBox.getSelectedItem() != null) {
if (groupComboBox.getSelectedItem().equals(CarManager.NONE)) {
car.setKernel(null);
} else if (!car.getKernelName().equals(groupComboBox.getSelectedItem())) {
car.setKernel(carManager.getKernelByName((String) groupComboBox.getSelectedItem()));
// if car has FRED or caboose make lead
if (car.hasFred() || car.isCaboose()) {
car.getKernel().setLead(car);
}
car.setBlocking(car.getKernel().getSize());
}
}
if (loadComboBox.getSelectedItem() != null && !car.getLoadName().equals(loadComboBox.getSelectedItem())) {
car.setLoadName((String) loadComboBox.getSelectedItem());
// check to see if car is part of kernel, and ask if all the other cars in the kernel should be changed
if (car.getKernel() != null) {
List<Car> cars = car.getKernel().getCars();
if (cars.size() > 1) {
if (JOptionPane.showConfirmDialog(this, MessageFormat.format(Bundle.getMessage("carInKernelLoad"),
new Object[]{car.toString(), car.getLoadName()}),
MessageFormat.format(Bundle.getMessage("carPartKernel"),
new Object[]{car.getKernelName()}),
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
// go through the entire list and change the loads for all cars
for (Car c : cars) {
if (InstanceManager.getDefault(CarLoads.class).containsName(c.getTypeName(),
car.getLoadName())) {
c.setLoadName(car.getLoadName());
}
}
}
}
}
}
// update blocking
pBlocking.setVisible(passengerCheckBox.isSelected() || car.getKernel() != null);
blockingTextField.setText(Integer.toString(car.getBlocking()));
// is this car part of a kernel? Ask if all cars should have the same location and track
if (car.getKernel() != null) {
List<Car> cars = car.getKernel().getCars();
if (cars.size() > 1) {
for (Car kcar : cars) {
if (kcar != car) {
if (kcar.getLocation() != car.getLocation() || kcar.getTrack() != car.getTrack()) {
int results = JOptionPane.showConfirmDialog(this, MessageFormat.format(Bundle
.getMessage("carInKernelLocation"),
new Object[]{car.toString(), car.getLocationName(), car.getTrackName()}),
MessageFormat
.format(Bundle.getMessage("carPartKernel"),
new Object[]{car.getKernelName()}),
JOptionPane.YES_NO_OPTION);
if (results == JOptionPane.NO_OPTION) {
break; // done
}
// change the location for all cars in kernel
for (Car kcar2 : cars) {
if (kcar2 != car) {
setLocationAndTrack(kcar2);
}
}
break; // done
}
}
}
}
}
}
CarAttributeEditFrame carAttributeEditFrame;
// edit buttons only one frame active at a time
@Override
public void buttonEditActionPerformed(java.awt.event.ActionEvent ae) {
if (carAttributeEditFrame != null) {
carAttributeEditFrame.dispose();
}
carAttributeEditFrame = new CarAttributeEditFrame();
carAttributeEditFrame.setLocationRelativeTo(this);
carAttributeEditFrame.addPropertyChangeListener(this);
if (ae.getSource() == editRoadButton) {
carAttributeEditFrame.initComponents(CarAttributeEditFrame.ROAD, (String) roadComboBox.getSelectedItem());
}
if (ae.getSource() == editTypeButton) {
carAttributeEditFrame.initComponents(CarAttributeEditFrame.TYPE, (String) typeComboBox.getSelectedItem());
}
if (ae.getSource() == editColorButton) {
carAttributeEditFrame.initComponents(CarAttributeEditFrame.COLOR, (String) colorComboBox.getSelectedItem());
}
if (ae.getSource() == editLengthButton) {
carAttributeEditFrame.initComponents(CarAttributeEditFrame.LENGTH,
(String) lengthComboBox.getSelectedItem());
}
if (ae.getSource() == editOwnerButton) {
carAttributeEditFrame.initComponents(CarAttributeEditFrame.OWNER, (String) ownerComboBox.getSelectedItem());
}
if (ae.getSource() == editGroupButton) {
carAttributeEditFrame.initComponents(CarAttributeEditFrame.KERNEL,
(String) groupComboBox.getSelectedItem());
}
}
@Override
protected void addPropertyChangeListeners() {
InstanceManager.getDefault(CarLoads.class).addPropertyChangeListener(this);
InstanceManager.getDefault(CarColors.class).addPropertyChangeListener(this);
carManager.addPropertyChangeListener(this);
super.addPropertyChangeListeners();
}
@Override
protected void removePropertyChangeListeners() {
InstanceManager.getDefault(CarLoads.class).removePropertyChangeListener(this);
InstanceManager.getDefault(CarColors.class).removePropertyChangeListener(this);
carManager.removePropertyChangeListener(this);
if (_rs != null) {
_rs.removePropertyChangeListener(this);
}
super.removePropertyChangeListeners();
}
@Override
public void propertyChange(java.beans.PropertyChangeEvent e) {
// if (Control.SHOW_PROPERTY) {
log.debug("Property change: ({}) old: ({}) new: ({})", e.getPropertyName(), e.getOldValue(), e
.getNewValue());
// }
super.propertyChange(e);
if (e.getPropertyName().equals(CarLengths.CARLENGTHS_CHANGED_PROPERTY)) {
InstanceManager.getDefault(CarLengths.class).updateComboBox(lengthComboBox);
if (_rs != null) {
lengthComboBox.setSelectedItem(_rs.getLength());
}
}
if (e.getPropertyName().equals(CarColors.CARCOLORS_CHANGED_PROPERTY)) {
InstanceManager.getDefault(CarColors.class).updateComboBox(colorComboBox);
if (_rs != null) {
colorComboBox.setSelectedItem(_rs.getColor());
}
}
if (e.getPropertyName().equals(CarManager.KERNEL_LISTLENGTH_CHANGED_PROPERTY) ||
e.getPropertyName().equals(Car.KERNEL_NAME_CHANGED_PROPERTY)) {
carManager.updateKernelComboBox(groupComboBox);
if (_rs != null) {
groupComboBox.setSelectedItem(((Car) _rs).getKernelName());
}
}
if (e.getPropertyName().equals(CarLoads.LOAD_CHANGED_PROPERTY)) {
InstanceManager.getDefault(CarLoads.class).updateComboBox((String) typeComboBox.getSelectedItem(),
loadComboBox);
}
if (e.getPropertyName().equals(Car.LOAD_CHANGED_PROPERTY) ||
e.getPropertyName().equals(CarLoads.LOAD_CHANGED_PROPERTY)) {
if (_rs != null) {
loadComboBox.setSelectedItem(((Car) _rs).getLoadName());
}
}
if (e.getPropertyName().equals(CarAttributeEditFrame.DISPOSE)) {
carAttributeEditFrame = null;
}
}
private final static Logger log = LoggerFactory.getLogger(CarEditFrame.class);
}