OOP2

Controller.java

1
import java.util.List;
2
import java.util.ArrayList;
3
import javax.swing.JCheckBox;
4
import javax.swing.JComponent;
5
import javax.swing.JButton;
6
/**
7
 * @author Maarten Vangeneugden - 1438256
8
 */
9
public class Controller {
10
11
	private List<Article> articles;
12
	private List<Client> clients;
13
	private List<Penalty> penalties;
14
	private Window window;
15
	private List<JComponent> mainScreenComponents;
16
17
	public Controller(List<Article> articles, List<Client> clients) { 
18
		this.articles = articles;
19
		this.clients = clients;
20
		this.penalties = new ArrayList();
21
		this.mainScreenComponents = new ArrayList();
22
		this.createMainScreen();
23
		
24
	}
25
26
	/**
27
	 * Creates the main screen, out of which the user can choose the different
28
	 * things to do.
29
	 */
30
	private void createMainScreen() {
31
		Window gui = new Window("Bibliotheek");
32
		this.window = gui;
33
		this.mainScreenComponents.add(gui.createButton(
34
				"Leen artikels uit",
35
				"",
36
				"createLendingScreen",
37
				this
38
				));
39
		this.mainScreenComponents.add(gui.createButton(
40
				"Beheer wachtlijsten",
41
				"",
42
				"createQueueScreen",
43
				this
44
				));
45
		this.mainScreenComponents.add(gui.createButton(
46
				"Schrijf boete uit",
47
				"",
48
				"createPenaltyScreen",
49
				this
50
				));
51
	}
52
53
	public void createQueueScreen() {
54
	}
55
56
	/**
57
	 * Swaps the visibility state of the main screen buttons.
58
	 */
59
	private void swapMainButtonsState() {
60
		for(JComponent component: this.mainScreenComponents) {
61
			component.setVisible(!component.isVisible());
62
		}
63
	}
64
65
	public void createLendingScreen() {
66
		//this.swapMainButtonsState();
67
		LendingController lendingController = new LendingController(this.articles, this.clients, this.window);
68
		//this.swapMainButtonsState();
69
70
		Window lendingScreen = new Window("Artikels uitlenen");
71
		String[] testing = this.getClients().toArray(new String[0]);
72
		System.out.println(String.valueOf(testing.length));
73
		//lendingScreen.addComboBox(this.getClients().toArray(new String[0]));
74
		lendingScreen.addComboBox(testing);
75
		List<Article> availableArticles = new ArrayList();
76
		for(Article article: this.articles) {
77
			if(article.getLendedSince() == null) { // Available article
78
				availableArticles.add(article);
79
			}
80
		}
81
82
83
	}
84
85
	public void createPenaltyScreen() {
86
		//this.swapMainButtonsState();
87
		//this.window.createButton("Sluiten", "", "closeWindow", this);
88
		PenaltyController penaltyController = new PenaltyController(this.penalties, this.window);
89
		//JButton closeButton = this.window.createButton("Sluiten", "", "removePenalties", penaltyController);
90
		//this.swapMainButtonsState();
91
	}
92
93
94
95
96
97
98
99
		
100
101
	public void setArticles(List<Article> articles) {
102
		this.articles = articles;
103
	}
104
105
	public List<Article> getArticles() {	
106
		return articles;
107
	}
108
109
	public void setClients(List<Client> clients) {
110
		this.clients = clients;
111
	}
112
113
	public List<Client> getClients() {	
114
		return clients;
115
	}
116
117
	/**
118
	 * Translates a given date to an array of 3 integers.
119
	 * @param stringDate The date to translate.
120
	 * @pre stringDate must be of form DD-MM-YYYY
121
	 */
122
	public static int[] getDate(String stringDate) {
123
		int[] date = new int[3];
124
		String[] dateParts = stringDate.split("-");
125
		for(int i=0; i<date.length; i++) {
126
			date[i] = Integer.parseInt(dateParts[i]);
127
		}
128
		return date;
129
	}
130
}
131