Reorganize the PersonView :
[Persons_Comparator.git] / src / PersonPanel.java
diff --git a/src/PersonPanel.java b/src/PersonPanel.java
new file mode 100644 (file)
index 0000000..7c8e241
--- /dev/null
@@ -0,0 +1,59 @@
+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;
+
+    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 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;
+    }
+}