KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exolab > jms > tools > admin > AdminInfo


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2000 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  * $Id: AdminInfo.java,v 1.1 2004/11/26 01:51:15 tanderson Exp $
44  *
45  * Date Author Changes
46  * $Date jimm Created
47  */

48
49
50 package org.exolab.jms.tools.admin;
51
52 import java.awt.Component JavaDoc;
53 import java.awt.FlowLayout JavaDoc;
54
55 import javax.swing.Box JavaDoc;
56 import javax.swing.JPanel JavaDoc;
57 import javax.swing.JTextField JavaDoc;
58 import javax.swing.JTree JavaDoc;
59 import javax.swing.UIManager JavaDoc;
60 import javax.swing.tree.DefaultTreeCellRenderer JavaDoc;
61
62
63 /**
64  * Extracts information about a queue/topic and consumer from the OpenJMSServer
65  * and displays it next to the appropriate cell, in a JTextField.
66  *
67  * The class inherits from DefaultTreeCellrenderer, and is called each time
68  * the tree object needs to redraw itself.
69  *
70  * @version $Revision: 1.1 $ $Date: 2004/11/26 01:51:15 $
71  * @author <a HREF="mailto:mourikis@exolab.org">Jim Mourikis</a>
72  */

73 public class AdminInfo extends DefaultTreeCellRenderer JavaDoc {
74
75     // The text field used to display the info for the cell.
76
protected JTextField JavaDoc field_ = new JTextField JavaDoc("No Messages");
77
78     // The Horizontal box structure the JTextField is inserted into,
79
// to make the cell and text field appear next to each other.
80
private Component JavaDoc strut_ = Box.createHorizontalStrut(5);
81
82     // The panel use to contain the above two swing objects.
83
private JPanel JavaDoc panel_ = new JPanel JavaDoc();
84
85     /**
86      * Construct the panel, and set the background to be that of the tree.
87      * Add the cell, display text field and the horizontal layout to the panel.
88      *
89      */

90     public AdminInfo() {
91         panel_.setBackground(UIManager.getColor("Tree.textBackground"));
92         setOpaque(false);
93         field_.setOpaque(false);
94         panel_.setOpaque(false);
95
96         panel_.setLayout(new FlowLayout JavaDoc(FlowLayout.CENTER, 0, 0));
97         panel_.add(this);
98         panel_.add(strut_);
99         panel_.add(field_);
100     }
101
102
103     /**
104      * A draw request for the cell has been made. If the cell is a queue/topic
105      * fetch all the relevant details, and write the string to the textfield.
106      * If the cell is a consumer, fetch all the consumer details, and write
107      * them into the text field.
108      * For all other cell types do not display the textfield.
109      *
110      * @param tree The JTree this cell belongs to.
111      * @param value The cell being rendered.
112      * @param selected True if this cell has been selected.
113      * @param expanded True if this cell has been opened up.
114      * @param leaf True if this is a leaf node.
115      * @param row The row this node is in.
116      * @param hasFocus True is this node currently has the focus.
117      * @return Component The panel all the object belong to.
118      *
119      */

120     public Component JavaDoc getTreeCellRendererComponent
121         (JTree JavaDoc tree, Object JavaDoc value, boolean selected, boolean expanded,
122          boolean leaf, int row, boolean hasFocus) {
123         super.getTreeCellRendererComponent(tree, value, selected, expanded,
124             leaf, row, hasFocus);
125         if (value instanceof OpenJMSNode) {
126             field_.setForeground(java.awt.Color.black);
127             if (value instanceof OpenJMSQueue) {
128                 if (AbstractAdminConnection.instance() != null) {
129                     OpenJMSQueue queue = (OpenJMSQueue) value;
130
131                     int num = AbstractAdminConnection.instance().getQueueMessageCount(
132                         queue.toString());
133                     String JavaDoc st = Integer.toString(num);
134                     field_.setText(st);
135                     field_.setVisible(true);
136                 }
137             } else if (value instanceof OpenJMSTopic) {
138                 // do nothing
139
field_.setVisible(false);
140             } else if (value instanceof OpenJMSUser) {
141                 // do nothing
142
field_.setVisible(false);
143             } else if (value instanceof OpenJMSConsumer) {
144                 if (AbstractAdminConnection.instance() != null) {
145                     OpenJMSConsumer consumer = (OpenJMSConsumer) value;
146                     OpenJMSTopic topic = (OpenJMSTopic) consumer.getParent();
147
148                     int num = AbstractAdminConnection.instance().getDurableConsumerMessageCount(
149                         topic.toString(), consumer.toString());
150                     String JavaDoc st = Integer.toString(num);
151
152                     if (AbstractAdminConnection.instance().isConnected(
153                         consumer.toString())) {
154                         field_.setForeground(java.awt.Color.red);
155                     }
156                     field_.setText(st);
157                     field_.setVisible(true);
158                 }
159             }
160         } else {
161             field_.setVisible(false);
162         }
163
164         return panel_;
165     }
166
167 } // End AdminInfo
168
Popular Tags