Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions src/main/java/prog/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,44 @@
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import prog.huffman.Hzipping;
import prog.huffman.Hunzipping;
import prog.lzw.Lzipping;
import prog.lzw.Lunzipping;
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 opened_file, other_file;
static long past, future;
static JLabel redLabel, blueLabel, redScore, blueScore;
static public File openedFile, outputFile;
static long originalSize, compressedSize;
static JLabel originalSizeLabel, compressedSizeLabel, originalSizeValue, compressedSizeValue;
static JPanel buttonPanel, titlePanel, scorePanel;
static JButton ZH, UH, ZL, UL, EX;
static JButton huffmanCompressButton, huffmanDecompressButton, lzwCompressButton, lzwDecompressButton, exitButton;

public JPanel createContentPane() {
return MainPanel.createContentPane(this);
}

private void handleHuffmanCompression() {
Hzipping.beginHzipping(opened_file.getPath());
HuffmanCompressor.beginHuffmanCompression(openedFile.getPath());
showCompressionCompleteDialog("Zipping");
updateFileStats(".huffz");
}

private void handleHuffmanDecompression() {
Hunzipping.beginHunzipping(opened_file.getPath());
HuffmanDecompressor.beginHuffmanDecompression(openedFile.getPath());
showCompressionCompleteDialog("UnZipping");
updateDecompressionStats();
}

private void handleLZWCompression() {
Lzipping.beginLzipping(opened_file.getPath());
LzwCompressor.beginLzwCompression(openedFile.getPath());
showCompressionCompleteDialog("Zipping");
updateFileStats(".LmZWp");
}

private void handleLZWDecompression() {
Lunzipping.beginLunzipping(opened_file.getPath());
LzwDecompressor.beginLzwDecompression(openedFile.getPath());
showCompressionCompleteDialog("UnZipping");
updateDecompressionStats();
}
Expand All @@ -59,31 +59,31 @@ private void showCompressionCompleteDialog(String operation) {
}

private void updateFileStats(String extension) {
redScore.setText(opened_file.length() + "Bytes");
other_file = new File(opened_file.getPath() + extension);
future = other_file.length();
blueScore.setText(future + "Bytes");
originalSizeValue.setText(openedFile.length() + "Bytes");
outputFile = new File(openedFile.getPath() + extension);
compressedSize = outputFile.length();
compressedSizeValue.setText(compressedSize + "Bytes");
}

private void updateDecompressionStats() {
redScore.setText(opened_file.length() + "Bytes");
String s = opened_file.getPath();
originalSizeValue.setText(openedFile.length() + "Bytes");
String s = openedFile.getPath();
s = s.substring(0, s.length() - 6);
other_file = new File(s);
future = other_file.length();
blueScore.setText(future + "Bytes");
outputFile = new File(s);
compressedSize = outputFile.length();
compressedSizeValue.setText(compressedSize + "Bytes");
}

public void actionPerformed(ActionEvent e) {
if (e.getSource() == ZH) {
if (e.getSource() == huffmanCompressButton) {
handleHuffmanCompression();
} else if (e.getSource() == UH) {
} else if (e.getSource() == huffmanDecompressButton) {
handleHuffmanDecompression();
} else if (e.getSource() == ZL) {
} else if (e.getSource() == lzwCompressButton) {
handleLZWCompression();
} else if (e.getSource() == UL) {
} else if (e.getSource() == lzwDecompressButton) {
handleLZWDecompression();
} else if (e.getSource() == EX) {
} else if (e.getSource() == exitButton) {
System.exit(0);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/prog/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ private static void handleFileOpen() {
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result = fileChooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
Main.opened_file = fileChooser.getSelectedFile();
Main.past = Main.opened_file.length();
Main.redScore.setText(Main.past + "Bytes");
Main.blueScore.setText("NotYetCalculated");
Main.openedFile = fileChooser.getSelectedFile();
Main.originalSize = Main.openedFile.length();
Main.originalSizeValue.setText(Main.originalSize + "Bytes");
Main.compressedSizeValue.setText("NotYetCalculated");
}
}

Expand Down
40 changes: 20 additions & 20 deletions src/main/java/prog/MainPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ private static void createTitlePanel(JPanel mainPanel) {
mainPanel.add(Main.titlePanel);

// Create and add labels
Main.redLabel = createLabel("Selected File Size: ", 43, 0, 150, 30);
Main.blueLabel = createLabel("After zip/unzip the file size: ", 10, 30, 170, 30);
Main.titlePanel.add(Main.redLabel);
Main.titlePanel.add(Main.blueLabel);
Main.originalSizeLabel = createLabel("Selected File Size: ", 43, 0, 150, 30);
Main.compressedSizeLabel = createLabel("After zip/unzip the file size: ", 10, 30, 170, 30);

Main.titlePanel.add(Main.originalSizeLabel);
Main.titlePanel.add(Main.compressedSizeLabel);
}

private static void createScorePanel(JPanel mainPanel) {
Expand All @@ -46,11 +46,11 @@ private static void createScorePanel(JPanel mainPanel) {
mainPanel.add(Main.scorePanel);

// Create and add score labels
Main.redScore = createLabel("", 0, 0, 100, 30);
Main.blueScore = createLabel("", 0, 30, 100, 30);
Main.scorePanel.add(Main.redScore);
Main.scorePanel.add(Main.blueScore);
Main.originalSizeValue = createLabel("", 0, 0, 100, 30);
Main.compressedSizeValue = createLabel("", 0, 30, 100, 30);

Main.scorePanel.add(Main.originalSizeValue);
Main.scorePanel.add(Main.compressedSizeValue);
}

private static JLabel createLabel(String text, int x, int y, int width, int height) {
Expand All @@ -77,18 +77,18 @@ private static void createButtonPanel(JPanel mainPanel, ActionListener listener)
mainPanel.add(Main.buttonPanel);

// Create compression buttons
Main.ZH = createButton("ZIP HuffZ", 0, 0, 120, 30, listener);
Main.UH = createButton("UNZIP HuffZ", 130, 0, 120, 30, listener);
Main.ZL = createButton("ZIP LmZWp", 260, 0, 120, 30, listener);
Main.UL = createButton("UNZIP LmZWp", 390, 0, 120, 30, listener);
Main.EX = createButton("EXIT", 130, 70, 250, 30, listener);
Main.huffmanCompressButton = createButton("ZIP HuffZ", 0, 0, 120, 30, listener);
Main.huffmanDecompressButton = createButton("UNZIP HuffZ", 130, 0, 120, 30, listener);
Main.lzwCompressButton = createButton("ZIP LmZWp", 260, 0, 120, 30, listener);
Main.lzwDecompressButton = createButton("UNZIP LmZWp", 390, 0, 120, 30, listener);
Main.exitButton = createButton("EXIT", 130, 70, 250, 30, listener);

// Add buttons to panel
Main.buttonPanel.add(Main.ZH);
Main.buttonPanel.add(Main.UH);
Main.buttonPanel.add(Main.ZL);
Main.buttonPanel.add(Main.UL);
Main.buttonPanel.add(Main.EX);
Main.buttonPanel.add(Main.huffmanCompressButton);
Main.buttonPanel.add(Main.huffmanDecompressButton);
Main.buttonPanel.add(Main.lzwCompressButton);
Main.buttonPanel.add(Main.lzwDecompressButton);
Main.buttonPanel.add(Main.exitButton);
}

public static JPanel createContentPane(ActionListener listener) {
Expand Down
Loading