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); ObservableReader debugReader = new ObservableReader(reader);
readerListener = new ReaderListener() { readerListener = new ReaderListener() {
public void read(String str) { 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(">"); int index = str.lastIndexOf(">");
if (index != -1) { if (index != -1) {
receivedText.append(str.substring(0, index + 1)); receivedText.append(str.substring(0, index + 1));
@ -345,6 +351,12 @@ public class EnhancedDebugger implements SmackDebugger {
ObservableWriter debugWriter = new ObservableWriter(writer); ObservableWriter debugWriter = new ObservableWriter(writer);
writerListener = new WriterListener() { writerListener = new WriterListener() {
public void write(String str) { 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); sentText.append(str);
if (str.endsWith(">")) { if (str.endsWith(">")) {
sentText.append(NEWLINE); sentText.append(NEWLINE);
@ -627,49 +639,61 @@ public class EnhancedDebugger implements SmackDebugger {
* @param dateFormatter the SimpleDateFormat to use to format Dates * @param dateFormatter the SimpleDateFormat to use to format Dates
* @param packet the read packet to add to the table * @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) {
String messageType = null; SwingUtilities.invokeLater(new Runnable() {
String from = packet.getFrom(); public void run() {
String type = ""; String messageType = null;
Icon packetTypeIcon; String from = packet.getFrom();
receivedPackets++; String type = "";
if (packet instanceof IQ) { Icon packetTypeIcon;
packetTypeIcon = iqPacketIcon; receivedPackets++;
messageType = "IQ Received (class=" + packet.getClass().getName() + ")"; if (packet instanceof IQ) {
type = ((IQ) packet).getType().toString(); packetTypeIcon = iqPacketIcon;
receivedIQPackets++; messageType = "IQ Received (class=" + packet.getClass().getName() + ")";
} type = ((IQ) packet).getType().toString();
else if (packet instanceof Message) { receivedIQPackets++;
packetTypeIcon = messagePacketIcon; }
messageType = "Message Received"; else if (packet instanceof Message) {
type = ((Message) packet).getType().toString(); packetTypeIcon = messagePacketIcon;
receivedMessagePackets++; messageType = "Message Received";
} type = ((Message) packet).getType().toString();
else if (packet instanceof Presence) { receivedMessagePackets++;
packetTypeIcon = presencePacketIcon; }
messageType = "Presence Received"; else if (packet instanceof Presence) {
type = ((Presence) packet).getType().toString(); packetTypeIcon = presencePacketIcon;
receivedPresencePackets++; messageType = "Presence Received";
} type = ((Presence) packet).getType().toString();
else { receivedPresencePackets++;
packetTypeIcon = unknownPacketTypeIcon; }
messageType = packet.getClass().getName() + " Received"; else {
receivedOtherPackets++; packetTypeIcon = unknownPacketTypeIcon;
} messageType = packet.getClass().getName() + " Received";
receivedOtherPackets++;
}
messagesTable.addRow( // Check if we need to remove old rows from the table to keep memory consumption low
new Object[] { if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER) {
formatXML(packet.toXML()), if (EnhancedDebuggerWindow.MAX_TABLE_ROWS > 0 &&
dateFormatter.format(new Date()), messagesTable.getRowCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
packetReceivedIcon, messagesTable.removeRow(0);
packetTypeIcon, }
messageType, }
packet.getPacketID(),
type, messagesTable.addRow(
"", new Object[] {
from }); formatXML(packet.toXML()),
// Update the statistics table dateFormatter.format(new Date()),
updateStatistics(); packetReceivedIcon,
packetTypeIcon,
messageType,
packet.getPacketID(),
type,
"",
from });
// Update the statistics table
updateStatistics();
}
});
} }
/** /**
@ -678,50 +702,62 @@ public class EnhancedDebugger implements SmackDebugger {
* @param dateFormatter the SimpleDateFormat to use to format Dates * @param dateFormatter the SimpleDateFormat to use to format Dates
* @param packet the sent packet to add to the table * @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) {
String messageType = null; SwingUtilities.invokeLater(new Runnable() {
String to = packet.getTo(); public void run() {
String type = ""; String messageType = null;
Icon packetTypeIcon; String to = packet.getTo();
sentPackets++; String type = "";
if (packet instanceof IQ) { Icon packetTypeIcon;
packetTypeIcon = iqPacketIcon; sentPackets++;
messageType = "IQ Sent (class=" + packet.getClass().getName() + ")"; if (packet instanceof IQ) {
type = ((IQ) packet).getType().toString(); packetTypeIcon = iqPacketIcon;
sentIQPackets++; messageType = "IQ Sent (class=" + packet.getClass().getName() + ")";
} type = ((IQ) packet).getType().toString();
else if (packet instanceof Message) { sentIQPackets++;
packetTypeIcon = messagePacketIcon; }
messageType = "Message Sent"; else if (packet instanceof Message) {
type = ((Message) packet).getType().toString(); packetTypeIcon = messagePacketIcon;
sentMessagePackets++; messageType = "Message Sent";
} type = ((Message) packet).getType().toString();
else if (packet instanceof Presence) { sentMessagePackets++;
packetTypeIcon = presencePacketIcon; }
messageType = "Presence Sent"; else if (packet instanceof Presence) {
type = ((Presence) packet).getType().toString(); packetTypeIcon = presencePacketIcon;
sentPresencePackets++; messageType = "Presence Sent";
} type = ((Presence) packet).getType().toString();
else { sentPresencePackets++;
packetTypeIcon = unknownPacketTypeIcon; }
messageType = packet.getClass().getName() + " Sent"; else {
sentOtherPackets++; packetTypeIcon = unknownPacketTypeIcon;
} messageType = packet.getClass().getName() + " Sent";
sentOtherPackets++;
}
messagesTable.addRow( // Check if we need to remove old rows from the table to keep memory consumption low
new Object[] { if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER) {
formatXML(packet.toXML()), if (EnhancedDebuggerWindow.MAX_TABLE_ROWS > 0 &&
dateFormatter.format(new Date()), messagesTable.getRowCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
packetSentIcon, messagesTable.removeRow(0);
packetTypeIcon, }
messageType, }
packet.getPacketID(),
type,
to,
"" });
// Update the statistics table messagesTable.addRow(
updateStatistics(); new Object[] {
formatXML(packet.toXML()),
dateFormatter.format(new Date()),
packetSentIcon,
packetTypeIcon,
messageType,
packet.getPacketID(),
type,
to,
"" });
// Update the statistics table
updateStatistics();
}
});
} }
private String formatXML(String str) { private String formatXML(String str) {