* Code cleanup;
[Persons_Comparator.git] / src / WeightView.java
1 import javax.swing.*;
2 import java.awt.event.ItemEvent;
3 import java.awt.event.ItemListener;
4
5 public class WeightView extends JPanel implements ItemListener {
6 private Weight weightObj;
7 private JLabel label;
8 private JComboBox<Integer> comboBox;
9
10 WeightView(Weight weightObj) {
11 setWeightObj(weightObj);
12 this.label = new JLabel();
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());
19 this.comboBox.addItemListener(this);
20 add(label);
21 add(comboBox);
22 }
23
24 public Weight getWeightObj() {
25 return weightObj;
26 }
27
28 public void setWeightObj(Weight weightObj) {
29 this.weightObj = weightObj;
30 }
31
32 public JComboBox<Integer> getComboBox() {
33 return comboBox;
34 }
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 }
44 }