psmith      2003/09/13 21:08:16

  Modified:    src/java/org/apache/log4j/chainsaw LogPanel.java
                        TableColorizingRenderer.java
  Added:       src/java/org/apache/log4j/chainsaw/color Colorizer.java
                        DefaultColorizer.java
  Log:
  Modified the mechanism used for Coloring an event row.
  
  A default Colourizer is used initially that colors Warn levels Yellow
  and Error and Fatal events red.
  
  A Rule based Colorizer will be introduced eventually.
  
  Revision  Changes    Path
  1.9       +10 -23    jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogPanel.java
  
  Index: LogPanel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogPanel.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- LogPanel.java     13 Sep 2003 05:56:13 -0000      1.8
  +++ LogPanel.java     14 Sep 2003 04:08:16 -0000      1.9
  @@ -168,7 +168,6 @@
     private boolean paused = false;
     private boolean logTreePanelVisible = true;
     private final FilterModel filterModel = new FilterModel();
  -  final ColorFilter colorFilter = new ColorFilter();
     private final RuleMediator ruleMediator = new RuleMediator();
     final EventContainer tableModel;
     final JEditorPane detail;
  @@ -289,20 +288,8 @@
       //      displayFilter.addFilterChangedListener(tableModel);
       SettingsManager.getInstance().addSettingsListener(renderer);
   
  -    renderer.setColorFilter(colorFilter);
  -
       table.setDefaultRenderer(Object.class, renderer);
   
  -    //if the color filter changes, trigger the tablemodel update
  -    colorFilter.addFilterChangedListener(
  -      new FilterChangedListener() {
  -        public void filterChanged() {
  -          if (tableModel instanceof AbstractTableModel) {
  -            ((AbstractTableModel) tableModel).fireTableDataChanged();
  -          }
  -        }
  -      });
  -
       final ColumnSelector columnSelector =
         new ColumnSelector(
           ident, new Vector(ChainsawColumns.getColumnsNames()), table);
  @@ -865,15 +852,15 @@
       menuItemScrollBottom.setIcon(
         new ImageIcon(ChainsawIcons.SCROLL_TO_BOTTOM));
   
  -    JMenuItem menuItemRemoveColorFilter =
  -      new JMenuItem("Remove all color filters");
  -    menuItemRemoveColorFilter.addActionListener(
  -      new ActionListener() {
  -        public void actionPerformed(ActionEvent evt) {
  -          //            colorDisplaySelector.clearColors();
  -          colorFilter.clear();
  -        }
  -      });
  +//    JMenuItem menuItemRemoveColorFilter =
  +//      new JMenuItem("Remove all color filters");
  +//    menuItemRemoveColorFilter.addActionListener(
  +//      new ActionListener() {
  +//        public void actionPerformed(ActionEvent evt) {
  +//          //            colorDisplaySelector.clearColors();
  +//          colorFilter.clear();
  +//        }
  +//      });
   
       JMenuItem menuItemColumnSelector =
         new JMenuItem("Select display columns...");
  @@ -942,7 +929,7 @@
   
       selectSubMenu.add(menuItemColumnSelector);
   
  -    removeSubMenu.add(menuItemRemoveColorFilter);
  +//    removeSubMenu.add(menuItemRemoveColorFilter);
       removeSubMenu.add(menuItemRemoveDisplayFilter);
   
       p.add(selectSubMenu);
  
  
  
  1.5       +45 -48    
jakarta-log4j/src/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java
  
  Index: TableColorizingRenderer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TableColorizingRenderer.java      11 Sep 2003 03:35:05 -0000      1.4
  +++ TableColorizingRenderer.java      14 Sep 2003 04:08:16 -0000      1.5
  @@ -49,33 +49,28 @@
   
   package org.apache.log4j.chainsaw;
   
  -import java.awt.BorderLayout;
   import java.awt.Color;
   import java.awt.Component;
  -import java.awt.event.ActionEvent;
   import java.text.DateFormat;
   import java.util.Calendar;
   import java.util.Date;
   import java.util.Map;
  -import java.util.Vector;
   
  -import javax.swing.AbstractAction;
   import javax.swing.BorderFactory;
   import javax.swing.Icon;
  -import javax.swing.JButton;
   import javax.swing.JLabel;
  -import javax.swing.JPanel;
   import javax.swing.JTable;
   import javax.swing.table.DefaultTableCellRenderer;
   import javax.swing.table.TableModel;
   
  +import org.apache.log4j.chainsaw.color.Colorizer;
  +import org.apache.log4j.chainsaw.color.DefaultColorizer;
   import org.apache.log4j.chainsaw.icons.LevelIconFactory;
   import org.apache.log4j.chainsaw.prefs.LoadSettingsEvent;
   import org.apache.log4j.chainsaw.prefs.SaveSettingsEvent;
   import org.apache.log4j.chainsaw.prefs.SettingsListener;
   import org.apache.log4j.helpers.ISO8601DateFormat;
   import org.apache.log4j.spi.LoggingEvent;
  -import org.apache.log4j.spi.ThrowableInformation;
   
   
   /**
  @@ -92,8 +87,10 @@
     private static final DateFormat DATE_FORMATTER =
       new ISO8601DateFormat(Calendar.getInstance().getTimeZone());
     private Map iconMap = LevelIconFactory.getInstance().getLevelToIconMap();
  -  private ColorFilter colorFilter;
  +
  +  //  private ColorFilter colorFilter;
     private JTable table;
  +  private Colorizer colorizer = new DefaultColorizer();
     private Color background = new Color(255, 255, 254);
     private final Color COLOR_ODD = new Color(230, 230, 230);
     private final JLabel idComponent = new JLabel();
  @@ -112,20 +109,9 @@
       levelComponent.setOpaque(true);
       levelComponent.setHorizontalAlignment(JLabel.CENTER);
   
  - 
  -
       levelComponent.setText("");
     }
   
  -  /**
  -  *TODO
  -  *
  -  * @param colorFilter TODO
  -  */
  -  public void setColorFilter(ColorFilter colorFilter) {
  -    this.colorFilter = colorFilter;
  -  }
  -
     public void loadSettings(LoadSettingsEvent event) {
       levelDisplay = event.getSetting(ChainsawConstants.LEVEL_DISPLAY);
     }
  @@ -133,28 +119,17 @@
     public void saveSettings(SaveSettingsEvent event) {
     }
   
  -  /**
  -   *TODO
  -   *
  -   * @param table TODO
  -   * @param value TODO
  -   * @param isSelected TODO
  -   * @param hasFocus TODO
  -   * @param row TODO
  -   * @param col TODO
  -   *
  -   * @return TODO
  -   */
     public Component getTableCellRendererComponent(
       JTable table, Object value, boolean isSelected, boolean hasFocus, int row,
       int col) {
       value = formatField(value);
   
  -    Color color = null;
  +    Color backgroundColor = null;
  +    Color foregroundColor = null;
   
       Component c =
  -       super.getTableCellRendererComponent(
  -                 table, value, isSelected, hasFocus, row, col);
  +      super.getTableCellRendererComponent(
  +        table, value, isSelected, hasFocus, row, col);
       int colIndex = table.getColumnModel().getColumn(col).getModelIndex() + 1;
   
       switch (colIndex) {
  @@ -165,15 +140,18 @@
         c = idComponent;
   
         break;
  -      
  +
       case ChainsawColumns.INDEX_THROWABLE_COL_NAME:
  -     String[] ti = (String[]) value;
  -     if(ti!=null) {
  -                     ((JLabel)c).setText(ti[0]);
  -     } else {
  -                     ((JLabel)c).setText("");
  -     }
  -     break;
  +
  +      String[] ti = (String[]) value;
  +
  +      if (ti != null) {
  +        ((JLabel) c).setText(ti[0]);
  +      } else {
  +        ((JLabel) c).setText("");
  +      }
  +
  +      break;
   
       case ChainsawColumns.INDEX_LEVEL_COL_NAME:
   
  @@ -207,11 +185,10 @@
   
       this.table = table;
   
  -    Vector colNames = null;
  -
  -    if ((color == null) && (colorFilter != null)) {
  +    if ((backgroundColor == null) && (getColorizer() != null)) {
         TableModel model = table.getModel();
         LoggingEvent event = null;
  +
         if (model instanceof EventContainer) {
           EventContainer model2 = (EventContainer) model;
           event = model2.getRow(row);
  @@ -225,11 +202,12 @@
             getClass() + " can only support an EventContainer TableModel");
         }
   
  -      color = colorFilter.getColor(ChainsawColumns.getColumnsNames(), event);
  +      backgroundColor = getColorizer().getBackgroundColor(event);
  +      foregroundColor = getColorizer().getForegroundColor(event);
       }
   
  -    if ((color != null)) {
  -      c.setBackground(color);
  +    if ((backgroundColor != null)) {
  +      c.setBackground(backgroundColor);
       } else if (!isSelected) {
         /**
          * Colourize based on row striping
  @@ -240,6 +218,11 @@
           c.setBackground(background);
         }
       }
  +    if(foregroundColor!=null){
  +      c.setForeground(foregroundColor);
  +    }else {
  +      c.setForeground(Color.black);
  +    }
   
       return c;
     }
  @@ -257,5 +240,19 @@
       } else {
         return DATE_FORMATTER.format((Date) o);
       }
  +  }
  +
  +  /**
  +   * @param colorizer
  +   */
  +  public void setColorizer(Colorizer colorizer) {
  +    this.colorizer = colorizer;
  +  }
  +
  +  /**
  +   * @return
  +   */
  +  public Colorizer getColorizer() {
  +    return colorizer;
     }
   }
  
  
  
  1.1                  
jakarta-log4j/src/java/org/apache/log4j/chainsaw/color/Colorizer.java
  
  Index: Colorizer.java
  ===================================================================
  /*
   * ============================================================================
   *                   The Apache Software License, Version 1.1
   * ============================================================================
   *
   *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modifica-
   * tion, are permitted provided that the following conditions are met:
   *
   * 1. Redistributions of  source code must  retain the above copyright  notice,
   *    this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if any, must
   *    include  the following  acknowledgment:  "This product includes  software
   *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
   *    Alternately, this  acknowledgment may  appear in the software itself,  if
   *    and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
   *    endorse  or promote  products derived  from this  software without  prior
   *    written permission. For written permission, please contact
   *    [EMAIL PROTECTED]
   *
   * 5. Products  derived from this software may not  be called "Apache", nor may
   *    "Apache" appear  in their name,  without prior written permission  of the
   *    Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software  consists of voluntary contributions made  by many individuals
   * on  behalf of the Apache Software  Foundation.  For more  information on the
   * Apache Software Foundation, please see <http://www.apache.org/>.
   *
   */
  
  package org.apache.log4j.chainsaw.color;
  
  import org.apache.log4j.spi.LoggingEvent;
  
  import java.awt.Color;
  
  
  /**
   * Given a LoggingEvent, can determine an appropriate
   * Color to use based on whatever this implementation
   * has been coded.
   * 
   * @author Paul Smith <[EMAIL PROTECTED]>
   * @author Scott Deboy <[EMAIL PROTECTED]>
   */
  public interface Colorizer {
    /**
     * Given a LoggingEvent, returns a Color to use for background, 
     * or null if this instance cannot determine one, or that
     * the stanard color should be used.
     * @param event
     * @return
     */
    public Color getBackgroundColor(LoggingEvent event);
    
    public Color getForegroundColor(LoggingEvent event);
  }
  
  
  
  1.1                  
jakarta-log4j/src/java/org/apache/log4j/chainsaw/color/DefaultColorizer.java
  
  Index: DefaultColorizer.java
  ===================================================================
  /*
   * ============================================================================
   *                   The Apache Software License, Version 1.1
   * ============================================================================
   *
   *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modifica-
   * tion, are permitted provided that the following conditions are met:
   *
   * 1. Redistributions of  source code must  retain the above copyright  notice,
   *    this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if any, must
   *    include  the following  acknowledgment:  "This product includes  software
   *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
   *    Alternately, this  acknowledgment may  appear in the software itself,  if
   *    and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
   *    endorse  or promote  products derived  from this  software without  prior
   *    written permission. For written permission, please contact
   *    [EMAIL PROTECTED]
   *
   * 5. Products  derived from this software may not  be called "Apache", nor may
   *    "Apache" appear  in their name,  without prior written permission  of the
   *    Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software  consists of voluntary contributions made  by many individuals
   * on  behalf of the Apache Software  Foundation.  For more  information on the
   * Apache Software Foundation, please see <http://www.apache.org/>.
   *
   */
  
  package org.apache.log4j.chainsaw.color;
  
  import java.awt.Color;
  import java.util.HashMap;
  import java.util.Map;
  
  import org.apache.log4j.Level;
  import org.apache.log4j.spi.LoggingEvent;
  
  /**
   * This default Colorizer simply colors the event based on Levels,
   * 
   * @author Paul Smith <[EMAIL PROTECTED]> 
   */
  public class DefaultColorizer implements Colorizer {
    
    private Map backgroundColorMap = new HashMap();
    private Map foregroundColorMap = new HashMap();
    public DefaultColorizer(){
      backgroundColorMap.put(Level.FATAL, new Color(147,22,0));
      backgroundColorMap.put(Level.ERROR, new Color(147,22,0));
      backgroundColorMap.put(Level.WARN, Color.yellow.brighter());
      
      foregroundColorMap.put(Level.ERROR, Color.white);
      foregroundColorMap.put(Level.FATAL, Color.white);
    }
    
    /* (non-Javadoc)
     * @see 
org.apache.log4j.chainsaw.color.Colorizer#colorize(org.apache.log4j.spi.LoggingEvent)
     */
    public Color getBackgroundColor(LoggingEvent event) {
      if(backgroundColorMap.containsKey(event.getLevel())){
        return (Color) backgroundColorMap.get(event.getLevel());
      }
      return null;
    }
  
    /* (non-Javadoc)
     * @see 
org.apache.log4j.chainsaw.color.Colorizer#getForegroundColor(org.apache.log4j.spi.LoggingEvent)
     */
    public Color getForegroundColor(LoggingEvent event) {
      if(foregroundColorMap.containsKey(event.getLevel())){
        return (Color) foregroundColorMap.get(event.getLevel());
      }
      return null;
    }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to