311
|
1 |
diff -Nbdru org/jivesoftware/smack/ConnectionConfiguration.java /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/ConnectionConfiguration.java |
|
2 |
--- org/jivesoftware/smack/ConnectionConfiguration.java 2009-06-26 21:11:24.609252239 +0200 |
|
3 |
+++ /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/ConnectionConfiguration.java 2009-06-25 22:41:46.281648000 +0200 |
|
4 |
@@ -63,7 +63,7 @@ |
|
5 |
*/ |
|
6 |
private CallbackHandler callbackHandler; |
|
7 |
|
|
8 |
- private boolean debuggerEnabled = XMPPConnection.DEBUG_ENABLED; |
|
9 |
+ private boolean debuggerEnabled = false; |
|
10 |
|
|
11 |
// Flag that indicates if a reconnection should be attempted when abruptly disconnected |
|
12 |
private boolean reconnectionAllowed = true; |
|
13 |
diff -Nbdru org/jivesoftware/smack/debugger/LiteDebugger.java /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/debugger/LiteDebugger.java |
|
14 |
--- org/jivesoftware/smack/debugger/LiteDebugger.java 2009-06-26 21:11:22.316252115 +0200 |
|
15 |
+++ /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/debugger/LiteDebugger.java 1970-01-01 01:00:00.000000000 +0100 |
|
16 |
@@ -1,336 +0,0 @@ |
|
17 |
-/** |
|
18 |
- * $RCSfile$ |
|
19 |
- * $Revision: 7071 $ |
|
20 |
- * $Date: 2007-02-12 01:59:05 +0100 (Mon, 12 Feb 2007) $ |
|
21 |
- * |
|
22 |
- * Copyright 2003-2007 Jive Software. |
|
23 |
- * |
|
24 |
- * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); |
|
25 |
- * you may not use this file except in compliance with the License. |
|
26 |
- * You may obtain a copy of the License at |
|
27 |
- * |
|
28 |
- * http://www.apache.org/licenses/LICENSE-2.0 |
|
29 |
- * |
|
30 |
- * Unless required by applicable law or agreed to in writing, software |
|
31 |
- * distributed under the License is distributed on an "AS IS" BASIS, |
|
32 |
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
33 |
- * See the License for the specific language governing permissions and |
|
34 |
- * limitations under the License. |
|
35 |
- */ |
|
36 |
- |
|
37 |
-package org.jivesoftware.smack.debugger; |
|
38 |
- |
|
39 |
-import java.awt.*; |
|
40 |
-import java.awt.datatransfer.*; |
|
41 |
-import java.awt.event.*; |
|
42 |
-import java.io.*; |
|
43 |
- |
|
44 |
-import javax.swing.*; |
|
45 |
- |
|
46 |
-import org.jivesoftware.smack.*; |
|
47 |
-import org.jivesoftware.smack.packet.*; |
|
48 |
-import org.jivesoftware.smack.util.*; |
|
49 |
- |
|
50 |
-/** |
|
51 |
- * The LiteDebugger is a very simple debugger that allows to debug sent, received and |
|
52 |
- * interpreted messages. |
|
53 |
- * |
|
54 |
- * @author Gaston Dombiak |
|
55 |
- */ |
|
56 |
-public class LiteDebugger implements SmackDebugger { |
|
57 |
- |
|
58 |
- private static final String NEWLINE = "\n"; |
|
59 |
- |
|
60 |
- private JFrame frame = null; |
|
61 |
- private XMPPConnection connection = null; |
|
62 |
- |
|
63 |
- private PacketListener listener = null; |
|
64 |
- |
|
65 |
- private Writer writer; |
|
66 |
- private Reader reader; |
|
67 |
- private ReaderListener readerListener; |
|
68 |
- private WriterListener writerListener; |
|
69 |
- |
|
70 |
- public LiteDebugger(XMPPConnection connection, Writer writer, Reader reader) { |
|
71 |
- this.connection = connection; |
|
72 |
- this.writer = writer; |
|
73 |
- this.reader = reader; |
|
74 |
- createDebug(); |
|
75 |
- } |
|
76 |
- |
|
77 |
- /** |
|
78 |
- * Creates the debug process, which is a GUI window that displays XML traffic. |
|
79 |
- */ |
|
80 |
- private void createDebug() { |
|
81 |
- frame = new JFrame("Smack Debug Window -- " + connection.getServiceName() + ":" + |
|
82 |
- connection.getPort()); |
|
83 |
- |
|
84 |
- // Add listener for window closing event |
|
85 |
- frame.addWindowListener(new WindowAdapter() { |
|
86 |
- public void windowClosing(WindowEvent evt) { |
|
87 |
- rootWindowClosing(evt); |
|
88 |
- } |
|
89 |
- }); |
|
90 |
- |
|
91 |
- // We'll arrange the UI into four tabs. The first tab contains all data, the second |
|
92 |
- // client generated XML, the third server generated XML, and the fourth is packet |
|
93 |
- // data from the server as seen by Smack. |
|
94 |
- JTabbedPane tabbedPane = new JTabbedPane(); |
|
95 |
- |
|
96 |
- JPanel allPane = new JPanel(); |
|
97 |
- allPane.setLayout(new GridLayout(3, 1)); |
|
98 |
- tabbedPane.add("All", allPane); |
|
99 |
- |
|
100 |
- // Create UI elements for client generated XML traffic. |
|
101 |
- final JTextArea sentText1 = new JTextArea(); |
|
102 |
- final JTextArea sentText2 = new JTextArea(); |
|
103 |
- sentText1.setEditable(false); |
|
104 |
- sentText2.setEditable(false); |
|
105 |
- sentText1.setForeground(new Color(112, 3, 3)); |
|
106 |
- sentText2.setForeground(new Color(112, 3, 3)); |
|
107 |
- allPane.add(new JScrollPane(sentText1)); |
|
108 |
- tabbedPane.add("Sent", new JScrollPane(sentText2)); |
|
109 |
- |
|
110 |
- // Add pop-up menu. |
|
111 |
- JPopupMenu menu = new JPopupMenu(); |
|
112 |
- JMenuItem menuItem1 = new JMenuItem("Copy"); |
|
113 |
- menuItem1.addActionListener(new ActionListener() { |
|
114 |
- public void actionPerformed(ActionEvent e) { |
|
115 |
- // Get the clipboard |
|
116 |
- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); |
|
117 |
- // Set the sent text as the new content of the clipboard |
|
118 |
- clipboard.setContents(new StringSelection(sentText1.getText()), null); |
|
119 |
- } |
|
120 |
- }); |
|
121 |
- |
|
122 |
- JMenuItem menuItem2 = new JMenuItem("Clear"); |
|
123 |
- menuItem2.addActionListener(new ActionListener() { |
|
124 |
- public void actionPerformed(ActionEvent e) { |
|
125 |
- sentText1.setText(""); |
|
126 |
- sentText2.setText(""); |
|
127 |
- } |
|
128 |
- }); |
|
129 |
- |
|
130 |
- // Add listener to the text area so the popup menu can come up. |
|
131 |
- MouseListener popupListener = new PopupListener(menu); |
|
132 |
- sentText1.addMouseListener(popupListener); |
|
133 |
- sentText2.addMouseListener(popupListener); |
|
134 |
- menu.add(menuItem1); |
|
135 |
- menu.add(menuItem2); |
|
136 |
- |
|
137 |
- // Create UI elements for server generated XML traffic. |
|
138 |
- final JTextArea receivedText1 = new JTextArea(); |
|
139 |
- final JTextArea receivedText2 = new JTextArea(); |
|
140 |
- receivedText1.setEditable(false); |
|
141 |
- receivedText2.setEditable(false); |
|
142 |
- receivedText1.setForeground(new Color(6, 76, 133)); |
|
143 |
- receivedText2.setForeground(new Color(6, 76, 133)); |
|
144 |
- allPane.add(new JScrollPane(receivedText1)); |
|
145 |
- tabbedPane.add("Received", new JScrollPane(receivedText2)); |
|
146 |
- |
|
147 |
- // Add pop-up menu. |
|
148 |
- menu = new JPopupMenu(); |
|
149 |
- menuItem1 = new JMenuItem("Copy"); |
|
150 |
- menuItem1.addActionListener(new ActionListener() { |
|
151 |
- public void actionPerformed(ActionEvent e) { |
|
152 |
- // Get the clipboard |
|
153 |
- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); |
|
154 |
- // Set the sent text as the new content of the clipboard |
|
155 |
- clipboard.setContents(new StringSelection(receivedText1.getText()), null); |
|
156 |
- } |
|
157 |
- }); |
|
158 |
- |
|
159 |
- menuItem2 = new JMenuItem("Clear"); |
|
160 |
- menuItem2.addActionListener(new ActionListener() { |
|
161 |
- public void actionPerformed(ActionEvent e) { |
|
162 |
- receivedText1.setText(""); |
|
163 |
- receivedText2.setText(""); |
|
164 |
- } |
|
165 |
- }); |
|
166 |
- |
|
167 |
- // Add listener to the text area so the popup menu can come up. |
|
168 |
- popupListener = new PopupListener(menu); |
|
169 |
- receivedText1.addMouseListener(popupListener); |
|
170 |
- receivedText2.addMouseListener(popupListener); |
|
171 |
- menu.add(menuItem1); |
|
172 |
- menu.add(menuItem2); |
|
173 |
- |
|
174 |
- // Create UI elements for interpreted XML traffic. |
|
175 |
- final JTextArea interpretedText1 = new JTextArea(); |
|
176 |
- final JTextArea interpretedText2 = new JTextArea(); |
|
177 |
- interpretedText1.setEditable(false); |
|
178 |
- interpretedText2.setEditable(false); |
|
179 |
- interpretedText1.setForeground(new Color(1, 94, 35)); |
|
180 |
- interpretedText2.setForeground(new Color(1, 94, 35)); |
|
181 |
- allPane.add(new JScrollPane(interpretedText1)); |
|
182 |
- tabbedPane.add("Interpreted", new JScrollPane(interpretedText2)); |
|
183 |
- |
|
184 |
- // Add pop-up menu. |
|
185 |
- menu = new JPopupMenu(); |
|
186 |
- menuItem1 = new JMenuItem("Copy"); |
|
187 |
- menuItem1.addActionListener(new ActionListener() { |
|
188 |
- public void actionPerformed(ActionEvent e) { |
|
189 |
- // Get the clipboard |
|
190 |
- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); |
|
191 |
- // Set the sent text as the new content of the clipboard |
|
192 |
- clipboard.setContents(new StringSelection(interpretedText1.getText()), null); |
|
193 |
- } |
|
194 |
- }); |
|
195 |
- |
|
196 |
- menuItem2 = new JMenuItem("Clear"); |
|
197 |
- menuItem2.addActionListener(new ActionListener() { |
|
198 |
- public void actionPerformed(ActionEvent e) { |
|
199 |
- interpretedText1.setText(""); |
|
200 |
- interpretedText2.setText(""); |
|
201 |
- } |
|
202 |
- }); |
|
203 |
- |
|
204 |
- // Add listener to the text area so the popup menu can come up. |
|
205 |
- popupListener = new PopupListener(menu); |
|
206 |
- interpretedText1.addMouseListener(popupListener); |
|
207 |
- interpretedText2.addMouseListener(popupListener); |
|
208 |
- menu.add(menuItem1); |
|
209 |
- menu.add(menuItem2); |
|
210 |
- |
|
211 |
- frame.getContentPane().add(tabbedPane); |
|
212 |
- |
|
213 |
- frame.setSize(550, 400); |
|
214 |
- frame.setVisible(true); |
|
215 |
- |
|
216 |
- // Create a special Reader that wraps the main Reader and logs data to the GUI. |
|
217 |
- ObservableReader debugReader = new ObservableReader(reader); |
|
218 |
- readerListener = new ReaderListener() { |
|
219 |
- public void read(String str) { |
|
220 |
- int index = str.lastIndexOf(">"); |
|
221 |
- if (index != -1) { |
|
222 |
- receivedText1.append(str.substring(0, index + 1)); |
|
223 |
- receivedText2.append(str.substring(0, index + 1)); |
|
224 |
- receivedText1.append(NEWLINE); |
|
225 |
- receivedText2.append(NEWLINE); |
|
226 |
- if (str.length() > index) { |
|
227 |
- receivedText1.append(str.substring(index + 1)); |
|
228 |
- receivedText2.append(str.substring(index + 1)); |
|
229 |
- } |
|
230 |
- } |
|
231 |
- else { |
|
232 |
- receivedText1.append(str); |
|
233 |
- receivedText2.append(str); |
|
234 |
- } |
|
235 |
- } |
|
236 |
- }; |
|
237 |
- debugReader.addReaderListener(readerListener); |
|
238 |
- |
|
239 |
- // Create a special Writer that wraps the main Writer and logs data to the GUI. |
|
240 |
- ObservableWriter debugWriter = new ObservableWriter(writer); |
|
241 |
- writerListener = new WriterListener() { |
|
242 |
- public void write(String str) { |
|
243 |
- sentText1.append(str); |
|
244 |
- sentText2.append(str); |
|
245 |
- if (str.endsWith(">")) { |
|
246 |
- sentText1.append(NEWLINE); |
|
247 |
- sentText2.append(NEWLINE); |
|
248 |
- } |
|
249 |
- } |
|
250 |
- }; |
|
251 |
- debugWriter.addWriterListener(writerListener); |
|
252 |
- |
|
253 |
- // Assign the reader/writer objects to use the debug versions. The packet reader |
|
254 |
- // and writer will use the debug versions when they are created. |
|
255 |
- reader = debugReader; |
|
256 |
- writer = debugWriter; |
|
257 |
- |
|
258 |
- // Create a thread that will listen for all incoming packets and write them to |
|
259 |
- // the GUI. This is what we call "interpreted" packet data, since it's the packet |
|
260 |
- // data as Smack sees it and not as it's coming in as raw XML. |
|
261 |
- listener = new PacketListener() { |
|
262 |
- public void processPacket(Packet packet) { |
|
263 |
- interpretedText1.append(packet.toXML()); |
|
264 |
- interpretedText2.append(packet.toXML()); |
|
265 |
- interpretedText1.append(NEWLINE); |
|
266 |
- interpretedText2.append(NEWLINE); |
|
267 |
- } |
|
268 |
- }; |
|
269 |
- } |
|
270 |
- |
|
271 |
- /** |
|
272 |
- * Notification that the root window is closing. Stop listening for received and |
|
273 |
- * transmitted packets. |
|
274 |
- * |
|
275 |
- * @param evt the event that indicates that the root window is closing |
|
276 |
- */ |
|
277 |
- public void rootWindowClosing(WindowEvent evt) { |
|
278 |
- connection.removePacketListener(listener); |
|
279 |
- ((ObservableReader)reader).removeReaderListener(readerListener); |
|
280 |
- ((ObservableWriter)writer).removeWriterListener(writerListener); |
|
281 |
- } |
|
282 |
- |
|
283 |
- /** |
|
284 |
- * Listens for debug window popup dialog events. |
|
285 |
- */ |
|
286 |
- private class PopupListener extends MouseAdapter { |
|
287 |
- JPopupMenu popup; |
|
288 |
- |
|
289 |
- PopupListener(JPopupMenu popupMenu) { |
|
290 |
- popup = popupMenu; |
|
291 |
- } |
|
292 |
- |
|
293 |
- public void mousePressed(MouseEvent e) { |
|
294 |
- maybeShowPopup(e); |
|
295 |
- } |
|
296 |
- |
|
297 |
- public void mouseReleased(MouseEvent e) { |
|
298 |
- maybeShowPopup(e); |
|
299 |
- } |
|
300 |
- |
|
301 |
- private void maybeShowPopup(MouseEvent e) { |
|
302 |
- if (e.isPopupTrigger()) { |
|
303 |
- popup.show(e.getComponent(), e.getX(), e.getY()); |
|
304 |
- } |
|
305 |
- } |
|
306 |
- } |
|
307 |
- |
|
308 |
- public Reader newConnectionReader(Reader newReader) { |
|
309 |
- ((ObservableReader)reader).removeReaderListener(readerListener); |
|
310 |
- ObservableReader debugReader = new ObservableReader(newReader); |
|
311 |
- debugReader.addReaderListener(readerListener); |
|
312 |
- reader = debugReader; |
|
313 |
- return reader; |
|
314 |
- } |
|
315 |
- |
|
316 |
- public Writer newConnectionWriter(Writer newWriter) { |
|
317 |
- ((ObservableWriter)writer).removeWriterListener(writerListener); |
|
318 |
- ObservableWriter debugWriter = new ObservableWriter(newWriter); |
|
319 |
- debugWriter.addWriterListener(writerListener); |
|
320 |
- writer = debugWriter; |
|
321 |
- return writer; |
|
322 |
- } |
|
323 |
- |
|
324 |
- public void userHasLogged(String user) { |
|
325 |
- boolean isAnonymous = "".equals(StringUtils.parseName(user)); |
|
326 |
- String title = |
|
327 |
- "Smack Debug Window -- " |
|
328 |
- + (isAnonymous ? "" : StringUtils.parseBareAddress(user)) |
|
329 |
- + "@" |
|
330 |
- + connection.getServiceName() |
|
331 |
- + ":" |
|
332 |
- + connection.getPort(); |
|
333 |
- title += "/" + StringUtils.parseResource(user); |
|
334 |
- frame.setTitle(title); |
|
335 |
- } |
|
336 |
- |
|
337 |
- public Reader getReader() { |
|
338 |
- return reader; |
|
339 |
- } |
|
340 |
- |
|
341 |
- public Writer getWriter() { |
|
342 |
- return writer; |
|
343 |
- } |
|
344 |
- |
|
345 |
- public PacketListener getReaderListener() { |
|
346 |
- return listener; |
|
347 |
- } |
|
348 |
- |
|
349 |
- public PacketListener getWriterListener() { |
|
350 |
- return null; |
|
351 |
- } |
|
352 |
-} |
|
353 |
diff -Nbdru org/jivesoftware/smack/sasl/SASLGSSAPIMechanism.java /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/sasl/SASLGSSAPIMechanism.java |
|
354 |
--- org/jivesoftware/smack/sasl/SASLGSSAPIMechanism.java 2009-06-26 21:11:23.436473310 +0200 |
|
355 |
+++ /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/sasl/SASLGSSAPIMechanism.java 2009-06-26 20:56:01.656252399 +0200 |
|
356 |
@@ -25,8 +25,9 @@ |
|
357 |
import java.io.IOException; |
|
358 |
import java.util.Map; |
|
359 |
import java.util.HashMap; |
|
360 |
-import javax.security.sasl.Sasl; |
|
361 |
-import javax.security.sasl.SaslClient; |
|
362 |
+ |
|
363 |
+import security.javax.security.sasl.Sasl; |
|
364 |
+ |
|
365 |
import javax.security.auth.callback.CallbackHandler; |
|
366 |
|
|
367 |
/** |
|
368 |
@@ -63,7 +64,7 @@ |
|
369 |
String[] mechanisms = { getName() }; |
|
370 |
Map props = new HashMap(); |
|
371 |
props.put(Sasl.SERVER_AUTH,"TRUE"); |
|
372 |
- sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, cbh); |
|
373 |
+ sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, (javax.security.auth.callback.CallbackHandler)cbh); |
|
374 |
authenticate(); |
|
375 |
} |
|
376 |
|
|
377 |
diff -Nbdru org/jivesoftware/smack/sasl/SASLMechanism.java /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/sasl/SASLMechanism.java |
|
378 |
--- org/jivesoftware/smack/sasl/SASLMechanism.java 2009-06-26 21:11:23.436473310 +0200 |
|
379 |
+++ /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/sasl/SASLMechanism.java 2009-06-26 21:23:03.244251498 +0200 |
|
380 |
@@ -20,23 +20,25 @@ |
|
381 |
|
|
382 |
package org.jivesoftware.smack.sasl; |
|
383 |
|
|
384 |
-import org.jivesoftware.smack.XMPPException; |
|
385 |
-import org.jivesoftware.smack.SASLAuthentication; |
|
386 |
-import org.jivesoftware.smack.util.Base64; |
|
387 |
- |
|
388 |
import java.io.IOException; |
|
389 |
-import java.util.Map; |
|
390 |
import java.util.HashMap; |
|
391 |
-import javax.security.auth.callback.CallbackHandler; |
|
392 |
-import javax.security.auth.callback.UnsupportedCallbackException; |
|
393 |
+import java.util.Map; |
|
394 |
+ |
|
395 |
import javax.security.auth.callback.Callback; |
|
396 |
-import javax.security.auth.callback.NameCallback; |
|
397 |
+import javax.security.auth.callback.CallbackHandler; |
|
398 |
import javax.security.auth.callback.PasswordCallback; |
|
399 |
-import javax.security.sasl.RealmCallback; |
|
400 |
-import javax.security.sasl.RealmChoiceCallback; |
|
401 |
-import javax.security.sasl.Sasl; |
|
402 |
-import javax.security.sasl.SaslClient; |
|
403 |
-import javax.security.sasl.SaslException; |
|
404 |
+import javax.security.auth.callback.UnsupportedCallbackException; |
|
405 |
+ |
|
406 |
+import org.jivesoftware.smack.SASLAuthentication; |
|
407 |
+import org.jivesoftware.smack.XMPPException; |
|
408 |
+import org.jivesoftware.smack.util.Base64; |
|
409 |
+ |
|
410 |
+import security.javax.security.auth.callback.NameCallback; |
|
411 |
+import security.javax.security.sasl.RealmCallback; |
|
412 |
+import security.javax.security.sasl.RealmChoiceCallback; |
|
413 |
+import security.javax.security.sasl.Sasl; |
|
414 |
+import security.javax.security.sasl.SaslClient; |
|
415 |
+import security.javax.security.sasl.SaslException; |
|
416 |
|
|
417 |
/** |
|
418 |
* Base class for SASL mechanisms. Subclasses must implement these methods: |
|
419 |
@@ -148,12 +150,13 @@ |
|
420 |
} else { |
|
421 |
response = sc.evaluateChallenge(null); |
|
422 |
} |
|
423 |
- |
|
424 |
- String authenticationText = Base64.encodeBytes(response,Base64.DONT_BREAK_LINES); |
|
425 |
+ String authenticationText = ""; |
|
426 |
+ if (response != null) { |
|
427 |
+ authenticationText = Base64.encodeBytes(response,Base64.DONT_BREAK_LINES); |
|
428 |
if(authenticationText.equals("")) { |
|
429 |
authenticationText = "="; |
|
430 |
} |
|
431 |
- |
|
432 |
+ } |
|
433 |
stanza.append("<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"); |
|
434 |
stanza.append(authenticationText); |
|
435 |
stanza.append("</response>"); |
|
436 |
diff -Nbdru org/jivesoftware/smack/SASLAuthentication.java /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/SASLAuthentication.java |
|
437 |
--- org/jivesoftware/smack/SASLAuthentication.java 2009-06-26 21:11:24.597252589 +0200 |
|
438 |
+++ /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/SASLAuthentication.java 2009-06-26 21:31:16.445251493 +0200 |
|
439 |
@@ -84,17 +84,15 @@ |
|
440 |
|
|
441 |
// Register SASL mechanisms supported by Smack |
|
442 |
registerSASLMechanism("EXTERNAL", SASLExternalMechanism.class); |
|
443 |
- registerSASLMechanism("GSSAPI", SASLGSSAPIMechanism.class); |
|
444 |
registerSASLMechanism("DIGEST-MD5", SASLDigestMD5Mechanism.class); |
|
445 |
registerSASLMechanism("CRAM-MD5", SASLCramMD5Mechanism.class); |
|
446 |
registerSASLMechanism("PLAIN", SASLPlainMechanism.class); |
|
447 |
registerSASLMechanism("ANONYMOUS", SASLAnonymous.class); |
|
448 |
|
|
449 |
- supportSASLMechanism("GSSAPI",0); |
|
450 |
- supportSASLMechanism("DIGEST-MD5",1); |
|
451 |
- supportSASLMechanism("CRAM-MD5",2); |
|
452 |
- supportSASLMechanism("PLAIN",3); |
|
453 |
- supportSASLMechanism("ANONYMOUS",4); |
|
454 |
+ supportSASLMechanism("DIGEST-MD5",0); |
|
455 |
+ supportSASLMechanism("CRAM-MD5",1); |
|
456 |
+ supportSASLMechanism("PLAIN",2); |
|
457 |
+ supportSASLMechanism("ANONYMOUS",3); |
|
458 |
|
|
459 |
} |
|
460 |
|
|
461 |
diff -Nbdru org/jivesoftware/smack/util/DNSUtil.java /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/util/DNSUtil.java |
|
462 |
--- org/jivesoftware/smack/util/DNSUtil.java 2009-06-26 21:11:24.585252398 +0200 |
|
463 |
+++ /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/util/DNSUtil.java 2009-06-26 00:41:16.932251881 +0200 |
|
464 |
@@ -22,12 +22,6 @@ |
|
465 |
import java.util.Hashtable; |
|
466 |
import java.util.Map; |
|
467 |
|
|
468 |
-import javax.naming.NamingEnumeration; |
|
469 |
-import javax.naming.directory.Attribute; |
|
470 |
-import javax.naming.directory.Attributes; |
|
471 |
-import javax.naming.directory.DirContext; |
|
472 |
-import javax.naming.directory.InitialDirContext; |
|
473 |
- |
|
474 |
/** |
|
475 |
* Utilty class to perform DNS lookups for XMPP services. |
|
476 |
* |
|
477 |
@@ -41,13 +35,13 @@ |
|
478 |
*/ |
|
479 |
private static Map cache = new Cache(100, 1000*60*10); |
|
480 |
|
|
481 |
- private static DirContext context; |
|
482 |
+// private static DirContext context; |
|
483 |
|
|
484 |
static { |
|
485 |
try { |
|
486 |
Hashtable env = new Hashtable(); |
|
487 |
env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory"); |
|
488 |
- context = new InitialDirContext(env); |
|
489 |
+ // context = new InitialDirContext(env); |
|
490 |
} |
|
491 |
catch (Exception e) { |
|
492 |
// Ignore. |
|
493 |
@@ -79,65 +73,8 @@ |
|
494 |
* server can be reached at for the specified domain. |
|
495 |
*/ |
|
496 |
public static HostAddress resolveXMPPDomain(String domain) { |
|
497 |
- if (context == null) { |
|
498 |
return new HostAddress(domain, 5222); |
|
499 |
} |
|
500 |
- String key = "c" + domain; |
|
501 |
- // Return item from cache if it exists. |
|
502 |
- if (cache.containsKey(key)) { |
|
503 |
- HostAddress address = (HostAddress)cache.get(key); |
|
504 |
- if (address != null) { |
|
505 |
- return address; |
|
506 |
- } |
|
507 |
- } |
|
508 |
- String bestHost = domain; |
|
509 |
- int bestPort = 5222; |
|
510 |
- int bestPriority = 0; |
|
511 |
- int bestWeight = 0; |
|
512 |
- try { |
|
513 |
- Attributes dnsLookup = context.getAttributes("_xmpp-client._tcp." + domain, new String[]{"SRV"}); |
|
514 |
- Attribute srvAttribute = dnsLookup.get("SRV"); |
|
515 |
- NamingEnumeration srvRecords = srvAttribute.getAll(); |
|
516 |
- while(srvRecords.hasMore()) { |
|
517 |
- String srvRecord = (String) srvRecords.next(); |
|
518 |
- String [] srvRecordEntries = srvRecord.split(" "); |
|
519 |
- int priority = Integer.parseInt(srvRecordEntries[srvRecordEntries.length - 4]); |
|
520 |
- int port = Integer.parseInt(srvRecordEntries[srvRecordEntries.length-2]); |
|
521 |
- int weight = Integer.parseInt(srvRecordEntries[srvRecordEntries.length - 3]); |
|
522 |
- String host = srvRecordEntries[srvRecordEntries.length-1]; |
|
523 |
- |
|
524 |
- // Randomize the weight. |
|
525 |
- weight *= Math.random() * weight; |
|
526 |
- |
|
527 |
- if ((bestPriority == 0) || (priority < bestPriority)) { |
|
528 |
- // Choose a server with the lowest priority. |
|
529 |
- bestPriority = priority; |
|
530 |
- bestWeight = weight; |
|
531 |
- bestHost = host; |
|
532 |
- bestPort = port; |
|
533 |
- } else if (priority == bestPriority) { |
|
534 |
- // When we have like priorities then randomly choose a server based on its weight |
|
535 |
- // The weights were randomized above. |
|
536 |
- if (weight > bestWeight) { |
|
537 |
- bestWeight = weight; |
|
538 |
- bestHost = host; |
|
539 |
- bestPort = port; |
|
540 |
- } |
|
541 |
- } |
|
542 |
- } |
|
543 |
- } |
|
544 |
- catch (Exception e) { |
|
545 |
- // Ignore. |
|
546 |
- } |
|
547 |
- // Host entries in DNS should end with a ".". |
|
548 |
- if (bestHost.endsWith(".")) { |
|
549 |
- bestHost = bestHost.substring(0, bestHost.length()-1); |
|
550 |
- } |
|
551 |
- HostAddress address = new HostAddress(bestHost, bestPort); |
|
552 |
- // Add item to cache. |
|
553 |
- cache.put(key, address); |
|
554 |
- return address; |
|
555 |
- } |
|
556 |
|
|
557 |
/** |
|
558 |
* Returns the host name and port that the specified XMPP server can be |
|
559 |
@@ -157,50 +94,8 @@ |
|
560 |
* server can be reached at for the specified domain. |
|
561 |
*/ |
|
562 |
public static HostAddress resolveXMPPServerDomain(String domain) { |
|
563 |
- if (context == null) { |
|
564 |
return new HostAddress(domain, 5269); |
|
565 |
} |
|
566 |
- String key = "s" + domain; |
|
567 |
- // Return item from cache if it exists. |
|
568 |
- if (cache.containsKey(key)) { |
|
569 |
- HostAddress address = (HostAddress)cache.get(key); |
|
570 |
- if (address != null) { |
|
571 |
- return address; |
|
572 |
- } |
|
573 |
- } |
|
574 |
- String host = domain; |
|
575 |
- int port = 5269; |
|
576 |
- try { |
|
577 |
- Attributes dnsLookup = |
|
578 |
- context.getAttributes("_xmpp-server._tcp." + domain, new String[]{"SRV"}); |
|
579 |
- String srvRecord = (String)dnsLookup.get("SRV").get(); |
|
580 |
- String [] srvRecordEntries = srvRecord.split(" "); |
|
581 |
- port = Integer.parseInt(srvRecordEntries[srvRecordEntries.length-2]); |
|
582 |
- host = srvRecordEntries[srvRecordEntries.length-1]; |
|
583 |
- } |
|
584 |
- catch (Exception e) { |
|
585 |
- // Attempt lookup with older "jabber" name. |
|
586 |
- try { |
|
587 |
- Attributes dnsLookup = |
|
588 |
- context.getAttributes("_jabber._tcp." + domain, new String[]{"SRV"}); |
|
589 |
- String srvRecord = (String)dnsLookup.get("SRV").get(); |
|
590 |
- String [] srvRecordEntries = srvRecord.split(" "); |
|
591 |
- port = Integer.parseInt(srvRecordEntries[srvRecordEntries.length-2]); |
|
592 |
- host = srvRecordEntries[srvRecordEntries.length-1]; |
|
593 |
- } |
|
594 |
- catch (Exception e2) { |
|
595 |
- // Ignore. |
|
596 |
- } |
|
597 |
- } |
|
598 |
- // Host entries in DNS should end with a ".". |
|
599 |
- if (host.endsWith(".")) { |
|
600 |
- host = host.substring(0, host.length()-1); |
|
601 |
- } |
|
602 |
- HostAddress address = new HostAddress(host, port); |
|
603 |
- // Add item to cache. |
|
604 |
- cache.put(key, address); |
|
605 |
- return address; |
|
606 |
- } |
|
607 |
|
|
608 |
/** |
|
609 |
* Encapsulates a hostname and port. |
|
610 |
diff -Nbdru org/jivesoftware/smack/util/PacketParserUtils.java /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/util/PacketParserUtils.java |
|
611 |
--- org/jivesoftware/smack/util/PacketParserUtils.java 2009-06-26 21:11:24.585252398 +0200 |
|
612 |
+++ /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/util/PacketParserUtils.java 2009-06-25 22:34:41.252416000 +0200 |
|
613 |
@@ -25,7 +25,7 @@ |
|
614 |
import org.jivesoftware.smack.provider.ProviderManager; |
|
615 |
import org.xmlpull.v1.XmlPullParser; |
|
616 |
|
|
617 |
-import java.beans.PropertyDescriptor; |
|
618 |
+//import java.beans.PropertyDescriptor; |
|
619 |
import java.io.ByteArrayInputStream; |
|
620 |
import java.io.ObjectInputStream; |
|
621 |
import java.util.ArrayList; |
|
622 |
@@ -428,26 +428,26 @@ |
|
623 |
{ |
|
624 |
boolean done = false; |
|
625 |
Object object = objectClass.newInstance(); |
|
626 |
- while (!done) { |
|
627 |
- int eventType = parser.next(); |
|
628 |
- if (eventType == XmlPullParser.START_TAG) { |
|
629 |
- String name = parser.getName(); |
|
630 |
- String stringValue = parser.nextText(); |
|
631 |
- PropertyDescriptor descriptor = new PropertyDescriptor(name, objectClass); |
|
632 |
- // Load the class type of the property. |
|
633 |
- Class propertyType = descriptor.getPropertyType(); |
|
634 |
- // Get the value of the property by converting it from a |
|
635 |
- // String to the correct object type. |
|
636 |
- Object value = decode(propertyType, stringValue); |
|
637 |
- // Set the value of the bean. |
|
638 |
- descriptor.getWriteMethod().invoke(object, value); |
|
639 |
- } |
|
640 |
- else if (eventType == XmlPullParser.END_TAG) { |
|
641 |
- if (parser.getName().equals(elementName)) { |
|
642 |
- done = true; |
|
643 |
- } |
|
644 |
- } |
|
645 |
- } |
|
646 |
+// while (!done) { |
|
647 |
+// int eventType = parser.next(); |
|
648 |
+// if (eventType == XmlPullParser.START_TAG) { |
|
649 |
+// String name = parser.getName(); |
|
650 |
+// String stringValue = parser.nextText(); |
|
651 |
+// PropertyDescriptor descriptor = new PropertyDescriptor(name, objectClass); |
|
652 |
+// // Load the class type of the property. |
|
653 |
+// Class propertyType = descriptor.getPropertyType(); |
|
654 |
+// // Get the value of the property by converting it from a |
|
655 |
+// // String to the correct object type. |
|
656 |
+// Object value = decode(propertyType, stringValue); |
|
657 |
+// // Set the value of the bean. |
|
658 |
+// descriptor.getWriteMethod().invoke(object, value); |
|
659 |
+// } |
|
660 |
+// else if (eventType == XmlPullParser.END_TAG) { |
|
661 |
+// if (parser.getName().equals(elementName)) { |
|
662 |
+// done = true; |
|
663 |
+// } |
|
664 |
+// } |
|
665 |
+// } |
|
666 |
return object; |
|
667 |
} |
|
668 |
|
|
669 |
diff -Nbdru org/jivesoftware/smack/XMPPConnection.java /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/XMPPConnection.java |
|
670 |
--- org/jivesoftware/smack/XMPPConnection.java 2009-06-26 21:11:24.601252412 +0200 |
|
671 |
+++ /home/nikita/devel/beem-ui/src/org/jivesoftware/smack/XMPPConnection.java 2009-06-25 22:34:41.252416000 +0200 |
|
672 |
@@ -1082,7 +1082,7 @@ |
|
673 |
catch (Exception ex) { |
|
674 |
try { |
|
675 |
debuggerClass = |
|
676 |
- Class.forName("org.jivesoftware.smack.debugger.LiteDebugger"); |
|
677 |
+ Class.forName("org.jivesoftware.smack.debugger.ConsoleDebugger"); |
|
678 |
} |
|
679 |
catch (Exception ex2) { |
|
680 |
ex2.printStackTrace(); |
|
681 |
diff -Nbdru org/jivesoftware/smackx/debugger/EnhancedDebugger.java /home/nikita/devel/beem-ui/src/org/jivesoftware/smackx/debugger/EnhancedDebugger.java |
|
682 |
--- org/jivesoftware/smackx/debugger/EnhancedDebugger.java 2009-06-26 21:11:18.348252001 +0200 |
|
683 |
+++ /home/nikita/devel/beem-ui/src/org/jivesoftware/smackx/debugger/EnhancedDebugger.java 1970-01-01 01:00:00.000000000 +0100 |
|
684 |
@@ -1,1005 +0,0 @@ |
|
685 |
-/** |
|
686 |
- * $RCSfile$ |
|
687 |
- * $Revision: 11024 $ |
|
688 |
- * $Date: 2009-06-04 13:58:25 +0200 (Thu, 04 Jun 2009) $ |
|
689 |
- * |
|
690 |
- * Copyright 2003-2007 Jive Software. |
|
691 |
- * |
|
692 |
- * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); |
|
693 |
- * you may not use this file except in compliance with the License. |
|
694 |
- * You may obtain a copy of the License at |
|
695 |
- * |
|
696 |
- * http://www.apache.org/licenses/LICENSE-2.0 |
|
697 |
- * |
|
698 |
- * Unless required by applicable law or agreed to in writing, software |
|
699 |
- * distributed under the License is distributed on an "AS IS" BASIS, |
|
700 |
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
701 |
- * See the License for the specific language governing permissions and |
|
702 |
- * limitations under the License. |
|
703 |
- */ |
|
704 |
- |
|
705 |
-package org.jivesoftware.smackx.debugger; |
|
706 |
- |
|
707 |
-import org.jivesoftware.smack.ConnectionListener; |
|
708 |
-import org.jivesoftware.smack.PacketListener; |
|
709 |
-import org.jivesoftware.smack.XMPPConnection; |
|
710 |
-import org.jivesoftware.smack.debugger.SmackDebugger; |
|
711 |
-import org.jivesoftware.smack.packet.IQ; |
|
712 |
-import org.jivesoftware.smack.packet.Message; |
|
713 |
-import org.jivesoftware.smack.packet.Packet; |
|
714 |
-import org.jivesoftware.smack.packet.Presence; |
|
715 |
-import org.jivesoftware.smack.util.*; |
|
716 |
- |
|
717 |
-import javax.swing.*; |
|
718 |
-import javax.swing.event.ListSelectionEvent; |
|
719 |
-import javax.swing.event.ListSelectionListener; |
|
720 |
-import javax.swing.table.DefaultTableModel; |
|
721 |
-import javax.swing.text.BadLocationException; |
|
722 |
-import javax.xml.transform.*; |
|
723 |
-import javax.xml.transform.stream.StreamResult; |
|
724 |
-import javax.xml.transform.stream.StreamSource; |
|
725 |
-import java.awt.*; |
|
726 |
-import java.awt.datatransfer.Clipboard; |
|
727 |
-import java.awt.datatransfer.StringSelection; |
|
728 |
-import java.awt.event.ActionEvent; |
|
729 |
-import java.awt.event.ActionListener; |
|
730 |
-import java.awt.event.MouseAdapter; |
|
731 |
-import java.awt.event.MouseEvent; |
|
732 |
-import java.io.Reader; |
|
733 |
-import java.io.StringReader; |
|
734 |
-import java.io.StringWriter; |
|
735 |
-import java.io.Writer; |
|
736 |
-import java.net.URL; |
|
737 |
-import java.text.SimpleDateFormat; |
|
738 |
-import java.util.Date; |
|
739 |
- |
|
740 |
-/** |
|
741 |
- * The EnhancedDebugger is a debugger that allows to debug sent, received and interpreted messages |
|
742 |
- * but also provides the ability to send ad-hoc messages composed by the user.<p> |
|
743 |
- * <p/> |
|
744 |
- * A new EnhancedDebugger will be created for each connection to debug. All the EnhancedDebuggers |
|
745 |
- * will be shown in the same debug window provided by the class EnhancedDebuggerWindow. |
|
746 |
- * |
|
747 |
- * @author Gaston Dombiak |
|
748 |
- */ |
|
749 |
-public class EnhancedDebugger implements SmackDebugger { |
|
750 |
- |
|
751 |
- private static final String NEWLINE = "\n"; |
|
752 |
- |
|
753 |
- private static ImageIcon packetReceivedIcon; |
|
754 |
- private static ImageIcon packetSentIcon; |
|
755 |
- private static ImageIcon presencePacketIcon; |
|
756 |
- private static ImageIcon iqPacketIcon; |
|
757 |
- private static ImageIcon messagePacketIcon; |
|
758 |
- private static ImageIcon unknownPacketTypeIcon; |
|
759 |
- |
|
760 |
- { |
|
761 |
- URL url; |
|
762 |
- // Load the image icons |
|
763 |
- url = |
|
764 |
- Thread.currentThread().getContextClassLoader().getResource("images/nav_left_blue.png"); |
|
765 |
- if (url != null) { |
|
766 |
- packetReceivedIcon = new ImageIcon(url); |
|
767 |
- } |
|
768 |
- url = |
|
769 |
- Thread.currentThread().getContextClassLoader().getResource("images/nav_right_red.png"); |
|
770 |
- if (url != null) { |
|
771 |
- packetSentIcon = new ImageIcon(url); |
|
772 |
- } |
|
773 |
- url = |
|
774 |
- Thread.currentThread().getContextClassLoader().getResource("images/photo_portrait.png"); |
|
775 |
- if (url != null) { |
|
776 |
- presencePacketIcon = new ImageIcon(url); |
|
777 |
- } |
|
778 |
- url = |
|
779 |
- Thread.currentThread().getContextClassLoader().getResource( |
|
780 |
- "images/question_and_answer.png"); |
|
781 |
- if (url != null) { |
|
782 |
- iqPacketIcon = new ImageIcon(url); |
|
783 |
- } |
|
784 |
- url = Thread.currentThread().getContextClassLoader().getResource("images/message.png"); |
|
785 |
- if (url != null) { |
|
786 |
- messagePacketIcon = new ImageIcon(url); |
|
787 |
- } |
|
788 |
- url = Thread.currentThread().getContextClassLoader().getResource("images/unknown.png"); |
|
789 |
- if (url != null) { |
|
790 |
- unknownPacketTypeIcon = new ImageIcon(url); |
|
791 |
- } |
|
792 |
- } |
|
793 |
- |
|
794 |
- private DefaultTableModel messagesTable = null; |
|
795 |
- private JTextArea messageTextArea = null; |
|
796 |
- private JFormattedTextField userField = null; |
|
797 |
- private JFormattedTextField statusField = null; |
|
798 |
- |
|
799 |
- private XMPPConnection connection = null; |
|
800 |
- |
|
801 |
- private PacketListener packetReaderListener = null; |
|
802 |
- private PacketListener packetWriterListener = null; |
|
803 |
- private ConnectionListener connListener = null; |
|
804 |
- |
|
805 |
- private Writer writer; |
|
806 |
- private Reader reader; |
|
807 |
- private ReaderListener readerListener; |
|
808 |
- private WriterListener writerListener; |
|
809 |
- |
|
810 |
- private Date creationTime = new Date(); |
|
811 |
- |
|
812 |
- // Statistics variables |
|
813 |
- private DefaultTableModel statisticsTable = null; |
|
814 |
- private int sentPackets = 0; |
|
815 |
- private int receivedPackets = 0; |
|
816 |
- private int sentIQPackets = 0; |
|
817 |
- private int receivedIQPackets = 0; |
|
818 |
- private int sentMessagePackets = 0; |
|
819 |
- private int receivedMessagePackets = 0; |
|
820 |
- private int sentPresencePackets = 0; |
|
821 |
- private int receivedPresencePackets = 0; |
|
822 |
- private int sentOtherPackets = 0; |
|
823 |
- private int receivedOtherPackets = 0; |
|
824 |
- |
|
825 |
- JTabbedPane tabbedPane; |
|
826 |
- |
|
827 |
- public EnhancedDebugger(XMPPConnection connection, Writer writer, Reader reader) { |
|
828 |
- this.connection = connection; |
|
829 |
- this.writer = writer; |
|
830 |
- this.reader = reader; |
|
831 |
- createDebug(); |
|
832 |
- EnhancedDebuggerWindow.addDebugger(this); |
|
833 |
- } |
|
834 |
- |
|
835 |
- /** |
|
836 |
- * Creates the debug process, which is a GUI window that displays XML traffic. |
|
837 |
- */ |
|
838 |
- private void createDebug() { |
|
839 |
- // We'll arrange the UI into six tabs. The first tab contains all data, the second |
|
840 |
- // client generated XML, the third server generated XML, the fourth allows to send |
|
841 |
- // ad-hoc messages and the fifth contains connection information. |
|
842 |
- tabbedPane = new JTabbedPane(); |
|
843 |
- |
|
844 |
- // Add the All Packets, Sent, Received and Interpreted panels |
|
845 |
- addBasicPanels(); |
|
846 |
- |
|
847 |
- // Add the panel to send ad-hoc messages |
|
848 |
- addAdhocPacketPanel(); |
|
849 |
- |
|
850 |
- // Add the connection information panel |
|
851 |
- addInformationPanel(); |
|
852 |
- |
|
853 |
- // Create a thread that will listen for all incoming packets and write them to |
|
854 |
- // the GUI. This is what we call "interpreted" packet data, since it's the packet |
|
855 |
- // data as Smack sees it and not as it's coming in as raw XML. |
|
856 |
- packetReaderListener = new PacketListener() { |
|
857 |
- SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss aaa"); |
|
858 |
- |
|
859 |
- public void processPacket(final Packet packet) { |
|
860 |
- SwingUtilities.invokeLater(new Runnable() { |
|
861 |
- public void run() { |
|
862 |
- addReadPacketToTable(dateFormatter, packet); |
|
863 |
- } |
|
864 |
- }); |
|
865 |
- |
|
866 |
- } |
|
867 |
- }; |
|
868 |
- |
|
869 |
- // Create a thread that will listen for all outgoing packets and write them to |
|
870 |
- // the GUI. |
|
871 |
- packetWriterListener = new PacketListener() { |
|
872 |
- SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss aaa"); |
|
873 |
- |
|
874 |
- public void processPacket(final Packet packet) { |
|
875 |
- SwingUtilities.invokeLater(new Runnable() { |
|
876 |
- public void run() { |
|
877 |
- addSentPacketToTable(dateFormatter, packet); |
|
878 |
- } |
|
879 |
- }); |
|
880 |
- |
|
881 |
- } |
|
882 |
- }; |
|
883 |
- |
|
884 |
- // Create a thread that will listen for any connection closed event |
|
885 |
- connListener = new ConnectionListener() { |
|
886 |
- public void connectionClosed() { |
|
887 |
- SwingUtilities.invokeLater(new Runnable() { |
|
888 |
- public void run() { |
|
889 |
- statusField.setValue("Closed"); |
|
890 |
- EnhancedDebuggerWindow.connectionClosed(EnhancedDebugger.this); |
|
891 |
- } |
|
892 |
- }); |
|
893 |
- |
|
894 |
- } |
|
895 |
- |
|
896 |
- public void connectionClosedOnError(final Exception e) { |
|
897 |
- SwingUtilities.invokeLater(new Runnable() { |
|
898 |
- public void run() { |
|
899 |
- statusField.setValue("Closed due to an exception"); |
|
900 |
- EnhancedDebuggerWindow.connectionClosedOnError(EnhancedDebugger.this, e); |
|
901 |
- } |
|
902 |
- }); |
|
903 |
- |
|
904 |
- } |
|
905 |
- public void reconnectingIn(final int seconds){ |
|
906 |
- SwingUtilities.invokeLater(new Runnable() { |
|
907 |
- public void run() { |
|
908 |
- statusField.setValue("Attempt to reconnect in " + seconds + " seconds"); |
|
909 |
- } |
|
910 |
- }); |
|
911 |
- } |
|
912 |
- |
|
913 |
- public void reconnectionSuccessful() { |
|
914 |
- SwingUtilities.invokeLater(new Runnable() { |
|
915 |
- public void run() { |
|
916 |
- statusField.setValue("Reconnection stablished"); |
|
917 |
- EnhancedDebuggerWindow.connectionEstablished(EnhancedDebugger.this); |
|
918 |
- } |
|
919 |
- }); |
|
920 |
- } |
|
921 |
- |
|
922 |
- public void reconnectionFailed(Exception e) { |
|
923 |
- SwingUtilities.invokeLater(new Runnable() { |
|
924 |
- public void run() { |
|
925 |
- statusField.setValue("Reconnection failed"); |
|
926 |
- } |
|
927 |
- }); |
|
928 |
- } |
|
929 |
- }; |
|
930 |
- } |
|
931 |
- |
|
932 |
- private void addBasicPanels() { |
|
933 |
- JSplitPane allPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
|
934 |
- allPane.setOneTouchExpandable(true); |
|
935 |
- |
|
936 |
- messagesTable = |
|
937 |
- new DefaultTableModel( |
|
938 |
- new Object[]{"Hide", "Timestamp", "", "", "Message", "Id", "Type", "To", "From"}, |
|
939 |
- 0) { |
|
940 |
- private static final long serialVersionUID = 8136121224474217264L; |
|
941 |
- public boolean isCellEditable(int rowIndex, int mColIndex) { |
|
942 |
- return false; |
|
943 |
- } |
|
944 |
- |
|
945 |
- public Class getColumnClass(int columnIndex) { |
|
946 |
- if (columnIndex == 2 || columnIndex == 3) { |
|
947 |
- return Icon.class; |
|
948 |
- } |
|
949 |
- return super.getColumnClass(columnIndex); |
|
950 |
- } |
|
951 |
- |
|
952 |
- }; |
|
953 |
- JTable table = new JTable(messagesTable); |
|
954 |
- // Allow only single a selection |
|
955 |
- table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
|
956 |
- // Hide the first column |
|
957 |
- table.getColumnModel().getColumn(0).setMaxWidth(0); |
|
958 |
- table.getColumnModel().getColumn(0).setMinWidth(0); |
|
959 |
- table.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0); |
|
960 |
- table.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0); |
|
961 |
- // Set the column "timestamp" size |
|
962 |
- table.getColumnModel().getColumn(1).setMaxWidth(300); |
|
963 |
- table.getColumnModel().getColumn(1).setPreferredWidth(70); |
|
964 |
- // Set the column "direction" icon size |
|
965 |
- table.getColumnModel().getColumn(2).setMaxWidth(50); |
|
966 |
- table.getColumnModel().getColumn(2).setPreferredWidth(30); |
|
967 |
- // Set the column "packet type" icon size |
|
968 |
- table.getColumnModel().getColumn(3).setMaxWidth(50); |
|
969 |
- table.getColumnModel().getColumn(3).setPreferredWidth(30); |
|
970 |
- // Set the column "Id" size |
|
971 |
- table.getColumnModel().getColumn(5).setMaxWidth(100); |
|
972 |
- table.getColumnModel().getColumn(5).setPreferredWidth(55); |
|
973 |
- // Set the column "type" size |
|
974 |
- table.getColumnModel().getColumn(6).setMaxWidth(200); |
|
975 |
- table.getColumnModel().getColumn(6).setPreferredWidth(50); |
|
976 |
- // Set the column "to" size |
|
977 |
- table.getColumnModel().getColumn(7).setMaxWidth(300); |
|
978 |
- table.getColumnModel().getColumn(7).setPreferredWidth(90); |
|
979 |
- // Set the column "from" size |
|
980 |
- table.getColumnModel().getColumn(8).setMaxWidth(300); |
|
981 |
- table.getColumnModel().getColumn(8).setPreferredWidth(90); |
|
982 |
- // Create a table listener that listen for row selection events |
|
983 |
- SelectionListener selectionListener = new SelectionListener(table); |
|
984 |
- table.getSelectionModel().addListSelectionListener(selectionListener); |
|
985 |
- table.getColumnModel().getSelectionModel().addListSelectionListener(selectionListener); |
|
986 |
- allPane.setTopComponent(new JScrollPane(table)); |
|
987 |
- messageTextArea = new JTextArea(); |
|
988 |
- messageTextArea.setEditable(false); |
|
989 |
- // Add pop-up menu. |
|
990 |
- JPopupMenu menu = new JPopupMenu(); |
|
991 |
- JMenuItem menuItem1 = new JMenuItem("Copy"); |
|
992 |
- menuItem1.addActionListener(new ActionListener() { |
|
993 |
- public void actionPerformed(ActionEvent e) { |
|
994 |
- // Get the clipboard |
|
995 |
- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); |
|
996 |
- // Set the sent text as the new content of the clipboard |
|
997 |
- clipboard.setContents(new StringSelection(messageTextArea.getText()), null); |
|
998 |
- } |
|
999 |
- }); |
|
1000 |
- menu.add(menuItem1); |
|
1001 |
- // Add listener to the text area so the popup menu can come up. |
|
1002 |
- messageTextArea.addMouseListener(new PopupListener(menu)); |
|
1003 |
- allPane.setBottomComponent(new JScrollPane(messageTextArea)); |
|
1004 |
- allPane.setDividerLocation(150); |
|
1005 |
- |
|
1006 |
- tabbedPane.add("All Packets", allPane); |
|
1007 |
- tabbedPane.setToolTipTextAt(0, "Sent and received packets processed by Smack"); |
|
1008 |
- |
|
1009 |
- // Create UI elements for client generated XML traffic. |
|
1010 |
- final JTextArea sentText = new JTextArea(); |
|
1011 |
- sentText.setWrapStyleWord(true); |
|
1012 |
- sentText.setLineWrap(true); |
|
1013 |
- sentText.setEditable(false); |
|
1014 |
- sentText.setForeground(new Color(112, 3, 3)); |
|
1015 |
- tabbedPane.add("Raw Sent Packets", new JScrollPane(sentText)); |
|
1016 |
- tabbedPane.setToolTipTextAt(1, "Raw text of the sent packets"); |
|
1017 |
- |
|
1018 |
- // Add pop-up menu. |
|
1019 |
- menu = new JPopupMenu(); |
|
1020 |
- menuItem1 = new JMenuItem("Copy"); |
|
1021 |
- menuItem1.addActionListener(new ActionListener() { |
|
1022 |
- public void actionPerformed(ActionEvent e) { |
|
1023 |
- // Get the clipboard |
|
1024 |
- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); |
|
1025 |
- // Set the sent text as the new content of the clipboard |
|
1026 |
- clipboard.setContents(new StringSelection(sentText.getText()), null); |
|
1027 |
- } |
|
1028 |
- }); |
|
1029 |
- |
|
1030 |
- JMenuItem menuItem2 = new JMenuItem("Clear"); |
|
1031 |
- menuItem2.addActionListener(new ActionListener() { |
|
1032 |
- public void actionPerformed(ActionEvent e) { |
|
1033 |
- sentText.setText(""); |
|
1034 |
- } |
|
1035 |
- }); |
|
1036 |
- |
|
1037 |
- // Add listener to the text area so the popup menu can come up. |
|
1038 |
- sentText.addMouseListener(new PopupListener(menu)); |
|
1039 |
- menu.add(menuItem1); |
|
1040 |
- menu.add(menuItem2); |
|
1041 |
- |
|
1042 |
- // Create UI elements for server generated XML traffic. |
|
1043 |
- final JTextArea receivedText = new JTextArea(); |
|
1044 |
- receivedText.setWrapStyleWord(true); |
|
1045 |
- receivedText.setLineWrap(true); |
|
1046 |
- receivedText.setEditable(false); |
|
1047 |
- receivedText.setForeground(new Color(6, 76, 133)); |
|
1048 |
- tabbedPane.add("Raw Received Packets", new JScrollPane(receivedText)); |
|
1049 |
- tabbedPane.setToolTipTextAt( |
|
1050 |
- 2, |
|
1051 |
- "Raw text of the received packets before Smack process them"); |
|
1052 |
- |
|
1053 |
- // Add pop-up menu. |
|
1054 |
- menu = new JPopupMenu(); |
|
1055 |
- menuItem1 = new JMenuItem("Copy"); |
|
1056 |
- menuItem1.addActionListener(new ActionListener() { |
|
1057 |
- public void actionPerformed(ActionEvent e) { |
|
1058 |
- // Get the clipboard |
|
1059 |
- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); |
|
1060 |
- // Set the sent text as the new content of the clipboard |
|
1061 |
- clipboard.setContents(new StringSelection(receivedText.getText()), null); |
|
1062 |
- } |
|
1063 |
- }); |
|
1064 |
- |
|
1065 |
- menuItem2 = new JMenuItem("Clear"); |
|
1066 |
- menuItem2.addActionListener(new ActionListener() { |
|
1067 |
- public void actionPerformed(ActionEvent e) { |
|
1068 |
- receivedText.setText(""); |
|
1069 |
- } |
|
1070 |
- }); |
|
1071 |
- |
|
1072 |
- // Add listener to the text area so the popup menu can come up. |
|
1073 |
- receivedText.addMouseListener(new PopupListener(menu)); |
|
1074 |
- menu.add(menuItem1); |
|
1075 |
- menu.add(menuItem2); |
|
1076 |
- |
|
1077 |
- // Create a special Reader that wraps the main Reader and logs data to the GUI. |
|
1078 |
- ObservableReader debugReader = new ObservableReader(reader); |
|
1079 |
- readerListener = new ReaderListener() { |
|
1080 |
- public void read(final String str) { |
|
1081 |
- SwingUtilities.invokeLater(new Runnable() { |
|
1082 |
- public void run() { |
|
1083 |
- if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER && |
|
1084 |
- !EnhancedDebuggerWindow.getInstance().isVisible()) { |
|
1085 |
- // Do not add content if the parent is not visible |
|
1086 |
- return; |
|
1087 |
- } |
|
1088 |
- |
|
1089 |
- int index = str.lastIndexOf(">"); |
|
1090 |
- if (index != -1) { |
|
1091 |
- if (receivedText.getLineCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) |
|
1092 |
- { |
|
1093 |
- try { |
|
1094 |
- receivedText.replaceRange("", 0, receivedText.getLineEndOffset(0)); |
|
1095 |
- } |
|
1096 |
- catch (BadLocationException e) { |
|
1097 |
- e.printStackTrace(); |
|
1098 |
- } |
|
1099 |
- } |
|
1100 |
- receivedText.append(str.substring(0, index + 1)); |
|
1101 |
- receivedText.append(NEWLINE); |
|
1102 |
- if (str.length() > index) { |
|
1103 |
- receivedText.append(str.substring(index + 1)); |
|
1104 |
- } |
|
1105 |
- } |
|
1106 |
- else { |
|
1107 |
- receivedText.append(str); |
|
1108 |
- } |
|
1109 |
- } |
|
1110 |
- }); |
|
1111 |
- } |
|
1112 |
- }; |
|
1113 |
- debugReader.addReaderListener(readerListener); |
|
1114 |
- |
|
1115 |
- // Create a special Writer that wraps the main Writer and logs data to the GUI. |
|
1116 |
- ObservableWriter debugWriter = new ObservableWriter(writer); |
|
1117 |
- writerListener = new WriterListener() { |
|
1118 |
- public void write(final String str) { |
|
1119 |
- SwingUtilities.invokeLater(new Runnable() { |
|
1120 |
- public void run() { |
|
1121 |
- if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER && |
|
1122 |
- !EnhancedDebuggerWindow.getInstance().isVisible()) { |
|
1123 |
- // Do not add content if the parent is not visible |
|
1124 |
- return; |
|
1125 |
- } |
|
1126 |
- |
|
1127 |
- if (sentText.getLineCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) { |
|
1128 |
- try { |
|
1129 |
- sentText.replaceRange("", 0, sentText.getLineEndOffset(0)); |
|
1130 |
- } |
|
1131 |
- catch (BadLocationException e) { |
|
1132 |
- e.printStackTrace(); |
|
1133 |
- } |
|
1134 |
- } |
|
1135 |
- |
|
1136 |
- sentText.append(str); |
|
1137 |
- if (str.endsWith(">")) { |
|
1138 |
- sentText.append(NEWLINE); |
|
1139 |
- } |
|
1140 |
- } |
|
1141 |
- }); |
|
1142 |
- |
|
1143 |
- |
|
1144 |
- } |
|
1145 |
- }; |
|
1146 |
- debugWriter.addWriterListener(writerListener); |
|
1147 |
- |
|
1148 |
- // Assign the reader/writer objects to use the debug versions. The packet reader |
|
1149 |
- // and writer will use the debug versions when they are created. |
|
1150 |
- reader = debugReader; |
|
1151 |
- writer = debugWriter; |
|
1152 |
- |
|
1153 |
- } |
|
1154 |
- |
|
1155 |
- private void addAdhocPacketPanel() { |
|
1156 |
- // Create UI elements for sending ad-hoc messages. |
|
1157 |
- final JTextArea adhocMessages = new JTextArea(); |
|
1158 |
- adhocMessages.setEditable(true); |
|
1159 |
- adhocMessages.setForeground(new Color(1, 94, 35)); |
|
1160 |
- tabbedPane.add("Ad-hoc message", new JScrollPane(adhocMessages)); |
|
1161 |
- tabbedPane.setToolTipTextAt(3, "Panel that allows you to send adhoc packets"); |
|
1162 |
- |
|
1163 |
- // Add pop-up menu. |
|
1164 |
- JPopupMenu menu = new JPopupMenu(); |
|
1165 |
- JMenuItem menuItem = new JMenuItem("Message"); |
|
1166 |
- menuItem.addActionListener(new ActionListener() { |
|
1167 |
- public void actionPerformed(ActionEvent e) { |
|
1168 |
- adhocMessages.setText( |
|
1169 |
- "<message to=\"\" id=\"" |
|
1170 |
- + StringUtils.randomString(5) |
|
1171 |
- + "-X\"><body></body></message>"); |
|
1172 |
- } |
|
1173 |
- }); |
|
1174 |
- menu.add(menuItem); |
|
1175 |
- |
|
1176 |
- menuItem = new JMenuItem("IQ Get"); |
|
1177 |
- menuItem.addActionListener(new ActionListener() { |
|
1178 |
- public void actionPerformed(ActionEvent e) { |
|
1179 |
- adhocMessages.setText( |
|
1180 |
- "<iq type=\"get\" to=\"\" id=\"" |
|
1181 |
- + StringUtils.randomString(5) |
|
1182 |
- + "-X\"><query xmlns=\"\"></query></iq>"); |
|
1183 |
- } |
|
1184 |
- }); |
|
1185 |
- menu.add(menuItem); |
|
1186 |
- |
|
1187 |
- menuItem = new JMenuItem("IQ Set"); |
|
1188 |
- menuItem.addActionListener(new ActionListener() { |
|
1189 |
- public void actionPerformed(ActionEvent e) { |
|
1190 |
- adhocMessages.setText( |
|
1191 |
- "<iq type=\"set\" to=\"\" id=\"" |
|
1192 |
- + StringUtils.randomString(5) |
|
1193 |
- + "-X\"><query xmlns=\"\"></query></iq>"); |
|
1194 |
- } |
|
1195 |
- }); |
|
1196 |
- menu.add(menuItem); |
|
1197 |
- |
|
1198 |
- menuItem = new JMenuItem("Presence"); |
|
1199 |
- menuItem.addActionListener(new ActionListener() { |
|
1200 |
- public void actionPerformed(ActionEvent e) { |
|
1201 |
- adhocMessages.setText( |
|
1202 |
- "<presence to=\"\" id=\"" + StringUtils.randomString(5) + "-X\"/>"); |
|
1203 |
- } |
|
1204 |
- }); |
|
1205 |
- menu.add(menuItem); |
|
1206 |
- menu.addSeparator(); |
|
1207 |
- |
|
1208 |
- menuItem = new JMenuItem("Send"); |
|
1209 |
- menuItem.addActionListener(new ActionListener() { |
|
1210 |
- public void actionPerformed(ActionEvent e) { |
|
1211 |
- if (!"".equals(adhocMessages.getText())) { |
|
1212 |
- AdHocPacket packetToSend = new AdHocPacket(adhocMessages.getText()); |
|
1213 |
- connection.sendPacket(packetToSend); |
|
1214 |
- } |
|
1215 |
- } |
|
1216 |
- }); |
|
1217 |
- menu.add(menuItem); |
|
1218 |
- |
|
1219 |
- menuItem = new JMenuItem("Clear"); |
|
1220 |
- menuItem.addActionListener(new ActionListener() { |
|
1221 |
- public void actionPerformed(ActionEvent e) { |
|
1222 |
- adhocMessages.setText(null); |
|
1223 |
- } |
|
1224 |
- }); |
|
1225 |
- menu.add(menuItem); |
|
1226 |
- |
|
1227 |
- // Add listener to the text area so the popup menu can come up. |
|
1228 |
- adhocMessages.addMouseListener(new PopupListener(menu)); |
|
1229 |
- } |
|
1230 |
- |
|
1231 |
- private void addInformationPanel() { |
|
1232 |
- // Create UI elements for connection information. |
|
1233 |
- JPanel informationPanel = new JPanel(); |
|
1234 |
- informationPanel.setLayout(new BorderLayout()); |
|
1235 |
- |
|
1236 |
- // Add the Host information |
|
1237 |
- JPanel connPanel = new JPanel(); |
|
1238 |
- connPanel.setLayout(new GridBagLayout()); |
|
1239 |
- connPanel.setBorder(BorderFactory.createTitledBorder("Connection information")); |
|
1240 |
- |
|
1241 |
- JLabel label = new JLabel("Host: "); |
|
1242 |
- label.setMinimumSize(new java.awt.Dimension(150, 14)); |
|
1243 |
- label.setMaximumSize(new java.awt.Dimension(150, 14)); |
|
1244 |
- connPanel.add( |
|
1245 |
- label, |
|
1246 |
- new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0)); |
|
1247 |
- JFormattedTextField field = new JFormattedTextField(connection.getServiceName()); |
|
1248 |
- field.setMinimumSize(new java.awt.Dimension(150, 20)); |
|
1249 |
- field.setMaximumSize(new java.awt.Dimension(150, 20)); |
|
1250 |
- field.setEditable(false); |
|
1251 |
- field.setBorder(null); |
|
1252 |
- connPanel.add( |
|
1253 |
- field, |
|
1254 |
- new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0)); |
|
1255 |
- |
|
1256 |
- // Add the Port information |
|
1257 |
- label = new JLabel("Port: "); |
|
1258 |
- label.setMinimumSize(new java.awt.Dimension(150, 14)); |
|
1259 |
- label.setMaximumSize(new java.awt.Dimension(150, 14)); |
|
1260 |
- connPanel.add( |
|
1261 |
- label, |
|
1262 |
- new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0)); |
|
1263 |
- field = new JFormattedTextField(connection.getPort()); |
|
1264 |
- field.setMinimumSize(new java.awt.Dimension(150, 20)); |
|
1265 |
- field.setMaximumSize(new java.awt.Dimension(150, 20)); |
|
1266 |
- field.setEditable(false); |
|
1267 |
- field.setBorder(null); |
|
1268 |
- connPanel.add( |
|
1269 |
- field, |
|
1270 |
- new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0)); |
|
1271 |
- |
|
1272 |
- // Add the connection's User information |
|
1273 |
- label = new JLabel("User: "); |
|
1274 |
- label.setMinimumSize(new java.awt.Dimension(150, 14)); |
|
1275 |
- label.setMaximumSize(new java.awt.Dimension(150, 14)); |
|
1276 |
- connPanel.add( |
|
1277 |
- label, |
|
1278 |
- new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0)); |
|
1279 |
- userField = new JFormattedTextField(); |
|
1280 |
- userField.setMinimumSize(new java.awt.Dimension(150, 20)); |
|
1281 |
- userField.setMaximumSize(new java.awt.Dimension(150, 20)); |
|
1282 |
- userField.setEditable(false); |
|
1283 |
- userField.setBorder(null); |
|
1284 |
- connPanel.add( |
|
1285 |
- userField, |
|
1286 |
- new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0)); |
|
1287 |
- |
|
1288 |
- // Add the connection's creationTime information |
|
1289 |
- label = new JLabel("Creation time: "); |
|
1290 |
- label.setMinimumSize(new java.awt.Dimension(150, 14)); |
|
1291 |
- label.setMaximumSize(new java.awt.Dimension(150, 14)); |
|
1292 |
- connPanel.add( |
|
1293 |
- label, |
|
1294 |
- new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0)); |
|
1295 |
- field = new JFormattedTextField(new SimpleDateFormat("yyyy.MM.dd hh:mm:ss aaa")); |
|
1296 |
- field.setMinimumSize(new java.awt.Dimension(150, 20)); |
|
1297 |
- field.setMaximumSize(new java.awt.Dimension(150, 20)); |
|
1298 |
- field.setValue(creationTime); |
|
1299 |
- field.setEditable(false); |
|
1300 |
- field.setBorder(null); |
|
1301 |
- connPanel.add( |
|
1302 |
- field, |
|
1303 |
- new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0)); |
|
1304 |
- |
|
1305 |
- // Add the connection's creationTime information |
|
1306 |
- label = new JLabel("Status: "); |
|
1307 |
- label.setMinimumSize(new java.awt.Dimension(150, 14)); |
|
1308 |
- label.setMaximumSize(new java.awt.Dimension(150, 14)); |
|
1309 |
- connPanel.add( |
|
1310 |
- label, |
|
1311 |
- new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0)); |
|
1312 |
- statusField = new JFormattedTextField(); |
|
1313 |
- statusField.setMinimumSize(new java.awt.Dimension(150, 20)); |
|
1314 |
- statusField.setMaximumSize(new java.awt.Dimension(150, 20)); |
|
1315 |
- statusField.setValue("Active"); |
|
1316 |
- statusField.setEditable(false); |
|
1317 |
- statusField.setBorder(null); |
|
1318 |
- connPanel.add( |
|
1319 |
- statusField, |
|
1320 |
- new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0)); |
|
1321 |
- // Add the connection panel to the information panel |
|
1322 |
- informationPanel.add(connPanel, BorderLayout.NORTH); |
|
1323 |
- |
|
1324 |
- // Add the Number of sent packets information |
|
1325 |
- JPanel packetsPanel = new JPanel(); |
|
1326 |
- packetsPanel.setLayout(new GridLayout(1, 1)); |
|
1327 |
- packetsPanel.setBorder(BorderFactory.createTitledBorder("Transmitted Packets")); |
|
1328 |
- |
|
1329 |
- statisticsTable = |
|
1330 |
- new DefaultTableModel(new Object[][]{{"IQ", 0, 0}, {"Message", 0, 0}, |
|
1331 |
- {"Presence", 0, 0}, {"Other", 0, 0}, {"Total", 0, 0}}, |
|
1332 |
- new Object[]{"Type", "Received", "Sent"}) { |
|
1333 |
- private static final long serialVersionUID = -6793886085109589269L; |
|
1334 |
- public boolean isCellEditable(int rowIndex, int mColIndex) { |
|
1335 |
- return false; |
|
1336 |
- } |
|
1337 |
- }; |
|
1338 |
- JTable table = new JTable(statisticsTable); |
|
1339 |
- // Allow only single a selection |
|
1340 |
- table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
|
1341 |
- packetsPanel.add(new JScrollPane(table)); |
|
1342 |
- |
|
1343 |
- // Add the packets panel to the information panel |
|
1344 |
- informationPanel.add(packetsPanel, BorderLayout.CENTER); |
|
1345 |
- |
|
1346 |
- tabbedPane.add("Information", new JScrollPane(informationPanel)); |
|
1347 |
- tabbedPane.setToolTipTextAt(4, "Information and statistics about the debugged connection"); |
|
1348 |
- } |
|
1349 |
- |
|
1350 |
- public Reader newConnectionReader(Reader newReader) { |
|
1351 |
- ((ObservableReader) reader).removeReaderListener(readerListener); |
|
1352 |
- ObservableReader debugReader = new ObservableReader(newReader); |
|
1353 |
- debugReader.addReaderListener(readerListener); |
|
1354 |
- reader = debugReader; |
|
1355 |
- return reader; |
|
1356 |
- } |
|
1357 |
- |
|
1358 |
- public Writer newConnectionWriter(Writer newWriter) { |
|
1359 |
- ((ObservableWriter) writer).removeWriterListener(writerListener); |
|
1360 |
- ObservableWriter debugWriter = new ObservableWriter(newWriter); |
|
1361 |
- debugWriter.addWriterListener(writerListener); |
|
1362 |
- writer = debugWriter; |
|
1363 |
- return writer; |
|
1364 |
- } |
|
1365 |
- |
|
1366 |
- public void userHasLogged(final String user) { |
|
1367 |
- final EnhancedDebugger debugger = this; |
|
1368 |
- SwingUtilities.invokeLater(new Runnable() { |
|
1369 |
- public void run() { |
|
1370 |
- userField.setText(user); |
|
1371 |
- EnhancedDebuggerWindow.userHasLogged(debugger, user); |
|
1372 |
- // Add the connection listener to the connection so that the debugger can be notified |
|
1373 |
- // whenever the connection is closed. |
|
1374 |
- connection.addConnectionListener(connListener); |
|
1375 |
- } |
|
1376 |
- }); |
|
1377 |
- |
|
1378 |
- } |
|
1379 |
- |
|
1380 |
- public Reader getReader() { |
|
1381 |
- return reader; |
|
1382 |
- } |
|
1383 |
- |
|
1384 |
- public Writer getWriter() { |
|
1385 |
- return writer; |
|
1386 |
- } |
|
1387 |
- |
|
1388 |
- public PacketListener getReaderListener() { |
|
1389 |
- return packetReaderListener; |
|
1390 |
- } |
|
1391 |
- |
|
1392 |
- public PacketListener getWriterListener() { |
|
1393 |
- return packetWriterListener; |
|
1394 |
- } |
|
1395 |
- |
|
1396 |
- /** |
|
1397 |
- * Updates the statistics table |
|
1398 |
- */ |
|
1399 |
- private void updateStatistics() { |
|
1400 |
- statisticsTable.setValueAt(Integer.valueOf(receivedIQPackets), 0, 1); |
|
1401 |
- statisticsTable.setValueAt(Integer.valueOf(sentIQPackets), 0, 2); |
|
1402 |
- |
|
1403 |
- statisticsTable.setValueAt(Integer.valueOf(receivedMessagePackets), 1, 1); |
|
1404 |
- statisticsTable.setValueAt(Integer.valueOf(sentMessagePackets), 1, 2); |
|
1405 |
- |
|
1406 |
- statisticsTable.setValueAt(Integer.valueOf(receivedPresencePackets), 2, 1); |
|
1407 |
- statisticsTable.setValueAt(Integer.valueOf(sentPresencePackets), 2, 2); |
|
1408 |
- |
|
1409 |
- statisticsTable.setValueAt(Integer.valueOf(receivedOtherPackets), 3, 1); |
|
1410 |
- statisticsTable.setValueAt(Integer.valueOf(sentOtherPackets), 3, 2); |
|
1411 |
- |
|
1412 |
- statisticsTable.setValueAt(Integer.valueOf(receivedPackets), 4, 1); |
|
1413 |
- statisticsTable.setValueAt(Integer.valueOf(sentPackets), 4, 2); |
|
1414 |
- } |
|
1415 |
- |
|
1416 |
- /** |
|
1417 |
- * Adds the received packet detail to the messages table. |
|
1418 |
- * |
|
1419 |
- * @param dateFormatter the SimpleDateFormat to use to format Dates |
|
1420 |
- * @param packet the read packet to add to the table |
|
1421 |
- */ |
|
1422 |
- private void addReadPacketToTable(final SimpleDateFormat dateFormatter, final Packet packet) { |
|
1423 |
- SwingUtilities.invokeLater(new Runnable() { |
|
1424 |
- public void run() { |
|
1425 |
- String messageType; |
|
1426 |
- String from = packet.getFrom(); |
|
1427 |
- String type = ""; |
|
1428 |
- Icon packetTypeIcon; |
|
1429 |
- receivedPackets++; |
|
1430 |
- if (packet instanceof IQ) { |
|
1431 |
- packetTypeIcon = iqPacketIcon; |
|
1432 |
- messageType = "IQ Received (class=" + packet.getClass().getName() + ")"; |
|
1433 |
- type = ((IQ) packet).getType().toString(); |
|
1434 |
- receivedIQPackets++; |
|
1435 |
- } |
|
1436 |
- else if (packet instanceof Message) { |
|
1437 |
- packetTypeIcon = messagePacketIcon; |
|
1438 |
- messageType = "Message Received"; |
|
1439 |
- type = ((Message) packet).getType().toString(); |
|
1440 |
- receivedMessagePackets++; |
|
1441 |
- } |
|
1442 |
- else if (packet instanceof Presence) { |
|
1443 |
- packetTypeIcon = presencePacketIcon; |
|
1444 |
- messageType = "Presence Received"; |
|
1445 |
- type = ((Presence) packet).getType().toString(); |
|
1446 |
- receivedPresencePackets++; |
|
1447 |
- } |
|
1448 |
- else { |
|
1449 |
- packetTypeIcon = unknownPacketTypeIcon; |
|
1450 |
- messageType = packet.getClass().getName() + " Received"; |
|
1451 |
- receivedOtherPackets++; |
|
1452 |
- } |
|
1453 |
- |
|
1454 |
- // Check if we need to remove old rows from the table to keep memory consumption low |
|
1455 |
- if (EnhancedDebuggerWindow.MAX_TABLE_ROWS > 0 && |
|
1456 |
- messagesTable.getRowCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) { |
|
1457 |
- messagesTable.removeRow(0); |
|
1458 |
- } |
|
1459 |
- |
|
1460 |
- messagesTable.addRow( |
|
1461 |
- new Object[]{ |
|
1462 |
- formatXML(packet.toXML()), |
|
1463 |
- dateFormatter.format(new Date()), |
|
1464 |
- packetReceivedIcon, |
|
1465 |
- packetTypeIcon, |
|
1466 |
- messageType, |
|
1467 |
- packet.getPacketID(), |
|
1468 |
- type, |
|
1469 |
- "", |
|
1470 |
- from}); |
|
1471 |
- // Update the statistics table |
|
1472 |
- updateStatistics(); |
|
1473 |
- } |
|
1474 |
- }); |
|
1475 |
- } |
|
1476 |
- |
|
1477 |
- /** |
|
1478 |
- * Adds the sent packet detail to the messages table. |
|
1479 |
- * |
|
1480 |
- * @param dateFormatter the SimpleDateFormat to use to format Dates |
|
1481 |
- * @param packet the sent packet to add to the table |
|
1482 |
- */ |
|
1483 |
- private void addSentPacketToTable(final SimpleDateFormat dateFormatter, final Packet packet) { |
|
1484 |
- SwingUtilities.invokeLater(new Runnable() { |
|
1485 |
- public void run() { |
|
1486 |
- String messageType; |
|
1487 |
- String to = packet.getTo(); |
|
1488 |
- String type = ""; |
|
1489 |
- Icon packetTypeIcon; |
|
1490 |
- sentPackets++; |
|
1491 |
- if (packet instanceof IQ) { |
|
1492 |
- packetTypeIcon = iqPacketIcon; |
|
1493 |
- messageType = "IQ Sent (class=" + packet.getClass().getName() + ")"; |
|
1494 |
- type = ((IQ) packet).getType().toString(); |
|
1495 |
- sentIQPackets++; |
|
1496 |
- } |
|
1497 |
- else if (packet instanceof Message) { |
|
1498 |
- packetTypeIcon = messagePacketIcon; |
|
1499 |
- messageType = "Message Sent"; |
|
1500 |
- type = ((Message) packet).getType().toString(); |
|
1501 |
- sentMessagePackets++; |
|
1502 |
- } |
|
1503 |
- else if (packet instanceof Presence) { |
|
1504 |
- packetTypeIcon = presencePacketIcon; |
|
1505 |
- messageType = "Presence Sent"; |
|
1506 |
- type = ((Presence) packet).getType().toString(); |
|
1507 |
- sentPresencePackets++; |
|
1508 |
- } |
|
1509 |
- else { |
|
1510 |
- packetTypeIcon = unknownPacketTypeIcon; |
|
1511 |
- messageType = packet.getClass().getName() + " Sent"; |
|
1512 |
- sentOtherPackets++; |
|
1513 |
- } |
|
1514 |
- |
|
1515 |
- // Check if we need to remove old rows from the table to keep memory consumption low |
|
1516 |
- if (EnhancedDebuggerWindow.MAX_TABLE_ROWS > 0 && |
|
1517 |
- messagesTable.getRowCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) { |
|
1518 |
- messagesTable.removeRow(0); |
|
1519 |
- } |
|
1520 |
- |
|
1521 |
- messagesTable.addRow( |
|
1522 |
- new Object[]{ |
|
1523 |
- formatXML(packet.toXML()), |
|
1524 |
- dateFormatter.format(new Date()), |
|
1525 |
- packetSentIcon, |
|
1526 |
- packetTypeIcon, |
|
1527 |
- messageType, |
|
1528 |
- packet.getPacketID(), |
|
1529 |
- type, |
|
1530 |
- to, |
|
1531 |
- ""}); |
|
1532 |
- |
|
1533 |
- // Update the statistics table |
|
1534 |
- updateStatistics(); |
|
1535 |
- } |
|
1536 |
- }); |
|
1537 |
- } |
|
1538 |
- |
|
1539 |
- private String formatXML(String str) { |
|
1540 |
- try { |
|
1541 |
- // Use a Transformer for output |
|
1542 |
- TransformerFactory tFactory = TransformerFactory.newInstance(); |
|
1543 |
- // Surround this setting in a try/catch for compatibility with Java 1.4. This setting is required |
|
1544 |
- // for Java 1.5 |
|
1545 |
- try { |
|
1546 |
- tFactory.setAttribute("indent-number", 2); |
|
1547 |
- } |
|
1548 |
- catch (IllegalArgumentException e) { |
|
1549 |
- // Ignore |
|
1550 |
- } |
|
1551 |
- Transformer transformer = tFactory.newTransformer(); |
|
1552 |
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); |
|
1553 |
- transformer.setOutputProperty(OutputKeys.INDENT, "yes"); |
|
1554 |
- transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); |
|
1555 |
- |
|
1556 |
- // Transform the requested string into a nice formatted XML string |
|
1557 |
- StreamSource source = new StreamSource(new StringReader(str)); |
|
1558 |
- StringWriter sw = new StringWriter(); |
|
1559 |
- StreamResult result = new StreamResult(sw); |
|
1560 |
- transformer.transform(source, result); |
|
1561 |
- return sw.toString(); |
|
1562 |
- |
|
1563 |
- } |
|
1564 |
- catch (TransformerConfigurationException tce) { |
|
1565 |
- // Error generated by the parser |
|
1566 |
- System.out.println("\n** Transformer Factory error"); |
|
1567 |
- System.out.println(" " + tce.getMessage()); |
|
1568 |
- |
|
1569 |
- // Use the contained exception, if any |
|
1570 |
- Throwable x = tce; |
|
1571 |
- if (tce.getException() != null) |
|
1572 |
- x = tce.getException(); |
|
1573 |
- x.printStackTrace(); |
|
1574 |
- |
|
1575 |
- } |
|
1576 |
- catch (TransformerException te) { |
|
1577 |
- // Error generated by the parser |
|
1578 |
- System.out.println("\n** Transformation error"); |
|
1579 |
- System.out.println(" " + te.getMessage()); |
|
1580 |
- |
|
1581 |
- // Use the contained exception, if any |
|
1582 |
- Throwable x = te; |
|
1583 |
- if (te.getException() != null) |
|
1584 |
- x = te.getException(); |
|
1585 |
- x.printStackTrace(); |
|
1586 |
- |
|
1587 |
- } |
|
1588 |
- return str; |
|
1589 |
- } |
|
1590 |
- |
|
1591 |
- /** |
|
1592 |
- * Returns true if the debugger's connection with the server is up and running. |
|
1593 |
- * |
|
1594 |
- * @return true if the connection with the server is active. |
|
1595 |
- */ |
|
1596 |
- boolean isConnectionActive() { |
|
1597 |
- return connection.isConnected(); |
|
1598 |
- } |
|
1599 |
- |
|
1600 |
- /** |
|
1601 |
- * Stops debugging the connection. Removes any listener on the connection. |
|
1602 |
- */ |
|
1603 |
- void cancel() { |
|
1604 |
- connection.removeConnectionListener(connListener); |
|
1605 |
- connection.removePacketListener(packetReaderListener); |
|
1606 |
- connection.removePacketWriterListener(packetWriterListener); |
|
1607 |
- ((ObservableReader) reader).removeReaderListener(readerListener); |
|
1608 |
- ((ObservableWriter) writer).removeWriterListener(writerListener); |
|
1609 |
- messagesTable = null; |
|
1610 |
- } |
|
1611 |
- |
|
1612 |
- /** |
|
1613 |
- * An ad-hoc packet is like any regular packet but with the exception that it's intention is |
|
1614 |
- * to be used only <b>to send packets</b>.<p> |
|
1615 |
- * <p/> |
|
1616 |
- * The whole text to send must be passed to the constructor. This implies that the client of |
|
1617 |
- * this class is responsible for sending a valid text to the constructor. |
|
1618 |
- */ |
|
1619 |
- private class AdHocPacket extends Packet { |
|
1620 |
- |
|
1621 |
- private String text; |
|
1622 |
- |
|
1623 |
- /** |
|
1624 |
- * Create a new AdHocPacket with the text to send. The passed text must be a valid text to |
|
1625 |
- * send to the server, no validation will be done on the passed text. |
|
1626 |
- * |
|
1627 |
- * @param text the whole text of the packet to send |
|
1628 |
- */ |
|
1629 |
- public AdHocPacket(String text) { |
|
1630 |
- this.text = text; |
|
1631 |
- } |
|
1632 |
- |
|
1633 |
- public String toXML() { |
|
1634 |
- return text; |
|
1635 |
- } |
|
1636 |
- |
|
1637 |
- } |
|
1638 |
- |
|
1639 |
- /** |
|
1640 |
- * Listens for debug window popup dialog events. |
|
1641 |
- */ |
|
1642 |
- private class PopupListener extends MouseAdapter { |
|
1643 |
- |
|
1644 |
- JPopupMenu popup; |
|
1645 |
- |
|
1646 |
- PopupListener(JPopupMenu popupMenu) { |
|
1647 |
- popup = popupMenu; |
|
1648 |
- } |
|
1649 |
- |
|
1650 |
- public void mousePressed(MouseEvent e) { |
|
1651 |
- maybeShowPopup(e); |
|
1652 |
- } |
|
1653 |
- |
|
1654 |
- public void mouseReleased(MouseEvent e) { |
|
1655 |
- maybeShowPopup(e); |
|
1656 |
- } |
|
1657 |
- |
|
1658 |
- private void maybeShowPopup(MouseEvent e) { |
|
1659 |
- if (e.isPopupTrigger()) { |
|
1660 |
- popup.show(e.getComponent(), e.getX(), e.getY()); |
|
1661 |
- } |
|
1662 |
- } |
|
1663 |
- } |
|
1664 |
- |
|
1665 |
- private class SelectionListener implements ListSelectionListener { |
|
1666 |
- |
|
1667 |
- JTable table; |
|
1668 |
- |
|
1669 |
- // It is necessary to keep the table since it is not possible |
|
1670 |
- // to determine the table from the event's source |
|
1671 |
- SelectionListener(JTable table) { |
|
1672 |
- this.table = table; |
|
1673 |
- } |
|
1674 |
- |
|
1675 |
- public void valueChanged(ListSelectionEvent e) { |
|
1676 |
- if (table.getSelectedRow() == -1) { |
|
1677 |
- // Clear the messageTextArea since there is none packet selected |
|
1678 |
- messageTextArea.setText(null); |
|
1679 |
- } |
|
1680 |
- else { |
|
1681 |
- // Set the detail of the packet in the messageTextArea |
|
1682 |
- messageTextArea.setText( |
|
1683 |
- (String) table.getModel().getValueAt(table.getSelectedRow(), 0)); |
|
1684 |
- // Scroll up to the top |
|
1685 |
- messageTextArea.setCaretPosition(0); |
|
1686 |
- } |
|
1687 |
- } |
|
1688 |
- } |
|
1689 |
-} |
|
1690 |
diff -Nbdru org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java /home/nikita/devel/beem-ui/src/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java |
|
1691 |
--- org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java 2009-06-26 21:11:18.348252001 +0200 |
|
1692 |
+++ /home/nikita/devel/beem-ui/src/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java 1970-01-01 01:00:00.000000000 +0100 |
|
1693 |
@@ -1,375 +0,0 @@ |
|
1694 |
-/** |
|
1695 |
- * $RCSfile$ |
|
1696 |
- * $Revision: 7071 $ |
|
1697 |
- * $Date: 2007-02-12 01:59:05 +0100 (Mon, 12 Feb 2007) $ |
|
1698 |
- * |
|
1699 |
- * Copyright 2003-2007 Jive Software. |
|
1700 |
- * |
|
1701 |
- * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); |
|
1702 |
- * you may not use this file except in compliance with the License. |
|
1703 |
- * You may obtain a copy of the License at |
|
1704 |
- * |
|
1705 |
- * http://www.apache.org/licenses/LICENSE-2.0 |
|
1706 |
- * |
|
1707 |
- * Unless required by applicable law or agreed to in writing, software |
|
1708 |
- * distributed under the License is distributed on an "AS IS" BASIS, |
|
1709 |
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
1710 |
- * See the License for the specific language governing permissions and |
|
1711 |
- * limitations under the License. |
|
1712 |
- */ |
|
1713 |
- |
|
1714 |
-package org.jivesoftware.smackx.debugger; |
|
1715 |
- |
|
1716 |
-import org.jivesoftware.smack.SmackConfiguration; |
|
1717 |
-import org.jivesoftware.smack.provider.ProviderManager; |
|
1718 |
- |
|
1719 |
-import javax.swing.*; |
|
1720 |
-import java.awt.*; |
|
1721 |
-import java.awt.event.*; |
|
1722 |
-import java.net.URL; |
|
1723 |
-import java.util.ArrayList; |
|
1724 |
-import java.util.Collections; |
|
1725 |
-import java.util.Vector; |
|
1726 |
- |
|
1727 |
-/** |
|
1728 |
- * The EnhancedDebuggerWindow is the main debug window that will show all the EnhancedDebuggers. |
|
1729 |
- * For each connection to debug there will be an EnhancedDebugger that will be shown in the |
|
1730 |
- * EnhancedDebuggerWindow.<p> |
|
1731 |
- * <p/> |
|
1732 |
- * This class also provides information about Smack like for example the Smack version and the |
|
1733 |
- * installed providers. |
|
1734 |
- * |
|
1735 |
- * @author Gaston Dombiak |
|
1736 |
- */ |
|
1737 |
-public class EnhancedDebuggerWindow { |
|
1738 |
- |
|
1739 |
- private static EnhancedDebuggerWindow instance; |
|
1740 |
- |
|
1741 |
- private static ImageIcon connectionCreatedIcon; |
|
1742 |
- private static ImageIcon connectionActiveIcon; |
|
1743 |
- private static ImageIcon connectionClosedIcon; |
|
1744 |
- private static ImageIcon connectionClosedOnErrorIcon; |
|
1745 |
- |
|
1746 |
- public static boolean PERSISTED_DEBUGGER = false; |
|
1747 |
- /** |
|
1748 |
- * Keeps the max number of rows to keep in the tables. A value less than 0 means that packets |
|
1749 |
- * will never be removed. If you are planning to use this debugger in a |
|
1750 |
- * production environment then you should set a lower value (e.g. 50) to prevent the debugger |
|
1751 |
- * from consuming all the JVM memory. |
|
1752 |
- */ |
|
1753 |
- public static int MAX_TABLE_ROWS = 150; |
|
1754 |
- |
|
1755 |
- { |
|
1756 |
- URL url; |
|
1757 |
- |
|
1758 |
- url = |
|
1759 |
- Thread.currentThread().getContextClassLoader().getResource( |
|
1760 |
- "images/trafficlight_off.png"); |
|
1761 |
- if (url != null) { |
|
1762 |
- connectionCreatedIcon = new ImageIcon(url); |
|
1763 |
- } |
|
1764 |
- url = |
|
1765 |
- Thread.currentThread().getContextClassLoader().getResource( |
|
1766 |
- "images/trafficlight_green.png"); |
|
1767 |
- if (url != null) { |
|
1768 |
- connectionActiveIcon = new ImageIcon(url); |
|
1769 |
- } |
|
1770 |
- url = |
|
1771 |
- Thread.currentThread().getContextClassLoader().getResource( |
|
1772 |
- "images/trafficlight_red.png"); |
|
1773 |
- if (url != null) { |
|
1774 |
- connectionClosedIcon = new ImageIcon(url); |
|
1775 |
- } |
|
1776 |
- url = Thread.currentThread().getContextClassLoader().getResource("images/warning.png"); |
|
1777 |
- if (url != null) { |
|
1778 |
- connectionClosedOnErrorIcon = new ImageIcon(url); |
|
1779 |
- } |
|
1780 |
- |
|
1781 |
- } |
|
1782 |
- |
|
1783 |
- private JFrame frame = null; |
|
1784 |
- private JTabbedPane tabbedPane = null; |
|
1785 |
- private java.util.List<EnhancedDebugger> debuggers = new ArrayList<EnhancedDebugger>(); |
|
1786 |
- |
|
1787 |
- private EnhancedDebuggerWindow() { |
|
1788 |
- } |
|
1789 |
- |
|
1790 |
- /** |
|
1791 |
- * Returns the unique EnhancedDebuggerWindow instance available in the system. |
|
1792 |
- * |
|
1793 |
- * @return the unique EnhancedDebuggerWindow instance |
|
1794 |
- */ |
|
1795 |
- public static EnhancedDebuggerWindow getInstance() { |
|
1796 |
- if (instance == null) { |
|
1797 |
- instance = new EnhancedDebuggerWindow(); |
|
1798 |
- } |
|
1799 |
- return instance; |
|
1800 |
- } |
|
1801 |
- |
|
1802 |
- /** |
|
1803 |
- * Adds the new specified debugger to the list of debuggers to show in the main window. |
|
1804 |
- * |
|
1805 |
- * @param debugger the new debugger to show in the debug window |
|
1806 |
- */ |
|
1807 |
- synchronized static void addDebugger(EnhancedDebugger debugger) { |
|
1808 |
- getInstance().showNewDebugger(debugger); |
|
1809 |
- } |
|
1810 |
- |
|
1811 |
- /** |
|
1812 |
- * Shows the new debugger in the debug window. |
|
1813 |
- * |
|
1814 |
- * @param debugger the new debugger to show |
|
1815 |
- */ |
|
1816 |
- private void showNewDebugger(EnhancedDebugger debugger) { |
|
1817 |
- if (frame == null) { |
|
1818 |
- createDebug(); |
|
1819 |
- } |
|
1820 |
- debugger.tabbedPane.setName("Connection_" + tabbedPane.getComponentCount()); |
|
1821 |
- tabbedPane.add(debugger.tabbedPane, tabbedPane.getComponentCount() - 1); |
|
1822 |
- tabbedPane.setIconAt(tabbedPane.indexOfComponent(debugger.tabbedPane), connectionCreatedIcon); |
|
1823 |
- frame.setTitle( |
|
1824 |
- "Smack Debug Window -- Total connections: " + (tabbedPane.getComponentCount() - 1)); |
|
1825 |
- // Keep the added debugger for later access |
|
1826 |
- debuggers.add(debugger); |
|
1827 |
- } |
|
1828 |
- |
|
1829 |
- /** |
|
1830 |
- * Notification that a user has logged in to the server. A new title will be set |
|
1831 |
- * to the tab of the given debugger. |
|
1832 |
- * |
|
1833 |
- * @param debugger the debugger whose connection logged in to the server |
|
1834 |
- * @param user the user@host/resource that has just logged in |
|
1835 |
- */ |
|
1836 |
- synchronized static void userHasLogged(EnhancedDebugger debugger, String user) { |
|
1837 |
- int index = getInstance().tabbedPane.indexOfComponent(debugger.tabbedPane); |
|
1838 |
- getInstance().tabbedPane.setTitleAt( |
|
1839 |
- index, |
|
1840 |
- user); |
|
1841 |
- getInstance().tabbedPane.setIconAt( |
|
1842 |
- index, |
|
1843 |
- connectionActiveIcon); |
|
1844 |
- } |
|
1845 |
- |
|
1846 |
- /** |
|
1847 |
- * Notification that the connection was properly closed. |
|
1848 |
- * |
|
1849 |
- * @param debugger the debugger whose connection was properly closed. |
|
1850 |
- */ |
|
1851 |
- synchronized static void connectionClosed(EnhancedDebugger debugger) { |
|
1852 |
- getInstance().tabbedPane.setIconAt( |
|
1853 |
- getInstance().tabbedPane.indexOfComponent(debugger.tabbedPane), |
|
1854 |
- connectionClosedIcon); |
|
1855 |
- } |
|
1856 |
- |
|
1857 |
- /** |
|
1858 |
- * Notification that the connection was closed due to an exception. |
|
1859 |
- * |
|
1860 |
- * @param debugger the debugger whose connection was closed due to an exception. |
|
1861 |
- * @param e the exception. |
|
1862 |
- */ |
|
1863 |
- synchronized static void connectionClosedOnError(EnhancedDebugger debugger, Exception e) { |
|
1864 |
- int index = getInstance().tabbedPane.indexOfComponent(debugger.tabbedPane); |
|
1865 |
- getInstance().tabbedPane.setToolTipTextAt( |
|
1866 |
- index, |
|
1867 |
- "Connection closed due to the exception: " + e.getMessage()); |
|
1868 |
- getInstance().tabbedPane.setIconAt( |
|
1869 |
- index, |
|
1870 |
- connectionClosedOnErrorIcon); |
|
1871 |
- } |
|
1872 |
- |
|
1873 |
- synchronized static void connectionEstablished(EnhancedDebugger debugger) { |
|
1874 |
- getInstance().tabbedPane.setIconAt( |
|
1875 |
- getInstance().tabbedPane.indexOfComponent(debugger.tabbedPane), |
|
1876 |
- connectionActiveIcon); |
|
1877 |
- } |
|
1878 |
- |
|
1879 |
- /** |
|
1880 |
- * Creates the main debug window that provides information about Smack and also shows |
|
1881 |
- * a tab panel for each connection that is being debugged. |
|
1882 |
- */ |
|
1883 |
- private void createDebug() { |
|
1884 |
- |
|
1885 |
- frame = new JFrame("Smack Debug Window"); |
|
1886 |
- |
|
1887 |
- if (!PERSISTED_DEBUGGER) { |
|
1888 |
- // Add listener for window closing event |
|
1889 |
- frame.addWindowListener(new WindowAdapter() { |
|
1890 |
- public void windowClosing(WindowEvent evt) { |
|
1891 |
- rootWindowClosing(evt); |
|
1892 |
- } |
|
1893 |
- }); |
|
1894 |
- } |
|
1895 |
- |
|
1896 |
- // We'll arrange the UI into tabs. The last tab contains Smack's information. |
|
1897 |
- // All the connection debugger tabs will be shown before the Smack info tab. |
|
1898 |
- tabbedPane = new JTabbedPane(); |
|
1899 |
- |
|
1900 |
- // Create the Smack info panel |
|
1901 |
- JPanel informationPanel = new JPanel(); |
|
1902 |
- informationPanel.setLayout(new BoxLayout(informationPanel, BoxLayout.Y_AXIS)); |
|
1903 |
- |
|
1904 |
- // Add the Smack version label |
|
1905 |
- JPanel versionPanel = new JPanel(); |
|
1906 |
- versionPanel.setLayout(new BoxLayout(versionPanel, BoxLayout.X_AXIS)); |
|
1907 |
- versionPanel.setMaximumSize(new Dimension(2000, 31)); |
|
1908 |
- versionPanel.add(new JLabel(" Smack version: ")); |
|
1909 |
- JFormattedTextField field = new JFormattedTextField(SmackConfiguration.getVersion()); |
|
1910 |
- field.setEditable(false); |
|
1911 |
- field.setBorder(null); |
|
1912 |
- versionPanel.add(field); |
|
1913 |
- informationPanel.add(versionPanel); |
|
1914 |
- |
|
1915 |
- // Add the list of installed IQ Providers |
|
1916 |
- JPanel iqProvidersPanel = new JPanel(); |
|
1917 |
- iqProvidersPanel.setLayout(new GridLayout(1, 1)); |
|
1918 |
- iqProvidersPanel.setBorder(BorderFactory.createTitledBorder("Installed IQ Providers")); |
|
1919 |
- Vector<String> providers = new Vector<String>(); |
|
1920 |
- for (Object provider : ProviderManager.getInstance().getIQProviders()) { |
|
1921 |
- if (provider.getClass() == Class.class) { |
|
1922 |
- providers.add(((Class) provider).getName()); |
|
1923 |
- } |
|
1924 |
- else { |
|
1925 |
- providers.add(provider.getClass().getName()); |
|
1926 |
- } |
|
1927 |
- } |
|
1928 |
- // Sort the collection of providers |
|
1929 |
- Collections.sort(providers); |
|
1930 |
- JList list = new JList(providers); |
|
1931 |
- iqProvidersPanel.add(new JScrollPane(list)); |
|
1932 |
- informationPanel.add(iqProvidersPanel); |
|
1933 |
- |
|
1934 |
- // Add the list of installed Extension Providers |
|
1935 |
- JPanel extensionProvidersPanel = new JPanel(); |
|
1936 |
- extensionProvidersPanel.setLayout(new GridLayout(1, 1)); |
|
1937 |
- extensionProvidersPanel.setBorder(BorderFactory.createTitledBorder("Installed Extension Providers")); |
|
1938 |
- providers = new Vector<String>(); |
|
1939 |
- for (Object provider : ProviderManager.getInstance().getExtensionProviders()) { |
|
1940 |
- if (provider.getClass() == Class.class) { |
|
1941 |
- providers.add(((Class) provider).getName()); |
|
1942 |
- } |
|
1943 |
- else { |
|
1944 |
- providers.add(provider.getClass().getName()); |
|
1945 |
- } |
|
1946 |
- } |
|
1947 |
- // Sort the collection of providers |
|
1948 |
- Collections.sort(providers); |
|
1949 |
- list = new JList(providers); |
|
1950 |
- extensionProvidersPanel.add(new JScrollPane(list)); |
|
1951 |
- informationPanel.add(extensionProvidersPanel); |
|
1952 |
- |
|
1953 |
- tabbedPane.add("Smack Info", informationPanel); |
|
1954 |
- |
|
1955 |
- // Add pop-up menu. |
|
1956 |
- JPopupMenu menu = new JPopupMenu(); |
|
1957 |
- // Add a menu item that allows to close the current selected tab |
|
1958 |
- JMenuItem menuItem = new JMenuItem("Close"); |
|
1959 |
- menuItem.addActionListener(new ActionListener() { |
|
1960 |
- public void actionPerformed(ActionEvent e) { |
|
1961 |
- // Remove the selected tab pane if it's not the Smack info pane |
|
1962 |
- if (tabbedPane.getSelectedIndex() < tabbedPane.getComponentCount() - 1) { |
|
1963 |
- int index = tabbedPane.getSelectedIndex(); |
|
1964 |
- // Notify to the debugger to stop debugging |
|
1965 |
- EnhancedDebugger debugger = debuggers.get(index); |
|
1966 |
- debugger.cancel(); |
|
1967 |
- // Remove the debugger from the root window |
|
1968 |
- tabbedPane.remove(debugger.tabbedPane); |
|
1969 |
- debuggers.remove(debugger); |
|
1970 |
- // Update the root window title |
|
1971 |
- frame.setTitle( |
|
1972 |
- "Smack Debug Window -- Total connections: " |
|
1973 |
- + (tabbedPane.getComponentCount() - 1)); |
|
1974 |
- } |
|
1975 |
- } |
|
1976 |
- }); |
|
1977 |
- menu.add(menuItem); |
|
1978 |
- // Add a menu item that allows to close all the tabs that have their connections closed |
|
1979 |
- menuItem = new JMenuItem("Close All Not Active"); |
|
1980 |
- menuItem.addActionListener(new ActionListener() { |
|
1981 |
- public void actionPerformed(ActionEvent e) { |
|
1982 |
- ArrayList<EnhancedDebugger> debuggersToRemove = new ArrayList<EnhancedDebugger>(); |
|
1983 |
- // Remove all the debuggers of which their connections are no longer valid |
|
1984 |
- for (int index = 0; index < tabbedPane.getComponentCount() - 1; index++) { |
|
1985 |
- EnhancedDebugger debugger = debuggers.get(index); |
|
1986 |
- if (!debugger.isConnectionActive()) { |
|
1987 |
- // Notify to the debugger to stop debugging |
|
1988 |
- debugger.cancel(); |
|
1989 |
- debuggersToRemove.add(debugger); |
|
1990 |
- } |
|
1991 |
- } |
|
1992 |
- for (EnhancedDebugger debugger : debuggersToRemove) { |
|
1993 |
- // Remove the debugger from the root window |
|
1994 |
- tabbedPane.remove(debugger.tabbedPane); |
|
1995 |
- debuggers.remove(debugger); |
|
1996 |
- } |
|
1997 |
- // Update the root window title |
|
1998 |
- frame.setTitle( |
|
1999 |
- "Smack Debug Window -- Total connections: " |
|
2000 |
- + (tabbedPane.getComponentCount() - 1)); |
|
2001 |
- } |
|
2002 |
- }); |
|
2003 |
- menu.add(menuItem); |
|
2004 |
- // Add listener to the text area so the popup menu can come up. |
|
2005 |
- tabbedPane.addMouseListener(new PopupListener(menu)); |
|
2006 |
- |
|
2007 |
- frame.getContentPane().add(tabbedPane); |
|
2008 |
- |
|
2009 |
- frame.setSize(650, 400); |
|
2010 |
- |
|
2011 |
- if (!PERSISTED_DEBUGGER) { |
|
2012 |
- frame.setVisible(true); |
|
2013 |
- } |
|
2014 |
- } |
|
2015 |
- |
|
2016 |
- /** |
|
2017 |
- * Notification that the root window is closing. Stop listening for received and |
|
2018 |
- * transmitted packets in all the debugged connections. |
|
2019 |
- * |
|
2020 |
- * @param evt the event that indicates that the root window is closing |
|
2021 |
- */ |
|
2022 |
- public void rootWindowClosing(WindowEvent evt) { |
|
2023 |
- // Notify to all the debuggers to stop debugging |
|
2024 |
- for (EnhancedDebugger debugger : debuggers) { |
|
2025 |
- debugger.cancel(); |
|
2026 |
- } |
|
2027 |
- // Release any reference to the debuggers |
|
2028 |
- debuggers.removeAll(debuggers); |
|
2029 |
- // Release the default instance |
|
2030 |
- instance = null; |
|
2031 |
- } |
|
2032 |
- |
|
2033 |
- /** |
|
2034 |
- * Listens for debug window popup dialog events. |
|
2035 |
- */ |
|
2036 |
- private class PopupListener extends MouseAdapter { |
|
2037 |
- |
|
2038 |
- JPopupMenu popup; |
|
2039 |
- |
|
2040 |
- PopupListener(JPopupMenu popupMenu) { |
|
2041 |
- popup = popupMenu; |
|
2042 |
- } |
|
2043 |
- |
|
2044 |
- public void mousePressed(MouseEvent e) { |
|
2045 |
- maybeShowPopup(e); |
|
2046 |
- } |
|
2047 |
- |
|
2048 |
- public void mouseReleased(MouseEvent e) { |
|
2049 |
- maybeShowPopup(e); |
|
2050 |
- } |
|
2051 |
- |
|
2052 |
- private void maybeShowPopup(MouseEvent e) { |
|
2053 |
- if (e.isPopupTrigger()) { |
|
2054 |
- popup.show(e.getComponent(), e.getX(), e.getY()); |
|
2055 |
- } |
|
2056 |
- } |
|
2057 |
- } |
|
2058 |
- |
|
2059 |
- public void setVisible(boolean visible) { |
|
2060 |
- if (frame != null) { |
|
2061 |
- frame.setVisible(visible); |
|
2062 |
- } |
|
2063 |
- } |
|
2064 |
- |
|
2065 |
- public boolean isVisible() { |
|
2066 |
- return frame != null && frame.isVisible(); |
|
2067 |
- } |
|
2068 |
-} |
|
2069 |
diff -Nbdru org/jivesoftware/smackx/debugger/package.html /home/nikita/devel/beem-ui/src/org/jivesoftware/smackx/debugger/package.html |
|
2070 |
--- org/jivesoftware/smackx/debugger/package.html 2009-06-26 21:11:18.352250912 +0200 |
|
2071 |
+++ /home/nikita/devel/beem-ui/src/org/jivesoftware/smackx/debugger/package.html 1970-01-01 01:00:00.000000000 +0100 |
|
2072 |
@@ -1 +0,0 @@ |
|
2073 |
-<body>Smack optional Debuggers.</body> |
|
2074 |
\ No newline at end of file |