1
2
3
4 package ca.spaz.cron.ui;
5
6 import java.awt.*;
7 import java.util.*;
8 import java.util.List;
9
10 import javax.swing.*;
11 import javax.swing.event.*;
12
13 import ca.spaz.cron.user.*;
14 import ca.spaz.cron.user.impl.*;
15
16 public class BiomarkerPanel extends JPanel {
17 private Date curDate = new Date();
18 private JSpinner weightSpinner;
19
20
21 public BiomarkerPanel() {
22
23 JPanel lp = new JPanel(new GridLayout(5,1,8,8));
24 lp.add(new JCheckBox("Weight:"));
25 lp.add(new JCheckBox("Systolic:"));
26 lp.add(new JCheckBox("Diastolic:"));
27 lp.add(new JCheckBox("Resting Heart Rate:"));
28 lp.add(new JCheckBox("Body Temperature:"));
29
30 JPanel rp = new JPanel(new GridLayout(5,1,8,8));
31 rp.add(getWeightSpinner());
32 rp.add(new JSpinner());
33 rp.add(new JSpinner());
34 rp.add(new JSpinner());
35 rp.add(new JSpinner());
36
37 JPanel fp = new JPanel(new BorderLayout(4, 4));
38 fp.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
39 fp.add(lp, BorderLayout.WEST);
40 fp.add(rp, BorderLayout.CENTER);
41
42 setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
43 setLayout(new BorderLayout(4, 4));
44 add(fp, BorderLayout.NORTH);
45 }
46
47 private JSpinner getWeightSpinner() {
48 if (weightSpinner == null) {
49 weightSpinner = new JSpinner(new SpinnerNumberModel(150,0,1000,1));
50 weightSpinner.addChangeListener(new ChangeListener() {
51 public void stateChanged(ChangeEvent e) {
52 WeightMetric wm = new WeightMetric();
53 wm.setValue((Number)weightSpinner.getValue());
54 getUserMetrics().addMetric(wm);
55 }
56 });
57 List l = getUserMetrics().getMetrics();
58 Iterator iter = l.iterator();
59 while (iter.hasNext()) {
60 Metric m = (Metric)iter.next();
61 if (m instanceof WeightMetric) {
62 weightSpinner.setValue(m.getValue());
63 }
64 }
65 }
66 return weightSpinner;
67 }
68
69 public void setDate(Date d) {
70 this.curDate = d;
71 }
72
73 private UserMetrics getUserMetrics() {
74 List metrics = CRONUser.getUser().getUserMetrics(curDate);
75 if (metrics == null) {
76 UserMetrics m = new UserMetrics(curDate);
77 CRONUser.getUser().addUserMetrics(curDate, m);
78 return m;
79 }
80 return (UserMetrics)metrics.get(0);
81 }
82 }