|  1 | 
        | 
         | 
    
    
      |  2 | 
        | 
         | 
    
    
      |  3 | 
        | 
         | 
    
    
      |  4 | 
        | 
       package ca.spaz.cron.summary;  | 
    
    
      |  5 | 
        | 
         | 
    
    
      |  6 | 
        | 
       import java.awt.*;  | 
    
    
      |  7 | 
        | 
       import java.util.*;  | 
    
    
      |  8 | 
        | 
       import java.util.List;  | 
    
    
      |  9 | 
        | 
         | 
    
    
      |  10 | 
        | 
       import javax.swing.*;  | 
    
    
      |  11 | 
        | 
         | 
    
    
      |  12 | 
        | 
       import ca.spaz.cron.database.*;  | 
    
    
      |  13 | 
        | 
         | 
    
    
      |  14 | 
        | 
       public class MacroNutrientSummaryPanel extends AbstractNutrientSummaryPanel { | 
    
    
      |  15 | 
       0 | 
          public MacroNutrientSummaryPanel() {       | 
    
    
      |  16 | 
       0 | 
             setLayout(new BorderLayout());  | 
    
    
      |  17 | 
       0 | 
             setBorder(BorderFactory.createEmptyBorder(4,4,4,4));  | 
    
    
      |  18 | 
       0 | 
             add(getNutrientTablePane(), BorderLayout.CENTER);  | 
    
    
      |  19 | 
       0 | 
          }  | 
    
    
      |  20 | 
        | 
          | 
    
    
      |  21 | 
        | 
          protected List getNutrientList() { | 
    
    
      |  22 | 
       0 | 
             return NutrientInfo.getMacroNutrients();  | 
    
    
      |  23 | 
        | 
          }  | 
    
    
      |  24 | 
        | 
           | 
    
    
      |  25 | 
        | 
          private double getAmount(List servings, NutrientInfo ni) { | 
    
    
      |  26 | 
       0 | 
             double total = 0;  | 
    
    
      |  27 | 
       0 | 
             for (Iterator iter = servings.iterator(); iter.hasNext();) { | 
    
    
      |  28 | 
       0 | 
                Serving serving = (Serving) iter.next();  | 
    
    
      |  29 | 
       0 | 
                double weight = serving.getGrams()/100.0;  | 
    
    
      |  30 | 
       0 | 
                total += weight * serving.getFood().getNutrientAmount(ni);  | 
    
    
      |  31 | 
       0 | 
            }  | 
    
    
      |  32 | 
       0 | 
            return total;  | 
    
    
      |  33 | 
        | 
          }  | 
    
    
      |  34 | 
        | 
         | 
    
    
      |  35 | 
        | 
          private NutrientTable getNutrientTable() { | 
    
    
      |  36 | 
       0 | 
             if (nutrientTable == null) { | 
    
    
      |  37 | 
       0 | 
                nutrientTable = new NutrientTable(NutrientInfo.getMacroNutrients());  | 
    
    
      |  38 | 
        | 
             }   | 
    
    
      |  39 | 
       0 | 
             return nutrientTable;  | 
    
    
      |  40 | 
        | 
          }  | 
    
    
      |  41 | 
        | 
            | 
    
    
      |  42 | 
        | 
       }  |