1
2
3
4 package ca.spaz.cron.summary;
5
6 import java.awt.*;
7
8 import javax.swing.JComponent;
9
10 public class MacroChart extends JComponent {
11
12 private double protein;
13 private double carbs;
14 private double fat;
15
16 public double getCarbs() {
17 return carbs;
18 }
19
20 public void setCarbs(double carbs) {
21 this.carbs = carbs;
22 repaint();
23 }
24
25 public double getFat() {
26 return fat;
27 }
28
29 public void setFat(double fat) {
30 this.fat = fat;
31 repaint();
32 }
33
34 public double getProtein() {
35 return protein;
36 }
37
38 public void setProtein(double protein) {
39 this.protein = protein;
40 repaint();
41 }
42
43
44 public void paint(Graphics g) {
45 Graphics2D g2d = (Graphics2D)g;
46 g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.75f));
47 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
48 double total = protein + carbs + fat;
49 int w = getWidth();
50 int h = getHeight();
51 int min = w<h?w:h;
52 g.setColor(Color.BLACK);
53
54
55 g.setColor(Color.GREEN);
56 int amount = 0;
57 g.fillArc(2,2,min-4,min-4, amount, (int)(360*(protein/total)));
58 amount += (int)(360*(protein/total));
59
60 g.setColor(Color.BLUE);
61 g.fillArc(2,2,min-4,min-4, amount, (int)(360*(carbs/total)));
62 amount += (int)(360*(carbs/total));
63
64 g.setColor(Color.RED);
65 g.fillArc(2,2,min-4,min-4, amount, (int)(360*(fat/total)));
66 }
67
68
69 }