PenaltyController.java
1 |
|
2 |
import java.util.List; |
3 |
import java.util.ArrayList; |
4 |
import javax.swing.JCheckBox; |
5 |
import javax.swing.JButton; |
6 |
|
7 |
/** |
8 |
* @author Maarten Vangeneugden - 1438256 |
9 |
*/ |
10 |
public class PenaltyController { |
11 |
|
12 |
private List<Penalty> penalties; |
13 |
private JCheckBox[] checkBoxes; |
14 |
public JButton closeButton; |
15 |
private Window window; |
16 |
|
17 |
public PenaltyController(List<Penalty> penalties, Window window) { |
18 |
this.penalties = penalties; |
19 |
this.window = window; |
20 |
this.createPenaltyScreen(); |
21 |
} |
22 |
|
23 |
public void setPenalties(List<Penalty> penalties) { |
24 |
this.penalties = penalties; |
25 |
} |
26 |
|
27 |
public List<Penalty> getPenalties() { |
28 |
return penalties; |
29 |
} |
30 |
|
31 |
public void createPenaltyScreen() { |
32 |
String[] penaltyTitles = new String[this.penalties.size()]; |
33 |
for(int i=0; i<this.penalties.size(); i++) { |
34 |
Penalty penalty = this.penalties.get(i); |
35 |
String clientName = penalty.getClient().getName(); |
36 |
String articleName = penalty.getArticles().get(0).getTitle(); |
37 |
String penaltyTitle = articleName +" door "+ clientName +"("+ Float.toString(penalty.computePenalty()) +")"; |
38 |
penaltyTitles[i] = penaltyTitle; |
39 |
} |
40 |
|
41 |
JCheckBox[] paidPenalties = new JCheckBox[this.penalties.size()]; |
42 |
for(int i=0; i<this.penalties.size(); i++) { |
43 |
paidPenalties[i] = this.window.createCheckbox(penaltyTitles[i]); |
44 |
} |
45 |
} |
46 |
|
47 |
public void removePenalties() { |
48 |
for(int i=0; i<this.checkBoxes.length; i++) { |
49 |
if(this.checkBoxes[i].isSelected()) { |
50 |
this.penalties.remove(i); |
51 |
} |
52 |
} |
53 |
|
54 |
this.closeWindow(); |
55 |
} |
56 |
|
57 |
private void closeWindow() { |
58 |
window.removeComponent(this.closeButton); |
59 |
for(JCheckBox checkBox: this.checkBoxes) { |
60 |
window.removeComponent(checkBox); |
61 |
} |
62 |
} |
63 |
} |
64 |