-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuiMediator.java
More file actions
78 lines (68 loc) · 2.3 KB
/
GuiMediator.java
File metadata and controls
78 lines (68 loc) · 2.3 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
package behavioral.mediator;
public class GuiMediator implements Mediator {
private final Login login;
private final Dashboard dashboard;
private final Dialog dialog;
public GuiMediator() {
login = new Login(this);
dashboard = new Dashboard(this);
dialog = new Dialog(this);
// startup state
login.setVisible(true);
dashboard.setVisible(false);
dialog.setVisible(false);
}
@Override
public void notify(Component component, String event) {
if (component == login) {
switch (event) {
case Login.EVENT_EMPTY_FIELD:
login.setVisible(false);
dashboard.setVisible(false);
dialog.setVisible(true);
dialog.showMessage(Login.MESSAGE_EMPTY_FIELD);
break;
case Login.EVENT_NO:
login.setVisible(false);
dashboard.setVisible(false);
dialog.setVisible(true);
dialog.showMessage(Login.MESSAGE_INVALID_USERNAME_PASSWORD);
break;
case Login.EVENT_YES:
login.setVisible(false);
dashboard.setVisible(true);
dialog.setVisible(false);
break;
}
} else if (component == dialog) {
switch (event) {
case Dialog.EVENT_OK:
login.setVisible(true);
dashboard.setVisible(false);
dialog.setVisible(false);
break;
}
} else if (component == dashboard) {
switch (event) {
// implement dashboard functionality here
}
}
}
public Login getLogin() {
return login.getVisible() ? login : null;
}
public Dashboard getDashboard() {
return dashboard.getVisible() ? dashboard : null;
}
public Dialog getDialog() {
return dialog.getVisible() ? dialog : null;
}
@Override
public String toString() {
return "GuiMediator{" +
this.login.toString() +
", " + this.dashboard.toString() +
", " + this.dialog.toString() +
'}';
}
}