-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataPanel.java
238 lines (219 loc) · 9.32 KB
/
DataPanel.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import java.awt.*;
import java.util.LinkedList;
import java.util.Observable;
import java.util.Observer;
import javax.swing.table.DefaultTableModel;
import org.jfree.chart.ui.Drawable;
import javax.swing.*;
/**
* DataPanel.java
*
* @author martin ituarte hernandez, Justin Rittmeyer, Ben Bousquet, Andrew Kuhl
* and Vikram Dattatri
* @since 12-1-20
* @version 17.2 build version 2
*/
public class DataPanel extends JPanel implements Observer {
// private instance variables
private Drawable d;
private JTable jt;
public DataPanel() {
// create a new jtable
jt = new JTable();
}
public void update(Observable o, Object arg) {
Repository repo = ((Repository) o);
// check if roster was loaded
if (repo.isRosterLoaded() == false) {
return;
}
// check if roster was changed
if (repo.isRosterChanged() == true) {
// reset frame
this.removeAll();
this.revalidate();
this.repaint();
// reset jtable
jt = new JTable();
// get tables model
DefaultTableModel model = (DefaultTableModel) jt.getModel();
// add columns and set their widths
String column[] = {"ID ", "First Name ", "Last Name ", "Program ", "Academic Level ", "Asurite "};
model.setColumnIdentifiers(column);
jt.getColumnModel().getColumn(0).setPreferredWidth(80);
jt.getColumnModel().getColumn(1).setPreferredWidth(40);
jt.getColumnModel().getColumn(2).setPreferredWidth(55);
jt.getColumnModel().getColumn(3).setPreferredWidth(100);
jt.getColumnModel().getColumn(4).setPreferredWidth(110);
jt.getColumnModel().getColumn(5).setPreferredWidth(65);
jt.setBounds(100, 100, 900, 900);
jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
// create scroll pane
JScrollPane scrollPane = new JScrollPane(jt);
// Force the scrollbars to always be displayed
scrollPane.setHorizontalScrollBarPolicy(
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
// make pane and table visible
this.add(scrollPane);
this.setVisible(true);
// get repo
LinkedList<Student> roster = repo.getRoster();
// add headers to table
String data[] = new String[6];
String idLabel = "ID";
String firstName = "First Name";
String lastName = "Last Name";
String level = "Level";
String program = "Program";
String asuRite = "AsuRite";
data[0] = idLabel;
data[1] = firstName;
data[2] = lastName;
data[3] = level;
data[4] = program;
data[5] = asuRite;
// add to table
model.addRow(data);
// loop through roster
for (int i = 0; i < roster.size(); i++) {
// add roster data for row
data = new String[6];
Student current = roster.get(i);
int id = current.getID();
firstName = current.getFirstName();
lastName = current.getLastName();
level = current.getLevel();
program = current.getProgram();
asuRite = current.getAsuRite();
data[0] = Integer.toString(id);
data[1] = firstName;
data[2] = lastName;
data[3] = level;
data[4] = program;
data[5] = asuRite;
// insert into table
model.addRow(data);
}
// add data to table
jt.setModel(model);
// update table
model.fireTableDataChanged();
} else {
// reset panel
this.removeAll();
this.revalidate();
this.repaint();
// reset table
jt = new JTable();
// get table model
DefaultTableModel model = (DefaultTableModel) jt.getModel();
// get dates
LinkedList<Date> dates = repo.getDates();
// add headers
String column[] = new String[6 + dates.size()];
column[0] = "ID";
column[1] = "First Name";
column[2] = "Last Name";
column[3] = "Program";
column[4] = "Academic Level";
column[5] = "Asurite";
// add dates to header
for (int i = 0; i < dates.size(); i++) {
String month = dates.get(i).getMonth();
String day = dates.get(i).getDay();
column[i + 6] = month + " " + day;
}
// set widths for columns
model.setColumnIdentifiers(column);
jt.getColumnModel().getColumn(0).setPreferredWidth(80);
jt.getColumnModel().getColumn(1).setPreferredWidth(40);
jt.getColumnModel().getColumn(2).setPreferredWidth(55);
jt.getColumnModel().getColumn(3).setPreferredWidth(100);
jt.getColumnModel().getColumn(4).setPreferredWidth(110);
jt.getColumnModel().getColumn(5).setPreferredWidth(65);
for (int i = 0; i < dates.size(); i++) {
jt.getColumnModel().getColumn(i).setPreferredWidth(100);
}
jt.setBounds(100, 100, 1500, 1500);
jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
JScrollPane scrollPane = new JScrollPane(jt);
// Force the scrollbars to always be displayed
scrollPane.setHorizontalScrollBarPolicy(
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
// make table visible
this.add(scrollPane);
this.setVisible(true);
// get roster from repo
LinkedList<Student> roster = repo.getRoster();
// add headers to table
String data[] = new String[6 + dates.size()];
String idLabel = "ID";
String firstName = "First Name";
String lastName = "Last Name";
String level = "Level";
String program = "Program";
String asuRite = "AsuRite";
data[0] = idLabel;
data[1] = firstName;
data[2] = lastName;
data[3] = level;
data[4] = program;
data[5] = asuRite;
// add dates to header
for (int i = 0; i < dates.size(); i++) {
String month = dates.get(i).getMonth();
String day = dates.get(i).getDay();
data[i + 6] = month + " " + day;
}
// add header to table
model.addRow(data);
// add roster to table
for (int i = 0; i < roster.size(); i++) {
// add roster data to table
data = new String[6 + dates.size()];
Student current = roster.get(i);
int id = current.getID();
firstName = current.getFirstName();
lastName = current.getLastName();
level = current.getLevel();
program = current.getProgram();
asuRite = current.getAsuRite();
data[0] = Integer.toString(id);
data[1] = firstName;
data[2] = lastName;
data[3] = level;
data[4] = program;
data[5] = asuRite;
// add attendance data to table
for (int j = 0; j < dates.size(); j++) {
// loop through the attendance and try to find when the asurite and month and day match up
LinkedList<Attendance> attendanceList = repo.getAttendance();
String time = " ";
// check if there are any attendance objects that have asurite, month and day that match
for (int k = 0; k < attendanceList.size(); k++) {
Date currentDate = dates.get(j);
String month = currentDate.getMonth();
String day = currentDate.getDay();
Attendance currentAttendance = attendanceList.get(k);
// if so then set the time
if (currentAttendance.getAsurite().equals(asuRite) && currentAttendance.getMonth().equals(month) && currentAttendance.getDay().equals(day)) {
time = Integer.toString(currentAttendance.getTime());
}
}
// set in table
data[j + 6] = time;
}
// add to table
model.addRow(data);
}
// add data to table
jt.setModel(model);
// update table
model.fireTableDataChanged();
}
}
}