View Javadoc

1   /*
2    * Created on 24-Apr-2005
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     public MacroNutrientSummaryPanel() {      
16        setLayout(new BorderLayout());
17        setBorder(BorderFactory.createEmptyBorder(4,4,4,4));
18        add(getNutrientTablePane(), BorderLayout.CENTER);
19     }
20   
21     protected List getNutrientList() {
22        return NutrientInfo.getMacroNutrients();
23     }
24    
25     private double getAmount(List servings, NutrientInfo ni) {
26        double total = 0;
27        for (Iterator iter = servings.iterator(); iter.hasNext();) {
28           Serving serving = (Serving) iter.next();
29           double weight = serving.getGrams()/100.0;
30           total += weight * serving.getFood().getNutrientAmount(ni);
31       }
32       return total;
33     }
34  
35     private NutrientTable getNutrientTable() {
36        if (nutrientTable == null) {
37           nutrientTable = new NutrientTable(NutrientInfo.getMacroNutrients());
38        } 
39        return nutrientTable;
40     }
41     
42  }