-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMain.java
More file actions
94 lines (79 loc) · 3.05 KB
/
Main.java
File metadata and controls
94 lines (79 loc) · 3.05 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
package prog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import prog.huffman.HuffmanCompressor;
import prog.huffman.HuffmanDecompressor;
import prog.lzw.LzwCompressor;
import prog.lzw.LzwDecompressor;
public class Main extends JFrame implements ActionListener {
// Definition of global values and items that are part of the GUI.
static public File openedFile, outputFile;
static long originalSize, compressedSize;
static JLabel originalSizeLabel, compressedSizeLabel, originalSizeValue, compressedSizeValue;
static JPanel buttonPanel, titlePanel, scorePanel;
static JButton huffmanCompressButton, huffmanDecompressButton, lzwCompressButton, lzwDecompressButton, exitButton;
public JPanel createContentPane() {
return MainPanel.createContentPane(this);
}
private void handleHuffmanCompression() {
HuffmanCompressor.beginHuffmanCompression(openedFile.getPath());
showCompressionCompleteDialog("Zipping");
updateFileStats(".huffz");
}
private void handleHuffmanDecompression() {
HuffmanDecompressor.beginHuffmanDecompression(openedFile.getPath());
showCompressionCompleteDialog("UnZipping");
updateDecompressionStats();
}
private void handleLZWCompression() {
LzwCompressor.beginLzwCompression(openedFile.getPath());
showCompressionCompleteDialog("Zipping");
updateFileStats(".LmZWp");
}
private void handleLZWDecompression() {
LzwDecompressor.beginLzwDecompression(openedFile.getPath());
showCompressionCompleteDialog("UnZipping");
updateDecompressionStats();
}
private void showCompressionCompleteDialog(String operation) {
JOptionPane.showMessageDialog(null,
"..........................." + operation + " Finished..........................",
"Status", JOptionPane.PLAIN_MESSAGE);
}
private void updateFileStats(String extension) {
originalSizeValue.setText(openedFile.length() + "Bytes");
outputFile = new File(openedFile.getPath() + extension);
compressedSize = outputFile.length();
compressedSizeValue.setText(compressedSize + "Bytes");
}
private void updateDecompressionStats() {
originalSizeValue.setText(openedFile.length() + "Bytes");
String s = openedFile.getPath();
s = s.substring(0, s.length() - 6);
outputFile = new File(s);
compressedSize = outputFile.length();
compressedSizeValue.setText(compressedSize + "Bytes");
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == huffmanCompressButton) {
handleHuffmanCompression();
} else if (e.getSource() == huffmanDecompressButton) {
handleHuffmanDecompression();
} else if (e.getSource() == lzwCompressButton) {
handleLZWCompression();
} else if (e.getSource() == lzwDecompressButton) {
handleLZWDecompression();
} else if (e.getSource() == exitButton) {
System.exit(0);
}
}
public static void main(String[] args) {
MainFrame.init();
}
}