Refactor the person drawing code.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 17 Jan 2019 13:01:01 +0000 (14:01 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 17 Jan 2019 13:01:01 +0000 (14:01 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/PersonLeftPanel.java
src/PersonRightPanel.java

index e5892a63a32642e94dcf01cd5e3b6b121c22dcae..d01abd000b1ef5ee56f946d2d034e2f9cc6f53dd 100644 (file)
@@ -18,9 +18,7 @@ public class PersonLeftPanel extends JPanel {
         }
     }
 
-    public void paintComponent(Graphics g) {
-        super.paintComponent(g);
-
+    private void draw(Graphics g) {
         // Draw
         Graphics2D g2d = (Graphics2D) g;
         int imageWidth = 120;
@@ -28,6 +26,19 @@ public class PersonLeftPanel extends JPanel {
         g2d.drawImage(this.personImage.getScaledInstance(imageWidth / 2, imageHeight / 2, Image.SCALE_SMOOTH), imageWidth / 4, imageHeight / 4, this);
     }
 
+    @Override
+    public void paintComponent(Graphics g) {
+        super.paintComponent(g);
+        draw(g);
+    }
+
+    //FIXME: redraw on resizing
+    /*@Override
+    public void paint(Graphics g) {
+        super.paint(g);
+        draw(g);
+    }*/
+
     public void drawEyes(Color color) {
         Graphics g = this.getGraphics();
         g.setColor(color);
index 0cf73436b5c8090f9ec1d84f1697a703ed6e356b..62067f6689bc2aa4d47e0e0a4c692b34fb9159ac 100644 (file)
@@ -27,12 +27,16 @@ public class PersonRightPanel extends JPanel {
         return contentText;
     }
 
-    public Image getPersonImage() {
-        return personImage;
-    }
+    //FIXME: redraw on resizing
+    /*@Override
+    public void paint(Graphics g) {
+        super.paint(g);
+        drawPerson();
+    }*/
 
     public void drawPerson(Person personObj) {
         Graphics g = this.getGraphics();
+        g.clearRect(0, 25, getWidth(), getHeight());
 
         // Draw
         g.drawString(getContentText(), 12, 35);
@@ -40,8 +44,8 @@ public class PersonRightPanel extends JPanel {
         int imageWidth = 120;
         int imageHeight = 180;
         g2d.drawImage(this.personImage.getScaledInstance(imageWidth / 2, imageHeight / 2, Image.SCALE_SMOOTH), imageWidth / 4, imageHeight / 4, this);
-        g.setColor(personObj.getEye().getColor());
-        g.fillOval(50, 50, 6, 3);
-        g.fillOval(62, 50, 6, 3);
+        g2d.setColor(personObj.getEye().getColor());
+        g2d.fillOval(50, 50, 6, 3);
+        g2d.fillOval(62, 50, 6, 3);
     }
 }