1
2
3
4
5
6
7 package org.wiztools.jenkryptor;
8
9 import java.awt.Component;
10 import java.awt.Cursor;
11 import java.awt.FlowLayout;
12 import java.awt.GridLayout;
13 import java.awt.Point;
14 import java.awt.event.KeyEvent;
15 import java.awt.event.KeyListener;
16 import java.awt.event.MouseEvent;
17 import java.awt.event.MouseListener;
18 import java.awt.event.WindowAdapter;
19 import java.awt.event.WindowEvent;
20 import java.io.File;
21 import java.io.IOException;
22 import java.lang.reflect.InvocationTargetException;
23 import java.util.Arrays;
24 import javax.swing.ImageIcon;
25 import javax.swing.JDialog;
26 import javax.swing.JFileChooser;
27 import javax.swing.JFrame;
28 import javax.swing.JOptionPane;
29 import javax.swing.JPanel;
30 import javax.swing.SwingUtilities;
31 import javax.swing.filechooser.FileFilter;
32 import org.wiztools.jenkryptor.util.FileUtil;
33 import org.wiztools.jenkryptor.validation.MixedFilesValidator;
34 import org.wiztools.jenkryptor.validation.SameFileValidator;
35 import org.wiztools.jenkryptor.validation.Validator;
36 import org.wiztools.jenkryptor.validation.ValidatorException;
37
38 /***
39 *
40 * @author subhash
41 */
42 public class MainJFrame extends javax.swing.JFrame {
43
44 private JFileChooser jfc = new JFileChooser();
45
46 private JDialog jd = null;
47
48 private PreferencesJPanel jpPreferences = new PreferencesJPanel();
49 private JPanel jpAbout = new AboutJPanel();
50
51
52 private final Validator validator = new MixedFilesValidator().setNext(
53 new SameFileValidator().setNext(null)
54 );
55
56 /*** Creates new form MainJFrame */
57 public MainJFrame() {
58 initComponents();
59
60 setIconImage(new ImageIcon(
61 this.getClass().getClassLoader().getResource(
62 "org/wiztools/jenkryptor/logo.png")).getImage());
63
64 this.addWindowListener(new WindowAdapter() {
65 @Override
66 public void windowClosing(WindowEvent we){
67 exit(0);
68 }
69 });
70
71 this.setResizable(false);
72
73
74 jfc.setMultiSelectionEnabled(true);
75 jfc.setFileHidingEnabled(false);
76 jfc.setAcceptAllFileFilterUsed(false);
77 jfc.addChoosableFileFilter(new FileFilter() {
78 public boolean accept(File f) {
79 return f.getAbsolutePath()
80 .toLowerCase().endsWith(".wiz")?true:false;
81 }
82 public String getDescription() {
83 return "Encrypted files (*.wiz)";
84 }
85 });
86 jfc.addChoosableFileFilter(new FileFilter() {
87 public boolean accept(File f) {
88 return true;
89 }
90 public String getDescription() {
91 return "All files";
92 }
93 });
94
95
96 jpScrollbar.setLayout(new GridLayout(Globals.THREAD_SIZE, 2));
97
98 LabelProgressbarEnsc[] lpe_arr = Globals.PBPM.getLPEArr();
99 for(int i=0; i<Globals.THREAD_SIZE; i++){
100 LabelProgressbarEnsc lpbe = lpe_arr[i];
101
102 JPanel jp_label = new JPanel();
103 jp_label.setLayout(new FlowLayout(FlowLayout.LEFT));
104 jp_label.add(lpbe.getLabel());
105
106 JPanel jp_progressbar = new JPanel();
107 jp_progressbar.add(lpbe.getProgressBar());
108
109 jpScrollbar.add(jp_label);
110 jpScrollbar.add(jp_progressbar);
111 }
112
113 Globals.msgDisplayer = new MessageDisplay(jlStatus, jtaMessage);
114
115 Globals.MAIN_FRAME = this;
116
117 jd = new JDialog(this);
118 jd.setResizable(false);
119
120 }
121
122 public void exit(final int status){
123 if(Globals.isRunning){
124 JOptionPane.showMessageDialog(Globals.MAIN_FRAME,
125 "Encryption/Decryption Operation in progress. . .",
126 "Cannot close!", JOptionPane.ERROR_MESSAGE);
127 }
128 else{
129 System.exit(status);
130 }
131 }
132
133 public void setJDVisible(final boolean bool){
134 SwingUtilities.invokeLater(new Runnable(){
135 public void run(){
136 JFrame jf = Globals.MAIN_FRAME;
137 Point p = jf.getLocation();
138 jd.pack();
139 jd.setLocation(p.x+(jf.getWidth()-jd.getWidth())/2, p.y+(jf.getHeight()-jd.getHeight())/2);
140 jd.setVisible(bool);
141 }
142 });
143 }
144
145 class FreezeKeyListener implements KeyListener{
146 public void keyPressed(KeyEvent e) {
147 }
148 public void keyReleased(KeyEvent e) {
149 }
150 public void keyTyped(KeyEvent e) {
151 }
152 }
153
154 class FreezeMouseListener implements MouseListener{
155 public void mouseClicked(MouseEvent e) {
156 }
157 public void mouseEntered(MouseEvent e) {
158 }
159 public void mouseExited(MouseEvent e) {
160 }
161 public void mousePressed(MouseEvent e) {
162 }
163 public void mouseReleased(MouseEvent e) {
164 }
165 }
166
167 private final FreezeKeyListener FREEZE_KEY_LISTENER = new FreezeKeyListener();
168 private final FreezeMouseListener FREEZE_MOUSE_LISTENER = new FreezeMouseListener();
169
170 private final Cursor DEFAULT_CURSOR = new Cursor(Cursor.DEFAULT_CURSOR);
171 private final Cursor WAIT_CURSOR = new Cursor(Cursor.WAIT_CURSOR);
172
173 public void freeze(){
174 final Component gpane = this.getGlassPane();
175
176 gpane.addKeyListener(FREEZE_KEY_LISTENER);
177 gpane.addMouseListener(FREEZE_MOUSE_LISTENER);
178 try{
179 SwingUtilities.invokeAndWait(new Runnable() {
180 public void run() {
181 gpane.setCursor(WAIT_CURSOR);
182 gpane.setVisible(true);
183 }
184 });
185 }
186 catch(InvocationTargetException ite){
187 ite.printStackTrace();
188 }
189 catch(InterruptedException ie){
190 ie.printStackTrace();
191 }
192 }
193
194 public void unfreeze(){
195 final Component gpane = this.getGlassPane();
196 try{
197 SwingUtilities.invokeAndWait(new Runnable() {
198 public void run() {
199 gpane.removeKeyListener(FREEZE_KEY_LISTENER);
200 gpane.removeMouseListener(FREEZE_MOUSE_LISTENER);
201 gpane.setVisible(false);
202 gpane.setCursor(DEFAULT_CURSOR);
203 }
204 });
205 }
206 catch(InvocationTargetException ite){
207 ite.printStackTrace();
208 }
209 catch(InterruptedException ie){
210 ie.printStackTrace();
211 }
212 }
213
214 /*** This method is called from within the constructor to
215 * initialize the form.
216 * WARNING: Do NOT modify this code. The content of this method is
217 * always regenerated by the Form Editor.
218 */
219
220 private void initComponents() {
221 jPanel1 = new javax.swing.JPanel();
222 jPanel2 = new javax.swing.JPanel();
223 jlStatus = new javax.swing.JLabel();
224 controlPanel = new javax.swing.JPanel();
225 jLabel1 = new javax.swing.JLabel();
226 jtfFiles = new javax.swing.JTextField();
227 jbFileOpen = new javax.swing.JButton();
228 jpf1 = new javax.swing.JPasswordField();
229 jpf2 = new javax.swing.JPasswordField();
230 jLabel2 = new javax.swing.JLabel();
231 jLabel3 = new javax.swing.JLabel();
232 jbProcess = new javax.swing.JButton();
233 jScrollPane1 = new javax.swing.JScrollPane();
234 jpScrollbar = new javax.swing.JPanel();
235 jScrollPane2 = new javax.swing.JScrollPane();
236 jtaMessage = new javax.swing.JTextArea();
237 jMenuBar2 = new javax.swing.JMenuBar();
238 jmFile = new javax.swing.JMenu();
239 jmtExit = new javax.swing.JMenuItem();
240 jmEdit = new javax.swing.JMenu();
241 jmiClearLog = new javax.swing.JMenuItem();
242 jmiClearFileSelection = new javax.swing.JMenuItem();
243 jmiClearPassword = new javax.swing.JMenuItem();
244 jSeparator1 = new javax.swing.JSeparator();
245 jmiClearAll = new javax.swing.JMenuItem();
246 jmTools = new javax.swing.JMenu();
247 jmiPreferences = new javax.swing.JMenuItem();
248 jmHelp = new javax.swing.JMenu();
249 jmtAbout = new javax.swing.JMenuItem();
250
251 setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
252 setTitle("jEnkryptor");
253 jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
254 jlStatus.setText("jEnkryptor");
255
256 javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
257 jPanel2.setLayout(jPanel2Layout);
258 jPanel2Layout.setHorizontalGroup(
259 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
260 .addComponent(jlStatus, javax.swing.GroupLayout.DEFAULT_SIZE, 411, Short.MAX_VALUE)
261 );
262 jPanel2Layout.setVerticalGroup(
263 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
264 .addComponent(jlStatus)
265 );
266
267 controlPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("jEnkryptor"));
268 controlPanel.setName("ControlPanel");
269 jLabel1.setText("Files: ");
270
271 jtfFiles.setEditable(false);
272
273 jbFileOpen.setMnemonic('r');
274 jbFileOpen.setText("Browse");
275 jbFileOpen.addActionListener(new java.awt.event.ActionListener() {
276 public void actionPerformed(java.awt.event.ActionEvent evt) {
277 jbFileOpenActionPerformed(evt);
278 }
279 });
280
281 jpf1.setPreferredSize(new java.awt.Dimension(109, 19));
282
283 jpf2.setPreferredSize(new java.awt.Dimension(109, 19));
284
285 jLabel2.setText("Password:");
286
287 jLabel3.setText("Re-enter Password (only for encrypt):");
288
289 jbProcess.setMnemonic('y');
290 jbProcess.setText("Encrypt / Decrypt");
291 jbProcess.addActionListener(new java.awt.event.ActionListener() {
292 public void actionPerformed(java.awt.event.ActionEvent evt) {
293 jbProcessActionPerformed(evt);
294 }
295 });
296
297 javax.swing.GroupLayout controlPanelLayout = new javax.swing.GroupLayout(controlPanel);
298 controlPanel.setLayout(controlPanelLayout);
299 controlPanelLayout.setHorizontalGroup(
300 controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
301 .addGroup(controlPanelLayout.createSequentialGroup()
302 .addContainerGap()
303 .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
304 .addGroup(controlPanelLayout.createSequentialGroup()
305 .addComponent(jLabel1)
306 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
307 .addComponent(jtfFiles, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE)
308 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
309 .addComponent(jbFileOpen))
310 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, controlPanelLayout.createSequentialGroup()
311 .addComponent(jLabel3)
312 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
313 .addComponent(jpf2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
314 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, controlPanelLayout.createSequentialGroup()
315 .addComponent(jLabel2)
316 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 209, Short.MAX_VALUE)
317 .addComponent(jpf1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
318 .addComponent(jbProcess, javax.swing.GroupLayout.Alignment.TRAILING))
319 .addContainerGap())
320 );
321 controlPanelLayout.setVerticalGroup(
322 controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
323 .addGroup(controlPanelLayout.createSequentialGroup()
324 .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
325 .addComponent(jLabel1)
326 .addComponent(jbFileOpen)
327 .addComponent(jtfFiles, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
328 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
329 .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
330 .addComponent(jpf1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
331 .addComponent(jLabel2))
332 .addGap(14, 14, 14)
333 .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
334 .addComponent(jpf2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
335 .addComponent(jLabel3))
336 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
337 .addComponent(jbProcess)
338 .addContainerGap(14, Short.MAX_VALUE))
339 );
340
341 javax.swing.GroupLayout jpScrollbarLayout = new javax.swing.GroupLayout(jpScrollbar);
342 jpScrollbar.setLayout(jpScrollbarLayout);
343 jpScrollbarLayout.setHorizontalGroup(
344 jpScrollbarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
345 .addGap(0, 397, Short.MAX_VALUE)
346 );
347 jpScrollbarLayout.setVerticalGroup(
348 jpScrollbarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
349 .addGap(0, 231, Short.MAX_VALUE)
350 );
351 jScrollPane1.setViewportView(jpScrollbar);
352
353 jtaMessage.setColumns(20);
354 jtaMessage.setEditable(false);
355 jtaMessage.setRows(5);
356 jScrollPane2.setViewportView(jtaMessage);
357
358 javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
359 jPanel1.setLayout(jPanel1Layout);
360 jPanel1Layout.setHorizontalGroup(
361 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
362 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
363 .addContainerGap()
364 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
365 .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 415, Short.MAX_VALUE)
366 .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
367 .addComponent(controlPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
368 .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 415, Short.MAX_VALUE))
369 .addContainerGap())
370 );
371 jPanel1Layout.setVerticalGroup(
372 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
373 .addGroup(jPanel1Layout.createSequentialGroup()
374 .addContainerGap()
375 .addComponent(controlPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
376 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
377 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
378 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
379 .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)
380 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
381 .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
382 .addContainerGap())
383 );
384
385 jmFile.setMnemonic('f');
386 jmFile.setText("File");
387 jmFile.addActionListener(new java.awt.event.ActionListener() {
388 public void actionPerformed(java.awt.event.ActionEvent evt) {
389 jmFileActionPerformed(evt);
390 }
391 });
392
393 jmtExit.setMnemonic('x');
394 jmtExit.setText("Exit");
395 jmtExit.addActionListener(new java.awt.event.ActionListener() {
396 public void actionPerformed(java.awt.event.ActionEvent evt) {
397 jmtExitActionPerformed(evt);
398 }
399 });
400
401 jmFile.add(jmtExit);
402
403 jMenuBar2.add(jmFile);
404
405 jmEdit.setMnemonic('e');
406 jmEdit.setText("Edit");
407 jmiClearLog.setMnemonic('l');
408 jmiClearLog.setText("Clear Log");
409 jmiClearLog.addActionListener(new java.awt.event.ActionListener() {
410 public void actionPerformed(java.awt.event.ActionEvent evt) {
411 jmiClearLogActionPerformed(evt);
412 }
413 });
414
415 jmEdit.add(jmiClearLog);
416
417 jmiClearFileSelection.setMnemonic('f');
418 jmiClearFileSelection.setText("Clear File Selection");
419 jmiClearFileSelection.addActionListener(new java.awt.event.ActionListener() {
420 public void actionPerformed(java.awt.event.ActionEvent evt) {
421 jmiClearFileSelectionActionPerformed(evt);
422 }
423 });
424
425 jmEdit.add(jmiClearFileSelection);
426
427 jmiClearPassword.setMnemonic('p');
428 jmiClearPassword.setText("Clear Password Fields");
429 jmiClearPassword.addActionListener(new java.awt.event.ActionListener() {
430 public void actionPerformed(java.awt.event.ActionEvent evt) {
431 jmiClearPasswordActionPerformed(evt);
432 }
433 });
434
435 jmEdit.add(jmiClearPassword);
436
437 jmEdit.add(jSeparator1);
438
439 jmiClearAll.setMnemonic('a');
440 jmiClearAll.setText("Clear All");
441 jmiClearAll.addActionListener(new java.awt.event.ActionListener() {
442 public void actionPerformed(java.awt.event.ActionEvent evt) {
443 jmiClearAllActionPerformed(evt);
444 }
445 });
446
447 jmEdit.add(jmiClearAll);
448
449 jMenuBar2.add(jmEdit);
450
451 jmTools.setMnemonic('t');
452 jmTools.setText("Tools");
453 jmTools.addActionListener(new java.awt.event.ActionListener() {
454 public void actionPerformed(java.awt.event.ActionEvent evt) {
455 jmToolsActionPerformed(evt);
456 }
457 });
458
459 jmiPreferences.setMnemonic('r');
460 jmiPreferences.setText("Preferences");
461 jmiPreferences.addActionListener(new java.awt.event.ActionListener() {
462 public void actionPerformed(java.awt.event.ActionEvent evt) {
463 jmiPreferencesActionPerformed(evt);
464 }
465 });
466
467 jmTools.add(jmiPreferences);
468
469 jMenuBar2.add(jmTools);
470
471 jmHelp.setMnemonic('h');
472 jmHelp.setText("Help");
473 jmtAbout.setMnemonic('a');
474 jmtAbout.setText("About");
475 jmtAbout.addActionListener(new java.awt.event.ActionListener() {
476 public void actionPerformed(java.awt.event.ActionEvent evt) {
477 jmtAboutActionPerformed(evt);
478 }
479 });
480
481 jmHelp.add(jmtAbout);
482
483 jMenuBar2.add(jmHelp);
484
485 setJMenuBar(jMenuBar2);
486
487 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
488 getContentPane().setLayout(layout);
489 layout.setHorizontalGroup(
490 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
491 .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
492 );
493 layout.setVerticalGroup(
494 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
495 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 560, javax.swing.GroupLayout.PREFERRED_SIZE)
496 );
497 pack();
498 }
499
500 private void jmiClearPasswordActionPerformed(java.awt.event.ActionEvent evt) {
501 SwingUtilities.invokeLater(new Runnable(){
502 public void run(){
503 clearPasswordFields();
504 }
505 });
506 }
507
508 private void jmiClearAllActionPerformed(java.awt.event.ActionEvent evt) {
509 clearFileSelection();
510 Globals.msgDisplayer.clear();
511 clearPasswordFields();
512 }
513
514 private void clearPasswordFields(){
515 SwingUtilities.invokeLater(new Runnable(){
516 public void run(){
517 jpf1.setText("");
518 jpf2.setText("");
519 }
520 });
521 }
522
523 private void clearFileSelection(){
524 SwingUtilities.invokeLater(new Runnable(){
525 public void run(){
526 Globals.files = null;
527 jtfFiles.setText("");
528 }
529 });
530 }
531
532 private void jmiClearFileSelectionActionPerformed(java.awt.event.ActionEvent evt) {
533 clearFileSelection();
534 }
535
536 private void jmiClearLogActionPerformed(java.awt.event.ActionEvent evt) {
537 Globals.msgDisplayer.clear();
538 }
539
540 private void jmtAboutActionPerformed(java.awt.event.ActionEvent evt) {
541 SwingUtilities.invokeLater(new Runnable(){
542 public void run(){
543 jd.setContentPane(jpAbout);
544 setJDVisible(true);
545 }
546 });
547 }
548
549 private void jmiPreferencesActionPerformed(java.awt.event.ActionEvent evt) {
550 SwingUtilities.invokeLater(new Runnable(){
551 public void run(){
552 jpPreferences.setPreferences(Preferences.overwriteDestination_pref,
553 Preferences.deleteSource_pref);
554 jd.setContentPane(jpPreferences);
555 setJDVisible(true);
556 }
557 });
558
559 }
560
561 private void jmtExitActionPerformed(java.awt.event.ActionEvent evt) {
562 exit(0);
563 }
564
565 private void jmToolsActionPerformed(java.awt.event.ActionEvent evt) {
566
567 }
568
569 private void jmFileActionPerformed(java.awt.event.ActionEvent evt) {
570
571 }
572
573 private void jbProcessActionPerformed(java.awt.event.ActionEvent evt) {
574
575 if(Globals.files == null){
576 final String msg = "No files selected!";
577 JOptionPane.showMessageDialog(this, msg, msg, JOptionPane.ERROR_MESSAGE);
578 return;
579 }
580
581 char[] pwd1 = jpf1.getPassword();
582 char[] pwd2 = jpf2.getPassword();
583
584 if(pwd1.length == 0){
585 final String msg = "Password is empty!";
586 JOptionPane.showMessageDialog(this, msg, msg, JOptionPane.ERROR_MESSAGE);
587 return;
588 }
589
590 final String msg = "Password not equal!";
591 if(Globals.mode == Globals.MODE_ENCRYPT){
592 if(!Arrays.equals(pwd1, pwd2)){
593 JOptionPane.showMessageDialog(this, msg, msg, JOptionPane.ERROR_MESSAGE);
594 return;
595 }
596 }
597
598 if(Globals.mode == Globals.MODE_DECRYPT){
599 if(pwd2.length != 0 && !Arrays.equals(pwd1, pwd2)){
600 JOptionPane.showMessageDialog(this, msg, msg, JOptionPane.ERROR_MESSAGE);
601 return;
602 }
603 }
604
605 Globals.password = new String(pwd1);
606
607 Globals.msgDisplayer.clear();
608 Processor.getInstance().process();
609 }
610
611 private void jbFileOpenActionPerformed(java.awt.event.ActionEvent evt) {
612 jfc.showOpenDialog(this);
613 File[] files = jfc.getSelectedFiles();
614
615 if(files == null || files.length == 0){
616
617 return;
618 }
619
620 try{
621 validator.validate(files);
622 }
623 catch(ValidatorException ve){
624 JOptionPane.showMessageDialog(this, ve.getMessage(), "Validation Error!", JOptionPane.ERROR_MESSAGE);
625 return;
626 }
627
628 try{
629 final String filesCSV = FileUtil.getFileNamesCSV(files);
630 SwingUtilities.invokeLater(new Runnable(){
631 public void run(){
632 jtfFiles.setText(filesCSV);
633 }
634 });
635
636
637 }
638 catch(ValidatorException ve){
639 JOptionPane.showMessageDialog(this, ve.getMessage(), "Validation Error!", JOptionPane.ERROR_MESSAGE);
640 return;
641 }
642 catch(IOException ioe){
643 Globals.msgDisplayer.appendMessage("ERROR: "+ioe.getMessage());
644 return;
645 }
646
647 }
648
649
650 private javax.swing.JPanel controlPanel;
651 private javax.swing.JLabel jLabel1;
652 private javax.swing.JLabel jLabel2;
653 private javax.swing.JLabel jLabel3;
654 private javax.swing.JMenuBar jMenuBar2;
655 private javax.swing.JPanel jPanel1;
656 private javax.swing.JPanel jPanel2;
657 private javax.swing.JScrollPane jScrollPane1;
658 private javax.swing.JScrollPane jScrollPane2;
659 private javax.swing.JSeparator jSeparator1;
660 private javax.swing.JButton jbFileOpen;
661 private javax.swing.JButton jbProcess;
662 private javax.swing.JLabel jlStatus;
663 private javax.swing.JMenu jmEdit;
664 private javax.swing.JMenu jmFile;
665 private javax.swing.JMenu jmHelp;
666 private javax.swing.JMenu jmTools;
667 private javax.swing.JMenuItem jmiClearAll;
668 private javax.swing.JMenuItem jmiClearFileSelection;
669 private javax.swing.JMenuItem jmiClearLog;
670 private javax.swing.JMenuItem jmiClearPassword;
671 private javax.swing.JMenuItem jmiPreferences;
672 private javax.swing.JMenuItem jmtAbout;
673 private javax.swing.JMenuItem jmtExit;
674 private javax.swing.JPanel jpScrollbar;
675 private javax.swing.JPasswordField jpf1;
676 private javax.swing.JPasswordField jpf2;
677 private javax.swing.JTextArea jtaMessage;
678 private javax.swing.JTextField jtfFiles;
679
680
681 }