KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > lf5 > viewer > categoryexplorer > CategoryNodeRenderer


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.log4j.lf5.viewer.categoryexplorer;
17
18 import javax.swing.*;
19 import javax.swing.tree.DefaultTreeCellRenderer JavaDoc;
20 import java.awt.*;
21 import java.net.URL JavaDoc;
22
23 /**
24  * CategoryNodeRenderer
25  *
26  * @author Michael J. Sikorsky
27  * @author Robert Shaw
28  */

29
30 // Contributed by ThoughtWorks Inc.
31

32 public class CategoryNodeRenderer extends DefaultTreeCellRenderer JavaDoc {
33   //--------------------------------------------------------------------------
34
// Constants:
35
//--------------------------------------------------------------------------
36

37   public static final Color FATAL_CHILDREN = new Color(189, 113, 0);
38
39   //--------------------------------------------------------------------------
40
// Protected Variables:
41
//--------------------------------------------------------------------------
42
protected JCheckBox _checkBox = new JCheckBox();
43   protected JPanel _panel = new JPanel();
44   protected static ImageIcon _sat = null;
45 // protected JLabel _label = new JLabel();
46

47   //--------------------------------------------------------------------------
48
// Private Variables:
49
//--------------------------------------------------------------------------
50

51   //--------------------------------------------------------------------------
52
// Constructors:
53
//--------------------------------------------------------------------------
54
public CategoryNodeRenderer() {
55     _panel.setBackground(UIManager.getColor("Tree.textBackground"));
56
57     if (_sat == null) {
58       // Load the satellite image.
59
String JavaDoc resource =
60           "/org/apache/log4j/lf5/viewer/images/channelexplorer_satellite.gif";
61       URL JavaDoc satURL = getClass().getResource(resource);
62
63       _sat = new ImageIcon(satURL);
64     }
65
66     setOpaque(false);
67     _checkBox.setOpaque(false);
68     _panel.setOpaque(false);
69
70     // The flowlayout set to LEFT is very important so that the editor
71
// doesn't jump around.
72
_panel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
73     _panel.add(_checkBox);
74     _panel.add(this);
75
76     setOpenIcon(_sat);
77     setClosedIcon(_sat);
78     setLeafIcon(_sat);
79   }
80
81   //--------------------------------------------------------------------------
82
// Public Methods:
83
//--------------------------------------------------------------------------
84
public Component getTreeCellRendererComponent(
85       JTree tree, Object JavaDoc value,
86       boolean selected, boolean expanded,
87       boolean leaf, int row,
88       boolean hasFocus) {
89
90     CategoryNode node = (CategoryNode) value;
91     //FileNode node = (FileNode)value;
92
//String s = tree.convertValueToText(value, selected,
93
// expanded, leaf, row, hasFocus);
94

95     super.getTreeCellRendererComponent(
96         tree, value, selected, expanded,
97         leaf, row, hasFocus);
98
99     if (row == 0) {
100       // Root row -- no check box
101
_checkBox.setVisible(false);
102     } else {
103       _checkBox.setVisible(true);
104       _checkBox.setSelected(node.isSelected());
105     }
106     String JavaDoc toolTip = buildToolTip(node);
107     _panel.setToolTipText(toolTip);
108     if (node.hasFatalChildren()) {
109       this.setForeground(FATAL_CHILDREN);
110     }
111     if (node.hasFatalRecords()) {
112       this.setForeground(Color.red);
113     }
114
115     return _panel;
116   }
117
118   public Dimension getCheckBoxOffset() {
119     return new Dimension(0, 0);
120   }
121
122   //--------------------------------------------------------------------------
123
// Protected Methods:
124
//--------------------------------------------------------------------------
125

126   protected String JavaDoc buildToolTip(CategoryNode node) {
127     StringBuffer JavaDoc result = new StringBuffer JavaDoc();
128     result.append(node.getTitle()).append(" contains a total of ");
129     result.append(node.getTotalNumberOfRecords());
130     result.append(" LogRecords.");
131     result.append(" Right-click for more info.");
132     return result.toString();
133   }
134   //--------------------------------------------------------------------------
135
// Private Methods:
136
//--------------------------------------------------------------------------
137

138   //--------------------------------------------------------------------------
139
// Nested Top-Level Classes or Interfaces:
140
//--------------------------------------------------------------------------
141

142 }
143
144
145
146
147
148
149
Popular Tags