From 523beeac559aa8996b9160f3fd50531d7bd18263 Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Sat, 27 Aug 2005 02:23:36 +0000 Subject: [PATCH] Added option to recreate wrappers of new reader and writer. SMACK-76 git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2730 b35dd754-fafc-0310-a699-88a17e54d16e --- .../smack/debugger/ConsoleDebugger.java | 18 ++++++++++++++++- .../smack/debugger/LiteDebugger.java | 20 +++++++++++++++++-- .../smack/debugger/SmackDebugger.java | 16 +++++++++++++++ .../smackx/debugger/EnhancedDebugger.java | 18 ++++++++++++++++- 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/source/org/jivesoftware/smack/debugger/ConsoleDebugger.java b/source/org/jivesoftware/smack/debugger/ConsoleDebugger.java index d068d9460..a3757cb2a 100644 --- a/source/org/jivesoftware/smack/debugger/ConsoleDebugger.java +++ b/source/org/jivesoftware/smack/debugger/ConsoleDebugger.java @@ -111,13 +111,29 @@ public class ConsoleDebugger implements SmackDebugger { }; } + public Reader newConnectionReader(Reader newReader) { + ((ObservableReader)reader).removeReaderListener(readerListener); + ObservableReader debugReader = new ObservableReader(newReader); + debugReader.addReaderListener(readerListener); + reader = debugReader; + return reader; + } + + public Writer newConnectionWriter(Writer newWriter) { + ((ObservableWriter)writer).removeWriterListener(writerListener); + ObservableWriter debugWriter = new ObservableWriter(newWriter); + debugWriter.addWriterListener(writerListener); + writer = debugWriter; + return writer; + } + public void userHasLogged(String user) { boolean isAnonymous = "".equals(StringUtils.parseName(user)); String title = "User logged (" + connection.hashCode() + "): " + (isAnonymous ? "" : StringUtils.parseBareAddress(user)) + "@" - + connection.getHost() + + connection.getServiceName() + ":" + connection.getPort(); title += "/" + StringUtils.parseResource(user); diff --git a/source/org/jivesoftware/smack/debugger/LiteDebugger.java b/source/org/jivesoftware/smack/debugger/LiteDebugger.java index c07c81557..3646121ce 100644 --- a/source/org/jivesoftware/smack/debugger/LiteDebugger.java +++ b/source/org/jivesoftware/smack/debugger/LiteDebugger.java @@ -62,7 +62,7 @@ public class LiteDebugger implements SmackDebugger { * Creates the debug process, which is a GUI window that displays XML traffic. */ private void createDebug() { - frame = new JFrame("Smack Debug Window -- " + connection.getHost() + ":" + + frame = new JFrame("Smack Debug Window -- " + connection.getServiceName() + ":" + connection.getPort()); // Add listener for window closing event @@ -289,13 +289,29 @@ public class LiteDebugger implements SmackDebugger { } } + public Reader newConnectionReader(Reader newReader) { + ((ObservableReader)reader).removeReaderListener(readerListener); + ObservableReader debugReader = new ObservableReader(newReader); + debugReader.addReaderListener(readerListener); + reader = debugReader; + return reader; + } + + public Writer newConnectionWriter(Writer newWriter) { + ((ObservableWriter)writer).removeWriterListener(writerListener); + ObservableWriter debugWriter = new ObservableWriter(newWriter); + debugWriter.addWriterListener(writerListener); + writer = debugWriter; + return writer; + } + public void userHasLogged(String user) { boolean isAnonymous = "".equals(StringUtils.parseName(user)); String title = "Smack Debug Window -- " + (isAnonymous ? "" : StringUtils.parseBareAddress(user)) + "@" - + connection.getHost() + + connection.getServiceName() + ":" + connection.getPort(); title += "/" + StringUtils.parseResource(user); diff --git a/source/org/jivesoftware/smack/debugger/SmackDebugger.java b/source/org/jivesoftware/smack/debugger/SmackDebugger.java index 8f3246c53..bdc5c108e 100644 --- a/source/org/jivesoftware/smack/debugger/SmackDebugger.java +++ b/source/org/jivesoftware/smack/debugger/SmackDebugger.java @@ -58,6 +58,22 @@ public interface SmackDebugger { */ public abstract Writer getWriter(); + /** + * Returns a new special Reader that wraps the new connection Reader. The connection + * has been secured so he now have a new reader and writer. + * + * @return a new special Reader that wraps the new connection Reader. + */ + public abstract Reader newConnectionReader(Reader reader); + + /** + * Returns a new special Writer that wraps the new connection Writer. The connection + * has been secured so he now have a new reader and writer. + * + * @return a new special Writer that wraps the new connection Writer. + */ + public abstract Writer newConnectionWriter(Writer writer); + /** * Returns the thread that will listen for all incoming packets and write them to the GUI. * This is what we call "interpreted" packet data, since it's the packet data as Smack sees diff --git a/source/org/jivesoftware/smackx/debugger/EnhancedDebugger.java b/source/org/jivesoftware/smackx/debugger/EnhancedDebugger.java index 61f35ae22..f201a0168 100644 --- a/source/org/jivesoftware/smackx/debugger/EnhancedDebugger.java +++ b/source/org/jivesoftware/smackx/debugger/EnhancedDebugger.java @@ -452,7 +452,7 @@ public class EnhancedDebugger implements SmackDebugger { connPanel.add( label, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0)); - JFormattedTextField field = new JFormattedTextField(connection.getHost()); + JFormattedTextField field = new JFormattedTextField(connection.getServiceName()); field.setMinimumSize(new java.awt.Dimension(150, 20)); field.setMaximumSize(new java.awt.Dimension(150, 20)); field.setEditable(false); @@ -561,6 +561,22 @@ public class EnhancedDebugger implements SmackDebugger { tabbedPane.setToolTipTextAt(4, "Information and statistics about the debugged connection"); } + public Reader newConnectionReader(Reader newReader) { + ((ObservableReader)reader).removeReaderListener(readerListener); + ObservableReader debugReader = new ObservableReader(newReader); + debugReader.addReaderListener(readerListener); + reader = debugReader; + return reader; + } + + public Writer newConnectionWriter(Writer newWriter) { + ((ObservableWriter)writer).removeWriterListener(writerListener); + ObservableWriter debugWriter = new ObservableWriter(newWriter); + debugWriter.addWriterListener(writerListener); + writer = debugWriter; + return writer; + } + public void userHasLogged(String user) { userField.setText(user); EnhancedDebuggerWindow.userHasLogged(this, user);