X-Git-Url: https://git.piment-noir.org/?p=Persons_Comparator.git;a=blobdiff_plain;f=src%2FPersonView.java;h=8cee3e23e100c5ed70d01dd669f78c294693b0da;hp=a98c1e7d89796ce7d1078d0b1c202252b261a104;hb=5687dc10a68b52d28b63151d8c16a45775ef2e77;hpb=9b3bfcdd95253a04ed12a676ee29a9d777c1e496 diff --git a/src/PersonView.java b/src/PersonView.java index a98c1e7..8cee3e2 100644 --- a/src/PersonView.java +++ b/src/PersonView.java @@ -8,6 +8,7 @@ public class PersonView extends JPanel implements ActionListener { private int width = 400; private int height = 600; private Person personObj; + private ArrayList 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 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 getPersonArrayList() { + return personArrayList; + } + + public void setPersonArrayList(ArrayList 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 personArrayList = this.getPersonObj().getPersonArrayList(); - personArrayList.add(this.getPersonObj()); - this.getPersonObj().displayArrayList(personArrayList); + ArrayList 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); } } }