-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.java
More file actions
59 lines (54 loc) · 2.32 KB
/
Controller.java
File metadata and controls
59 lines (54 loc) · 2.32 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
package sample;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import java.util.ArrayList;
public class Controller {
@FXML
TextField txt1 = new TextField();
@FXML
TextField txt2 = new TextField();
@FXML
Label lbl2 = new Label();
@FXML
Label lbl3 = new Label();
@FXML
void compress()
{
RunLengthEncoding obj = new RunLengthEncoding();
String inputStream = txt1.getText();
obj.setInputStream(inputStream);
obj.generateTags();
System.out.println("Input Stream: ");
System.out.println(inputStream);
System.out.println("------------------------------------------------------");
System.out.println("Tags: ");
System.out.println(obj.getTags());
System.out.println("------------------------------------------------------");
System.out.println("Huffman table: ");
obj.generateHuffmanTable();
ArrayList<HuffmanNode> list=obj.getHuffmanTable();
for (int i = 0; i <list.size() ; i++) {
System.out.println(list.get(i).getTag()+" "+list.get(i).getProbability());
}
System.out.println("------------------------------------------------------");
System.out.println("Tags with its huffman codes: ");
obj.HuffmanCompression();
ArrayList<HuffmanNode>list2=obj.getHuffmanTable();
for (int i = 0; i <list2.size() ; i++) {
System.out.println(list2.get(i).getTag()+" "+list2.get(i).getCode());
}
System.out.println("------------------------------------------------------");
obj.generateCompressedStream();
String x = obj.getCompressedStream();
System.out.println("Compressed stream: ");
System.out.println(obj.getCompressedStream());
lbl2.setText("Compressed Stream: "+obj.getCompressedStream());
System.out.println("------------------------------------------------------");
System.out.println("Decompressed stream: ");
String decompressedStream = obj.decompress();
System.out.println(decompressedStream);
lbl3.setText("Decompressed Stream: "+decompressedStream);
System.out.println("------------------------------------------------------");
}
}