This repository has been archived by the owner on Dec 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainFrame.java
671 lines (607 loc) · 33.4 KB
/
MainFrame.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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* MainFrame.java
*
* Created on May 11, 2010, 8:55:26 AM
*/
package jstego;
import java.awt.CardLayout;
import java.awt.Cursor;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
/**
*
* @author signallock
*/
public class MainFrame extends javax.swing.JFrame {
private File input = null;
private File cover = null;
private File secret = null;
private File stego = null;
private int stegoType = 1;
private File currentDir = null;
/** Creates new form MainFrame */
public MainFrame() {
initComponents();
progressBar.setVisible(false);
currentDir = new File(System.getProperty("user.dir"));
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jSeparator1 = new javax.swing.JSeparator();
mainPanel = new javax.swing.JPanel();
initPanel = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
hidePanel = new javax.swing.JPanel();
hideInputImageTextField = new javax.swing.JTextField();
hideCoverImageTextField = new javax.swing.JTextField();
hideSecretFileTextField = new javax.swing.JTextField();
hideStegoImageTextField = new javax.swing.JTextField();
hideInputImageButton = new javax.swing.JButton();
hideCoverImageButton = new javax.swing.JButton();
hideSecretFileButton = new javax.swing.JButton();
hideStegoImageButton = new javax.swing.JButton();
hideButton = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
algoComboBox = new javax.swing.JComboBox();
algoWarningLabel = new javax.swing.JLabel();
calculateMaxSecretFileSizeButton = new javax.swing.JButton();
seekPanel = new javax.swing.JPanel();
seekStegoImageTextField = new javax.swing.JTextField();
seekStegoImageButton = new javax.swing.JButton();
seekButton = new javax.swing.JButton();
jLabel6 = new javax.swing.JLabel();
statusLabel = new javax.swing.JLabel();
progressBar = new javax.swing.JProgressBar();
menuBar = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
hideMenuItem = new javax.swing.JMenuItem();
seekMenuItem = new javax.swing.JMenuItem();
jSeparator2 = new javax.swing.JPopupMenu.Separator();
quitMenuItem = new javax.swing.JMenuItem();
helpMenu = new javax.swing.JMenu();
aboutMenuItem = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
mainPanel.setLayout(new java.awt.CardLayout());
jTextArea1.setColumns(20);
jTextArea1.setEditable(false);
jTextArea1.setRows(5);
jTextArea1.setText("Welcome to jstego, a Java software to hide/seek secret\ninformation to/from JPEG files. It's licensed under Apache License\nv2. Current version is 0.3 Alpha. For hiding, just go to\nFile -> Hide, and go to File -> Seek for seeking. You may be\ncurious about the way it works, if so, please visit the project's\nhome page:\nhttp://jstego.sourceforge.net\n\nIf you want any further information, please contact the author:\n\[email protected]\n\nNote: The current version is still unstable and should not be\nused in critical area, although the author is trying his best to make\nimprovements.\n\njstego by signallock\npendulum swings");
jTextArea1.setWrapStyleWord(true);
jScrollPane1.setViewportView(jTextArea1);
javax.swing.GroupLayout initPanelLayout = new javax.swing.GroupLayout(initPanel);
initPanel.setLayout(initPanelLayout);
initPanelLayout.setHorizontalGroup(
initPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(initPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)
.addContainerGap())
);
initPanelLayout.setVerticalGroup(
initPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(initPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
.addContainerGap())
);
mainPanel.add(initPanel, "initPanel");
hideInputImageButton.setText("Browse");
hideInputImageButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hideInputImageButtonActionPerformed(evt);
}
});
hideCoverImageButton.setText("Browse");
hideCoverImageButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hideCoverImageButtonActionPerformed(evt);
}
});
hideSecretFileButton.setText("Browse");
hideSecretFileButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hideSecretFileButtonActionPerformed(evt);
}
});
hideStegoImageButton.setText("Browse");
hideStegoImageButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hideStegoImageButtonActionPerformed(evt);
}
});
hideButton.setText("Hide");
hideButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hideButtonActionPerformed(evt);
}
});
jLabel2.setText("Input image:");
jLabel3.setText("Generated cover image:");
jLabel4.setText("Secret file:");
jLabel5.setText("Generated stego image:");
jLabel1.setText("Algorithm:");
algoComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Jsteg", "F5" }));
algoComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
algoComboBoxActionPerformed(evt);
}
});
algoWarningLabel.setText("recommended");
calculateMaxSecretFileSizeButton.setText("Calculate Max Size");
calculateMaxSecretFileSizeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
calculateMaxSecretFileSizeButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout hidePanelLayout = new javax.swing.GroupLayout(hidePanel);
hidePanel.setLayout(hidePanelLayout);
hidePanelLayout.setHorizontalGroup(
hidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(hidePanelLayout.createSequentialGroup()
.addGroup(hidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(hidePanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(hidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(hidePanelLayout.createSequentialGroup()
.addComponent(hideInputImageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(hideInputImageButton))
.addComponent(jLabel2)
.addComponent(jLabel3)
.addGroup(hidePanelLayout.createSequentialGroup()
.addComponent(hideCoverImageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(hideCoverImageButton))
.addComponent(jLabel4)
.addGroup(hidePanelLayout.createSequentialGroup()
.addComponent(hideSecretFileTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(hideSecretFileButton))
.addComponent(jLabel5)
.addGroup(hidePanelLayout.createSequentialGroup()
.addGroup(hidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(calculateMaxSecretFileSizeButton)
.addComponent(hideStegoImageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(hidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(hideButton)
.addComponent(hideStegoImageButton)))))
.addGroup(hidePanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(algoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(algoWarningLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)))
.addContainerGap())
);
hidePanelLayout.setVerticalGroup(
hidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, hidePanelLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(hidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(algoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(algoWarningLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(hidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(hideInputImageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(hideInputImageButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(hidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(hideCoverImageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(hideCoverImageButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(hidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(hideSecretFileTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(hideSecretFileButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(hidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(hideStegoImageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(hideStegoImageButton))
.addGap(18, 18, 18)
.addGroup(hidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(hideButton)
.addComponent(calculateMaxSecretFileSizeButton))
.addContainerGap())
);
mainPanel.add(hidePanel, "hidePanel");
seekStegoImageButton.setText("Browse");
seekStegoImageButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
seekStegoImageButtonActionPerformed(evt);
}
});
seekButton.setText("Seek");
seekButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
seekButtonActionPerformed(evt);
}
});
jLabel6.setText("Stego image:");
javax.swing.GroupLayout seekPanelLayout = new javax.swing.GroupLayout(seekPanel);
seekPanel.setLayout(seekPanelLayout);
seekPanelLayout.setHorizontalGroup(
seekPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(seekPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(seekPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(seekPanelLayout.createSequentialGroup()
.addGroup(seekPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(seekButton)
.addComponent(seekStegoImageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(seekStegoImageButton))
.addComponent(jLabel6))
.addContainerGap(130, Short.MAX_VALUE))
);
seekPanelLayout.setVerticalGroup(
seekPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(seekPanelLayout.createSequentialGroup()
.addGap(53, 53, 53)
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(seekPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(seekStegoImageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(seekStegoImageButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 167, Short.MAX_VALUE)
.addComponent(seekButton)
.addContainerGap())
);
mainPanel.add(seekPanel, "seekPanel");
fileMenu.setText("File");
hideMenuItem.setText("Hide");
hideMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hideMenuItemActionPerformed(evt);
}
});
fileMenu.add(hideMenuItem);
seekMenuItem.setText("Seek");
seekMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
seekMenuItemActionPerformed(evt);
}
});
fileMenu.add(seekMenuItem);
fileMenu.add(jSeparator2);
quitMenuItem.setText("Quit");
quitMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
quitMenuItemActionPerformed(evt);
}
});
fileMenu.add(quitMenuItem);
menuBar.add(fileMenu);
helpMenu.setText("Help");
aboutMenuItem.setText("About");
aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
aboutMenuItemActionPerformed(evt);
}
});
helpMenu.add(aboutMenuItem);
menuBar.add(helpMenu);
setJMenuBar(menuBar);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(statusLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(statusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void quitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitMenuItemActionPerformed
System.exit(0);
}//GEN-LAST:event_quitMenuItemActionPerformed
private void hideMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hideMenuItemActionPerformed
CardLayout cl = (CardLayout) mainPanel.getLayout();
cl.show(mainPanel, "hidePanel");
}//GEN-LAST:event_hideMenuItemActionPerformed
private void seekMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_seekMenuItemActionPerformed
CardLayout cl = (CardLayout) mainPanel.getLayout();
cl.show(mainPanel, "seekPanel");
}//GEN-LAST:event_seekMenuItemActionPerformed
private void hideInputImageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hideInputImageButtonActionPerformed
final JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setCurrentDirectory(currentDir);
int retval = fc.showOpenDialog(hidePanel);
if (retval != JFileChooser.APPROVE_OPTION) {
return;
}
String dir = fc.getSelectedFile().getPath();
hideInputImageTextField.setText(dir);
String fileName = fc.getSelectedFile().getName();
dir = dir.subSequence(0, dir.length() - fileName.length()).toString();
currentDir = new File(dir);
String coverFileName = dir + "cover.jpg";
hideCoverImageTextField.setText(coverFileName);
String stegoFileName = dir + "stego.jpg";
hideStegoImageTextField.setText(stegoFileName);
}//GEN-LAST:event_hideInputImageButtonActionPerformed
private void hideCoverImageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hideCoverImageButtonActionPerformed
final JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setCurrentDirectory(currentDir);
int retval = fc.showOpenDialog(hidePanel);
if (retval != JFileChooser.APPROVE_OPTION) {
return;
}
hideCoverImageTextField.setText(
fc.getSelectedFile().getPath());
}//GEN-LAST:event_hideCoverImageButtonActionPerformed
private void hideSecretFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hideSecretFileButtonActionPerformed
final JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setCurrentDirectory(currentDir);
int retval = fc.showOpenDialog(hidePanel);
if (retval != JFileChooser.APPROVE_OPTION) {
return;
}
hideSecretFileTextField.setText(
fc.getSelectedFile().getPath());
}//GEN-LAST:event_hideSecretFileButtonActionPerformed
private void hideStegoImageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hideStegoImageButtonActionPerformed
final JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setCurrentDirectory(currentDir);
int retval = fc.showOpenDialog(hidePanel);
if (retval != JFileChooser.APPROVE_OPTION) {
return;
}
hideStegoImageTextField.setText(
fc.getSelectedFile().getPath());
}//GEN-LAST:event_hideStegoImageButtonActionPerformed
private void hideButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hideButtonActionPerformed
if (hideInputImageTextField.getText().equals("")
|| hideCoverImageTextField.getText().equals("")
|| hideSecretFileTextField.getText().equals("")
|| hideStegoImageTextField.getText().equals("")) {
JOptionPane.showConfirmDialog(hidePanel,
"Please specify the file path.",
"Error",
JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
return;
}
input = new File(hideInputImageTextField.getText());
cover = new File(hideCoverImageTextField.getText());
secret = new File(hideSecretFileTextField.getText());
stego = new File(hideStegoImageTextField.getText());
mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
progressBar.setIndeterminate(true);
progressBar.setVisible(true);
Runnable hideRun = new Runnable() {
public void run() {
Jstego js = new Jstego();
try {
statusLabel.setText("Generating cover image...");
js.generateCover(input, cover);
statusLabel.setText("Huffman decoding...");
js.huffmanDecode();
statusLabel.setText("Hiding information...");
if (stegoType == 1) {
js.jstegHide(secret);
} else if (stegoType == 2) {
js.f5Hide(secret);
} else {
throw new Exception();
}
statusLabel.setText("Huffman encoding...");
js.huffmanEncode(stego);
statusLabel.setText("Hide complete.");
} catch (Exception ex) {
Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
statusLabel.setText("Operation failed.");
} finally {
progressBar.setVisible(false);
mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
};
Thread hideThread = new Thread(hideRun);
hideThread.start();
}//GEN-LAST:event_hideButtonActionPerformed
private void seekStegoImageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_seekStegoImageButtonActionPerformed
final JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setCurrentDirectory(currentDir);
int retval = fc.showOpenDialog(hidePanel);
if (retval != JFileChooser.APPROVE_OPTION) {
return;
}
seekStegoImageTextField.setText(
fc.getSelectedFile().getPath());
}//GEN-LAST:event_seekStegoImageButtonActionPerformed
private void seekButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_seekButtonActionPerformed
if (seekStegoImageTextField.getText().equals("")) {
JOptionPane.showConfirmDialog(seekPanel,
"Please specify the file path.",
"Error",
JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
return;
}
stego = new File(seekStegoImageTextField.getText());
mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
progressBar.setIndeterminate(true);
progressBar.setVisible(true);
Runnable seekRun = new Runnable() {
public void run() {
try {
Jstego js = new Jstego(stego);
statusLabel.setText("Huffman decoding...");
js.huffmanDecode();
statusLabel.setText("Seeking information...");
js.getSecretFileInfo();
int type = js.getStegoType();
if (type == 1) {
js.jstegSeek();
} else if (type == 2) {
js.f5Seek();
} else {
throw new Exception();
}
String algo = null;
if (type == 1) {
algo = "Jsteg";
} else if (type == 2) {
algo = "F5";
}
statusLabel.setText("Seek complete. Algorithm is " + algo);
} catch (Exception ex) {
Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
statusLabel.setText("Operation failed.");
} finally {
progressBar.setVisible(false);
mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
};
Thread seekThread = new Thread(seekRun);
seekThread.start();
}//GEN-LAST:event_seekButtonActionPerformed
private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
CardLayout cl = (CardLayout) mainPanel.getLayout();
cl.show(mainPanel, "initPanel");
}//GEN-LAST:event_aboutMenuItemActionPerformed
private void algoComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_algoComboBoxActionPerformed
stegoType = algoComboBox.getSelectedIndex() + 1;
if (stegoType == 2) {
algoWarningLabel.setText("for experimental only");
} else {
algoWarningLabel.setText("recommended");
}
}//GEN-LAST:event_algoComboBoxActionPerformed
private void calculateMaxSecretFileSizeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_calculateMaxSecretFileSizeButtonActionPerformed
if (hideInputImageTextField.getText().equals("")
|| hideCoverImageTextField.getText().equals("")) {
JOptionPane.showConfirmDialog(hidePanel,
"Please specify the file path.",
"Error",
JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
return;
}
input = new File(hideInputImageTextField.getText());
cover = new File(hideCoverImageTextField.getText());
mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
progressBar.setIndeterminate(true);
progressBar.setVisible(true);
Runnable calcRun = new Runnable() {
public void run() {
Jstego js = new Jstego();
try {
statusLabel.setText("Generating cover image...");
js.generateCover(input, cover);
statusLabel.setText("Huffman decoding...");
js.huffmanDecode();
statusLabel.setText("Calculating max secret file size...");
int maxSize = js.jstegMaxFileSize();
String maxSizeString = new Integer(maxSize).toString();
statusLabel.setText("Max secret file size is " + maxSizeString + " bytes.");
} catch (Exception ex) {
Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
statusLabel.setText("Operation failed.");
} finally {
progressBar.setVisible(false);
mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
};
Thread calcThread = new Thread(calcRun);
calcThread.start();
}//GEN-LAST:event_calculateMaxSecretFileSizeButtonActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenuItem aboutMenuItem;
private javax.swing.JComboBox algoComboBox;
private javax.swing.JLabel algoWarningLabel;
private javax.swing.JButton calculateMaxSecretFileSizeButton;
private javax.swing.JMenu fileMenu;
private javax.swing.JMenu helpMenu;
private javax.swing.JButton hideButton;
private javax.swing.JButton hideCoverImageButton;
private javax.swing.JTextField hideCoverImageTextField;
private javax.swing.JButton hideInputImageButton;
private javax.swing.JTextField hideInputImageTextField;
private javax.swing.JMenuItem hideMenuItem;
private javax.swing.JPanel hidePanel;
private javax.swing.JButton hideSecretFileButton;
private javax.swing.JTextField hideSecretFileTextField;
private javax.swing.JButton hideStegoImageButton;
private javax.swing.JTextField hideStegoImageTextField;
private javax.swing.JPanel initPanel;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JPopupMenu.Separator jSeparator2;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JPanel mainPanel;
private javax.swing.JMenuBar menuBar;
private javax.swing.JProgressBar progressBar;
private javax.swing.JMenuItem quitMenuItem;
private javax.swing.JButton seekButton;
private javax.swing.JMenuItem seekMenuItem;
private javax.swing.JPanel seekPanel;
private javax.swing.JButton seekStegoImageButton;
private javax.swing.JTextField seekStegoImageTextField;
private javax.swing.JLabel statusLabel;
// End of variables declaration//GEN-END:variables
}