KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > lf5 > viewer > LogTableRowRenderer


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;
17
18 import org.apache.log4j.lf5.LogLevel;
19 import org.apache.log4j.lf5.LogRecord;
20
21 import javax.swing.*;
22 import javax.swing.table.DefaultTableCellRenderer JavaDoc;
23 import java.awt.*;
24
25 /**
26  * LogTableRowRenderer
27  *
28  * @author Michael J. Sikorsky
29  * @author Robert Shaw
30  * @author Brad Marlborough
31  */

32
33 // Contributed by ThoughtWorks Inc.
34

35 public class LogTableRowRenderer extends DefaultTableCellRenderer JavaDoc {
36   //--------------------------------------------------------------------------
37
// Constants:
38
//--------------------------------------------------------------------------
39

40   //--------------------------------------------------------------------------
41
// Protected Variables:
42
//--------------------------------------------------------------------------
43
protected boolean _highlightFatal = true;
44   protected Color _color = new Color(230, 230, 230);
45
46   //--------------------------------------------------------------------------
47
// Private Variables:
48
//--------------------------------------------------------------------------
49

50   //--------------------------------------------------------------------------
51
// Constructors:
52
//--------------------------------------------------------------------------
53

54   //--------------------------------------------------------------------------
55
// Public Methods:
56
//--------------------------------------------------------------------------
57

58   public Component getTableCellRendererComponent(JTable table,
59       Object JavaDoc value,
60       boolean isSelected,
61       boolean hasFocus,
62       int row,
63       int col) {
64
65     if ((row % 2) == 0) {
66       setBackground(_color);
67     } else {
68       setBackground(Color.white);
69     }
70
71     FilteredLogTableModel model = (FilteredLogTableModel) table.getModel();
72     LogRecord record = model.getFilteredRecord(row);
73
74     setForeground(getLogLevelColor(record.getLevel()));
75
76     return (super.getTableCellRendererComponent(table,
77         value,
78         isSelected,
79         hasFocus,
80         row, col));
81   }
82
83
84   //--------------------------------------------------------------------------
85
// Protected Methods:
86
//--------------------------------------------------------------------------
87
protected Color getLogLevelColor(LogLevel level) {
88     return (Color) LogLevel.getLogLevelColorMap().get(level);
89   }
90
91   //--------------------------------------------------------------------------
92
// Private Methods:
93
//--------------------------------------------------------------------------
94

95   //--------------------------------------------------------------------------
96
// Nested Top-Level Classes or Interfaces:
97
//--------------------------------------------------------------------------
98

99 }
100
101
102
103
104
105
106
Popular Tags