From: Jérôme Benoit Date: Thu, 17 Jan 2019 13:01:01 +0000 (+0100) Subject: Refactor the person drawing code. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=fcc86ba9387c6fd9c90ee69cfa92ec53cc64a827;p=Persons_Comparator.git Refactor the person drawing code. Signed-off-by: Jérôme Benoit --- diff --git a/src/PersonLeftPanel.java b/src/PersonLeftPanel.java index e5892a6..d01abd0 100644 --- a/src/PersonLeftPanel.java +++ b/src/PersonLeftPanel.java @@ -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); diff --git a/src/PersonRightPanel.java b/src/PersonRightPanel.java index 0cf7343..62067f6 100644 --- a/src/PersonRightPanel.java +++ b/src/PersonRightPanel.java @@ -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); } }