-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHuffmanGUI.java
208 lines (179 loc) · 7.47 KB
/
HuffmanGUI.java
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import java.awt.EventQueue;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.Font;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.JFileChooser;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.ImageIcon;
import java.awt.Desktop;
import java.net.URI;
import java.net.URISyntaxException;
public class HuffmanGUI extends JFrame {
StringBuilder sb = new StringBuilder();
private JPanel contentPane;
public HuffmanGUI(String[][] arr, String stringEncoded, String stringDecoded, double el, double sl, double r) {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 823, 689);
setExtendedState(JFrame.MAXIMIZED_BOTH);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JPanel panel = new JPanel();
panel.setBackground(Color.BLACK);
contentPane.add(panel, BorderLayout.CENTER);
panel.setLayout(null);
JLabel lblChooseInputFile = new JLabel("Select the Input File(.txt)");
lblChooseInputFile.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblChooseInputFile.setForeground(Color.WHITE);
lblChooseInputFile.setBounds(134, 150, 200, 34);
panel.add(lblChooseInputFile);
JButton btnNewButton = new JButton("Open");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(panel);
File f = chooser.getSelectedFile();
try (BufferedReader in = new BufferedReader(new FileReader(f))) {
String line = in.readLine();
while (line != null) {
sb.append(line + "");
line = in.readLine();
}
Desktop d = Desktop.getDesktop();
Runtime.getRuntime().exec("dot -Tpng outputDescriptionFile.dot -o finalOutputHuffmanTree.png");
String filePath = "finalOutputHuffmanTree.png";
File file = new File(filePath);
URI uri = file.toURI();
try {
d.browse(new URI(uri.toString()));
} catch (URISyntaxException r) {
}
} catch (IOException e) {
System.out.println(e);
}
String dotFile = "./outputDescriptionFile.dot";
HuffManDisplay h = new HuffManDisplay(sb.toString(), dotFile);
h.DisplayHuffman();
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
HuffmanGUI frame = new HuffmanGUI(h.DataArray, h.encodedString, h.DecodedString,h.sizeAfterCoding, h.sizeForGivenString, h.reductionPercentage);
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
});
btnNewButton.setBounds(281, 200, 137, 34);
panel.add(btnNewButton);
JLabel lblOutput = new JLabel("OUTPUT");
lblOutput.setForeground(Color.WHITE);
lblOutput.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblOutput.setBounds(33, 260, 64, 34);
panel.add(lblOutput);
JLabel lblInput = new JLabel("INPUT");
lblInput.setForeground(Color.WHITE);
lblInput.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblInput.setBounds(33, 110, 64, 34);
panel.add(lblInput);
String[] names = { "Letter", "Frequency", "Code" };
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(200, 310, 347, 95);
panel.add(scrollPane);
JTable table = new JTable(arr, names);
table.setShowGrid(false);
scrollPane.setViewportView(table);
table.setBackground(Color.ORANGE);
table.setFillsViewportHeight(true);
JSeparator separator = new JSeparator();
separator.setBounds(10, 470, 1500, 16);
panel.add(separator);
JSeparator separator_1 = new JSeparator();
separator_1.setBounds(10, 250, 1500, 16);
panel.add(separator_1);
JLabel lSize = new JLabel("SIZE");
lSize.setForeground(Color.WHITE);
lSize.setFont(new Font("Tahoma", Font.PLAIN, 14));
lSize.setBounds(33, 482, 64, 34);
panel.add(lSize);
JLabel lSizeOfOriginalString = new JLabel("Inputted String Size : ");
lSizeOfOriginalString.setForeground(Color.WHITE);
lSizeOfOriginalString.setFont(new Font("Tahoma", Font.PLAIN, 12));
lSizeOfOriginalString.setBounds(111, 514, 137, 28);
panel.add(lSizeOfOriginalString);
JLabel lSizeOfCodedString = new JLabel("Encoded String Size : ");
lSizeOfCodedString.setForeground(Color.WHITE);
lSizeOfCodedString.setFont(new Font("Tahoma", Font.PLAIN, 12));
lSizeOfCodedString.setBounds(111, 546, 140, 28);
panel.add(lSizeOfCodedString);
JLabel lReduction = new JLabel("Reduction % :");
lReduction.setForeground(Color.WHITE);
lReduction.setFont(new Font("Tahoma", Font.PLAIN, 12));
lReduction.setBounds(111, 576, 1307, 28);
panel.add(lReduction);
JLabel lTreeGeneration = new JLabel("Tree Generation : ");
lTreeGeneration.setForeground(Color.WHITE);
lTreeGeneration.setFont(new Font("Tahoma", Font.PLAIN, 12));
lTreeGeneration.setBounds(111, 607, 160, 28);
panel.add(lTreeGeneration);
JLabel lblNewLabel_1 = new JLabel("Huffman Encoding And Decoding");
JLabel lblNewLabel_2 = new JLabel("A Project By Jithin John(AM.EN.U4AIE20135) and N Moneesh(AM.EN.U4AIE20150)");
//lblNewLabel_1.setIcon(new ImageIcon("/home/Downloads/83648898.jpeg"));
lblNewLabel_1.setForeground(Color.WHITE);
lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 30));
lblNewLabel_1.setBounds(430, 11, 1000, 70);
lblNewLabel_2.setIcon(new ImageIcon("../"));
lblNewLabel_2.setForeground(Color.WHITE);
lblNewLabel_2.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 20));
lblNewLabel_2.setBounds(250, 650, 1000, 70);
panel.add(lblNewLabel_1);
panel.add(lblNewLabel_2);
JLabel lblVariable = new JLabel(Integer.toString((int) sl));
lblVariable.setForeground(Color.WHITE);
lblVariable.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblVariable.setBounds(247, 514, 137, 28);
panel.add(lblVariable);
JLabel lblVariablee = new JLabel(Integer.toString((int) el));
lblVariablee.setForeground(Color.WHITE);
lblVariablee.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblVariablee.setBounds(247, 546, 92, 28);
panel.add(lblVariablee);
JLabel lReductionValue = new JLabel(Integer.toString((int) r) + " %");
lReductionValue.setForeground(Color.WHITE);
lReductionValue.setFont(new Font("Tahoma", Font.PLAIN, 12));
lReductionValue.setBounds(247, 576, 92, 28);
panel.add(lReductionValue);
JLabel lblDone = new JLabel("Done");
lblDone.setForeground(Color.WHITE);
lblDone.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblDone.setBounds(247, 607, 92, 28);
panel.add(lblDone);
JLabel lEncodedSizeValue = new JLabel("Encoded String : " + stringEncoded);
lEncodedSizeValue.setForeground(Color.WHITE);
lEncodedSizeValue.setFont(new Font("Tahoma", Font.PLAIN, 12));
lEncodedSizeValue.setBounds(33, 415, 1370, 28);
panel.add(lEncodedSizeValue);
JLabel lOriginalSizeValue = new JLabel("Decoded String : " + stringDecoded);
lOriginalSizeValue.setForeground(Color.WHITE);
lOriginalSizeValue.setFont(new Font("Tahoma", Font.PLAIN, 12));
lOriginalSizeValue.setBounds(33, 436, 1370, 28);
panel.add(lOriginalSizeValue);
table.setVisible(true);
}
}