Implement the person comparator :
[Persons_Comparator.git] / src / PersonView.java
index a98c1e7d89796ce7d1078d0b1c202252b261a104..8cee3e23e100c5ed70d01dd669f78c294693b0da 100644 (file)
@@ -8,6 +8,7 @@ public class PersonView extends JPanel implements ActionListener {
     private int width = 400;
     private int height = 600;
     private Person personObj;
+    private ArrayList<Person> personArrayList;
     private FirstnameView firstnameView;
     private OriginView originView;
     private SizeView sizeView;
@@ -18,13 +19,14 @@ public class PersonView extends JPanel implements ActionListener {
     /*private ImageIcon originImage;
     private ImageIcon personImage;*/
 
-    PersonView(Person personObj) {
+    PersonView(Person personObj, ArrayList<Person> personArrayList) {
         setPersonObj(personObj);
         setFirstnameView(new FirstnameView(15, this.personObj.getFirstname()));
         setOriginView(new OriginView(this.personObj.getOrigin()));
         setSizeView(new SizeView(this.personObj.getPersonSize()));
         setWeightView(new WeightView(this.personObj.getWeight()));
         setEyeView(new EyeView(this.personObj.getEye()));
+        setPersonArrayList(personArrayList);
 
         this.compareButton.addActionListener(this);
         JLabel personLabel = new JLabel("Closest person found");
@@ -104,6 +106,13 @@ public class PersonView extends JPanel implements ActionListener {
         this.weightView = weightView;
     }
 
+    /**
+     * @return
+     */
+    public EyeView getEyeView() {
+        return eyeView;
+    }
+
     /**
      * @param eyeView
      */
@@ -111,11 +120,12 @@ public class PersonView extends JPanel implements ActionListener {
         this.eyeView = eyeView;
     }
 
-    /**
-     * @return
-     */
-    public EyeView getEyeView() {
-        return eyeView;
+    public ArrayList<Person> getPersonArrayList() {
+        return personArrayList;
+    }
+
+    public void setPersonArrayList(ArrayList<Person> personArrayList) {
+        this.personArrayList = personArrayList;
     }
 
     @Override
@@ -139,18 +149,15 @@ public class PersonView extends JPanel implements ActionListener {
             this.getPersonObj().setPersonSize(new Size(size));
             this.getPersonObj().setWeight(new Weight(weight));
             this.getPersonObj().setEye(new Eye(eye_color));
-            //this.getPersonObj().displayPersonArrayList();
-            ArrayList<Person> personArrayList = this.getPersonObj().getPersonArrayList();
-            personArrayList.add(this.getPersonObj());
-            this.getPersonObj().displayArrayList(personArrayList);
+            ArrayList<Person> personArrayList = this.getPersonArrayList();
+            //Utils.displayArrayList(personArrayList);
+            Utils.computeDistanceFrom(getPersonObj(), personArrayList);
             personArrayList.sort(getPersonObj());
-            this.getPersonObj().displayArrayList(personArrayList);
-            Integer previousPersonIndex = personArrayList.indexOf(this.getPersonObj()) - 1;
-            Integer nextPersonIndex = personArrayList.indexOf(this.getPersonObj()) + 1;
-            //Person previousPerson = personArrayList.get(personArrayList.indexOf(this.getPersonObj()) - 1);
-            //Person nextPerson = personArrayList.get(personArrayList.indexOf(this.getPersonObj()) + 1);
-            System.out.println(previousPersonIndex);
-            System.out.println(nextPersonIndex);
+            //Utils.displayArrayList(personArrayList);
+            Person closestPerson = personArrayList.get(personArrayList.indexOf(this.getPersonObj()) + 1);
+            JLabel closestPersonLabel = new JLabel();
+            closestPersonLabel.setText(closestPerson.toString());
+            this.personPanel.add(closestPersonLabel);
         }
     }
 }