Refine the weight max and its drawing.
[Persons_Comparator.git] / src / PersonRightPanel.java
CommitLineData
255d3354
JB
1import javax.imageio.ImageIO;
2import javax.swing.*;
3import java.awt.*;
4import java.io.File;
5import java.io.IOException;
6
7add5cb9 7public class PersonRightPanel extends JPanel {
255d3354
JB
8 private JLabel rightLabel = new JLabel();
9 private String contentText = new String();
10 private Image personImage;
11
7add5cb9 12 PersonRightPanel() {
255d3354
JB
13 rightLabel.setText("Closest person found");
14 add(rightLabel);
15 try {
16 this.personImage = ImageIO.read(new File("data/personImage.png"));
17 } catch (IOException e) {
e16e3b15 18 e.printStackTrace();
255d3354
JB
19 }
20 }
21
22 public void setContentText(String contentText) {
23 this.contentText = contentText;
24 }
25
26 public String getContentText() {
27 return contentText;
28 }
29
fcc86ba9
JB
30 //FIXME: redraw on resizing
31 /*@Override
32 public void paint(Graphics g) {
33 super.paint(g);
34 drawPerson();
35 }*/
255d3354 36
d418dae1
JB
37 public void drawPerson(Person personObj) {
38 Graphics g = this.getGraphics();
fcc86ba9 39 g.clearRect(0, 25, getWidth(), getHeight());
255d3354
JB
40
41 // Draw
d418dae1 42 g.drawString(getContentText(), 12, 35);
255d3354
JB
43 Graphics2D g2d = (Graphics2D) g;
44 int imageWidth = 120;
45 int imageHeight = 180;
46 g2d.drawImage(this.personImage.getScaledInstance(imageWidth / 2, imageHeight / 2, Image.SCALE_SMOOTH), imageWidth / 4, imageHeight / 4, this);
e16e3b15 47 // Eyes
fcc86ba9
JB
48 g2d.setColor(personObj.getEye().getColor());
49 g2d.fillOval(50, 50, 6, 3);
50 g2d.fillOval(62, 50, 6, 3);
e16e3b15
JB
51 // Weigth
52 g2d.setColor(Color.black);
dcde664f 53 g2d.fillOval(44, 80, 30, (personObj.getWeight().getWeight() * 30) / 250);
255d3354
JB
54 }
55}