-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathController.java
More file actions
153 lines (125 loc) · 3.65 KB
/
Controller.java
File metadata and controls
153 lines (125 loc) · 3.65 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
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
/**
* Controller for GUI, handles all changes that user will see, can be updated externally, notifies Messenger of typed messages/commands
*/
public class Controller implements Initializable{
/**
* Message display area
*/
@FXML TextArea messages;
/**
* User input field
*/
@FXML TextField input;
/**
* Confidentiality checkbox
*/
@FXML CheckBox confidentiality;
/**
* Confidentiality boolean
*/
Boolean confidentialityChecked = false;
/**
* Integrity checkbox
*/
@FXML CheckBox integrity;
/**
* Integrity boolean
*/
Boolean integrityChecked = false;
/**
* Authentication checkbox
*/
@FXML CheckBox authentication;
/**
* Authentication checkbox
*/
Boolean authenticationChecked = false;
/**
* Messenger object to store the parent
*/
private Messenger messenger;
/**
* Necessary method that runs when GUI is initialized
* @param url passed from JavaFX
* @param rb passed from JavaFX
*/
@Override
public void initialize(URL url, ResourceBundle rb){
//don't really have anything to do, but necessary to override
}
/**
* Runs when enter key is pressed in text field
* @param a passed from JavaFX
*/
@FXML
public void onEnter(ActionEvent a){
String msg = input.getText(); //get field value
if(msg.equals("")){
return;
}
input.clear(); //clear field once stored
if(msg.charAt(0) == ':'){ //if the input is a command
messenger.command(msg.substring(1)); //strip the ':'
}else{
messenger.typed(msg); //pass on the message
}
}
/**
* Runs when confidentiality check box is modified
* @param a passed from JavaFX
*/
@FXML
public void onClickConfidentiality(ActionEvent a){
confidentialityChecked = !confidentialityChecked;
messenger.setFlags(new Boolean[]{confidentialityChecked, integrityChecked, authenticationChecked});
}
/**
* Runs when integrity check box is modified
* @param a passed from JavaFX
*/
@FXML
public void onClickIntegrity(ActionEvent a){
integrityChecked = !integrityChecked;
messenger.setFlags(new Boolean[]{confidentialityChecked, integrityChecked, authenticationChecked});
}
/**
* Runs when authentication check box is modified
* @param a passed from JavaFX
*/
@FXML
public void onClickAuthentication(ActionEvent a){
authenticationChecked = !authenticationChecked;
messenger.setFlags(new Boolean[]{confidentialityChecked, integrityChecked, authenticationChecked});
}
/**
* Enable/disable checkboxes once connection is established/disconnected
* @param value set checkbox disabled value to this
*/
public void setCheckBoxes(Boolean value){
confidentiality.setDisable(value);
integrity.setDisable(value);
authentication.setDisable(value);
}
/**
* Add a line to the messaging window
* @param text line to add to the messaging window
*/
public void addText(String text){
messages.appendText(text); //append to GUI text area
}
/**
* Set local Messenger for passing on messages/commands
* @param mes parent's class
*/
public void setMessenger(Messenger mes){
messenger = mes;
}
}