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 org.apache.log4j.lf5.LogLevel;
20 import org.apache.log4j.lf5.LogRecord;
21
22 import javax.swing.*;
23 import javax.swing.table.DefaultTableCellRenderer;
24 import java.awt.*;
25
26 /***
27 * LogTableRowRenderer
28 *
29 * @author Michael J. Sikorsky
30 * @author Robert Shaw
31 * @author Brad Marlborough
32 */
33
34 // Contributed by ThoughtWorks Inc.
35
36 public class LogTableRowRenderer extends DefaultTableCellRenderer {
37 private static final long serialVersionUID = -3951639953706443213L;
38 //--------------------------------------------------------------------------
39 // Constants:
40 //--------------------------------------------------------------------------
41
42 //--------------------------------------------------------------------------
43 // Protected Variables:
44 //--------------------------------------------------------------------------
45 protected boolean _highlightFatal = true;
46 protected Color _color = new Color(230, 230, 230);
47
48 //--------------------------------------------------------------------------
49 // Private Variables:
50 //--------------------------------------------------------------------------
51
52 //--------------------------------------------------------------------------
53 // Constructors:
54 //--------------------------------------------------------------------------
55
56 //--------------------------------------------------------------------------
57 // Public Methods:
58 //--------------------------------------------------------------------------
59
60 public Component getTableCellRendererComponent(JTable table,
61 Object value,
62 boolean isSelected,
63 boolean hasFocus,
64 int row,
65 int col) {
66
67 if ((row % 2) == 0) {
68 setBackground(_color);
69 } else {
70 setBackground(Color.white);
71 }
72
73 FilteredLogTableModel model = (FilteredLogTableModel) table.getModel();
74 LogRecord record = model.getFilteredRecord(row);
75
76 setForeground(getLogLevelColor(record.getLevel()));
77
78 return (super.getTableCellRendererComponent(table,
79 value,
80 isSelected,
81 hasFocus,
82 row, col));
83 }
84
85
86 //--------------------------------------------------------------------------
87 // Protected Methods:
88 //--------------------------------------------------------------------------
89 protected Color getLogLevelColor(LogLevel level) {
90 return (Color) LogLevel.getLogLevelColorMap().get(level);
91 }
92
93 //--------------------------------------------------------------------------
94 // Private Methods:
95 //--------------------------------------------------------------------------
96
97 //--------------------------------------------------------------------------
98 // Nested Top-Level Classes or Interfaces:
99 //--------------------------------------------------------------------------
100
101 }
102
103
104
105
106
107