-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeachersPanel.java
More file actions
208 lines (126 loc) · 5.28 KB
/
Copy pathTeachersPanel.java
File metadata and controls
208 lines (126 loc) · 5.28 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
//Dylan Barrett
//Description
//11/14/24
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TeachersPanel extends CustomPanel {
private final BigDuty bigDuty;
private final Border border;
private Teacher activeTeacher;
private CustomPanel schedule;
private JPanel sidebarContainer;
public TeachersPanel(String panelName, Dimension d, BigDuty bigDuty) {
super(panelName, d);
this.bigDuty = bigDuty;
this.border = BorderFactory.createLineBorder(Color.BLACK);
this.activeTeacher = bigDuty.getTeacher(0);
initView();
}
public void initView() {
BorderLayout layout = new BorderLayout(1, 0);
this.setLayout(layout);
// teacher sidebar
sidebarContainer = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
for(Teacher t : bigDuty.getTeachers()) {
JButton button = new JButton();
button.setText(t.getName());
button.addActionListener(e -> {
updateScheduleDisplay(t);
for(Component c : sidebarContainer.getComponents()) {
if(c instanceof JButton) {
c.setForeground(Color.BLACK);
}
}
button.setForeground(Color.RED);
});
button.setComponentPopupMenu(new TeacherPopUp(t, bigDuty, this));
sidebarContainer.add(button, gbc);
gbc.gridy++;
}
sidebarContainer.getComponent(0).setForeground(Color.RED);
JScrollPane sideBar = new JScrollPane(sidebarContainer);
this.add(sideBar, BorderLayout.WEST);
// schedule display
this.schedule = new CustomPanel("Schedule Display", new Dimension((int) (GUIMain.WIDTH*(0.75)), this.getHeight()));
GridLayout scheduleLayout = new GridLayout(1, 5);
schedule.setLayout(scheduleLayout);
updateScheduleDisplay(activeTeacher);
this.add(schedule, BorderLayout.CENTER);
}
public JComponent createMenu(String day, int period) {
Assignment assignment = activeTeacher.getAssignment(day, new Period(period));
JComponent menu = null;
if (assignment != null) {
String text = assignment.getName();
if(assignment instanceof Free && !((Free) assignment).isLocked()) {
text = "<html>Free <br>" + activeTeacher.scoreAssignment(assignment) + "</html>";
} else if(assignment instanceof Free && ((Free) assignment).isLocked()) {
text = "<html> <font color=#0000ff>Locked Free</font></html>";
}
menu = new JLabel(text);
} else {
menu = new JLabel("No assignment found");
}
if(assignment instanceof Duty) menu.setForeground(Color.RED);
AssignmentPopUp popUp = new AssignmentPopUp(assignment, bigDuty, this);
menu.setComponentPopupMenu(popUp);
menu.setBorder(border);
return menu;
}
public void refreshPanel() {
updateScheduleDisplay(activeTeacher);
// for(int i = 0; i < sidebarContainer.getComponents().length; i++) {
//
// Component c = sidebarContainer.getComponents()[i];
//
// if(c instanceof JButton && c.getForeground() != Color.RED && bigDuty.getTeacher(i).isLocked()) {
// c.setForeground(Color.BLUE);
// } else if(c instanceof JButton && c.getForeground() != Color.RED) {
// c.setForeground(Color.BLACK);
// }
//
// }
super.refreshPanel();
}
public void updateScheduleDisplay(Teacher teacher) {
activeTeacher = teacher;
// schedule = new CustomPanel("Schedule Display", new Dimension((int) (GUIMain.WIDTH*(0.75)), this.getHeight()));
schedule.removeAll();
CustomPanel[] dayPanels = new CustomPanel[5];
String[] days = {"M", "T", "W", "R", "F"};
// set up panel
for(int i = 0; i < dayPanels.length; i++) {
dayPanels[i] = new CustomPanel(days[i], new Dimension(50, 100));
GridLayout mondayLayout = new GridLayout(9, 1);
GridLayout otherLayout = new GridLayout(7, 1);
if(i == 0) dayPanels[i].setLayout(mondayLayout);
else dayPanels[i].setLayout(otherLayout);
schedule.add(dayPanels[i]);
dayPanels[i].setBorder(border);
}
// fill in panel
for(int d = 0; d < days.length; d++) {
int offset = d == 0 ? 1 : 0;
for(int p = 1; p <= ((GridLayout) (dayPanels[d].getLayout())).getRows() - offset; p++) {
JComponent table = null;
if(d != 0 && p == 4) table = createMenu(days[d], -2);
else table = createMenu(days[d], p);
dayPanels[d].add(table);
if(d == 0 && p == 4) dayPanels[d].add(createMenu(days[d], -2));
}
}
repaint();
revalidate();
}
public Teacher getActiveTeacher() {
return activeTeacher;
}
}