From 4f8f6b4c17e9a69b5a086309f1f2997b363eaa6a Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Mon, 12 Jan 2004 16:09:07 +0000 Subject: [PATCH] Stops debugging the connections when the windows is closed git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2204 b35dd754-fafc-0310-a699-88a17e54d16e --- .../debugger/EnhancedDebuggerWindow.java | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/source/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java b/source/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java index cfc948e3e..9a24eaa0b 100644 --- a/source/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java +++ b/source/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java @@ -111,6 +111,7 @@ class EnhancedDebuggerWindow { private JFrame frame = null; private JTabbedPane tabbedPane = null; + private java.util.List debuggers = new ArrayList(); private EnhancedDebuggerWindow() { } @@ -150,6 +151,8 @@ class EnhancedDebuggerWindow { tabbedPane.setIconAt(tabbedPane.indexOfComponent(debugger.tabbedPane), connectionCreatedIcon); frame.setTitle( "Smack Debug Window -- Total connections: " + (tabbedPane.getComponentCount() - 1)); + // Keep the added debugger for later access + debuggers.add(debugger); } /** @@ -204,6 +207,13 @@ class EnhancedDebuggerWindow { frame = new JFrame("Smack Debug Window"); + // Add listener for window closing event + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent evt) { + rootWindowClosing(evt); + } + }); + // We'll arrange the UI into tabs. The last tab contains Smack's information. // All the connection debugger tabs will be shown before the Smack info tab. tabbedPane = new JTabbedPane(); @@ -255,7 +265,14 @@ class EnhancedDebuggerWindow { public void actionPerformed(ActionEvent e) { // Remove the selected tab pane if it's not the Smack info pane if (tabbedPane.getSelectedIndex() < tabbedPane.getComponentCount() - 1) { - tabbedPane.remove(tabbedPane.getSelectedComponent()); + int index = tabbedPane.getSelectedIndex(); + // Notify to the debugger to stop debugging + EnhancedDebugger debugger = (EnhancedDebugger)debuggers.get(index); + debugger.cancel(); + // Remove the debugger from the root window + tabbedPane.remove(debugger.tabbedPane); + debuggers.remove(debugger); + // Update the root window title frame.setTitle( "Smack Debug Window -- Total connections: " + (tabbedPane.getComponentCount() - 1)); @@ -273,6 +290,24 @@ class EnhancedDebuggerWindow { } + /** + * Notification that the root window is closing. Stop listening for received and + * transmitted packets in all the debugged connections. + * + * @param evt the event that indicates that the root window is closing + */ + public void rootWindowClosing(WindowEvent evt) { + // Notify to all the debuggers to stop debugging + for (Iterator it = debuggers.iterator(); it.hasNext();) { + EnhancedDebugger debugger = (EnhancedDebugger)it.next(); + debugger.cancel(); + } + // Release any reference to the debuggers + debuggers.removeAll(debuggers); + // Release the default instance + instance = null; + } + /** * Listens for debug window popup dialog events. */