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