* Code cleanup;
[Persons_Comparator.git] / src / WeightView.java
index 9e7ef20d8c0744377cef894240f2e82f6ce0f60e..7e029fa1799330896cd685bfec04b3d68d806c42 100644 (file)
@@ -1,14 +1,24 @@
 import javax.swing.*;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
 
-public class WeightView extends JPanel {
+public class WeightView extends JPanel implements ItemListener {
     private Weight weightObj;
     private JLabel label;
+    private JComboBox<Integer> comboBox;
 
     WeightView(Weight weightObj) {
         setWeightObj(weightObj);
         this.label = new JLabel();
-        this.label.setText("Weight");
+        this.label.setText("Weight (kilograms)");
+        this.comboBox = new JComboBox<>(this.getWeightObj().getValuesArray());
+        if (this.getWeightObj().getWeight() != 0)
+            this.comboBox.setSelectedItem(this.getWeightObj().getWeight());
+        else
+            this.comboBox.setSelectedItem(this.getWeightObj().getDefaultWeight());
+        this.comboBox.addItemListener(this);
         add(label);
+        add(comboBox);
     }
 
     public Weight getWeightObj() {
@@ -18,4 +28,17 @@ public class WeightView extends JPanel {
     public void setWeightObj(Weight weightObj) {
         this.weightObj = weightObj;
     }
+
+    public JComboBox<Integer> getComboBox() {
+        return comboBox;
+    }
+
+    @Override
+    public void itemStateChanged(ItemEvent event) {
+        if (event.getStateChange() == ItemEvent.SELECTED) {
+            Object item = event.getItem();
+            PersonLeftPanel personLeftPanel = MainWindowsView.getInstance().getCurrentPersonView().getPersonPanel().getLeftPanel();
+            personLeftPanel.drawWeight((int) item);
+        }
+    }
 }