X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FPersonView.java;h=b583cd5a9a499cbfcf1d51c25de9243652dce28d;hb=255d335423820ebc4316dfd8468dcb97bfd17451;hp=8cee3e23e100c5ed70d01dd669f78c294693b0da;hpb=5687dc10a68b52d28b63151d8c16a45775ef2e77;p=Persons_Comparator.git diff --git a/src/PersonView.java b/src/PersonView.java index 8cee3e2..b583cd5 100644 --- a/src/PersonView.java +++ b/src/PersonView.java @@ -4,8 +4,8 @@ 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; +public class PersonView extends JComponent implements ActionListener { + private int width = 600; private int height = 600; private Person personObj; private ArrayList personArrayList; @@ -14,14 +14,16 @@ 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(); private JButton compareButton = new JButton("Compare"); - /*private ImageIcon originImage; - private ImageIcon personImage;*/ PersonView(Person personObj, ArrayList personArrayList) { setPersonObj(personObj); - setFirstnameView(new FirstnameView(15, this.personObj.getFirstname())); + setFirstnameView(new FirstnameView(14, this.personObj.getFirstname())); setOriginView(new OriginView(this.personObj.getOrigin())); setSizeView(new SizeView(this.personObj.getPersonSize())); setWeightView(new WeightView(this.personObj.getWeight())); @@ -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.PAGE_AXIS)); + eastPanel.setBorder(BorderFactory.createRaisedSoftBevelBorder()); + eastPanel.add(sizeView); + eastPanel.add(weightView); + eastPanel.add(eyeView); + westPanel.setLayout(new BoxLayout(this.westPanel, BoxLayout.PAGE_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.setRightContentText(closestPerson.getFirstname().getFirstname() + " at distance " + closestPerson.getDistanceFromReference()); } } }