-
Notifications
You must be signed in to change notification settings - Fork 4
/
PrivacySettingPage.java
412 lines (336 loc) · 16.9 KB
/
PrivacySettingPage.java
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
/**
* This class is the graphical implementation of the Privacy Setting Page. Customers can set their privacy preferences
* on this page. They also have the option to change their password on this page.
*/
public class PrivacySettingPage extends JFrame implements ActionListener
{
// Constants
static final int WIDTH = 1920;
static final int LENGTH = 1080;
// GUI for change password
JPanel changePasswordPanel = new JPanel();
private final JPasswordField oldPasswordField;
private final JPasswordField newPasswordField_one;
private final JPasswordField newPasswordField_two;
// Objects
BankAutomated BA;
HomePage home;
CA customer;
// GUI Components for PrivacySettingPage
private final JButton backToHome;
private final JButton completeButton;
private final JButton changePasswordButton;
private final JComboBox<String> selectTrack; private final JComboBox<String> selectDataCollection;
private final JComboBox<String> selectSensitiveData; private final JComboBox<String> selectKeyLogger;
/**
* PrivacySettingPage Constructor, this sets all the frame specifications for the page
* @param home HomePage object, to allow the customer to go back to their homepage
* @param BA BankAutomated object, to process the validity of changed (e.g., password change) and process logout
* @param customer CA object, the customer that is currently logged in
*/
public PrivacySettingPage(HomePage home, BankAutomated BA, CA customer)
{
// Set title of the frame
this.setTitle("Privacy Settings");
this.setLayout(null);
this.home = home;
this.customer = customer;
this.BA = BA;
// GUI Components
Font labels = new Font("Raleway", Font.BOLD, 22);
Border emptyBorder = BorderFactory.createEmptyBorder();
String[] options = {"Select...", "Allow", "Don't Allow"};
boolean custLoc = customer.getLocationServices(); int indexLoc;
if (custLoc) {indexLoc = 1;} else {indexLoc = 2;}
boolean custDataColl = customer.getRequireDataCollection(); int indexData;
if (custDataColl) {indexData = 1;} else {indexData = 2;}
boolean custSensitiveData = customer.getSensitiveDataCollection(); int indexSensitiveData;
if (custSensitiveData) {indexSensitiveData = 1;} else {indexSensitiveData = 2;}
boolean custKeyLogger = customer.getKeyLogger(); int indexKeyLogger;
if (custKeyLogger) {indexKeyLogger = 1;} else {indexKeyLogger = 2;}
// GUI Components for location services
JLabel allowTrack = new JLabel("Allow us to access your location:");
allowTrack.setFont(labels);
allowTrack.setBorder(emptyBorder);
allowTrack.setForeground(Color.black);
allowTrack.setBounds(200,150,375,40);
this.add(allowTrack);
// GUI Components for setting location services to true or false
selectTrack = new JComboBox<>(options);
selectTrack.setSelectedIndex(indexLoc);
selectTrack.setFont(new Font("Arial", Font.PLAIN, 20));
selectTrack.setBounds(600, 150, 500, 40);
selectTrack.setCursor(new Cursor(Cursor.HAND_CURSOR));
selectTrack.addActionListener(this);
this.add(selectTrack);
// GUI Components for change password
changePasswordPanel.add(new JLabel("Old Password:"));
oldPasswordField = new JPasswordField();
changePasswordPanel.add(oldPasswordField);
changePasswordPanel.add(new JLabel("New Password:"));
newPasswordField_one = new JPasswordField();
changePasswordPanel.add(newPasswordField_one);
changePasswordPanel.add(new JLabel("New Password Again:"));
newPasswordField_two = new JPasswordField();
changePasswordPanel.add(newPasswordField_two);
// GUI Components for allowing data collection
JLabel allowBasicData = new JLabel("Allow us to access necessary data:");
allowBasicData.setFont(labels);
allowBasicData.setBorder(emptyBorder);
allowBasicData.setForeground(Color.black);
allowBasicData.setBounds(200,250,375,40);
this.add(allowBasicData);
// GUI Components for setting data collection to true or false
selectDataCollection = new JComboBox<>(options);
selectDataCollection.setSelectedIndex(indexData);
selectDataCollection.setFont(new Font("Arial", Font.PLAIN, 20));
selectDataCollection.setBounds(600, 250, 500, 40);
selectDataCollection.setCursor(new Cursor(Cursor.HAND_CURSOR));
selectDataCollection.addActionListener(this);
this.add(selectDataCollection);
// GUI Components for allowing sensitive data collection
JLabel allowSensitiveData = new JLabel("Allow us to access sensitive data:");
allowSensitiveData.setFont(labels);
allowSensitiveData.setBorder(emptyBorder);
allowSensitiveData.setForeground(Color.black);
allowSensitiveData.setBounds(200,350,375,40);
this.add(allowSensitiveData);
// GUI Components for setting sensitive data collection to true or false
selectSensitiveData = new JComboBox<>(options);
selectSensitiveData.setSelectedIndex(indexSensitiveData);
selectSensitiveData.setFont(new Font("Arial", Font.PLAIN, 20));
selectSensitiveData.setBounds(600, 350, 500, 40);
selectSensitiveData.setCursor(new Cursor(Cursor.HAND_CURSOR));
selectSensitiveData.addActionListener(this);
this.add(selectSensitiveData);
// GUI Components for allowing keylogger
JLabel allowKeyLogger = new JLabel("Allow us to use a key logger:");
allowKeyLogger.setFont(labels);
allowKeyLogger.setBorder(emptyBorder);
allowKeyLogger.setForeground(Color.black);
allowKeyLogger.setBounds(200,450,375,40);
this.add(allowKeyLogger);
// GUI Components for setting key logger to true or false
selectKeyLogger = new JComboBox<>(options);
selectKeyLogger.setSelectedIndex(indexKeyLogger);
selectKeyLogger.setFont(new Font("Arial", Font.PLAIN, 20));
selectKeyLogger.setBounds(600, 450, 500, 40);
selectKeyLogger.setCursor(new Cursor(Cursor.HAND_CURSOR));
selectKeyLogger.addActionListener(this);
this.add(selectKeyLogger);
// GUI Components for saving preferences
completeButton = new JButton("Save Preferences");
completeButton.setFont(new Font("SansSerif", Font.PLAIN, 22));
completeButton.setBounds(275, 525, 350, 40);
completeButton.setBackground(Color.black);
completeButton.setForeground(Color.white);
completeButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
completeButton.setBorder(emptyBorder);
completeButton.addActionListener(this);
this.add(completeButton);
// GUI Components for changing password
changePasswordPanel.setLayout(new GridLayout(0, 1));
changePasswordButton = new JButton("Change Password");
changePasswordButton.setFont(new Font("SansSerif", Font.PLAIN, 22));
changePasswordButton.setBounds(650, 525, 350, 40);
changePasswordButton.setBackground(Color.black);
changePasswordButton.setForeground(Color.white);
changePasswordButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
changePasswordButton.setBorder(emptyBorder);
changePasswordButton.addActionListener(this);
this.add(changePasswordButton);
// GUI Components for going back to home
backToHome = new JButton("Back to Home");
backToHome.setFont(new Font("SansSerif", Font.PLAIN, 22));
backToHome.setBounds(475, 575, 350, 50);
backToHome.setBackground(Color.white);
backToHome.setForeground(new Color(57, 107, 170));
backToHome.setCursor(new Cursor(Cursor.HAND_CURSOR));
backToHome.setContentAreaFilled(false);
backToHome.setFocusPainted(false);
backToHome.setBorder(emptyBorder);
backToHome.setContentAreaFilled(false);
backToHome.addActionListener(this);
this.add(backToHome);
// Windows listener for logging out when the window is closed
this.addWindowListener(new WindowEventHandler() {
@Override
public void windowClosing(WindowEvent evt) {
//BA.logout (logic.logout) would be called here
//Write all changes to the file
BA.logout();
Window[] windows = Window.getWindows();
for (Window window : windows) {
window.dispose();
}
System.exit(0);
}
});
// GUI Components for the frame
this.getContentPane().setBackground(Color.white);
this.getRootPane().setDefaultButton(completeButton);
this.setSize(WIDTH, LENGTH);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(false);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
}
/**
* paint method, overrides the JFrame paint method in order to allow for custom graphical design
* @param g Graphics object
*/
public void paint(Graphics g)
{
super.paint(g);
// Paint the background
Graphics2D g2 = (Graphics2D) g;
Color myRed = new Color(230, 30, 30);
Color myBlack = new Color(160, 32, 32);
GradientPaint redToBlack = new GradientPaint(0, 0, myRed, 0, 150, myBlack);
g2.setPaint(redToBlack);
g2.fillRect(0, 0, WIDTH+1, 150);
// set font
Font regFont = new Font("Raleway", Font.BOLD, 60);
g2.setFont(regFont);
g2.setColor(new Color(250, 185, 60));
g2.drawString("Select Your Privacy Settings", 25, 110);
}
/**
* actionPerformed method (implementing ActionListener). When the "Back To Home" button is clicked, it sends
* the customer back to their homepage. The customer can make changes to their privacy preferences and save them
* by clicking the "Save Preferences" button. They could also change their password by clicking "Change Password".
* @param e ActionEvent object, which listens and keeps track of any button clicks
*/
@Override
public void actionPerformed(ActionEvent e)
{
// if the user clicks the back to home button
if (e.getSource() == backToHome)
{
this.setVisible(false);
home.setVisible(true);
}
// If the user clicks the complete button
else if (e.getSource() == changePasswordButton)
{
// make JPanel changePassword visible
boolean changePassword = false;
boolean isSelected = false;
// GUI Components for changing password
do {
// GUI Components for changing password
String[] options = {"Change", "Cancel", "Show Passwords"};
int result = JOptionPane.showOptionDialog(null, changePasswordPanel, "Change Password", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
String oldPassword = new String(oldPasswordField.getPassword());
String newPassword_one = new String(newPasswordField_one.getPassword());
String newPassword_two = new String(newPasswordField_two.getPassword());
// If the user clicks the change button
if (result == 0) {
// If the user does not fill in all fields
if (oldPassword.equals("") || newPassword_one.equals("") || newPassword_two.equals("")) {
JOptionPane.showMessageDialog(this, "Please fill in all fields.");
// User enters the correct old password
} else if (oldPassword.equals(customer.getPassword())) {
// If the user enters the same new password twice
if (oldPassword.equals(newPassword_one) || oldPassword.equals(newPassword_two)) {
JOptionPane.showMessageDialog(this, "New password cannot be the same as the old password.");
// If the user enters two different new passwords
} else if (newPassword_one.equals(newPassword_two)) {
// If the new password is invalid
if (!BA.validPassword(newPassword_two)) {
JOptionPane.showMessageDialog(this, "Password is invalid. Password must contain:\n" +
"\n-At least one lowercase and one uppercase character\n-At least one number\n-At least one" +
" special character\n-At least 8 characters overall.");
// If the new password is valid
} else {
BA.changePassword(customer, newPassword_two);
JOptionPane.showMessageDialog(this, "Password changed successfully.");
changePassword = true;
break;
}
// If the user enters two different new passwords
} else {
JOptionPane.showMessageDialog(this, "New passwords do not match.");
}
} else {
JOptionPane.showMessageDialog(this, "Old password is incorrect.");
}
// If the user clicks the cancel button
} else if (result == 1) {
int choice = JOptionPane.showOptionDialog(null, "Are you sure you want to cancel password change?", "Password Change exit", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null);
if (choice == JOptionPane.YES_OPTION) {
break;
}
// If the user clicks the show passwords button
} else if (result == 2) {
// If the passwords are not shown
if (!isSelected) {
oldPasswordField.setEchoChar((char) 0);
newPasswordField_one.setEchoChar((char) 0);
newPasswordField_two.setEchoChar((char) 0);
isSelected = true;
// If the passwords are shown
} else {
oldPasswordField.setEchoChar('*');
newPasswordField_one.setEchoChar('*');
newPasswordField_two.setEchoChar('*');
isSelected = false;
}
}
}while (!changePassword);
// If the user clicks the complete button
} else if (e.getSource() == completeButton)
{
// If the user does not select all preferences
if(selectTrack.getSelectedIndex()==0 || selectDataCollection.getSelectedIndex()==0 ||
selectSensitiveData.getSelectedIndex()==0 || selectKeyLogger.getSelectedIndex()==0)
{
JOptionPane.showMessageDialog(this, "Please select all preferences before saving.");
}
// If the user selects all preferences
else
{
if (selectTrack.getSelectedIndex() == 1)
{
customer.setLocationServices(true);
}
else if (selectTrack.getSelectedIndex() == 2)
{
customer.setLocationServices(false);
}
if (selectDataCollection.getSelectedIndex() == 1)
{
customer.setRequireDataCollection(true);
}
else if (selectDataCollection.getSelectedIndex() == 2)
{
customer.setRequireDataCollection(false);
}
if (selectSensitiveData.getSelectedIndex() == 1)
{
customer.setSensitiveDataCollection(true);
}
else if (selectSensitiveData.getSelectedIndex() == 2)
{
customer.setSensitiveDataCollection(false);
}
if (selectKeyLogger.getSelectedIndex() == 1)
{
customer.setKeyLogger(true);
}
else if (selectKeyLogger.getSelectedIndex() == 2)
{
customer.setKeyLogger(false);
}
JOptionPane.showMessageDialog(this, "Your privacy settings have been updated.");
this.setVisible(false);
home.setVisible(true);
}
}
}
}