View Javadoc
1   package edu.jiangxin.apktoolbox.convert.protobuf.unsupervised;
2   
3   import edu.jiangxin.apktoolbox.swing.extend.EasyPanel;
4   import edu.jiangxin.apktoolbox.utils.Constants;
5   import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
6   import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
7   import org.fife.ui.rtextarea.RTextScrollPane;
8   
9   import javax.swing.*;
10  import java.awt.*;
11  import java.io.Serial;
12  
13  public class UnsupervisedProtobufConvertPanel extends EasyPanel {
14      @Serial
15      private static final long serialVersionUID = 1L;
16  
17      private JPanel contentPanel;
18  
19      private JPanel operationPanel;
20  
21      private JTextArea inputTextArea;
22      private RSyntaxTextArea outputTextArea;
23  
24      @Override
25      public void initUI() {
26          BoxLayout boxLayout = new BoxLayout(this, BoxLayout.Y_AXIS);
27          setLayout(boxLayout);
28  
29          createContentPanel();
30          add(contentPanel);
31          add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
32  
33          createOperationPanel();
34          add(operationPanel);
35      }
36  
37      private void createContentPanel() {
38          contentPanel = new JPanel();
39  
40          BoxLayout boxLayout = new BoxLayout(contentPanel, BoxLayout.X_AXIS);
41          contentPanel.setLayout(boxLayout);
42  
43          inputTextArea = new JTextArea();
44          inputTextArea.setLineWrap(true);
45          inputTextArea.setWrapStyleWord(true);
46          inputTextArea.setText("0a2f0a084a6f686e20446f6510011a106a6f686e406578616d706c652e636f6d220f0a0b3131312d3232322d33333310010a1e0a084a616e6520446f6510021a106a616e65406578616d706c652e636f6d");
47  
48          JScrollPane inputScrollPanel = new JScrollPane(inputTextArea);
49          inputScrollPanel.setPreferredSize(new Dimension(200, 500));
50  
51          outputTextArea = new RSyntaxTextArea();
52          outputTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
53          outputTextArea.setCodeFoldingEnabled(true);
54          outputTextArea.setEditable(false);
55  
56          RTextScrollPane outputScrollPane = new RTextScrollPane(outputTextArea);
57          outputScrollPane.setPreferredSize(new Dimension(200, 500));
58  
59          contentPanel.add(inputScrollPanel);
60          contentPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
61          contentPanel.add(outputScrollPane);
62      }
63  
64      private void createOperationPanel() {
65          operationPanel = new JPanel();
66  
67          BoxLayout boxLayout = new BoxLayout(operationPanel, BoxLayout.X_AXIS);
68          operationPanel.setLayout(boxLayout);
69  
70          JButton convertButton = new JButton("Convert");
71  
72          convertButton.addActionListener(e -> convertProtoToJson());
73  
74          operationPanel.add(convertButton);
75      }
76  
77      private void convertProtoToJson() {
78          String hexString = inputTextArea.getText();
79          byte[] byteArray = ByteUtil.hex2bytes(hexString);
80          String jsonString = ProtobufDecoder.bytesDecoder(byteArray);
81          outputTextArea.setText(jsonString);
82      }
83  }