Datasets:

ArXiv:
License:
File size: 2,756 Bytes
c574d3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package view;

import controller.DietController;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class UserPanel extends JPanel {

    private DietController dietController;
    private ViewMediator viewMediator;

    public UserPanel(DietController dietController, ViewMediator viewMediator) {

        this.dietController = dietController;
        this.viewMediator = viewMediator;

        setLayout(new GridLayout(4,1));

        JPanel nameEntryPanel = createNameEntryPanel();
        add(nameEntryPanel);

        JPanel weightEntryPanel = createWeightEntryPanel();
        add(weightEntryPanel);

        JPanel dailyGoals = createDailyGoalsPanel();
        add(dailyGoals);

        JButton saveButton = new JButton("Save");
        saveButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dietController.writeCSV();
            }
        });


        add(saveButton);

    }

    public JPanel createNameEntryPanel() {
        JPanel namePanel = new JPanel();
        namePanel.setLayout(new FlowLayout());
        JTextField nameField = new JTextField();
        nameField.setText("Enter Your Name");
        nameField.setPreferredSize(new Dimension(150,20));

        JButton nameButton = new JButton("Submit");
        nameButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dietController.setUserName(nameField.getText());
                viewMediator.updateDailyValues();
            }
        });

        namePanel.add(nameField);
        namePanel.add(nameButton);


        return namePanel;
    }

    public JPanel createWeightEntryPanel() {
        JPanel weightPanel = new JPanel();

        JTextField weightField = new JTextField();
        weightField.setText("Enter Your Weight");
        weightField.setPreferredSize(new Dimension(150,20));

        JButton weightButton = new JButton("Submit");
        weightButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dietController.setPersonalInfo(Double.parseDouble(weightField.getText()), dietController.getCurrentDate());
                viewMediator.updateDailyValues();
            }
        });

        weightPanel.add(weightField);
        weightPanel.add(weightButton);
        return weightPanel;
    }

    public JPanel createDailyGoalsPanel() {
        JPanel goalsPanel = new JPanel();

        JButton goalsButton = new JButton("Set Daily Goals");

        goalsPanel.add(goalsButton);
        return goalsPanel;
    }
}