Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/farzinzx/huffmancoding
This project implements Huffman Encoding and Decoding in Java, complete with a graphical user interface (GUI) to visualize the Huffman Tree, Huffman Codes, character frequencies, encoded text, and decoded text. The application also supports file upload and saving encoded and decoded text.
https://github.com/farzinzx/huffmancoding
huffman-algorithm huffman-coding huffman-compression-algorithm huffman-decoder huffman-encoder java java-swing-applications
Last synced: 1 day ago
JSON representation
This project implements Huffman Encoding and Decoding in Java, complete with a graphical user interface (GUI) to visualize the Huffman Tree, Huffman Codes, character frequencies, encoded text, and decoded text. The application also supports file upload and saving encoded and decoded text.
- Host: GitHub
- URL: https://github.com/farzinzx/huffmancoding
- Owner: FARZINzx
- Created: 2024-06-15T18:52:34.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-07-14T09:35:25.000Z (5 months ago)
- Last Synced: 2024-11-03T17:43:06.549Z (about 2 months ago)
- Topics: huffman-algorithm, huffman-coding, huffman-compression-algorithm, huffman-decoder, huffman-encoder, java, java-swing-applications
- Language: Java
- Homepage:
- Size: 97 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Huffman Encoding and Decoding in Java
This project implements Huffman Encoding and Decoding in Java, complete with a graphical user interface (GUI) to visualize the Huffman Tree, Huffman Codes, character frequencies, encoded text, and decoded text. The application also supports file upload and saving encoded and decoded text.
Features
- File Upload: Upload a text file to be encoded.
- Character Frequency Calculation: Analyze the uploaded text to calculate the frequency of each character.
- Huffman Tree Construction: Build a Huffman Tree based on the character frequencies.
- Huffman Code Generation: Generate Huffman codes for each character from the Huffman Tree.
- Encoding: Encode the text using the generated Huffman codes.
- Decoding: Decode the encoded text back to its original form using the Huffman Tree.
- File Saving: Save the encoded text, Huffman codes, and decoded text to files.
- Graphical Display: Display the character frequencies, Huffman Tree, Huffman codes, encoded text, and decoded text in a GUI.
How It Works
-
FileUploader: Provides functionality to select and upload a text file. -
TextAnalyzer: Analyzes the uploaded text to calculate character frequencies. -
HuffmanNode: Represents a node in the Huffman Tree. -
HuffmanTreeBuilder: Builds the Huffman Tree from the character frequencies. -
HuffmanCode: Generates Huffman codes from the Huffman Tree and encodes the text. -
HuffmanDecoder: Decodes the encoded text back to the original text using the Huffman Tree. -
FileSaver: Saves the encoded text, Huffman codes, and decoded text to files. -
GUI Components: Various panels (HuffmanTreePanel, HuffmanTablePanel, EncodedTextPanel, FrequencyPanel, DecodedTextPanel) to display the data.
Getting Started
Prerequisites
Java Development Kit (JDK) 8 or higher
Installing
Clone the repository:
git clone https://github.com/yourusername/huffman-encoding.git
cd huffman-encoding
Open the project in your IDE and build it.
Usage
- Run the
HuffmanEncodingApplication
main class. - Upload a text file when prompted.
- The application will display the character frequencies, Huffman Tree, Huffman codes, encoded text, and decoded text in separate tabs.
- Save the encoded text, Huffman codes, and decoded text using the file save options.
Javac HuffmanEncodingApplication.java
Java HuffmanEncodingApplication
Classes and Methods
FileUploader
-
uploadFile()
: Opens a file chooser to select a text file. -
readFile(File file)
: Reads the contents of a file and returns it as a string.
TextAnalyzer
-
analyzeText(String text)
: Analyzes the text to calculate character frequencies.
HuffmanNode
Represents a node in the Huffman Tree.
HuffmanTreeBuilder
-
buildTree(Map<Character, Integer> frequencyMap)
: Builds the Huffman Tree from the character frequencies.
HuffmanCode
-
generateCodes(HuffmanNode root)
: Generates Huffman codes from the Huffman Tree. -
encodeText(String text, Map<Character, String> huffmanCodes)
: Encodes the text using the Huffman codes.
HuffmanDecoder
-
decodeText(String encodedText, HuffmanNode root)
: Decodes the encoded text back to the original text using the Huffman Tree.
FileSaver
-
saveEncodedText(String encodedText)
: Saves the encoded text to a file. -
saveHuffmanCodes(Map<Character, String> huffmanCodes)
: Saves the Huffman codes to a file. -
saveDecodedText(String decodedText)
: Saves the decoded text to a file.
GUI Components
-
FrequencyPanel
: Displays character frequencies. -
HuffmanTreePanel
: Displays the Huffman Tree. -
HuffmanTablePanel
: Displays Huffman codes. -
EncodedTextPanel
: Displays the encoded text. -
DecodedTextPanel
: Displays the decoded text.
Contributing
Contributions are welcome! If you have suggestions for improvements, please submit a pull request or open an issue.
Made with ❤️ by FARZINzx