%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
ca.spaz.cron.summary.OldMacroNutrientSummaryPanel$FatProteinCarbChartContent |
|
|
1 | /* |
|
2 | ******************************************************************************* |
|
3 | * Copyright (c) 2005 Chris Rose and AIMedia |
|
4 | * All rights reserved. MacroNutrientSummaryPanel and the accompanying materials |
|
5 | * are made available under the terms of the Common Public License v1.0 |
|
6 | * which accompanies this distribution, and is available at |
|
7 | * http://www.eclipse.org/legal/cpl-v10.html |
|
8 | * |
|
9 | * Contributors: |
|
10 | * Chris Rose |
|
11 | *******************************************************************************/ |
|
12 | package ca.spaz.cron.summary; |
|
13 | ||
14 | import java.awt.Dimension; |
|
15 | import java.text.DecimalFormat; |
|
16 | import java.util.*; |
|
17 | ||
18 | import javax.swing.JPanel; |
|
19 | ||
20 | import org.jfree.chart.*; |
|
21 | import org.jfree.data.DefaultKeyedValues; |
|
22 | import org.jfree.data.general.*; |
|
23 | ||
24 | import ca.spaz.cron.database.NutrientInfo; |
|
25 | ||
26 | import com.aimedia.ui.IValueListUser; |
|
27 | ||
28 | /** |
|
29 | * A summary panel for macronutrients that provides both the standard numeric |
|
30 | * display and other visualizations. |
|
31 | * |
|
32 | * @deprecated No longer needed for UI |
|
33 | * @author Chris Rose |
|
34 | */ |
|
35 | public class OldMacroNutrientSummaryPanel extends SwitchableSummaryPanel { |
|
36 | ||
37 | /** |
|
38 | * A panel for inclusion in the MacroNutrientsSummaryPanel that will |
|
39 | * display a ratio chart of fat/protein/carbs. |
|
40 | * |
|
41 | * @author Chris Rose |
|
42 | */ |
|
43 | public class FatProteinCarbChartContent extends JPanel implements |
|
44 | IValueListUser { |
|
45 | ||
46 | private SummaryPanel dataSource; |
|
47 | private NutrientInfo protein; |
|
48 | private NutrientInfo carb; |
|
49 | private NutrientInfo fat; |
|
50 | ||
51 | /** |
|
52 | * Create a new chart panel in the given summaryPanel |
|
53 | * @param panel the panel that has the values to be charted. |
|
54 | */ |
|
55 | 0 | public FatProteinCarbChartContent(SummaryPanel panel) { |
56 | 0 | super(); |
57 | 0 | this.dataSource = panel; |
58 | 0 | fat = NutrientInfo.getByTableName("lipid"); |
59 | 0 | carb = NutrientInfo.getByTableName("carbs"); |
60 | 0 | protein = NutrientInfo.getByTableName("protein"); |
61 | 0 | } |
62 | ||
63 | /* (non-Javadoc) |
|
64 | * @see com.aimedia.ui.IValueListUser#setValueList(java.util.List) |
|
65 | */ |
|
66 | public void setValueList(List valueNames) { |
|
67 | 0 | DefaultKeyedValues dvals = new DefaultKeyedValues(); |
68 | 0 | dvals.setValue(fat.getName(), dataSource.getDoubleValue(fat.getTag())); |
69 | 0 | dvals.setValue(carb.getName(), dataSource.getDoubleValue(carb.getTag())); |
70 | 0 | dvals.setValue(protein.getName(), dataSource.getDoubleValue(protein.getTag())); |
71 | 0 | PieDataset data = new DefaultPieDataset(dvals); |
72 | 0 | JFreeChart chart = ChartFactory.createPieChart("Fat/Protein/Carbs", data, true, class="keyword">true, false); |
73 | 0 | removeAll(); |
74 | 0 | ChartPanel pan = new ChartPanel(chart); |
75 | 0 | pan.setPreferredSize(new Dimension(500, 140)); |
76 | 0 | add(pan); |
77 | 0 | } |
78 | ||
79 | } |
|
80 | /** |
|
81 | * Construct a new <code>MacroNutrientSummaryPanel</code> |
|
82 | */ |
|
83 | public OldMacroNutrientSummaryPanel() { |
|
84 | super(); |
|
85 | List macros = NutrientInfo.getMacroNutrients(); |
|
86 | for (Iterator iter = macros.iterator(); iter.hasNext();) { |
|
87 | NutrientInfo inf = (NutrientInfo) iter.next(); |
|
88 | addValueField(inf.getTag(), inf.getName(), inf.getUnits()); |
|
89 | } |
|
90 | df = new DecimalFormat("######0.0"); |
|
91 | // addContentPane("P:F:C", new FatProteinCarbChartContent(this)); |
|
92 | addContentPane("All", new SimpleSummaryContent(this)); |
|
93 | generateContentPane(); |
|
94 | } |
|
95 | ||
96 | /* (non-Javadoc) |
|
97 | * @see ca.spaz.cron.SummaryPanel#doDoubleString(java.lang.String, java.lang.Double) |
|
98 | */ |
|
99 | protected String doDoubleString(String valueName, Double value) { |
|
100 | return df.format(value) + " " + getUnit(valueName); |
|
101 | } |
|
102 | ||
103 | private DecimalFormat df; |
|
104 | ||
105 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |