KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > tools > admin > MessagePanel


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA.
18  *
19  * Initial developer(s): ScalAgent DT
20  * Contributor(s):
21  */

22 package org.objectweb.joram.client.tools.admin;
23
24 import java.awt.*;
25 import java.awt.event.*;
26 import javax.swing.*;
27 import java.util.*;
28
29 import javax.jms.*;
30
31 public class MessagePanel extends JPanel {
32   private JTextArea msgDisplay;
33
34   public MessagePanel() {
35     super(new BorderLayout());
36     msgDisplay = new JTextArea();
37     JScrollPane listScroller = new JScrollPane(msgDisplay);
38     listScroller.getViewport().setScrollMode(
39       JViewport.SIMPLE_SCROLL_MODE);
40     listScroller.setPreferredSize(new Dimension(400, 80));
41     listScroller.setMinimumSize(new Dimension(400, 80));
42     listScroller.setAlignmentX(LEFT_ALIGNMENT);
43     add(listScroller, BorderLayout.CENTER);
44   }
45
46   public void setMessage(Message msg) throws Exception JavaDoc {
47     StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
48     if (msg instanceof TextMessage) {
49       buf.append("Text message");
50       buf.append("\nText: " + ((TextMessage)msg).getText());
51     } else if (msg instanceof MapMessage) {
52       buf.append("Map message");
53       buf.append("\nMapped values:");
54       MapMessage mapMsg = (MapMessage)msg;
55       Enumeration e = mapMsg.getMapNames();
56       while (e.hasMoreElements()) {
57         String JavaDoc name = (String JavaDoc) e.nextElement();
58         buf.append("\n - " + name + ": " +
59                    mapMsg.getString(name));
60       }
61     } else if (msg instanceof ObjectMessage) {
62       buf.append("Object message");
63       buf.append(
64         "\nObject (as a string): " +
65         ((ObjectMessage)msg).getObject());
66     } else if (msg instanceof StreamMessage) {
67       buf.append("Stream message");
68     } else if (msg instanceof BytesMessage) {
69       buf.append("Bytes message");
70     }
71     buf.append("\nProperties: " + msg.getJMSType());
72     Enumeration propNames = msg.getPropertyNames();
73     while (propNames.hasMoreElements()) {
74       String JavaDoc propName = (String JavaDoc)propNames.nextElement();
75       buf.append("\n - " + propName + ": " +
76                  msg.getObjectProperty(propName));
77     }
78     buf.append("\nCorrelation id: " + msg.getJMSCorrelationID());
79     buf.append("\nDelivery mode: " + msg.getJMSDeliveryMode());
80     buf.append("\nDestination id: " + msg.getJMSDestination());
81     buf.append("\nExpiration time: " + msg.getJMSExpiration());
82     buf.append("\nIdentifier: " + msg.getJMSMessageID());
83     buf.append("\nPriority: " + msg.getJMSPriority());
84     buf.append("\nRedelivered: " + msg.getJMSRedelivered());
85     buf.append("\nReply to: " + msg.getJMSReplyTo());
86     buf.append("\nTime stamp: " + msg.getJMSTimestamp());
87     msgDisplay.setText(buf.toString());
88   }
89 }
90
Popular Tags