1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.log4j.lf5.viewer;
18
19 import java.awt.Color;
20 import java.awt.Component;
21
22 import javax.swing.JTable;
23 import javax.swing.table.DefaultTableCellRenderer;
24
25 import org.apache.log4j.lf5.LogLevel;
26 import org.apache.log4j.lf5.LogRecord;
27
28 /**
29 * LogTableRowRenderer
30 *
31 * @author Michael J. Sikorsky
32 * @author Robert Shaw
33 * @author Brad Marlborough
34 */
35
36 // Contributed by ThoughtWorks Inc.
37
38 public class LogTableRowRenderer extends DefaultTableCellRenderer {
39 private static final long serialVersionUID = -3951639953706443213L;
40 //--------------------------------------------------------------------------
41 // Constants:
42 //--------------------------------------------------------------------------
43
44 //--------------------------------------------------------------------------
45 // Protected Variables:
46 //--------------------------------------------------------------------------
47 protected boolean _highlightFatal = true;
48 protected Color _color = new Color(230, 230, 230);
49
50 //--------------------------------------------------------------------------
51 // Private Variables:
52 //--------------------------------------------------------------------------
53
54 //--------------------------------------------------------------------------
55 // Constructors:
56 //--------------------------------------------------------------------------
57
58 //--------------------------------------------------------------------------
59 // Public Methods:
60 //--------------------------------------------------------------------------
61
62 public Component getTableCellRendererComponent(JTable table,
63 Object value,
64 boolean isSelected,
65 boolean hasFocus,
66 int row,
67 int col) {
68
69 if ((row % 2) == 0) {
70 setBackground(_color);
71 } else {
72 setBackground(Color.white);
73 }
74
75 FilteredLogTableModel model = (FilteredLogTableModel) table.getModel();
76 LogRecord record = model.getFilteredRecord(row);
77
78 setForeground(getLogLevelColor(record.getLevel()));
79
80 return (super.getTableCellRendererComponent(table,
81 value,
82 isSelected,
83 hasFocus,
84 row, col));
85 }
86
87
88 //--------------------------------------------------------------------------
89 // Protected Methods:
90 //--------------------------------------------------------------------------
91 protected Color getLogLevelColor(LogLevel level) {
92 return (Color) LogLevel.getLogLevelColorMap().get(level);
93 }
94
95 //--------------------------------------------------------------------------
96 // Private Methods:
97 //--------------------------------------------------------------------------
98
99 //--------------------------------------------------------------------------
100 // Nested Top-Level Classes or Interfaces:
101 //--------------------------------------------------------------------------
102
103 }
104
105
106
107
108
109