01: /*
02: * JacORB - a free Java ORB
03: *
04: * Copyright (C) 1999-2004 Gerald Brose
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Library General Public
08: * License as published by the Free Software Foundation; either
09: * 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;
26: import org.jacorb.imr.*;
27:
28: /**
29: * This class sets the tooltip text for the tree cells,
30: * and, if possible, enhances the test with HTML.
31: *
32: * @author Nicolas Noffke
33: *
34: * $Id: ImRTreeCellRenderer.java,v 1.8 2004/05/06 12:39:59 nicolas Exp $
35: */
36:
37: public class ImRTreeCellRenderer extends DefaultTreeCellRenderer {
38: private boolean m_use_html_labels = false;
39:
40: public ImRTreeCellRenderer() {
41: super ();
42: }
43:
44: /**
45: * Set the tooltip text and overwrite the labels with HTML.
46: */
47: public Component getTreeCellRendererComponent(JTree tree,
48: Object value, boolean sel, boolean expanded, boolean leaf,
49: int row, boolean hasFocus) {
50:
51: super .getTreeCellRendererComponent(tree, value, sel, expanded,
52: leaf, row, hasFocus);
53:
54: Object _node = ((DefaultMutableTreeNode) value).getUserObject();
55:
56: if (_node instanceof ImRInfo) {
57: setText("Repository");
58: setToolTipText("Port: " + ((ImRInfo) _node).port
59: + ", Host: " + ((ImRInfo) _node).host);
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 _color = (_poa.active) ? "green" : "red";
67: setText("<html> <font color=" + _color + ">"
68: + _poa.name + "</font></html>");
69: } else
70: setText(_poa.name);
71: } else if (_node instanceof ServerInfo) {
72: ServerInfo _server = (ServerInfo) _node;
73:
74: setToolTipText("Server is "
75: + ((_server.active) ? "active" : "down")
76: + ((_server.holding) ? "and holding" : ""));
77:
78: if (m_use_html_labels) {
79: String _color = (_server.active) ? "green" : "red";
80: setText("<tml> <font color=" + _color + ">"
81: + ((_server.holding) ? "<blink>" : "")
82: + _server.name
83: + ((_server.holding) ? "</blink>" : "")
84: + "</font></html>");
85: } else
86: setText(_server.name);
87: }
88: return this ;
89: }
90: } // ImRTreeCellRenderer
|