1010import javax .swing .JOptionPane ;
1111import javax .swing .JPanel ;
1212
13- import prog .huffman .Hzipping ;
14- import prog .huffman .Hunzipping ;
15- import prog .lzw .Lzipping ;
16- import prog .lzw .Lunzipping ;
13+ import prog .huffman .HuffmanCompressor ;
14+ import prog .huffman .HuffmanDecompressor ;
15+ import prog .lzw .LzwCompressor ;
16+ import prog .lzw .LzwDecompressor ;
17+ import prog .util .Constants ;
1718
1819public class Main extends JFrame implements ActionListener {
1920 // Definition of global values and items that are part of the GUI.
2021
21- static public File opened_file , other_file ;
22- static long past , future ;
23- static JLabel redLabel , blueLabel , redScore , blueScore ;
22+ static public File openedFile , outputFile ;
23+ static long originalSize , compressedSize ;
24+ static JLabel originalSizeLabel , compressedSizeLabel , originalSizeValue , compressedSizeValue ;
2425 static JPanel buttonPanel , titlePanel , scorePanel ;
25- static JButton ZH , UH , ZL , UL , EX ;
26+ static JButton huffmanCompressButton , huffmanDecompressButton , lzwCompressButton , lzwDecompressButton , exitButton ;
2627
2728 public JPanel createContentPane () {
2829 return MainPanel .createContentPane (this );
2930 }
3031
3132 private void handleHuffmanCompression () {
32- Hzipping . beginHzipping ( opened_file .getPath ());
33+ HuffmanCompressor . beginHuffmanCompression ( openedFile .getPath ());
3334 showCompressionCompleteDialog ("Zipping" );
34- updateFileStats (".huffz" );
35+ updateFileStats (Constants . HUFFMAN_FILE_EXTENSION );
3536 }
3637
3738 private void handleHuffmanDecompression () {
38- Hunzipping . beginHunzipping ( opened_file .getPath ());
39+ HuffmanDecompressor . beginHuffmanDecompression ( openedFile .getPath ());
3940 showCompressionCompleteDialog ("UnZipping" );
4041 updateDecompressionStats ();
4142 }
4243
4344 private void handleLZWCompression () {
44- Lzipping . beginLzipping ( opened_file .getPath ());
45+ LzwCompressor . beginLzwCompression ( openedFile .getPath ());
4546 showCompressionCompleteDialog ("Zipping" );
46- updateFileStats (".LmZWp" );
47+ updateFileStats (Constants . LZW_FILE_EXTENSION );
4748 }
4849
4950 private void handleLZWDecompression () {
50- Lunzipping . beginLunzipping ( opened_file .getPath ());
51+ LzwDecompressor . beginLzwDecompression ( openedFile .getPath ());
5152 showCompressionCompleteDialog ("UnZipping" );
5253 updateDecompressionStats ();
5354 }
@@ -59,31 +60,31 @@ private void showCompressionCompleteDialog(String operation) {
5960 }
6061
6162 private void updateFileStats (String extension ) {
62- redScore .setText (opened_file .length () + "Bytes" );
63- other_file = new File (opened_file .getPath () + extension );
64- future = other_file .length ();
65- blueScore .setText (future + "Bytes" );
63+ originalSizeValue .setText (openedFile .length () + "Bytes" );
64+ outputFile = new File (openedFile .getPath () + extension );
65+ compressedSize = outputFile .length ();
66+ compressedSizeValue .setText (compressedSize + "Bytes" );
6667 }
6768
6869 private void updateDecompressionStats () {
69- redScore .setText (opened_file .length () + "Bytes" );
70- String s = opened_file .getPath ();
70+ originalSizeValue .setText (openedFile .length () + "Bytes" );
71+ String s = openedFile .getPath ();
7172 s = s .substring (0 , s .length () - 6 );
72- other_file = new File (s );
73- future = other_file .length ();
74- blueScore .setText (future + "Bytes" );
73+ outputFile = new File (s );
74+ compressedSize = outputFile .length ();
75+ compressedSizeValue .setText (compressedSize + "Bytes" );
7576 }
7677
7778 public void actionPerformed (ActionEvent e ) {
78- if (e .getSource () == ZH ) {
79+ if (e .getSource () == huffmanCompressButton ) {
7980 handleHuffmanCompression ();
80- } else if (e .getSource () == UH ) {
81+ } else if (e .getSource () == huffmanDecompressButton ) {
8182 handleHuffmanDecompression ();
82- } else if (e .getSource () == ZL ) {
83+ } else if (e .getSource () == lzwCompressButton ) {
8384 handleLZWCompression ();
84- } else if (e .getSource () == UL ) {
85+ } else if (e .getSource () == lzwDecompressButton ) {
8586 handleLZWDecompression ();
86- } else if (e .getSource () == EX ) {
87+ } else if (e .getSource () == exitButton ) {
8788 System .exit (0 );
8889 }
8990 }
0 commit comments