Reorganize the PersonView :
[Persons_Comparator.git] / src / PersonView.java
index 8cee3e23e100c5ed70d01dd669f78c294693b0da..6823579d2bc162a43ea1fc6d1b377a1e43c73fe0 100644 (file)
@@ -4,9 +4,9 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.util.ArrayList;
 
-public class PersonView extends JPanel implements ActionListener {
-    private int width = 400;
-    private int height = 600;
+public class PersonView extends JComponent implements ActionListener {
+    private int width = 800;
+    private int height = 500;
     private Person personObj;
     private ArrayList<Person> personArrayList;
     private FirstnameView firstnameView;
@@ -14,10 +14,12 @@ public class PersonView extends JPanel implements ActionListener {
     private SizeView sizeView;
     private WeightView weightView;
     private EyeView eyeView;
-    private JPanel personPanel = new JPanel();
+    private JPanel northPanel = new JPanel();
+    private JPanel southPanel = new JPanel();
+    private JPanel eastPanel = new JPanel();
+    private JPanel westPanel = new JPanel();
+    private PersonPanel personPanel = new PersonPanel("Person comparison");
     private JButton compareButton = new JButton("Compare");
-    /*private ImageIcon originImage;
-    private ImageIcon personImage;*/
 
     PersonView(Person personObj, ArrayList<Person> personArrayList) {
         setPersonObj(personObj);
@@ -29,17 +31,18 @@ public class PersonView extends JPanel implements ActionListener {
         setPersonArrayList(personArrayList);
 
         this.compareButton.addActionListener(this);
-        JLabel personLabel = new JLabel("Closest person found");
-        personPanel.add(personLabel);
-        setPreferredSize(new Dimension(this.width, this.height));
-        setLayout(new GridLayout(7, 1, 0, 4));
-        add(firstnameView);
-        add(originView);
-        add(sizeView);
-        add(weightView);
-        add(eyeView);
-        add(compareButton);
-        add(personPanel);
+        northPanel.setBorder(BorderFactory.createRaisedSoftBevelBorder());
+        northPanel.add(firstnameView);
+        southPanel.setBorder(BorderFactory.createRaisedSoftBevelBorder());
+        southPanel.add(compareButton);
+        eastPanel.setLayout(new BoxLayout(this.eastPanel, BoxLayout.Y_AXIS));
+        eastPanel.setBorder(BorderFactory.createRaisedSoftBevelBorder());
+        eastPanel.add(sizeView);
+        eastPanel.add(weightView);
+        eastPanel.add(eyeView);
+        westPanel.setLayout(new BoxLayout(this.westPanel, BoxLayout.Y_AXIS));
+        westPanel.setBorder(BorderFactory.createRaisedSoftBevelBorder());
+        westPanel.add(originView);
     }
 
     public Person getPersonObj() {
@@ -128,6 +131,30 @@ public class PersonView extends JPanel implements ActionListener {
         this.personArrayList = personArrayList;
     }
 
+    public Dimension getDimension() {
+        return new Dimension(this.width, this.height);
+    }
+
+    public JPanel getNorthPanel() {
+        return northPanel;
+    }
+
+    public JPanel getSouthPanel() {
+        return southPanel;
+    }
+
+    public JPanel getEastPanel() {
+        return eastPanel;
+    }
+
+    public JPanel getWestPanel() {
+        return westPanel;
+    }
+
+    public PersonPanel getPersonPanel() {
+        return personPanel;
+    }
+
     @Override
     public void actionPerformed(ActionEvent actionEvent) {
         //TODO: one can implement a smarter way of getting all inputs values inside the main panel.
@@ -155,9 +182,7 @@ public class PersonView extends JPanel implements ActionListener {
             personArrayList.sort(getPersonObj());
             //Utils.displayArrayList(personArrayList);
             Person closestPerson = personArrayList.get(personArrayList.indexOf(this.getPersonObj()) + 1);
-            JLabel closestPersonLabel = new JLabel();
-            closestPersonLabel.setText(closestPerson.toString());
-            this.personPanel.add(closestPersonLabel);
+            personPanel.setContentText(closestPerson.toString());
         }
     }
 }