-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignmentPopUp.java
More file actions
148 lines (90 loc) · 3.71 KB
/
Copy pathAssignmentPopUp.java
File metadata and controls
148 lines (90 loc) · 3.71 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
//Dylan Barrett
//Description
//11/14/24
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
public class AssignmentPopUp extends JPopupMenu {
private Assignment assignment;
private final BigDuty bigDuty;
private final TeachersPanel parent;
public AssignmentPopUp(Assignment assignment, BigDuty bigDuty, TeachersPanel parent) {
super(assignment != null ? assignment.getName() : "");
this.assignment = assignment;
this.bigDuty = bigDuty;
this.parent = parent;
addLockingFree();
addAssignDuty();
addRemoveDuty();
}
public void addLockingFree() {
boolean locked;
JMenuItem item;
if(assignment instanceof Free) {
locked = ((Free) assignment).isLocked();
if(locked) item = new JMenuItem("Unlock Free");
else item = new JMenuItem("Lock Free");
boolean finalLocked = locked;
item.addActionListener(e -> {
((Free) assignment).setLocked(!((Free) assignment).isLocked());
if(((Free) assignment).isLocked()) item.setText("Unlock Free");
else item.setText("Lock Free");
bigDuty.refreshPanels();
});
} else {
item = new JMenuItem("Lock Free");
item.setEnabled(false);
}
this.add(item);
}
public void addAssignDuty() {
JMenu menu = new JMenu("Assign Duty");
JMenuItem hall = new JMenuItem("Hall");
hall.addActionListener(e -> {
Duty duty = new Duty(assignment, "Hall", "Hall", DutyType.HALL);
replaceAssignment(duty);
});
menu.add(hall);
JMenuItem pascack = new JMenuItem("Pascack");
pascack.addActionListener(e -> {
Duty duty = new Duty(assignment, "Pascack", "Caf", DutyType.PASCACK);
replaceAssignment(duty);
});
menu.add(pascack);
JMenuItem coverage = new JMenuItem("Coverage");
coverage.addActionListener(e -> {
Duty duty = new Duty(assignment, "Coverage", "None", DutyType.COVERAGE);
replaceAssignment(duty);
});
menu.add(coverage);
JMenuItem froshPascack = new JMenuItem("Freshman Pascack");
froshPascack.addActionListener(e -> {
Duty duty = new Duty(assignment, Duty.FROSH_PASCACK, "Caf", DutyType.FROSH_PASCACK);
if(assignment.getTeacher().getDuties().size() >= assignment.getTeacher().getMaxDuties() && !(assignment instanceof Duty)) {
int n = JOptionPane.showConfirmDialog(this, "Your about to assign another duty to a teacher that already has their max number of duties! You need to increase their max duties in the Home Panel!", "Teacher at Max Duties!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if(n == 0) {
bigDuty.getPane().setSelectedIndex(0);
bigDuty.refreshPanels();
}
} else {
replaceAssignment(duty);
}
});
menu.add(froshPascack);
this.add(menu);
}
public void addRemoveDuty() {
JMenuItem removeDuty = new JMenuItem("Remove Duty");
if(!(assignment instanceof Duty)) removeDuty.setEnabled(false);
removeDuty.addActionListener(e -> {
Free free = new Free(assignment);
replaceAssignment(free);
});
this.add(removeDuty);
}
public void replaceAssignment(Assignment assignment) {
bigDuty.replaceAssignment(assignment);
this.assignment = assignment;
parent.updateScheduleDisplay(assignment.getTeacher());
}
}