From d418dae1d4529879f8d604d062df75008bb3e585 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 17 Jan 2019 11:43:00 +0100 Subject: [PATCH] Only draw eyes on selection and the full closest person on validation. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/EyeView.java | 1 + src/PersonLeftPanel.java | 8 +++++++- src/PersonRightPanel.java | 10 ++++++---- src/PersonView.java | 1 + 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/EyeView.java b/src/EyeView.java index bc1b89b..48ad0b5 100644 --- a/src/EyeView.java +++ b/src/EyeView.java @@ -48,6 +48,7 @@ public class EyeView extends JPanel implements ListSelectionListener { public void valueChanged(ListSelectionEvent listSelectionEvent) { Eye currentEye = new Eye((String) getColorsList().getSelectedValue()); PersonLeftPanel personLeftPanel = MainWindowsView.getInstance().getCurrentPersonView().getPersonPanel().getLeftPanel(); + personLeftPanel.drawEyes(currentEye.getColor()); } private static class EyeCellRenderer extends DefaultListCellRenderer { diff --git a/src/PersonLeftPanel.java b/src/PersonLeftPanel.java index a7022fb..e5892a6 100644 --- a/src/PersonLeftPanel.java +++ b/src/PersonLeftPanel.java @@ -22,10 +22,16 @@ public class PersonLeftPanel extends JPanel { 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); } + + public void drawEyes(Color color) { + Graphics g = this.getGraphics(); + g.setColor(color); + g.fillOval(50, 50, 6, 3); + g.fillOval(62, 50, 6, 3); + } } diff --git a/src/PersonRightPanel.java b/src/PersonRightPanel.java index 28099b2..0cf7343 100644 --- a/src/PersonRightPanel.java +++ b/src/PersonRightPanel.java @@ -31,15 +31,17 @@ public class PersonRightPanel extends JPanel { return personImage; } - public void paintComponent(Graphics g) { - super.paintComponent(g); + public void drawPerson(Person personObj) { + Graphics g = this.getGraphics(); // Draw - g.setColor(Color.black); - g.drawString(getContentText(), 5, 35); + g.drawString(getContentText(), 12, 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); + g.setColor(personObj.getEye().getColor()); + g.fillOval(50, 50, 6, 3); + g.fillOval(62, 50, 6, 3); } } diff --git a/src/PersonView.java b/src/PersonView.java index b583cd5..1998cec 100644 --- a/src/PersonView.java +++ b/src/PersonView.java @@ -183,6 +183,7 @@ public class PersonView extends JComponent implements ActionListener { //Utils.displayArrayList(personArrayList); Person closestPerson = personArrayList.get(personArrayList.indexOf(this.getPersonObj()) + 1); personPanel.setRightContentText(closestPerson.getFirstname().getFirstname() + " at distance " + closestPerson.getDistanceFromReference()); + personPanel.getRightPanel().drawPerson(closestPerson); } } } -- 2.34.1