mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-23 06:42:05 +01:00
Enhancements for the enhanced debugger
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@3411 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
892512c596
commit
9acdd912d9
2 changed files with 62 additions and 38 deletions
|
@ -34,6 +34,7 @@ import javax.swing.*;
|
|||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.xml.transform.*;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
@ -221,10 +222,8 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
}
|
||||
|
||||
private void addBasicPanels() {
|
||||
JPanel allPane = new JPanel();
|
||||
allPane.setLayout(new GridLayout(2, 1));
|
||||
tabbedPane.add("All Packets", allPane);
|
||||
tabbedPane.setToolTipTextAt(0, "Sent and received packets processed by Smack");
|
||||
JSplitPane allPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
|
||||
allPane.setOneTouchExpandable(true);
|
||||
|
||||
messagesTable =
|
||||
new DefaultTableModel(
|
||||
|
@ -275,7 +274,7 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
SelectionListener selectionListener = new SelectionListener(table);
|
||||
table.getSelectionModel().addListSelectionListener(selectionListener);
|
||||
table.getColumnModel().getSelectionModel().addListSelectionListener(selectionListener);
|
||||
allPane.add(new JScrollPane(table));
|
||||
allPane.setTopComponent(new JScrollPane(table));
|
||||
messageTextArea = new JTextArea();
|
||||
messageTextArea.setEditable(false);
|
||||
// Add pop-up menu.
|
||||
|
@ -292,10 +291,16 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
menu.add(menuItem1);
|
||||
// Add listener to the text area so the popup menu can come up.
|
||||
messageTextArea.addMouseListener(new PopupListener(menu));
|
||||
allPane.add(new JScrollPane(messageTextArea));
|
||||
allPane.setBottomComponent(new JScrollPane(messageTextArea));
|
||||
allPane.setDividerLocation(150);
|
||||
|
||||
tabbedPane.add("All Packets", allPane);
|
||||
tabbedPane.setToolTipTextAt(0, "Sent and received packets processed by Smack");
|
||||
|
||||
// Create UI elements for client generated XML traffic.
|
||||
final JTextArea sentText = new JTextArea();
|
||||
sentText.setWrapStyleWord(true);
|
||||
sentText.setLineWrap(true);
|
||||
sentText.setEditable(false);
|
||||
sentText.setForeground(new Color(112, 3, 3));
|
||||
tabbedPane.add("Raw Sent Packets", new JScrollPane(sentText));
|
||||
|
@ -327,6 +332,8 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
|
||||
// Create UI elements for server generated XML traffic.
|
||||
final JTextArea receivedText = new JTextArea();
|
||||
receivedText.setWrapStyleWord(true);
|
||||
receivedText.setLineWrap(true);
|
||||
receivedText.setEditable(false);
|
||||
receivedText.setForeground(new Color(6, 76, 133));
|
||||
tabbedPane.add("Raw Received Packets", new JScrollPane(receivedText));
|
||||
|
@ -361,7 +368,9 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
// Create a special Reader that wraps the main Reader and logs data to the GUI.
|
||||
ObservableReader debugReader = new ObservableReader(reader);
|
||||
readerListener = new ReaderListener() {
|
||||
public void read(String str) {
|
||||
public void read(final String str) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER &&
|
||||
!EnhancedDebuggerWindow.getInstance().isVisible()) {
|
||||
// Do not add content if the parent is not visible
|
||||
|
@ -370,6 +379,15 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
|
||||
int index = str.lastIndexOf(">");
|
||||
if (index != -1) {
|
||||
if (receivedText.getLineCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS)
|
||||
{
|
||||
try {
|
||||
receivedText.replaceRange("", 0, receivedText.getLineEndOffset(0));
|
||||
}
|
||||
catch (BadLocationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
receivedText.append(str.substring(0, index + 1));
|
||||
receivedText.append(NEWLINE);
|
||||
if (str.length() > index) {
|
||||
|
@ -380,6 +398,8 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
receivedText.append(str);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
debugReader.addReaderListener(readerListener);
|
||||
|
||||
|
@ -395,6 +415,15 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
return;
|
||||
}
|
||||
|
||||
if (sentText.getLineCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
|
||||
try {
|
||||
sentText.replaceRange("", 0, sentText.getLineEndOffset(0));
|
||||
}
|
||||
catch (BadLocationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
sentText.append(str);
|
||||
if (str.endsWith(">")) {
|
||||
sentText.append(NEWLINE);
|
||||
|
@ -720,12 +749,10 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
}
|
||||
|
||||
// Check if we need to remove old rows from the table to keep memory consumption low
|
||||
if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER) {
|
||||
if (EnhancedDebuggerWindow.MAX_TABLE_ROWS > 0 &&
|
||||
messagesTable.getRowCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
|
||||
messagesTable.removeRow(0);
|
||||
}
|
||||
}
|
||||
|
||||
messagesTable.addRow(
|
||||
new Object[]{
|
||||
|
@ -783,12 +810,10 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
}
|
||||
|
||||
// Check if we need to remove old rows from the table to keep memory consumption low
|
||||
if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER) {
|
||||
if (EnhancedDebuggerWindow.MAX_TABLE_ROWS > 0 &&
|
||||
messagesTable.getRowCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
|
||||
messagesTable.removeRow(0);
|
||||
}
|
||||
}
|
||||
|
||||
messagesTable.addRow(
|
||||
new Object[]{
|
||||
|
|
|
@ -54,12 +54,11 @@ public class EnhancedDebuggerWindow {
|
|||
public static boolean PERSISTED_DEBUGGER = false;
|
||||
/**
|
||||
* Keeps the max number of rows to keep in the tables. A value less than 0 means that packets
|
||||
* will never be removed. Since debuggers are meant to be used by developers the default is
|
||||
* to keep all the information. However, if you are planning to use this debugger in a
|
||||
* will never be removed. If you are planning to use this debugger in a
|
||||
* production environment then you should set a lower value (e.g. 50) to prevent the debugger
|
||||
* from consuming all the JVM memory.
|
||||
*/
|
||||
public static int MAX_TABLE_ROWS = -1;
|
||||
public static int MAX_TABLE_ROWS = 150;
|
||||
|
||||
{
|
||||
URL url;
|
||||
|
|
Loading…
Reference in a new issue