-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomePanel.java
More file actions
290 lines (167 loc) · 8.38 KB
/
Copy pathHomePanel.java
File metadata and controls
290 lines (167 loc) · 8.38 KB
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
//Dylan Barrett
//Description
//11/17/24
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
public class HomePanel extends CustomPanel {
private BigDuty bigDuty;
private final Border border;
private String[] headings = {"TEACHER", "CREDIT", "COURSES", "MAX DUTIES", "TOTAL", "PASCACKS", "HALLS", "COVERAGES", "FROSH PASCACKS"}; //tables
private String[][] data;
public HomePanel(String panelName, Dimension d, BigDuty bigDuty) {
super(panelName, d);
this.bigDuty = bigDuty;
this.data = new String[bigDuty.getTeachers().size()][headings.length];
BorderLayout layout = new BorderLayout(1, 1);
this.setLayout(layout);
this.border = BorderFactory.createLineBorder(Color.BLACK);
makePanel();
}
public void makePanel() {
GridLayout layout = new GridLayout(20, 0);
layout.setVgap(2);
// make the sidebar
JPanel sidebar = new JPanel(layout);
JButton saveButton = new JButton("Save Data");
saveButton.addActionListener(e -> {
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
// chooser.showSaveDialog(this);
System.out.println(bigDuty.dutySlotsToSaveString());
if(chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
System.out.println(chooser.getSelectedFile().getAbsolutePath());
FileUtility.downloadCurrentSchedule(SemesterTab.gui, chooser.getSelectedFile());
}
// FileUtility.downloadCurrentSchedule(bigDuty.getTeachers());
});
sidebar.add(saveButton);
JButton nextSemsesterButton = new JButton("Next Semester");
nextSemsesterButton.addActionListener(e -> {
int n = JOptionPane.showConfirmDialog(this, "Are you sure you want to start the next semester? This will lock Semester 1 and no more changes will be able to be made.", "Start New Semester?", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if(bigDuty.getSemester().equals("S1") && n == 0) {
ArrayList<Teacher> teachersCopy = new ArrayList<>();
teachersCopy.addAll(bigDuty.getTeachers());
BigDuty bd = new BigDuty(teachersCopy, null, "S2");
SemesterTab semesterTab = GUIMain.makeTeachersTabs(bd);
SemesterTab.gui.getSemesterTabs().add(bd.getSemester(), semesterTab);
SemesterTab.gui.semesters.add(semesterTab);
}
});
if(!bigDuty.getSemester().equals("S2")) {
sidebar.add(nextSemsesterButton);
}
JButton reassignDutiesButton = new JButton("Reassign Duties");
reassignDutiesButton.addActionListener(e -> {
int n = JOptionPane.showConfirmDialog(this, "Are you sure you want to assign duties? This will clear any previously assigned duties. Make sure you have configured everything!", "Assign Duties?", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if(n == 0) {
if(bigDuty.getNumberOfDutySlots() > bigDuty.getUnlockedTeachers().size()*3) {
n = JOptionPane.showConfirmDialog(this, "You have more duties that need to be filled than there are available teachers! If you continue all teachers WILL have 3 duties but not all available slots will be filled! You can go back and configure the duty slots if this is not OK.", "Assign Duties?", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
}
if(n == 0) {
bigDuty.reassignDuties();
}
}
});
sidebar.add(reassignDutiesButton);
JButton assignDutiesButton = new JButton("Assign Duties");
assignDutiesButton.addActionListener(e -> {
bigDuty.assignDuties();
bigDuty.refreshPanels();
});
sidebar.add(assignDutiesButton);
JButton clearDutiesButton = new JButton("Clear Duties");
clearDutiesButton.addActionListener(e -> {
int n = JOptionPane.showConfirmDialog(this, "Are you SURE you want to clear all duties? This will remove all duties, even ones assigned manually!", "Clear Duties?", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if(n == 0) {
System.out.println("Clearing duties");
bigDuty.clearDuties();
System.out.println("Done Clearing duties");
bigDuty.refreshPanels();
}
});
sidebar.add(clearDutiesButton);
// make the center area
JPanel center = new JPanel();
populateData();
DefaultTableModel model = new DefaultTableModel(data, headings) {
private static final long serialVersionUID = 1L;
@Override
public Class<?> getColumnClass(int column){
if(column > 0 || column < 9)
return Integer.class;
return super.getColumnClass(column);
}
public boolean isCellEditable(int row, int column) {
if(column == 3 || column == 1) return true;
return false;
}
};
model.addTableModelListener(e -> {
int val = (int) model.getValueAt(e.getFirstRow(), e.getColumn());
Teacher t = bigDuty.getTeachers().get(e.getFirstRow());
if(e.getFirstRow() == 1) { // changing the teachers social credit
t.setSocialCredit(val);
} else if(e.getFirstRow() == 3) { // changing the teachers max duties
if(t.getDuties().size() > val) {
int n = JOptionPane.showConfirmDialog(this, "<html>Your about to change this teachers max duties but the teacher already has <b>" + t.getDuties().size() + "</b> duties assigned! </html>", "Duties already assigned!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if(n == 0) {
t.setMaxDuties(val);
} else {
model.setValueAt(t.getMaxDuties(), e.getFirstRow(), e.getColumn());
}
} else {
t.setMaxDuties(val);
}
}
});
JTable table = new JTable(model);
table.setVisible(true);
table.setAutoCreateRowSorter(true);
table.setFont(new Font("Tratatello", Font.PLAIN, 14));
JTableHeader header = table.getTableHeader();
header.setBackground(Color.yellow);
JScrollPane pane = new JScrollPane(table);
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
table.setGridColor(Color.LIGHT_GRAY);
table.setComponentPopupMenu(new HomePopUp(bigDuty, table, this));
table.addMouseListener(new MouseAdapter() {
public void MousePressed(MouseEvent e) {
int r = table.rowAtPoint(e.getPoint());
int c = table.columnAtPoint(e.getPoint());
System.out.println(r + ", " + c);
}
});
this.removeAll();
this.add(sidebar, BorderLayout.WEST);
this.add(pane, BorderLayout.CENTER);
}
public void populateData() {
for(int r = 0; r < data.length; r++) {
Teacher t = bigDuty.getTeacher(r);
data[r][0] = t.getLastName();
data[r][1] = String.valueOf(t.getSocialCredit());
data[r][2] = String.valueOf(t.totalCourses());
data[r][3] = String.valueOf(t.getMaxDuties());
data[r][4] = String.valueOf(t.totalDuties());
data[r][5] = String.valueOf(t.getPascacks().size());
data[r][6] = String.valueOf(t.getHalls().size());
data[r][7] = String.valueOf(t.getCoverages().size());
data[r][8] = String.valueOf(t.getFroshPascacks().size());
}
}
@Override
public void refreshPanel() {
makePanel();
System.out.println("updateing home panel");
super.refreshPanel();
}
}