Split the person panel into two sub panels : one for the current person, one for...
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 16 Jan 2019 15:39:05 +0000 (16:39 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 16 Jan 2019 15:39:05 +0000 (16:39 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/LeftPersonPanel.java [new file with mode: 0644]
src/MainWindowsView.java
src/PersonPanel.java
src/PersonView.java
src/RightPersonPanel.java [new file with mode: 0644]

diff --git a/src/LeftPersonPanel.java b/src/LeftPersonPanel.java
new file mode 100644 (file)
index 0000000..95d7d02
--- /dev/null
@@ -0,0 +1,35 @@
+import javax.imageio.ImageIO;
+import javax.swing.*;
+import java.awt.*;
+import java.io.File;
+import java.io.IOException;
+
+public class LeftPersonPanel extends JPanel {
+    private JLabel leftLabel = new JLabel();
+    private Image personImage;
+
+    LeftPersonPanel() {
+        leftLabel.setText("Current person");
+        add(leftLabel);
+        try {
+            this.personImage = ImageIO.read(new File("data/personImage.png"));
+        } catch (IOException e) {
+            System.out.println(e.getStackTrace());
+        }
+    }
+
+    public Image getPersonImage() {
+        return personImage;
+    }
+
+    public void paintComponent(Graphics g) {
+        super.paintComponent(g);
+
+        // Draw
+        g.setColor(Color.black);
+        Graphics2D g2d = (Graphics2D) g;
+        int imageWidth = 120;
+        int imageHeight = 180;
+        g2d.drawImage(this.personImage.getScaledInstance(imageWidth / 2, imageHeight / 2, Image.SCALE_SMOOTH), imageWidth / 4, imageHeight / 4, this);
+    }
+}
index df6839f9813916af37709317683a550835ca2046..0ff9bbbe242bbcaaf3c2027d0204a910f929e94f 100644 (file)
@@ -85,7 +85,7 @@ public class MainWindowsView extends JFrame {
         System.out.println("Created GUI on EDT? " +
                 SwingUtilities.isEventDispatchThread());
         //Display the window.
-        //this.pack();
+        this.pack();
         this.setVisible(true);
     }
 }
\ No newline at end of file
index 7c8e2410c386211e68e3495c8995ead56ae3fc11..5b2e190531d076f7176feb09e213f546bc21b3bf 100644 (file)
@@ -1,59 +1,16 @@
-import javax.imageio.ImageIO;
 import javax.swing.*;
-import java.awt.*;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.Point2D;
-import java.io.File;
-import java.io.IOException;
 
 public class PersonPanel extends JPanel {
-    private boolean debug = true;
-    private String titleText = new String();
-    private JLabel personLabel = new JLabel();
-    private String contentText = new String();
-    private Image personImage;
+    private LeftPersonPanel leftPanel = new LeftPersonPanel();
+    private RightPersonPanel rightPanel = new RightPersonPanel();
 
-    public PersonPanel(String title) {
-        setTitleText(title);
-        personLabel.setText(this.getTitleText());
-        add(personLabel);
-        try {
-            this.personImage = ImageIO.read(new File("data/personImage.png"));
-        } catch (IOException e) {
-            System.out.println(e.getStackTrace());
-        }
+    public PersonPanel() {
+        setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
+        add(leftPanel);
+        add(rightPanel);
     }
 
-    public void setTitleText(String titleText) {
-        this.titleText = titleText;
-    }
-
-    public String getTitleText() {
-        return titleText;
-    }
-
-    public void setContentText(String contentText) {
-        this.contentText = contentText;
-    }
-
-    public String getContentText() {
-        return contentText;
-    }
-
-    public void paintComponent(Graphics g) {
-        super.paintComponent(g);
-
-        // Draw
-        g.setColor(Color.black);
-        if (debug)
-            // Below the JLabel
-            g.drawString(this.getContentText(), 5, 35);
-        Graphics2D g2d = (Graphics2D) g;
-        g2d.drawImage(this.personImage.getScaledInstance(getWidth() / 2, getHeight() / 2, Image.SCALE_SMOOTH), getWidth() / 4, getHeight() / 4, this);
-    }
-
-    private static Ellipse2D getCircleByCenter(Point2D center, double radius) {
-        Ellipse2D.Double myCircle = new Ellipse2D.Double(center.getX() - radius, center.getY() - radius, 2 * radius, 2 * radius);
-        return myCircle;
+    public void setRightContentText(String rightContentText) {
+        this.rightPanel.setContentText(rightContentText);
     }
 }
index 6823579d2bc162a43ea1fc6d1b377a1e43c73fe0..b583cd5a9a499cbfcf1d51c25de9243652dce28d 100644 (file)
@@ -5,8 +5,8 @@ import java.awt.event.ActionListener;
 import java.util.ArrayList;
 
 public class PersonView extends JComponent implements ActionListener {
-    private int width = 800;
-    private int height = 500;
+    private int width = 600;
+    private int height = 600;
     private Person personObj;
     private ArrayList<Person> personArrayList;
     private FirstnameView firstnameView;
@@ -18,12 +18,12 @@ public class PersonView extends JComponent implements ActionListener {
     private JPanel southPanel = new JPanel();
     private JPanel eastPanel = new JPanel();
     private JPanel westPanel = new JPanel();
-    private PersonPanel personPanel = new PersonPanel("Person comparison");
+    private PersonPanel personPanel = new PersonPanel();
     private JButton compareButton = new JButton("Compare");
 
     PersonView(Person personObj, ArrayList<Person> 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()));
@@ -35,12 +35,12 @@ public class PersonView extends JComponent implements ActionListener {
         northPanel.add(firstnameView);
         southPanel.setBorder(BorderFactory.createRaisedSoftBevelBorder());
         southPanel.add(compareButton);
-        eastPanel.setLayout(new BoxLayout(this.eastPanel, BoxLayout.Y_AXIS));
+        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.Y_AXIS));
+        westPanel.setLayout(new BoxLayout(this.westPanel, BoxLayout.PAGE_AXIS));
         westPanel.setBorder(BorderFactory.createRaisedSoftBevelBorder());
         westPanel.add(originView);
     }
@@ -182,7 +182,7 @@ public class PersonView extends JComponent implements ActionListener {
             personArrayList.sort(getPersonObj());
             //Utils.displayArrayList(personArrayList);
             Person closestPerson = personArrayList.get(personArrayList.indexOf(this.getPersonObj()) + 1);
-            personPanel.setContentText(closestPerson.toString());
+            personPanel.setRightContentText(closestPerson.getFirstname().getFirstname() + " at distance " + closestPerson.getDistanceFromReference());
         }
     }
 }
diff --git a/src/RightPersonPanel.java b/src/RightPersonPanel.java
new file mode 100644 (file)
index 0000000..2e3460b
--- /dev/null
@@ -0,0 +1,45 @@
+import javax.imageio.ImageIO;
+import javax.swing.*;
+import java.awt.*;
+import java.io.File;
+import java.io.IOException;
+
+public class RightPersonPanel extends JPanel {
+    private JLabel rightLabel = new JLabel();
+    private String contentText = new String();
+    private Image personImage;
+
+    RightPersonPanel() {
+        rightLabel.setText("Closest person found");
+        add(rightLabel);
+        try {
+            this.personImage = ImageIO.read(new File("data/personImage.png"));
+        } catch (IOException e) {
+            System.out.println(e.getStackTrace());
+        }
+    }
+
+    public void setContentText(String contentText) {
+        this.contentText = contentText;
+    }
+
+    public String getContentText() {
+        return contentText;
+    }
+
+    public Image getPersonImage() {
+        return personImage;
+    }
+
+    public void paintComponent(Graphics g) {
+        super.paintComponent(g);
+
+        // Draw
+        g.setColor(Color.black);
+        g.drawString(getContentText(), 5, 35);
+        Graphics2D g2d = (Graphics2D) g;
+        int imageWidth = 120;
+        int imageHeight = 180;
+        g2d.drawImage(this.personImage.getScaledInstance(imageWidth / 2, imageHeight / 2, Image.SCALE_SMOOTH), imageWidth / 4, imageHeight / 4, this);
+    }
+}