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

jiangxincode / ApkToolBoxGUI / #1297

15 Nov 2025 12:02PM UTC coverage: 2.795% (-0.03%) from 2.821%
#1297

push

jiangxincode
[Function Add]add ascii viewer

0 of 82 new or added lines in 2 files covered. (0.0%)

248 of 8873 relevant lines covered (2.79%)

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/convert/encoding/AsciiGbViewerPanel.java
1
package edu.jiangxin.apktoolbox.convert.encoding;
2

3
import edu.jiangxin.apktoolbox.swing.extend.EasyPanel;
4
import edu.jiangxin.apktoolbox.utils.Constants;
5

6
import javax.swing.*;
7
import javax.swing.border.TitledBorder;
8
import javax.swing.event.DocumentListener;
9
import java.awt.*;
10
import java.io.UnsupportedEncodingException;
11

12
public class AsciiGbViewerPanel extends EasyPanel {
13

14
    private JTextField inputField;
15
    private JTextArea hexArea;
16
    private JTextArea decArea;
17

NEW
18
    private static final String[] ASCII_NAMES = new String[128];
×
19

20
    static {
NEW
21
        for (int i = 0; i < 32; i++) {               // 控制字符
×
NEW
22
            ASCII_NAMES[i] = String.format("%-3s", getControlName(i));
×
23
        }
NEW
24
        ASCII_NAMES[32] = "SP";                        // 空格
×
NEW
25
        for (int i = 33; i < 127; i++) {               // 可见字符
×
NEW
26
            ASCII_NAMES[i] = String.valueOf((char) i);
×
27
        }
NEW
28
        ASCII_NAMES[127] = "DEL";                      // 删除
×
NEW
29
    }
×
30

31
    public AsciiGbViewerPanel() {
NEW
32
        super();
×
NEW
33
    }
×
34

35
    @Override
36
    public void initUI() {
NEW
37
        buildUI();
×
NEW
38
        refreshGb();
×
NEW
39
    }
×
40

41
    private static String getControlName(int c) {
NEW
42
        String[] n = {"NUL","SOH","STX","ETX","EOT","ENQ","ACK","BEL","BS","HT","LF","VT","FF","CR","SO","SI",
×
43
                "DLE","DC1","DC2","DC3","DC4","NAK","SYN","ETB","CAN","EM","SUB","ESC","FS","GS","RS","US"};
NEW
44
        return n[c];
×
45
    }
46

47
    private void buildUI() {
NEW
48
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
×
49

NEW
50
        createInputPanel();
×
NEW
51
        add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
52

NEW
53
        createHexPanel();
×
NEW
54
        add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
55

NEW
56
        createDecPanel();
×
NEW
57
        add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
58

NEW
59
        createAsciiTablePanel();
×
NEW
60
    }
×
61

62
    private void createInputPanel() {
NEW
63
        JPanel inputPanel = new JPanel();
×
NEW
64
        inputPanel.setLayout(new BorderLayout());
×
NEW
65
        inputPanel.setBorder(BorderFactory.createTitledBorder("输入汉字"));
×
66

NEW
67
        inputField = new JTextField("欢迎使用ApkToolBoxGUI", 20);
×
NEW
68
        inputField.getDocument().addDocumentListener(new MyDocumentListener());
×
69

NEW
70
        inputPanel.add(inputField);
×
NEW
71
        add(inputPanel);
×
NEW
72
    }
×
73

74
    private void createHexPanel() {
NEW
75
        JPanel hexPanel = new JPanel();
×
NEW
76
        hexPanel.setLayout(new BorderLayout());
×
NEW
77
        hexPanel.setBorder(BorderFactory.createTitledBorder("16进制表示(GB2312 编码)"));
×
78

NEW
79
        hexArea = new JTextArea(6, 18);
×
NEW
80
        hexArea.setEditable(false);
×
NEW
81
        hexArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));
×
82

NEW
83
        hexPanel.add(new JScrollPane(hexArea));
×
NEW
84
        add(hexPanel);
×
NEW
85
    }
×
86

87
    private void createDecPanel() {
NEW
88
        JPanel decPanel = new JPanel();
×
NEW
89
        decPanel.setLayout(new BorderLayout());
×
NEW
90
        decPanel.setBorder(BorderFactory.createTitledBorder("10进制表示(GB2312 编码)"));
×
91

NEW
92
        decArea = new JTextArea(6, 18);
×
NEW
93
        decArea.setEditable(false);
×
NEW
94
        decArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));
×
95

NEW
96
        decPanel.add(new JScrollPane(decArea));
×
NEW
97
        add(decPanel);
×
NEW
98
    }
×
99

100
    private void createAsciiTablePanel() {
NEW
101
        JPanel asciiTablePanel = new JPanel(new GridLayout(16, 8, 2, 2));
×
NEW
102
        asciiTablePanel.setBorder(new TitledBorder("标准 7-bit ASCII 表(128 字符),鼠标悬停可查看十/十六进制值"));
×
NEW
103
        asciiTablePanel.setPreferredSize(new Dimension(500, 400));
×
104

NEW
105
        for (int i = 0; i < 128; i++) {
×
NEW
106
            JLabel lab = new JLabel(ASCII_NAMES[i], SwingConstants.CENTER);
×
NEW
107
            lab.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
×
NEW
108
            lab.setToolTipText("Dec=" + i + "  Hex=0x" + Integer.toHexString(i).toUpperCase());
×
NEW
109
            asciiTablePanel.add(lab);
×
110
        }
111

NEW
112
        add(asciiTablePanel);
×
NEW
113
    }
×
114

NEW
115
    class MyDocumentListener implements DocumentListener {
×
NEW
116
        public void insertUpdate(javax.swing.event.DocumentEvent e) { refreshGb(); }
×
NEW
117
        public void removeUpdate(javax.swing.event.DocumentEvent e) { refreshGb(); }
×
NEW
118
        public void changedUpdate(javax.swing.event.DocumentEvent e) { refreshGb(); }
×
119
    }
120

121
    private void refreshGb() {
NEW
122
        String txt = inputField.getText();
×
NEW
123
        StringBuilder hex = new StringBuilder();
×
NEW
124
        StringBuilder dec = new StringBuilder();
×
125
        try {
NEW
126
            byte[] gb = txt.getBytes("GB2312");
×
NEW
127
            for (byte value : gb) {
×
NEW
128
                int b = value & 0xff; // 无符号
×
NEW
129
                hex.append(String.format("%02X ", b));
×
NEW
130
                dec.append(b).append(' ');
×
131
            }
NEW
132
        } catch (UnsupportedEncodingException ex) {
×
NEW
133
            hex.append("GB2312 不支持");
×
NEW
134
            dec.append("GB2312 不支持");
×
NEW
135
        }
×
NEW
136
        hexArea.setText(hex.toString());
×
NEW
137
        decArea.setText(dec.toString());
×
NEW
138
    }
×
139
}
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

© 2025 Coveralls, Inc