-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHistoryTab.java
216 lines (179 loc) · 7.54 KB
/
HistoryTab.java
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
package gritnessApp;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableCellRenderer;
//Jason
public class HistoryTab extends JPanel implements ActionListener{
JLabel age;
JFrame window;
JButton profile, workout, food, social, history;
JLabel dateLabel, workoutLabel, caloriesLabel;
JComboBox<String> dateComboBox;
JTable workoutTable, nutritionTable;
JScrollPane workoutScrollPane, nutritionScrollPane;
SimpleDateFormat dateFormat = new SimpleDateFormat("EE MMMM dd yyyy");
String selectedDate;
String[] workoutColumn, nutritionColumn;
Object[][] workoutData, nutritionData;
DemoMouseListener mouseListener;
final int NUMBER_ROWS_DISPLAYED = 5;
final int ROW_HEIGHT = 66;
final int TABLE_WIDTH = Const.MAIN_LENGTH / 2 - 40;
final int TABLE_HEIGHT = NUMBER_ROWS_DISPLAYED * ROW_HEIGHT;
HistoryTab(){
mouseListener = new DemoMouseListener();
dateComboBox = new JComboBox<>();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, 1);
for (int i = 0; i < 59; i++) {
Date date = calendar.getTime();
String dateString = dateFormat.format(date);
dateComboBox.addItem(dateString);
dateComboBox.setFont(new Font("Calibri", Font.PLAIN, 25));
calendar.add(Calendar.DATE, 1);
if(i == 0) {
selectedDate = dateString;
}
}
dateComboBox.addActionListener(this);
int x = (int)((Const.MAIN_LENGTH - 300)/2);
dateComboBox.setBounds(x,0,300,35);
dateComboBox.setSize(dateComboBox.getPreferredSize());
profile = newNavBarButton ("Profile", 0, Const.PROFILE_ICON);
history = newNavBarButton ("History", 256, Const.HISTORY_ICON);
workout = newNavBarButton ("Workout", 512, Const.WORKOUT_ICON);
food = newNavBarButton ("Food", 768, Const.FOOD_ICON);
social = newNavBarButton ("Social", 1024, Const.SOCIAL_ICON);
history.setBackground(Const.BUTTON_COLOUR2.brighter());
workoutColumn = new String[]{""};
workoutData = new Object[][]{
{"Lat Pulldown"},
{"1. 135 x 10lbs"},
{"Text 10"},
{"Text 10"},
{"Text 10"},
{"Text 10"},
{"Text 10"},
{"Text 10"},
{"Text 10"},
{"Text 10"},
{"Text 12"}
};
nutritionColumn = new String[] {"", "Total","Goal"};
nutritionData = new Object[][] {
{"","Total","Goal"},
{"Protein","",""},
{"Carbs","",""},
{"Fats","",""},
{"Sodium","",""}
};
nutritionTable = new JTable(nutritionData, nutritionColumn);
nutritionTable.setBorder(new LineBorder(Color.GRAY, 1));
workoutTable = newTable(workoutColumn, workoutData,30);
JScrollPane scrollPane = new JScrollPane(workoutTable);
scrollPane.setBounds(30,225,TABLE_WIDTH,TABLE_HEIGHT);
workoutTable.addMouseListener(mouseListener);
this.add(scrollPane, BorderLayout.CENTER);
nutritionTable = newTable(nutritionColumn, nutritionData,TABLE_WIDTH + 40);
dateLabel = newDisplayLabel(selectedDate, Const.HISTORY_LABEL_FONT,(Const.MAIN_LENGTH - 500)/ 2, 55,500, 65);
workoutLabel= newDisplayLabel("Workout", Const.HISTORY_LABEL_FONT, workoutTable.getX() + 75, 130, TABLE_WIDTH - 150, 90);
caloriesLabel = newDisplayLabel("Nutrition", Const.HISTORY_LABEL_FONT, nutritionTable.getX() + 75, 130, TABLE_WIDTH - 150, 90 );
this.addMouseListener(mouseListener);
this.add(dateComboBox);
this.setVisible(true);
this.setLayout(null);
}
public JTable newTable(String[] columns, Object[][] data, int x) {
JTable table = new JTable(data, columns);
table.setRowHeight(ROW_HEIGHT);
table.setFont(new Font("Calibri", Font.PLAIN, 30));
table.setShowHorizontalLines(false);
table.setShowVerticalLines(false);
table.setBounds(x,225,TABLE_WIDTH,330);
table.setBorder((new LineBorder(Color.GRAY, 1)));
table.setBackground(Const.BACKGROUND_COLOUR);
DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
centerRenderer.setHorizontalAlignment(JLabel.CENTER);
for(int i = 0; i < columns.length; i++) {
table.getColumnModel().getColumn(i).setCellRenderer(centerRenderer);
}
this.add(table);
return table;
}
public void mouseClicked(MouseEvent e) {
if(e.getButton() == MouseEvent.BUTTON1) {
System.out.println("a");
}
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == profile) {
Window.layout.show(Window.container, "profile");
}
else if(e.getSource() == history) {
Window.layout.show(Window.container, "history");
}
else if (e.getSource() == workout) {
Window.layout.show(Window.container, "workout");
}
else if (e.getSource() == food) {
Window.layout.show(Window.container, "nutrition");
}
else if (e.getSource() == social) {
Window.layout.show(Window.container, "social");
}
else if(e.getSource() == dateComboBox) {
selectedDate = (String)(dateComboBox.getSelectedItem());
dateLabel.setText(selectedDate.replace('-', ' '));
dateLabel.setSize(dateLabel.getPreferredSize());
}
}
public class DemoMouseListener implements MouseListener{
public void mouseClicked(MouseEvent e){
int row = workoutTable.rowAtPoint(e.getPoint());
int col = workoutTable.columnAtPoint(e.getPoint());
if (row >= 0 && col >= 0) {
JPopupMenu popup = new JPopupMenu();
workoutTable.setComponentPopupMenu(popup);
// JOptionPane.showMessageDialog(workoutTable, "Cell contents: " + workoutTable.getValueAt(row, col));
popup.show(workoutTable, e.getX(), e.getY());
}
}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
}
public JLabel newDisplayLabel(String text, Font font, int x, int y, int width, int height) {
JLabel label = new JLabel(text);
label.setFont(font);
label.setFocusable(true);
label.setBounds(x,y,width,height);
label.setOpaque(true);
label.setBackground(Const.BUTTON_COLOUR);
label.setForeground(Color.white);
label.setHorizontalAlignment(JLabel.CENTER);
label.setVerticalAlignment(JLabel.BOTTOM);
this.add(label);
return label;
}
public JButton newNavBarButton(String name, int x, ImageIcon icon) {
JButton button = new JButton(name);
button.setBackground(Const.NAV_BAR_COLOUR);
button.setForeground(Color.white);
button.setFocusable(false);
button.setBorderPainted(false);
button.addActionListener(this);
button.setIcon(icon);
button.setFont(Const.BUTTON_FONT);
button.setBounds(x, 570, 256, 125);
button.setHorizontalTextPosition(JButton.CENTER);
button.setVerticalTextPosition(JButton.BOTTOM);
this.add(button);
return button;
}
}