-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwingAppClient.java
365 lines (295 loc) · 11.2 KB
/
SwingAppClient.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
/*
* Libraries and packages used:
*/
package clientPackage;
import clientPackage.PaillierClient;
import clientPackage.Email;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.LayoutManager;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.math.BigInteger;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import javax.mail.MessagingException;
import javax.mail.internet.AddressException;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.OverlayLayout;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
public class SwingAppClient {
private static JFrame frame;
private static JLayeredPane pane;
private static JPanel bottomPane;
private JPanel topPanel;
private JPanel verifierPanel;
private JPanel thresholdPanel;
private JPanel banksPanel;
private JLabel verifierLabel;
private JLabel thresholdLabel;
private JLabel banksLabel;
private JTextField thresholdField;
private JTextField banksField;
private DefaultListModel bankList;
private String[] verifiers;
private JComboBox<String> verifierList;
private JButton submit;
private int banksAdded;
private JPanel leftBankPanel;
private JPanel innerLeftBankPanel;
private JPanel buttonLeftBankPanel;
private JButton addBank;
private JPanel rightBankPanel;
private JList newBankList;
private JTextArea instructions;
private JLabel topMargin;
private JLabel verifierMargin;
private JLabel thresholdMargin;
private JLabel banksMargin;
private JPanel bottomPanel;
private JButton submitButton;
private JLabel processingLabel;
private ImageIcon processingIcon;
private static String userId;
protected static String userName;
public SwingAppClient(String appName, String id, String name) {
frame = new JFrame(appName);
pane = new JLayeredPane();
bottomPane = new JPanel();
topPanel = new JPanel();
verifierPanel = new JPanel();
thresholdPanel = new JPanel();
banksPanel = new JPanel();
verifierLabel = new JLabel("Lender");
thresholdLabel = new JLabel("Amount");
banksLabel = new JLabel("Banks");
thresholdField = new JTextField(15);
banksField = new JTextField(15);
bankList = new DefaultListModel();
submit = new JButton("Submit");
banksAdded = 1;
leftBankPanel = new JPanel();
innerLeftBankPanel = new JPanel();
buttonLeftBankPanel = new JPanel();
addBank = new JButton("ADD");
rightBankPanel = new JPanel();
newBankList = new JList(bankList);
instructions = new JTextArea();
topMargin = new JLabel();
verifierMargin = new JLabel();
thresholdMargin = new JLabel();
banksMargin = new JLabel();
bottomPanel = new JPanel();
submitButton = new JButton("SUBMIT");
processingLabel = new JLabel("Processing");
processingIcon = new ImageIcon(this.getClass().getResource("ajax-loader (1).gif"));
processingLabel.setIcon(processingIcon);
userId = id;
userName = name;
}
public void initializeEverifyApp() {
/*
* Set frame, pane, bottomPane and topPane
*/
frame.setSize(500,600);
frame.setLayout(new BorderLayout());
frame.add(pane, BorderLayout.CENTER);
pane.setBounds(0, 0, 500, 600);
bottomPane.setBounds(0, 0, 500, 600);
bottomPane.setLayout(new BoxLayout(bottomPane, BoxLayout.Y_AXIS));
pane.add(bottomPane, new Integer(0), 0);
/*
* Set processingLabel
*/
processingLabel.setMaximumSize(new Dimension(200,150));
processingLabel.setFont(new Font("Tahoma", Font.BOLD, 18));
processingLabel.setForeground(Color.WHITE);
processingLabel.setBorder(new EmptyBorder(250,0,0,0));
/*
* Top panel top margin
*/
topMargin.setMaximumSize(new Dimension(500,15));
/*
* Top panel
*/
instructions.setText("Please enter all information and click submit. "
+ "Your encryption keys will be generated on your local machine and only shared with the verifier and your financial "
+ "institutions. You "
+ "can enter up to 5 banks for a single transaction.");
instructions.setBackground(topPanel.getBackground());
instructions.setLineWrap(true);
instructions.setWrapStyleWord(true);
instructions.setFont(new Font("Tahoma", Font.BOLD, 12));
instructions.setBorder(new EmptyBorder(10,10,10,10));
instructions.setEditable(false);
topPanel.setLayout(new BorderLayout());
topPanel.add(instructions, BorderLayout.CENTER);
topPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
topPanel.setMaximumSize(new Dimension(500,80));
topPanel.setBorder(new LineBorder(Color.LIGHT_GRAY));
/*
* Verifier panel top margin
*/
verifierMargin.setMaximumSize(new Dimension(500,20));
/*
* Verifier panel
*/
verifiers = new String[] {" -----Select Lender-----", "Bank of America", "Capital One", "Chase Bank", "Citibank", "Wells Fargo"};
verifierList = new JComboBox<String>(verifiers);
verifierLabel.setMaximumSize(new Dimension(80,25));
verifierLabel.setBorder(new EmptyBorder(0, 20, 0, 0));
verifierList.setMaximumSize(new Dimension(150,25));
verifierPanel.add(verifierLabel);
verifierPanel.add(verifierList);
verifierPanel.setLayout(new BoxLayout(verifierPanel, BoxLayout.X_AXIS));
verifierPanel.setBorder(new EmptyBorder(50,0,0,0));
verifierPanel.setBorder(BorderFactory.createTitledBorder("1. Verification Information"));
verifierPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
verifierPanel.setMaximumSize(new Dimension(500,100));
/*
* Threshold panel top margin
*/
thresholdMargin.setMaximumSize(new Dimension(500,10));
/*
* Threshold panel
*/
thresholdPanel.setLayout(new BoxLayout(thresholdPanel, BoxLayout.X_AXIS));
thresholdPanel.setBorder(BorderFactory.createTitledBorder("2. Qualifying Balance"));
thresholdLabel.setMaximumSize(new Dimension(80,25));
thresholdLabel.setBorder(new EmptyBorder(0, 20, 0, 0));
thresholdField.setMaximumSize(new Dimension(150,25));
thresholdPanel.add(thresholdLabel);
thresholdPanel.add(thresholdField);
thresholdPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
thresholdPanel.setMaximumSize(new Dimension(500,100));
/*
* Bank panel top margin
*/
banksMargin.setMaximumSize(new Dimension(500,10));
/*
* Bank panel
*/
banksPanel.setLayout(new BoxLayout(banksPanel, BoxLayout.X_AXIS));
banksPanel.setBorder(BorderFactory.createTitledBorder("3. Financial Institutions"));
/*
* Left side of bank panel
*/
leftBankPanel.setLayout(new BoxLayout(leftBankPanel, BoxLayout.Y_AXIS));
leftBankPanel.setMaximumSize(new Dimension(250,100));
innerLeftBankPanel.setLayout(new BoxLayout(innerLeftBankPanel, BoxLayout.X_AXIS));
innerLeftBankPanel.setMaximumSize(new Dimension(250,50));
buttonLeftBankPanel.setLayout(new BoxLayout(buttonLeftBankPanel, BoxLayout.X_AXIS));
buttonLeftBankPanel.setMaximumSize(new Dimension(250,50));
buttonLeftBankPanel.setBorder(new EmptyBorder(0,0,25,0));
banksLabel.setMaximumSize(new Dimension(80,25));
banksLabel.setBorder(new EmptyBorder(0, 20, 0, 0));
banksField.setMaximumSize(new Dimension(150,25));
innerLeftBankPanel.add(banksLabel);
innerLeftBankPanel.add(banksField);
addBank.setMaximumSize(new Dimension(58,25));
addBank.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(banksAdded < 6){
bankList.addElement(banksAdded++ + ". " + banksField.getText());
banksField.setText(null);
} else {
banksField.setText(null);
}
}
});
buttonLeftBankPanel.add(Box.createRigidArea(new Dimension(170,0)));
buttonLeftBankPanel.add(addBank);
leftBankPanel.add(innerLeftBankPanel);
leftBankPanel.add(buttonLeftBankPanel);
/*
* Right side of bank panel
*/
rightBankPanel.setLayout(new BoxLayout(rightBankPanel, BoxLayout.Y_AXIS));
rightBankPanel.setMaximumSize(new Dimension(250,100));
newBankList.setBackground(rightBankPanel.getBackground());
rightBankPanel.add(newBankList);
banksPanel.add(leftBankPanel);
banksPanel.add(rightBankPanel);
banksPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
banksPanel.setMaximumSize(new Dimension(500,150));
/*
* Bottom panel
*/
bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));
bottomPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
bottomPanel.setMaximumSize(new Dimension(500,100));
submitButton.setMaximumSize(new Dimension(80,25));
bottomPanel.add(Box.createRigidArea(new Dimension(210,0)));
bottomPanel.add(submitButton);
submitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
try {
sendParameters();
} catch (NumberFormatException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
/*
* Panels added
*/
bottomPane.add(topMargin);
bottomPane.add(topPanel);
bottomPane.add(verifierMargin);
bottomPane.add(verifierPanel);
bottomPane.add(thresholdMargin);
bottomPane.add(thresholdPanel);
bottomPane.add(banksMargin);
bottomPane.add(banksPanel);
bottomPane.add(bottomPanel);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public void sendParameters() throws NumberFormatException, IOException, AddressException, MessagingException {
String[] parameters = {thresholdField.getText(), Integer.toString(bankList.getSize()),
verifierList.getSelectedItem().toString(), userId};
PaillierClient.main(parameters);
}
public static void closeApp() {
JOptionPane.showMessageDialog(frame, "Your verification has been submitted! \n"
+ " Your total financial balance is:\n\n $" +
NumberFormat.getNumberInstance(Locale.US).format(PaillierClient.plainTextSum) +
"\n\n Thank you for using eVERIFY.\n\n");
frame.dispose();
}
public static void main(String[] args) {
SwingAppClient encryptionApp = new SwingAppClient("eVERIFY", args[0], args[1]);
encryptionApp.initializeEverifyApp();
}
}