* Code cleanup;
[Persons_Comparator.git] / src / WeightView.java
CommitLineData
089fcbfc 1import javax.swing.*;
e16e3b15
JB
2import java.awt.event.ItemEvent;
3import java.awt.event.ItemListener;
089fcbfc 4
e16e3b15 5public class WeightView extends JPanel implements ItemListener {
6977e614 6 private Weight weightObj;
883508ca 7 private JLabel label;
2bb2aa17 8 private JComboBox<Integer> comboBox;
6977e614 9
b974e749
JB
10 WeightView(Weight weightObj) {
11 setWeightObj(weightObj);
883508ca 12 this.label = new JLabel();
2bb2aa17
JB
13 this.label.setText("Weight (kilograms)");
14 this.comboBox = new JComboBox<>(this.getWeightObj().getValuesArray());
15 if (this.getWeightObj().getWeight() != 0)
16 this.comboBox.setSelectedItem(this.getWeightObj().getWeight());
17 else
18 this.comboBox.setSelectedItem(this.getWeightObj().getDefaultWeight());
e16e3b15 19 this.comboBox.addItemListener(this);
883508ca 20 add(label);
2bb2aa17 21 add(comboBox);
089fcbfc
JB
22 }
23
6977e614
JB
24 public Weight getWeightObj() {
25 return weightObj;
26 }
27
28 public void setWeightObj(Weight weightObj) {
29 this.weightObj = weightObj;
30 }
9b3bfcdd
JB
31
32 public JComboBox<Integer> getComboBox() {
33 return comboBox;
34 }
e16e3b15
JB
35
36 @Override
37 public void itemStateChanged(ItemEvent event) {
38 if (event.getStateChange() == ItemEvent.SELECTED) {
39 Object item = event.getItem();
40 PersonLeftPanel personLeftPanel = MainWindowsView.getInstance().getCurrentPersonView().getPersonPanel().getLeftPanel();
41 personLeftPanel.drawWeight((int) item);
42 }
43 }
6977e614 44}