• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jiangxincode / ApkToolBoxGUI / #734

19 May 2024 01:23PM UTC coverage: 3.151%. Remained the same
#734

push

jiangxincode
merge some menu to settings menu

0 of 127 new or added lines in 11 files covered. (0.0%)

229 existing lines in 9 files now uncovered.

236 of 7489 relevant lines covered (3.15%)

0.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/edu/jiangxin/apktoolbox/file/checksum/panel/StringHashPanel.java
1
package edu.jiangxin.apktoolbox.file.checksum.panel;
2

3
import edu.jiangxin.apktoolbox.file.checksum.CalculateType;
4
import edu.jiangxin.apktoolbox.swing.extend.EasyChildTabbedPanel;
5
import edu.jiangxin.apktoolbox.utils.Constants;
6
import org.apache.commons.codec.digest.DigestUtils;
7

8
import javax.swing.*;
9
import java.io.ByteArrayInputStream;
10
import java.io.IOException;
11
import java.nio.charset.StandardCharsets;
12
import java.util.zip.CRC32;
13

UNCOV
14
public class StringHashPanel extends EasyChildTabbedPanel {
×
15
    private static final long serialVersionUID = 63924900336217723L;
16

17
    private JPanel stringInputPanel;
18
    private JTextArea stringInputTextArea;
19

20
    private JPanel optionPanel;
21

22
    private JTextField stringLengthTextField;
23
    private JCheckBox md5CheckBox;
24
    private JTextField md5TextField;
25
    private JCheckBox sha1CheckBox;
26
    private JTextField sha1TextField;
27
    private JCheckBox sha256CheckBox;
28
    private JTextField sha256TextField;
29
    private JCheckBox sha384CheckBox;
30
    private JTextField sha384TextField;
31
    private JCheckBox sha512CheckBox;
32
    private JTextField sha512TextField;
33
    private JCheckBox crc32CheckBox;
34
    private JTextField crc32TextField;
35

36
    private JPanel operationPanel;
37
    private JProgressBar progressBar;
38

39
    @Override
40
    public void createUI() {
NEW
41
        BoxLayout boxLayout = new BoxLayout(this, BoxLayout.Y_AXIS);
×
NEW
42
        setLayout(boxLayout);
×
43

NEW
44
        add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
45
        createStringInputPanel();
×
NEW
46
        add(stringInputPanel);
×
47

NEW
48
        add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
49
        createOptionPanel();
×
NEW
50
        add(optionPanel);
×
51

NEW
52
        add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
53
        createOperationPanel();
×
NEW
54
        add(operationPanel);
×
55
    }
×
56

57
    private void createStringInputPanel() {
58
        stringInputPanel = new JPanel();
×
59
        BoxLayout boxLayout = new BoxLayout(stringInputPanel, BoxLayout.Y_AXIS);
×
60
        stringInputPanel.setLayout(boxLayout);
×
61

62
        JLabel stringInputLabel = new JLabel("Insert string to compute hash checksum:");
×
63
        stringInputTextArea = new JTextArea(5, 4);
×
64
        stringInputTextArea.setLineWrap(true);
×
65
        JScrollPane stringInputScrollPanel = new JScrollPane(stringInputTextArea);
×
66

UNCOV
67
        stringInputPanel.add(stringInputLabel);
×
68
        stringInputPanel.add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
69
        stringInputPanel.add(stringInputScrollPanel);
×
70
    }
×
71

72
    private void createOptionPanel() {
73
        optionPanel = new JPanel();
×
74
        BoxLayout boxLayout = new BoxLayout(optionPanel, BoxLayout.Y_AXIS);
×
75
        optionPanel.setLayout(boxLayout);
×
76

77
        JPanel stringLengthOptionPanel = new JPanel();
×
78
        JPanel md5OptionPanel = new JPanel();
×
UNCOV
79
        JPanel sha1OptionPanel = new JPanel();
×
80
        JPanel sha256OptionPanel = new JPanel();
×
81
        JPanel sha384OptionPanel = new JPanel();
×
82
        JPanel sha512OptionPanel = new JPanel();
×
83
        JPanel crc32OptionPanel = new JPanel();
×
84

85
        optionPanel.add(stringLengthOptionPanel);
×
86
        optionPanel.add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
87
        optionPanel.add(md5OptionPanel);
×
88
        optionPanel.add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
89
        optionPanel.add(sha1OptionPanel);
×
90
        optionPanel.add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
91
        optionPanel.add(sha256OptionPanel);
×
92
        optionPanel.add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
UNCOV
93
        optionPanel.add(sha384OptionPanel);
×
94
        optionPanel.add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
95
        optionPanel.add(sha512OptionPanel);
×
96
        optionPanel.add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
97
        optionPanel.add(crc32OptionPanel);
×
98

99
        stringLengthOptionPanel.setLayout(new BoxLayout(stringLengthOptionPanel, BoxLayout.X_AXIS));
×
UNCOV
100
        JLabel stringLengthLabel = new JLabel("String length:");
×
101
        stringLengthTextField = new JTextField();
×
102
        stringLengthOptionPanel.add(stringLengthLabel);
×
103
        stringLengthOptionPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
104
        stringLengthOptionPanel.add(stringLengthTextField);
×
105

106
        md5OptionPanel.setLayout(new BoxLayout(md5OptionPanel, BoxLayout.X_AXIS));
×
107
        md5CheckBox = new JCheckBox("MD5 checksum:");
×
UNCOV
108
        md5CheckBox.setSelected(true);
×
109
        md5TextField = new JTextField();
×
110
        md5OptionPanel.add(md5CheckBox);
×
111
        md5OptionPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
112
        md5OptionPanel.add(md5TextField);
×
113

114
        sha1OptionPanel.setLayout(new BoxLayout(sha1OptionPanel, BoxLayout.X_AXIS));
×
UNCOV
115
        sha1CheckBox = new JCheckBox("SHA1 checksum:");
×
116
        sha1TextField = new JTextField();
×
117
        sha1OptionPanel.add(sha1CheckBox);
×
118
        sha1OptionPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
119
        sha1OptionPanel.add(sha1TextField);
×
120

121
        sha256OptionPanel.setLayout(new BoxLayout(sha256OptionPanel, BoxLayout.X_AXIS));
×
UNCOV
122
        sha256CheckBox = new JCheckBox("SHA256 checksum:");
×
123
        sha256TextField = new JTextField();
×
124
        sha256OptionPanel.add(sha256CheckBox);
×
125
        sha256OptionPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
126
        sha256OptionPanel.add(sha256TextField);
×
127

128
        sha384OptionPanel.setLayout(new BoxLayout(sha384OptionPanel, BoxLayout.X_AXIS));
×
UNCOV
129
        sha384CheckBox = new JCheckBox("SHA384 checksum:");
×
130
        sha384TextField = new JTextField();
×
131
        sha384OptionPanel.add(sha384CheckBox);
×
132
        sha384OptionPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
133
        sha384OptionPanel.add(sha384TextField);
×
134

135
        sha512OptionPanel.setLayout(new BoxLayout(sha512OptionPanel, BoxLayout.X_AXIS));
×
UNCOV
136
        sha512CheckBox = new JCheckBox("SHA512 checksum:");
×
137
        sha512TextField = new JTextField();
×
138
        sha512OptionPanel.add(sha512CheckBox);
×
139
        sha512OptionPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
140
        sha512OptionPanel.add(sha512TextField);
×
141

142
        crc32OptionPanel.setLayout(new BoxLayout(crc32OptionPanel, BoxLayout.X_AXIS));
×
143
        crc32CheckBox = new JCheckBox("CRC32 checksum:");
×
UNCOV
144
        crc32TextField = new JTextField();
×
UNCOV
145
        crc32OptionPanel.add(crc32CheckBox);
×
146
        crc32OptionPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
UNCOV
147
        crc32OptionPanel.add(crc32TextField);
×
148
    }
×
149

150
    private void createOperationPanel() {
151
        operationPanel = new JPanel();
×
152

153
        JButton compareButton = new JButton("Compare");
×
154
        compareButton.setFocusPainted(false);
×
UNCOV
155
        compareButton.addActionListener(arg0 -> {
×
156
            String text = stringInputTextArea.getText();
×
157
            if (text == null) {
×
UNCOV
158
                logger.error("text is null");
×
159
                return;
×
160
            }
161
            calculate(text);
×
UNCOV
162
        });
×
163

164
        progressBar = new JProgressBar();
×
165
        progressBar.setStringPainted(true);
×
166
        progressBar.setMaximum(100);
×
167

168

169
        operationPanel.setLayout(new BoxLayout(operationPanel, BoxLayout.X_AXIS));
×
UNCOV
170
        operationPanel.add(compareButton);
×
UNCOV
171
        operationPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
172
        operationPanel.add(progressBar);
×
173

174
    }
×
175

176
    private void calculate(String text) {
UNCOV
177
        progressBar.setValue(0);
×
178
        new Thread(() -> {
×
179
            stringLengthTextField.setText(String.valueOf(text.length()));
×
180
            progressBar.setValue(progressBar.getValue() + 10);
×
UNCOV
181
        }).start();
×
182

UNCOV
183
        new Thread(() -> {
×
184
            if (md5CheckBox.isSelected()) {
×
185
                md5TextField.setText(calculate(CalculateType.Md5, text));
×
186
            } else {
187
                md5TextField.setText("");
×
188
            }
189
            progressBar.setValue(progressBar.getValue() + 15);
×
UNCOV
190
        }).start();
×
191

UNCOV
192
        new Thread(() -> {
×
193
            if (sha1CheckBox.isSelected()) {
×
194
                sha1TextField.setText(calculate(CalculateType.Sha1, text));
×
195
            } else {
196
                sha1TextField.setText("");
×
197
            }
198
            progressBar.setValue(progressBar.getValue() + 15);
×
UNCOV
199
        }).start();
×
200

UNCOV
201
        new Thread(() -> {
×
202
            if (sha256CheckBox.isSelected()) {
×
203
                sha256TextField.setText(calculate(CalculateType.Sha256, text));
×
204
            } else {
205
                sha256TextField.setText("");
×
206
            }
207
            progressBar.setValue(progressBar.getValue() + 15);
×
UNCOV
208
        }).start();
×
209

UNCOV
210
        new Thread(() -> {
×
211
            if (sha384CheckBox.isSelected()) {
×
212
                sha384TextField.setText(calculate(CalculateType.Sha384, text));
×
213
            } else {
214
                sha384TextField.setText("");
×
215
            }
216
            progressBar.setValue(progressBar.getValue() + 15);
×
UNCOV
217
        }).start();
×
218

UNCOV
219
        new Thread(() -> {
×
220
            if (sha512CheckBox.isSelected()) {
×
221
                sha512TextField.setText(calculate(CalculateType.Sha512, text));
×
222
            } else {
223
                sha512TextField.setText("");
×
224
            }
225
            progressBar.setValue(progressBar.getValue() + 15);
×
UNCOV
226
        }).start();
×
227

UNCOV
228
        new Thread(() -> {
×
229
            if (crc32CheckBox.isSelected()) {
×
230
                crc32TextField.setText(calculate(CalculateType.Crc32, text));
×
231
            } else {
UNCOV
232
                crc32TextField.setText("");
×
233
            }
234
            progressBar.setValue(progressBar.getValue() + 15);
×
235
        }).start();
×
236
    }
×
237

238
    private String calculate(final CalculateType selectedHash, final String text) {
239
        String result = "";
×
UNCOV
240
        try (ByteArrayInputStream bais = new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8))) {
×
UNCOV
241
            switch (selectedHash) {
×
242
                case Md5: {
243
                    result = DigestUtils.md5Hex(bais);
×
UNCOV
244
                    break;
×
245
                }
246
                case Sha1: {
247
                    result = DigestUtils.sha1Hex(bais);
×
UNCOV
248
                    break;
×
249
                }
250
                case Sha256: {
251
                    result = DigestUtils.sha256Hex(bais);
×
UNCOV
252
                    break;
×
253
                }
254
                case Sha384: {
255
                    result = DigestUtils.sha384Hex(bais);
×
UNCOV
256
                    break;
×
257
                }
258
                case Sha512: {
259
                    result = DigestUtils.sha512Hex(bais);
×
260
                    break;
×
261
                }
262
                case Crc32: {
UNCOV
263
                    CRC32 crc32 = new CRC32();
×
264
                    crc32.update(text.getBytes());
×
UNCOV
265
                    result = Long.toHexString(crc32.getValue());
×
UNCOV
266
                    break;
×
267
                }
268
                default: {
269
                    result = "Not support";
×
270
                    break;
271
                }
272
            }
UNCOV
273
        } catch (IOException e) {
×
UNCOV
274
            logger.error("calculate, IOException");
×
UNCOV
275
        }
×
UNCOV
276
        return result;
×
277
    }
278
}
279

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc