diff -r 517e80eedfd8 -r 3d9a315b12e6 libs/patch-smack-android-sasl.diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libs/patch-smack-android-sasl.diff Fri Jun 26 19:50:03 2009 +0200
@@ -0,0 +1,2074 @@
+diff -Nbdru org/jivesoftware/smack/ConnectionConfiguration.java /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/ConnectionConfiguration.java
+--- org/jivesoftware/smack/ConnectionConfiguration.java 2009-06-26 21:11:24.609252239 +0200
++++ /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/ConnectionConfiguration.java 2009-06-25 22:41:46.281648000 +0200
+@@ -63,7 +63,7 @@
+ */
+ private CallbackHandler callbackHandler;
+
+- private boolean debuggerEnabled = XMPPConnection.DEBUG_ENABLED;
++ private boolean debuggerEnabled = false;
+
+ // Flag that indicates if a reconnection should be attempted when abruptly disconnected
+ private boolean reconnectionAllowed = true;
+diff -Nbdru org/jivesoftware/smack/debugger/LiteDebugger.java /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/debugger/LiteDebugger.java
+--- org/jivesoftware/smack/debugger/LiteDebugger.java 2009-06-26 21:11:22.316252115 +0200
++++ /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/debugger/LiteDebugger.java 1970-01-01 01:00:00.000000000 +0100
+@@ -1,336 +0,0 @@
+-/**
+- * $RCSfile$
+- * $Revision: 7071 $
+- * $Date: 2007-02-12 01:59:05 +0100 (Mon, 12 Feb 2007) $
+- *
+- * Copyright 2003-2007 Jive Software.
+- *
+- * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+- * you may not use this file except in compliance with the License.
+- * You may obtain a copy of the License at
+- *
+- * http://www.apache.org/licenses/LICENSE-2.0
+- *
+- * Unless required by applicable law or agreed to in writing, software
+- * distributed under the License is distributed on an "AS IS" BASIS,
+- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+- * See the License for the specific language governing permissions and
+- * limitations under the License.
+- */
+-
+-package org.jivesoftware.smack.debugger;
+-
+-import java.awt.*;
+-import java.awt.datatransfer.*;
+-import java.awt.event.*;
+-import java.io.*;
+-
+-import javax.swing.*;
+-
+-import org.jivesoftware.smack.*;
+-import org.jivesoftware.smack.packet.*;
+-import org.jivesoftware.smack.util.*;
+-
+-/**
+- * The LiteDebugger is a very simple debugger that allows to debug sent, received and
+- * interpreted messages.
+- *
+- * @author Gaston Dombiak
+- */
+-public class LiteDebugger implements SmackDebugger {
+-
+- private static final String NEWLINE = "\n";
+-
+- private JFrame frame = null;
+- private XMPPConnection connection = null;
+-
+- private PacketListener listener = null;
+-
+- private Writer writer;
+- private Reader reader;
+- private ReaderListener readerListener;
+- private WriterListener writerListener;
+-
+- public LiteDebugger(XMPPConnection connection, Writer writer, Reader reader) {
+- this.connection = connection;
+- this.writer = writer;
+- this.reader = reader;
+- createDebug();
+- }
+-
+- /**
+- * Creates the debug process, which is a GUI window that displays XML traffic.
+- */
+- private void createDebug() {
+- frame = new JFrame("Smack Debug Window -- " + connection.getServiceName() + ":" +
+- connection.getPort());
+-
+- // Add listener for window closing event
+- frame.addWindowListener(new WindowAdapter() {
+- public void windowClosing(WindowEvent evt) {
+- rootWindowClosing(evt);
+- }
+- });
+-
+- // We'll arrange the UI into four tabs. The first tab contains all data, the second
+- // client generated XML, the third server generated XML, and the fourth is packet
+- // data from the server as seen by Smack.
+- JTabbedPane tabbedPane = new JTabbedPane();
+-
+- JPanel allPane = new JPanel();
+- allPane.setLayout(new GridLayout(3, 1));
+- tabbedPane.add("All", allPane);
+-
+- // Create UI elements for client generated XML traffic.
+- final JTextArea sentText1 = new JTextArea();
+- final JTextArea sentText2 = new JTextArea();
+- sentText1.setEditable(false);
+- sentText2.setEditable(false);
+- sentText1.setForeground(new Color(112, 3, 3));
+- sentText2.setForeground(new Color(112, 3, 3));
+- allPane.add(new JScrollPane(sentText1));
+- tabbedPane.add("Sent", new JScrollPane(sentText2));
+-
+- // Add pop-up menu.
+- JPopupMenu menu = new JPopupMenu();
+- JMenuItem menuItem1 = new JMenuItem("Copy");
+- menuItem1.addActionListener(new ActionListener() {
+- public void actionPerformed(ActionEvent e) {
+- // Get the clipboard
+- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+- // Set the sent text as the new content of the clipboard
+- clipboard.setContents(new StringSelection(sentText1.getText()), null);
+- }
+- });
+-
+- JMenuItem menuItem2 = new JMenuItem("Clear");
+- menuItem2.addActionListener(new ActionListener() {
+- public void actionPerformed(ActionEvent e) {
+- sentText1.setText("");
+- sentText2.setText("");
+- }
+- });
+-
+- // Add listener to the text area so the popup menu can come up.
+- MouseListener popupListener = new PopupListener(menu);
+- sentText1.addMouseListener(popupListener);
+- sentText2.addMouseListener(popupListener);
+- menu.add(menuItem1);
+- menu.add(menuItem2);
+-
+- // Create UI elements for server generated XML traffic.
+- final JTextArea receivedText1 = new JTextArea();
+- final JTextArea receivedText2 = new JTextArea();
+- receivedText1.setEditable(false);
+- receivedText2.setEditable(false);
+- receivedText1.setForeground(new Color(6, 76, 133));
+- receivedText2.setForeground(new Color(6, 76, 133));
+- allPane.add(new JScrollPane(receivedText1));
+- tabbedPane.add("Received", new JScrollPane(receivedText2));
+-
+- // Add pop-up menu.
+- menu = new JPopupMenu();
+- menuItem1 = new JMenuItem("Copy");
+- menuItem1.addActionListener(new ActionListener() {
+- public void actionPerformed(ActionEvent e) {
+- // Get the clipboard
+- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+- // Set the sent text as the new content of the clipboard
+- clipboard.setContents(new StringSelection(receivedText1.getText()), null);
+- }
+- });
+-
+- menuItem2 = new JMenuItem("Clear");
+- menuItem2.addActionListener(new ActionListener() {
+- public void actionPerformed(ActionEvent e) {
+- receivedText1.setText("");
+- receivedText2.setText("");
+- }
+- });
+-
+- // Add listener to the text area so the popup menu can come up.
+- popupListener = new PopupListener(menu);
+- receivedText1.addMouseListener(popupListener);
+- receivedText2.addMouseListener(popupListener);
+- menu.add(menuItem1);
+- menu.add(menuItem2);
+-
+- // Create UI elements for interpreted XML traffic.
+- final JTextArea interpretedText1 = new JTextArea();
+- final JTextArea interpretedText2 = new JTextArea();
+- interpretedText1.setEditable(false);
+- interpretedText2.setEditable(false);
+- interpretedText1.setForeground(new Color(1, 94, 35));
+- interpretedText2.setForeground(new Color(1, 94, 35));
+- allPane.add(new JScrollPane(interpretedText1));
+- tabbedPane.add("Interpreted", new JScrollPane(interpretedText2));
+-
+- // Add pop-up menu.
+- menu = new JPopupMenu();
+- menuItem1 = new JMenuItem("Copy");
+- menuItem1.addActionListener(new ActionListener() {
+- public void actionPerformed(ActionEvent e) {
+- // Get the clipboard
+- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+- // Set the sent text as the new content of the clipboard
+- clipboard.setContents(new StringSelection(interpretedText1.getText()), null);
+- }
+- });
+-
+- menuItem2 = new JMenuItem("Clear");
+- menuItem2.addActionListener(new ActionListener() {
+- public void actionPerformed(ActionEvent e) {
+- interpretedText1.setText("");
+- interpretedText2.setText("");
+- }
+- });
+-
+- // Add listener to the text area so the popup menu can come up.
+- popupListener = new PopupListener(menu);
+- interpretedText1.addMouseListener(popupListener);
+- interpretedText2.addMouseListener(popupListener);
+- menu.add(menuItem1);
+- menu.add(menuItem2);
+-
+- frame.getContentPane().add(tabbedPane);
+-
+- frame.setSize(550, 400);
+- frame.setVisible(true);
+-
+- // 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) {
+- int index = str.lastIndexOf(">");
+- if (index != -1) {
+- receivedText1.append(str.substring(0, index + 1));
+- receivedText2.append(str.substring(0, index + 1));
+- receivedText1.append(NEWLINE);
+- receivedText2.append(NEWLINE);
+- if (str.length() > index) {
+- receivedText1.append(str.substring(index + 1));
+- receivedText2.append(str.substring(index + 1));
+- }
+- }
+- else {
+- receivedText1.append(str);
+- receivedText2.append(str);
+- }
+- }
+- };
+- debugReader.addReaderListener(readerListener);
+-
+- // Create a special Writer that wraps the main Writer and logs data to the GUI.
+- ObservableWriter debugWriter = new ObservableWriter(writer);
+- writerListener = new WriterListener() {
+- public void write(String str) {
+- sentText1.append(str);
+- sentText2.append(str);
+- if (str.endsWith(">")) {
+- sentText1.append(NEWLINE);
+- sentText2.append(NEWLINE);
+- }
+- }
+- };
+- debugWriter.addWriterListener(writerListener);
+-
+- // Assign the reader/writer objects to use the debug versions. The packet reader
+- // and writer will use the debug versions when they are created.
+- reader = debugReader;
+- writer = debugWriter;
+-
+- // Create a 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 it and not as it's coming in as raw XML.
+- listener = new PacketListener() {
+- public void processPacket(Packet packet) {
+- interpretedText1.append(packet.toXML());
+- interpretedText2.append(packet.toXML());
+- interpretedText1.append(NEWLINE);
+- interpretedText2.append(NEWLINE);
+- }
+- };
+- }
+-
+- /**
+- * Notification that the root window is closing. Stop listening for received and
+- * transmitted packets.
+- *
+- * @param evt the event that indicates that the root window is closing
+- */
+- public void rootWindowClosing(WindowEvent evt) {
+- connection.removePacketListener(listener);
+- ((ObservableReader)reader).removeReaderListener(readerListener);
+- ((ObservableWriter)writer).removeWriterListener(writerListener);
+- }
+-
+- /**
+- * Listens for debug window popup dialog events.
+- */
+- private class PopupListener extends MouseAdapter {
+- JPopupMenu popup;
+-
+- PopupListener(JPopupMenu popupMenu) {
+- popup = popupMenu;
+- }
+-
+- public void mousePressed(MouseEvent e) {
+- maybeShowPopup(e);
+- }
+-
+- public void mouseReleased(MouseEvent e) {
+- maybeShowPopup(e);
+- }
+-
+- private void maybeShowPopup(MouseEvent e) {
+- if (e.isPopupTrigger()) {
+- popup.show(e.getComponent(), e.getX(), e.getY());
+- }
+- }
+- }
+-
+- 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.getServiceName()
+- + ":"
+- + connection.getPort();
+- title += "/" + StringUtils.parseResource(user);
+- frame.setTitle(title);
+- }
+-
+- public Reader getReader() {
+- return reader;
+- }
+-
+- public Writer getWriter() {
+- return writer;
+- }
+-
+- public PacketListener getReaderListener() {
+- return listener;
+- }
+-
+- public PacketListener getWriterListener() {
+- return null;
+- }
+-}
+diff -Nbdru org/jivesoftware/smack/sasl/SASLGSSAPIMechanism.java /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/sasl/SASLGSSAPIMechanism.java
+--- org/jivesoftware/smack/sasl/SASLGSSAPIMechanism.java 2009-06-26 21:11:23.436473310 +0200
++++ /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/sasl/SASLGSSAPIMechanism.java 2009-06-26 20:56:01.656252399 +0200
+@@ -25,8 +25,9 @@
+ import java.io.IOException;
+ import java.util.Map;
+ import java.util.HashMap;
+-import javax.security.sasl.Sasl;
+-import javax.security.sasl.SaslClient;
++
++import security.javax.security.sasl.Sasl;
++
+ import javax.security.auth.callback.CallbackHandler;
+
+ /**
+@@ -63,7 +64,7 @@
+ String[] mechanisms = { getName() };
+ Map props = new HashMap();
+ props.put(Sasl.SERVER_AUTH,"TRUE");
+- sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, cbh);
++ sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, (javax.security.auth.callback.CallbackHandler)cbh);
+ authenticate();
+ }
+
+diff -Nbdru org/jivesoftware/smack/sasl/SASLMechanism.java /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/sasl/SASLMechanism.java
+--- org/jivesoftware/smack/sasl/SASLMechanism.java 2009-06-26 21:11:23.436473310 +0200
++++ /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/sasl/SASLMechanism.java 2009-06-26 21:23:03.244251498 +0200
+@@ -20,23 +20,25 @@
+
+ package org.jivesoftware.smack.sasl;
+
+-import org.jivesoftware.smack.XMPPException;
+-import org.jivesoftware.smack.SASLAuthentication;
+-import org.jivesoftware.smack.util.Base64;
+-
+ import java.io.IOException;
+-import java.util.Map;
+ import java.util.HashMap;
+-import javax.security.auth.callback.CallbackHandler;
+-import javax.security.auth.callback.UnsupportedCallbackException;
++import java.util.Map;
++
+ import javax.security.auth.callback.Callback;
+-import javax.security.auth.callback.NameCallback;
++import javax.security.auth.callback.CallbackHandler;
+ import javax.security.auth.callback.PasswordCallback;
+-import javax.security.sasl.RealmCallback;
+-import javax.security.sasl.RealmChoiceCallback;
+-import javax.security.sasl.Sasl;
+-import javax.security.sasl.SaslClient;
+-import javax.security.sasl.SaslException;
++import javax.security.auth.callback.UnsupportedCallbackException;
++
++import org.jivesoftware.smack.SASLAuthentication;
++import org.jivesoftware.smack.XMPPException;
++import org.jivesoftware.smack.util.Base64;
++
++import security.javax.security.auth.callback.NameCallback;
++import security.javax.security.sasl.RealmCallback;
++import security.javax.security.sasl.RealmChoiceCallback;
++import security.javax.security.sasl.Sasl;
++import security.javax.security.sasl.SaslClient;
++import security.javax.security.sasl.SaslException;
+
+ /**
+ * Base class for SASL mechanisms. Subclasses must implement these methods:
+@@ -148,12 +150,13 @@
+ } else {
+ response = sc.evaluateChallenge(null);
+ }
+-
+- String authenticationText = Base64.encodeBytes(response,Base64.DONT_BREAK_LINES);
++ String authenticationText = "";
++ if (response != null) {
++ authenticationText = Base64.encodeBytes(response,Base64.DONT_BREAK_LINES);
+ if(authenticationText.equals("")) {
+ authenticationText = "=";
+ }
+-
++ }
+ stanza.append("
+- *
+- * A new EnhancedDebugger will be created for each connection to debug. All the EnhancedDebuggers +- * will be shown in the same debug window provided by the class EnhancedDebuggerWindow. +- * +- * @author Gaston Dombiak +- */ +-public class EnhancedDebugger implements SmackDebugger { +- +- private static final String NEWLINE = "\n"; +- +- private static ImageIcon packetReceivedIcon; +- private static ImageIcon packetSentIcon; +- private static ImageIcon presencePacketIcon; +- private static ImageIcon iqPacketIcon; +- private static ImageIcon messagePacketIcon; +- private static ImageIcon unknownPacketTypeIcon; +- +- { +- URL url; +- // Load the image icons +- url = +- Thread.currentThread().getContextClassLoader().getResource("images/nav_left_blue.png"); +- if (url != null) { +- packetReceivedIcon = new ImageIcon(url); +- } +- url = +- Thread.currentThread().getContextClassLoader().getResource("images/nav_right_red.png"); +- if (url != null) { +- packetSentIcon = new ImageIcon(url); +- } +- url = +- Thread.currentThread().getContextClassLoader().getResource("images/photo_portrait.png"); +- if (url != null) { +- presencePacketIcon = new ImageIcon(url); +- } +- url = +- Thread.currentThread().getContextClassLoader().getResource( +- "images/question_and_answer.png"); +- if (url != null) { +- iqPacketIcon = new ImageIcon(url); +- } +- url = Thread.currentThread().getContextClassLoader().getResource("images/message.png"); +- if (url != null) { +- messagePacketIcon = new ImageIcon(url); +- } +- url = Thread.currentThread().getContextClassLoader().getResource("images/unknown.png"); +- if (url != null) { +- unknownPacketTypeIcon = new ImageIcon(url); +- } +- } +- +- private DefaultTableModel messagesTable = null; +- private JTextArea messageTextArea = null; +- private JFormattedTextField userField = null; +- private JFormattedTextField statusField = null; +- +- private XMPPConnection connection = null; +- +- private PacketListener packetReaderListener = null; +- private PacketListener packetWriterListener = null; +- private ConnectionListener connListener = null; +- +- private Writer writer; +- private Reader reader; +- private ReaderListener readerListener; +- private WriterListener writerListener; +- +- private Date creationTime = new Date(); +- +- // Statistics variables +- private DefaultTableModel statisticsTable = null; +- private int sentPackets = 0; +- private int receivedPackets = 0; +- private int sentIQPackets = 0; +- private int receivedIQPackets = 0; +- private int sentMessagePackets = 0; +- private int receivedMessagePackets = 0; +- private int sentPresencePackets = 0; +- private int receivedPresencePackets = 0; +- private int sentOtherPackets = 0; +- private int receivedOtherPackets = 0; +- +- JTabbedPane tabbedPane; +- +- public EnhancedDebugger(XMPPConnection connection, Writer writer, Reader reader) { +- this.connection = connection; +- this.writer = writer; +- this.reader = reader; +- createDebug(); +- EnhancedDebuggerWindow.addDebugger(this); +- } +- +- /** +- * Creates the debug process, which is a GUI window that displays XML traffic. +- */ +- private void createDebug() { +- // We'll arrange the UI into six tabs. The first tab contains all data, the second +- // client generated XML, the third server generated XML, the fourth allows to send +- // ad-hoc messages and the fifth contains connection information. +- tabbedPane = new JTabbedPane(); +- +- // Add the All Packets, Sent, Received and Interpreted panels +- addBasicPanels(); +- +- // Add the panel to send ad-hoc messages +- addAdhocPacketPanel(); +- +- // Add the connection information panel +- addInformationPanel(); +- +- // Create a 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 it and not as it's coming in as raw XML. +- packetReaderListener = new PacketListener() { +- SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss aaa"); +- +- public void processPacket(final Packet packet) { +- SwingUtilities.invokeLater(new Runnable() { +- public void run() { +- addReadPacketToTable(dateFormatter, packet); +- } +- }); +- +- } +- }; +- +- // Create a thread that will listen for all outgoing packets and write them to +- // the GUI. +- packetWriterListener = new PacketListener() { +- SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss aaa"); +- +- public void processPacket(final Packet packet) { +- SwingUtilities.invokeLater(new Runnable() { +- public void run() { +- addSentPacketToTable(dateFormatter, packet); +- } +- }); +- +- } +- }; +- +- // Create a thread that will listen for any connection closed event +- connListener = new ConnectionListener() { +- public void connectionClosed() { +- SwingUtilities.invokeLater(new Runnable() { +- public void run() { +- statusField.setValue("Closed"); +- EnhancedDebuggerWindow.connectionClosed(EnhancedDebugger.this); +- } +- }); +- +- } +- +- public void connectionClosedOnError(final Exception e) { +- SwingUtilities.invokeLater(new Runnable() { +- public void run() { +- statusField.setValue("Closed due to an exception"); +- EnhancedDebuggerWindow.connectionClosedOnError(EnhancedDebugger.this, e); +- } +- }); +- +- } +- public void reconnectingIn(final int seconds){ +- SwingUtilities.invokeLater(new Runnable() { +- public void run() { +- statusField.setValue("Attempt to reconnect in " + seconds + " seconds"); +- } +- }); +- } +- +- public void reconnectionSuccessful() { +- SwingUtilities.invokeLater(new Runnable() { +- public void run() { +- statusField.setValue("Reconnection stablished"); +- EnhancedDebuggerWindow.connectionEstablished(EnhancedDebugger.this); +- } +- }); +- } +- +- public void reconnectionFailed(Exception e) { +- SwingUtilities.invokeLater(new Runnable() { +- public void run() { +- statusField.setValue("Reconnection failed"); +- } +- }); +- } +- }; +- } +- +- private void addBasicPanels() { +- JSplitPane allPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); +- allPane.setOneTouchExpandable(true); +- +- messagesTable = +- new DefaultTableModel( +- new Object[]{"Hide", "Timestamp", "", "", "Message", "Id", "Type", "To", "From"}, +- 0) { +- private static final long serialVersionUID = 8136121224474217264L; +- public boolean isCellEditable(int rowIndex, int mColIndex) { +- return false; +- } +- +- public Class getColumnClass(int columnIndex) { +- if (columnIndex == 2 || columnIndex == 3) { +- return Icon.class; +- } +- return super.getColumnClass(columnIndex); +- } +- +- }; +- JTable table = new JTable(messagesTable); +- // Allow only single a selection +- table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); +- // Hide the first column +- table.getColumnModel().getColumn(0).setMaxWidth(0); +- table.getColumnModel().getColumn(0).setMinWidth(0); +- table.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0); +- table.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0); +- // Set the column "timestamp" size +- table.getColumnModel().getColumn(1).setMaxWidth(300); +- table.getColumnModel().getColumn(1).setPreferredWidth(70); +- // Set the column "direction" icon size +- table.getColumnModel().getColumn(2).setMaxWidth(50); +- table.getColumnModel().getColumn(2).setPreferredWidth(30); +- // Set the column "packet type" icon size +- table.getColumnModel().getColumn(3).setMaxWidth(50); +- table.getColumnModel().getColumn(3).setPreferredWidth(30); +- // Set the column "Id" size +- table.getColumnModel().getColumn(5).setMaxWidth(100); +- table.getColumnModel().getColumn(5).setPreferredWidth(55); +- // Set the column "type" size +- table.getColumnModel().getColumn(6).setMaxWidth(200); +- table.getColumnModel().getColumn(6).setPreferredWidth(50); +- // Set the column "to" size +- table.getColumnModel().getColumn(7).setMaxWidth(300); +- table.getColumnModel().getColumn(7).setPreferredWidth(90); +- // Set the column "from" size +- table.getColumnModel().getColumn(8).setMaxWidth(300); +- table.getColumnModel().getColumn(8).setPreferredWidth(90); +- // Create a table listener that listen for row selection events +- SelectionListener selectionListener = new SelectionListener(table); +- table.getSelectionModel().addListSelectionListener(selectionListener); +- table.getColumnModel().getSelectionModel().addListSelectionListener(selectionListener); +- allPane.setTopComponent(new JScrollPane(table)); +- messageTextArea = new JTextArea(); +- messageTextArea.setEditable(false); +- // Add pop-up menu. +- JPopupMenu menu = new JPopupMenu(); +- JMenuItem menuItem1 = new JMenuItem("Copy"); +- menuItem1.addActionListener(new ActionListener() { +- public void actionPerformed(ActionEvent e) { +- // Get the clipboard +- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); +- // Set the sent text as the new content of the clipboard +- clipboard.setContents(new StringSelection(messageTextArea.getText()), null); +- } +- }); +- menu.add(menuItem1); +- // Add listener to the text area so the popup menu can come up. +- messageTextArea.addMouseListener(new PopupListener(menu)); +- 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)); +- tabbedPane.setToolTipTextAt(1, "Raw text of the sent packets"); +- +- // Add pop-up menu. +- menu = new JPopupMenu(); +- menuItem1 = new JMenuItem("Copy"); +- menuItem1.addActionListener(new ActionListener() { +- public void actionPerformed(ActionEvent e) { +- // Get the clipboard +- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); +- // Set the sent text as the new content of the clipboard +- clipboard.setContents(new StringSelection(sentText.getText()), null); +- } +- }); +- +- JMenuItem menuItem2 = new JMenuItem("Clear"); +- menuItem2.addActionListener(new ActionListener() { +- public void actionPerformed(ActionEvent e) { +- sentText.setText(""); +- } +- }); +- +- // Add listener to the text area so the popup menu can come up. +- sentText.addMouseListener(new PopupListener(menu)); +- menu.add(menuItem1); +- menu.add(menuItem2); +- +- // 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)); +- tabbedPane.setToolTipTextAt( +- 2, +- "Raw text of the received packets before Smack process them"); +- +- // Add pop-up menu. +- menu = new JPopupMenu(); +- menuItem1 = new JMenuItem("Copy"); +- menuItem1.addActionListener(new ActionListener() { +- public void actionPerformed(ActionEvent e) { +- // Get the clipboard +- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); +- // Set the sent text as the new content of the clipboard +- clipboard.setContents(new StringSelection(receivedText.getText()), null); +- } +- }); +- +- menuItem2 = new JMenuItem("Clear"); +- menuItem2.addActionListener(new ActionListener() { +- public void actionPerformed(ActionEvent e) { +- receivedText.setText(""); +- } +- }); +- +- // Add listener to the text area so the popup menu can come up. +- receivedText.addMouseListener(new PopupListener(menu)); +- menu.add(menuItem1); +- menu.add(menuItem2); +- +- // 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(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 +- return; +- } +- +- 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) { +- receivedText.append(str.substring(index + 1)); +- } +- } +- else { +- receivedText.append(str); +- } +- } +- }); +- } +- }; +- debugReader.addReaderListener(readerListener); +- +- // Create a special Writer that wraps the main Writer and logs data to the GUI. +- ObservableWriter debugWriter = new ObservableWriter(writer); +- writerListener = new WriterListener() { +- public void write(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 +- 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); +- } +- } +- }); +- +- +- } +- }; +- debugWriter.addWriterListener(writerListener); +- +- // Assign the reader/writer objects to use the debug versions. The packet reader +- // and writer will use the debug versions when they are created. +- reader = debugReader; +- writer = debugWriter; +- +- } +- +- private void addAdhocPacketPanel() { +- // Create UI elements for sending ad-hoc messages. +- final JTextArea adhocMessages = new JTextArea(); +- adhocMessages.setEditable(true); +- adhocMessages.setForeground(new Color(1, 94, 35)); +- tabbedPane.add("Ad-hoc message", new JScrollPane(adhocMessages)); +- tabbedPane.setToolTipTextAt(3, "Panel that allows you to send adhoc packets"); +- +- // Add pop-up menu. +- JPopupMenu menu = new JPopupMenu(); +- JMenuItem menuItem = new JMenuItem("Message"); +- menuItem.addActionListener(new ActionListener() { +- public void actionPerformed(ActionEvent e) { +- adhocMessages.setText( +- "+- *
+- * The whole text to send must be passed to the constructor. This implies that the client of +- * this class is responsible for sending a valid text to the constructor. +- */ +- private class AdHocPacket extends Packet { +- +- private String text; +- +- /** +- * Create a new AdHocPacket with the text to send. The passed text must be a valid text to +- * send to the server, no validation will be done on the passed text. +- * +- * @param text the whole text of the packet to send +- */ +- public AdHocPacket(String text) { +- this.text = text; +- } +- +- public String toXML() { +- return text; +- } +- +- } +- +- /** +- * Listens for debug window popup dialog events. +- */ +- private class PopupListener extends MouseAdapter { +- +- JPopupMenu popup; +- +- PopupListener(JPopupMenu popupMenu) { +- popup = popupMenu; +- } +- +- public void mousePressed(MouseEvent e) { +- maybeShowPopup(e); +- } +- +- public void mouseReleased(MouseEvent e) { +- maybeShowPopup(e); +- } +- +- private void maybeShowPopup(MouseEvent e) { +- if (e.isPopupTrigger()) { +- popup.show(e.getComponent(), e.getX(), e.getY()); +- } +- } +- } +- +- private class SelectionListener implements ListSelectionListener { +- +- JTable table; +- +- // It is necessary to keep the table since it is not possible +- // to determine the table from the event's source +- SelectionListener(JTable table) { +- this.table = table; +- } +- +- public void valueChanged(ListSelectionEvent e) { +- if (table.getSelectedRow() == -1) { +- // Clear the messageTextArea since there is none packet selected +- messageTextArea.setText(null); +- } +- else { +- // Set the detail of the packet in the messageTextArea +- messageTextArea.setText( +- (String) table.getModel().getValueAt(table.getSelectedRow(), 0)); +- // Scroll up to the top +- messageTextArea.setCaretPosition(0); +- } +- } +- } +-} +diff -Nbdru org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java /home/nikita/devel/beem-ui/src/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java +--- org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java 2009-06-26 21:11:18.348252001 +0200 ++++ /home/nikita/devel/beem-ui/src/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java 1970-01-01 01:00:00.000000000 +0100 +@@ -1,375 +0,0 @@ +-/** +- * $RCSfile$ +- * $Revision: 7071 $ +- * $Date: 2007-02-12 01:59:05 +0100 (Mon, 12 Feb 2007) $ +- * +- * Copyright 2003-2007 Jive Software. +- * +- * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); +- * you may not use this file except in compliance with the License. +- * You may obtain a copy of the License at +- * +- * http://www.apache.org/licenses/LICENSE-2.0 +- * +- * Unless required by applicable law or agreed to in writing, software +- * distributed under the License is distributed on an "AS IS" BASIS, +- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +- * See the License for the specific language governing permissions and +- * limitations under the License. +- */ +- +-package org.jivesoftware.smackx.debugger; +- +-import org.jivesoftware.smack.SmackConfiguration; +-import org.jivesoftware.smack.provider.ProviderManager; +- +-import javax.swing.*; +-import java.awt.*; +-import java.awt.event.*; +-import java.net.URL; +-import java.util.ArrayList; +-import java.util.Collections; +-import java.util.Vector; +- +-/** +- * The EnhancedDebuggerWindow is the main debug window that will show all the EnhancedDebuggers. +- * For each connection to debug there will be an EnhancedDebugger that will be shown in the +- * EnhancedDebuggerWindow.+- *
+- * This class also provides information about Smack like for example the Smack version and the +- * installed providers. +- * +- * @author Gaston Dombiak +- */ +-public class EnhancedDebuggerWindow { +- +- private static EnhancedDebuggerWindow instance; +- +- private static ImageIcon connectionCreatedIcon; +- private static ImageIcon connectionActiveIcon; +- private static ImageIcon connectionClosedIcon; +- private static ImageIcon connectionClosedOnErrorIcon; +- +- 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. 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 = 150; +- +- { +- URL url; +- +- url = +- Thread.currentThread().getContextClassLoader().getResource( +- "images/trafficlight_off.png"); +- if (url != null) { +- connectionCreatedIcon = new ImageIcon(url); +- } +- url = +- Thread.currentThread().getContextClassLoader().getResource( +- "images/trafficlight_green.png"); +- if (url != null) { +- connectionActiveIcon = new ImageIcon(url); +- } +- url = +- Thread.currentThread().getContextClassLoader().getResource( +- "images/trafficlight_red.png"); +- if (url != null) { +- connectionClosedIcon = new ImageIcon(url); +- } +- url = Thread.currentThread().getContextClassLoader().getResource("images/warning.png"); +- if (url != null) { +- connectionClosedOnErrorIcon = new ImageIcon(url); +- } +- +- } +- +- private JFrame frame = null; +- private JTabbedPane tabbedPane = null; +- private java.util.List