Limited number of rows to show in the table and append text to text area (raw tabs) only when visible. SMACK-95

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2977 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2005-10-18 19:04:12 +00:00 committed by gato
parent 52eb5a1049
commit 581c07eff7
1 changed files with 120 additions and 84 deletions

View File

@ -326,6 +326,12 @@ public class EnhancedDebugger implements SmackDebugger {
ObservableReader debugReader = new ObservableReader(reader);
readerListener = new ReaderListener() {
public void read(String str) {
if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER &&
!EnhancedDebuggerWindow.getInstance().isVisible()) {
// Do not add content if the parent is not visible
return;
}
int index = str.lastIndexOf(">");
if (index != -1) {
receivedText.append(str.substring(0, index + 1));
@ -345,6 +351,12 @@ public class EnhancedDebugger implements SmackDebugger {
ObservableWriter debugWriter = new ObservableWriter(writer);
writerListener = new WriterListener() {
public void write(String str) {
if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER &&
!EnhancedDebuggerWindow.getInstance().isVisible()) {
// Do not add content if the parent is not visible
return;
}
sentText.append(str);
if (str.endsWith(">")) {
sentText.append(NEWLINE);
@ -627,7 +639,9 @@ public class EnhancedDebugger implements SmackDebugger {
* @param dateFormatter the SimpleDateFormat to use to format Dates
* @param packet the read packet to add to the table
*/
private void addReadPacketToTable(SimpleDateFormat dateFormatter, Packet packet) {
private void addReadPacketToTable(final SimpleDateFormat dateFormatter, final Packet packet) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
String messageType = null;
String from = packet.getFrom();
String type = "";
@ -657,6 +671,14 @@ public class EnhancedDebugger implements SmackDebugger {
receivedOtherPackets++;
}
// 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[] {
formatXML(packet.toXML()),
@ -671,6 +693,8 @@ public class EnhancedDebugger implements SmackDebugger {
// Update the statistics table
updateStatistics();
}
});
}
/**
* Adds the sent packet detail to the messages table.
@ -678,7 +702,9 @@ public class EnhancedDebugger implements SmackDebugger {
* @param dateFormatter the SimpleDateFormat to use to format Dates
* @param packet the sent packet to add to the table
*/
private void addSentPacketToTable(SimpleDateFormat dateFormatter, Packet packet) {
private void addSentPacketToTable(final SimpleDateFormat dateFormatter, final Packet packet) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
String messageType = null;
String to = packet.getTo();
String type = "";
@ -708,6 +734,14 @@ public class EnhancedDebugger implements SmackDebugger {
sentOtherPackets++;
}
// 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[] {
formatXML(packet.toXML()),
@ -723,6 +757,8 @@ public class EnhancedDebugger implements SmackDebugger {
// Update the statistics table
updateStatistics();
}
});
}
private String formatXML(String str) {
try {