001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 * 
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 * 
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.log4j.lf5.viewer;
018
019import java.awt.Color;
020import java.awt.Component;
021
022import javax.swing.JTable;
023import javax.swing.table.DefaultTableCellRenderer;
024
025import org.apache.log4j.lf5.LogLevel;
026import org.apache.log4j.lf5.LogRecord;
027
028/**
029 * LogTableRowRenderer
030 *
031 * @author Michael J. Sikorsky
032 * @author Robert Shaw
033 * @author Brad Marlborough
034 */
035
036// Contributed by ThoughtWorks Inc.
037
038public class LogTableRowRenderer extends DefaultTableCellRenderer {
039  private static final long serialVersionUID = -3951639953706443213L;
040  //--------------------------------------------------------------------------
041  //   Constants:
042  //--------------------------------------------------------------------------
043
044  //--------------------------------------------------------------------------
045  //   Protected Variables:
046  //--------------------------------------------------------------------------
047  protected boolean _highlightFatal = true;
048  protected Color _color = new Color(230, 230, 230);
049
050  //--------------------------------------------------------------------------
051  //   Private Variables:
052  //--------------------------------------------------------------------------
053
054  //--------------------------------------------------------------------------
055  //   Constructors:
056  //--------------------------------------------------------------------------
057
058  //--------------------------------------------------------------------------
059  //   Public Methods:
060  //--------------------------------------------------------------------------
061
062  public Component getTableCellRendererComponent(JTable table,
063      Object value,
064      boolean isSelected,
065      boolean hasFocus,
066      int row,
067      int col) {
068
069    if ((row % 2) == 0) {
070      setBackground(_color);
071    } else {
072      setBackground(Color.white);
073    }
074
075    FilteredLogTableModel model = (FilteredLogTableModel) table.getModel();
076    LogRecord record = model.getFilteredRecord(row);
077
078    setForeground(getLogLevelColor(record.getLevel()));
079
080    return (super.getTableCellRendererComponent(table,
081        value,
082        isSelected,
083        hasFocus,
084        row, col));
085  }
086
087
088  //--------------------------------------------------------------------------
089  //   Protected Methods:
090  //--------------------------------------------------------------------------
091  protected Color getLogLevelColor(LogLevel level) {
092    return (Color) LogLevel.getLogLevelColorMap().get(level);
093  }
094
095  //--------------------------------------------------------------------------
096  //   Private Methods:
097  //--------------------------------------------------------------------------
098
099  //--------------------------------------------------------------------------
100  //   Nested Top-Level Classes or Interfaces:
101  //--------------------------------------------------------------------------
102
103}
104
105
106
107
108
109