Skip to content

Commit

Permalink
TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
bit4woo committed May 13, 2024
1 parent efb188a commit 31085d3
Show file tree
Hide file tree
Showing 5 changed files with 599 additions and 12 deletions.
91 changes: 91 additions & 0 deletions src/messageTab/Info/InfoEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package messageTab.Info;

import com.google.gson.Gson;

public class InfoEntry {

private String value = "";
private String type = "";
private boolean enable = true;
private boolean editable = true;//whether you can edit name and type
private String comment = "";

public static final String Type_URL ="Type_URL";
public static final String Type_Email ="Type_Email";

public InfoEntry() {
//to resolve "default constructor not found" error
}

public InfoEntry(String value, String type, boolean enable) {
this.value = value;
this.type = type;
this.enable = enable;
}

public InfoEntry(String value, String type, boolean enable, boolean editable) {
this.value = value;
this.type = type;
this.enable = enable;
this.editable = editable;
}

public InfoEntry(String value, String type, boolean enable, boolean editable, String comment) {
this.value = value;
this.type = type;
this.enable = enable;
this.editable = editable;
this.comment = comment;
}



public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public boolean isEnable() {
return enable;
}

public void setEnable(boolean enable) {
this.enable = enable;
}

public boolean isEditable() {
return editable;
}

public void setEditable(boolean editable) {
this.editable = editable;
}

public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}

public String ToJson() {//注意函数名称,如果是get set开头,会被认为是Getter和Setter函数,会在序列化过程中被调用。
return new Gson().toJson(this);
}

public InfoEntry FromJson(String json) {//注意函数名称,如果是get set开头,会被认为是Getter和Setter函数,会在序列化过程中被调用。
return new Gson().fromJson(json, InfoEntry.class);
}

}
156 changes: 156 additions & 0 deletions src/messageTab/Info/InfoPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
package messageTab.Info;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

public class InfoPanel extends JPanel {

private final JTextField searchField;
private final JLabel statusLabel = new JLabel(" 0 matches");
boolean isRequest;
private final JComponent parent;


InfoPanel(JComponent parent) {

this.parent = parent;
setBorder(new EmptyBorder(5, 5, 5, 5));
setLayout(new BorderLayout(0, 0));

JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
add(buttonPanel, BorderLayout.NORTH);

InfoTableModel model = new InfoTableModel();
InfoTable table = new InfoTable(model);
JScrollPane scrollPane = new JScrollPane();
scrollPane.add(table);
add(scrollPane, BorderLayout.CENTER);



JPanel footPanel = new JPanel(new BorderLayout());
searchField = new JTextField();
Timer searchTimer = createSearchTimer();
searchField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
searchTimer.restart();
}

@Override
public void removeUpdate(DocumentEvent e) {
searchTimer.restart();
}

@Override
public void changedUpdate(DocumentEvent e) {
searchTimer.restart();
}
});

JButton leftButton = new JButton("<");
leftButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
JButton rightButton = new JButton(">");
rightButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
JPanel panelA = new JPanel();
panelA.add(leftButton);
panelA.add(rightButton);

footPanel.add(panelA, BorderLayout.WEST);
footPanel.add(searchField, BorderLayout.CENTER);

footPanel.add(statusLabel, BorderLayout.EAST);

add(footPanel, BorderLayout.SOUTH);
}


private Timer createSearchTimer() {
Timer searchTimer = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// 执行搜索操作
String searchTerm = searchField.getText();
//search(searchTerm, false, false);
}
});
searchTimer.setRepeats(false); // 设置计时器只执行一次
return searchTimer;
}
/*
private void search(String searchTerm, boolean isRegex, boolean isCaseSensitive) {
if (searchTerm.isEmpty()) {
return;
}
int flags = 0;
if (!isCaseSensitive) {
flags |= Pattern.CASE_INSENSITIVE;
}
Pattern pattern;
if (isRegex) {
pattern = Pattern.compile(searchTerm, flags);
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
int start = matcher.start();
int end = matcher.end();
try {
highlighter.addHighlight(start, end, new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW));
} catch (BadLocationException ex) {
ex.printStackTrace();
}
}
} else {
int index = text.indexOf(searchTerm);
while (index != -1) {
try {
textArea.getHighlighter().addHighlight(index, index + searchTerm.length(), new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW));
index = text.indexOf(searchTerm, index + searchTerm.length()); // 继续搜索下一个匹配项
} catch (BadLocationException ex) {
ex.printStackTrace();
}
}
}
int num = textArea.getHighlighter().getHighlights().length;
statusLabel.setText(" " + num + " matches");
}*/



public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame jf = new JFrame();
InfoPanel panel = new InfoPanel(null);
jf.setContentPane(panel);
jf.setVisible(true);
jf.pack();
}
});
}
}
12 changes: 0 additions & 12 deletions src/messageTab/Info/InfoTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,7 @@ public byte[] getSelectedData()
return null;//TODO
}

public static boolean isJSON(byte[] content,boolean isRequest) {
if (isRequest) {
IRequestInfo requestInfo = helpers.analyzeRequest(content);
return requestInfo.getContentType() == IRequestInfo.CONTENT_TYPE_JSON;
} else {
IResponseInfo responseInfo = helpers.analyzeResponse(content);
return responseInfo.getInferredMimeType().equals("JSON");
}
}


public static void main(String[] args) {
String aaa = "STK_7411642209636022({\"errno\":1003,\"errmsg\":\"\\u7528\\u6237\\u672a\\u767b\\u5f55\",\"errmsg_lang\":{\"zh\":\"\\u7528\\u6237\\u672a\\u767b\\u5f55\",\"en\":\"User is not logged in.\",\"zh-HK\":\"\\u7528\\u6236\\u672a\\u767b\\u9304\"},\"data\":null});";
System.out.println(StringEscapeUtils.unescapeJava(aaa));
}
}
Loading

0 comments on commit 31085d3

Please sign in to comment.