Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/main/java/core/packetproxy/gui/GUILog.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
Expand All @@ -43,7 +45,7 @@ public static GUILog getInstance() {
}

public GUILog() {
text = new JTextPane();
text = new PlainTextCopyTextPane();
text.setEditable(false);
scrollPane = new JScrollPane(text);
scrollPane.getVerticalScrollBar().setUnitIncrement(16);
Expand All @@ -61,7 +63,7 @@ public void append(String s) {

synchronized (thread_lock) {
StyledDocument doc = text.getStyledDocument();
doc.insertString(doc.getLength(), s + "\n\r", null);
doc.insertString(doc.getLength(), s + "\n", null);
}
} catch (BadLocationException ex) {

Expand All @@ -76,10 +78,28 @@ public void appendErr(String s) {
StyleConstants.setBackground(keyWord, new Color(240, 150, 150));
StyleConstants.setBold(keyWord, true);
StyledDocument doc = text.getStyledDocument();
doc.insertString(doc.getLength() - 1, s + "\n", keyWord);
doc.insertString(doc.getLength(), s + "\n", keyWord);
}
} catch (BadLocationException ex) {

}
}

private static class PlainTextCopyTextPane extends JTextPane {

private static final long serialVersionUID = -7625487841725414375L;

@Override
public void copy() {
var selected = getSelectedText();
if (selected == null || selected.isEmpty()) {
super.copy();
return;
}

var clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
var selection = new StringSelection(selected);
clipboard.setContents(selection, selection);
}
}
}
Loading