KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > imr > util > ImRTreeCellRenderer


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21 package org.jacorb.imr.util;
22
23 import javax.swing.tree.*;
24 import javax.swing.*;
25 import java.awt.Component JavaDoc;
26 import org.jacorb.imr.*;
27 /**
28  * This class sets the tooltip text for the tree cells,
29  * and, if possible, enhances the test with HTML.
30  *
31  * @author Nicolas Noffke
32  *
33  * $Id: ImRTreeCellRenderer.java,v 1.8 2004/05/06 12:39:59 nicolas Exp $
34  */

35
36 public class ImRTreeCellRenderer extends DefaultTreeCellRenderer {
37     private boolean m_use_html_labels = false;
38     
39     public ImRTreeCellRenderer() {
40         super();
41     }
42
43     /**
44      * Set the tooltip text and overwrite the labels with HTML.
45      */

46     public Component JavaDoc getTreeCellRendererComponent(JTree tree, Object JavaDoc value,
47                                                   boolean sel, boolean expanded,
48                                                   boolean leaf, int row,
49                                                   boolean hasFocus) {
50     
51         super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
52
53         Object JavaDoc _node = ((DefaultMutableTreeNode) value).getUserObject();
54
55         if (_node instanceof ImRInfo) {
56             setText("Repository");
57             setToolTipText("Port: " + ((ImRInfo) _node).port +
58                            ", Host: " + ((ImRInfo) _node).host);
59         }
60         else if (_node instanceof POAInfo){
61             POAInfo _poa = (POAInfo) _node;
62             setToolTipText("POA is "
63                            + ((_poa.active)? "active" : "inactive"));
64
65             if (m_use_html_labels){
66                 String JavaDoc _color = (_poa.active)? "green" : "red";
67                 setText("<html> <font color=" + _color + ">" + _poa.name + "</font></html>");
68             }
69             else
70                 setText(_poa.name);
71         }
72         else if (_node instanceof ServerInfo){
73             ServerInfo _server = (ServerInfo) _node;
74
75             setToolTipText("Server is "
76                            + ((_server.active)? "active" : "down")
77                            + ((_server.holding)? "and holding" : ""));
78        
79             if (m_use_html_labels){
80                 String JavaDoc _color = (_server.active)? "green" : "red";
81                 setText("<tml> <font color=" + _color + ">" +
82                         ((_server.holding)? "<blink>" : "") +
83                         _server.name +
84                         ((_server.holding)? "</blink>" : "") +
85                         "</font></html>");
86             }
87             else
88                 setText(_server.name);
89         }
90         return this;
91     }
92 } // ImRTreeCellRenderer
93

94
95
96
97
98
99
100
101
102
103
104
105
106
107
Popular Tags