logging-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sde...@apache.org
Subject svn commit: r965026 - in /logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw: ChainsawCyclicBufferTableModel.java ExtendedLoggingEvent.java LogPanel.java LoggerNameTreePanel.java TableColorizingRenderer.java
Date Sat, 17 Jul 2010 07:51:38 GMT
Author: sdeboy
Date: Sat Jul 17 07:51:38 2010
New Revision: 965026

URL: http://svn.apache.org/viewvc?rev=965026&view=rev
Log:
Chainsaw rendering fixes and performance improvements
 - previously if you expanded a row by shrinking its width (with wrap enabled), the row would
never shrink in height - now it will
 - commented out use of an expensive cell height calculation method - no longer calculating
the height, letting Swing calculate it for us
 - LoggerNameTreePanel implemented Rule, but triggered propertychange events caused by Swing,
which were triggering rule re-evaluation...panel no longer implements Rule - no longer unnecessarily
re-running rule evaluation

Modified:
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ExtendedLoggingEvent.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java?rev=965026&r1=965025&r2=965026&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java
Sat Jul 17 07:51:38 2010
@@ -131,15 +131,22 @@ class ChainsawCyclicBufferTableModel ext
             previousSize = filteredList.size();
             filteredList.clear();
             if (displayRule == null) {
-                filteredList.addAll(unfilteredList);
+                for (Iterator iter = unfilteredList.iterator();iter.hasNext();) {
+                    ExtendedLoggingEvent e = (ExtendedLoggingEvent)iter.next();
+                    e.setDisplayed(true);
+                    filteredList.add(e);
+                }
             } else {
                 Iterator iter = unfilteredList.iterator();
 
                 while (iter.hasNext()) {
-                  LoggingEvent e = (LoggingEvent) iter.next();
+                  ExtendedLoggingEvent e = (ExtendedLoggingEvent) iter.next();
 
                   if (displayRule.evaluate(e, null)) {
+                    e.setDisplayed(true);
                     filteredList.add(e);
+                  } else {
+                    e.setDisplayed(false);
                   }
                 }
             }
@@ -290,6 +297,11 @@ class ChainsawCyclicBufferTableModel ext
           filteredListSize = filteredList.size();
           sort = (sortEnabled && filteredListSize > 0);
         if (sort) {
+            //reset display (used to ensure row height is updated)
+            for (Iterator iter = filteredList.iterator();iter.hasNext();) {
+                ExtendedLoggingEvent e = (ExtendedLoggingEvent)iter.next();
+                e.setDisplayed(true);
+            }
             Collections.sort(
               filteredList,
               new ColumnComparator(
@@ -595,8 +607,11 @@ class ChainsawCyclicBufferTableModel ext
         }
         unfilteredList.add(e);
         if ((displayRule == null) || (displayRule.evaluate(e, null))) {
+            e.setDisplayed(true);
             filteredList.add(e);
             rowAdded = true;
+        } else {
+            e.setDisplayed(false);
         }
     }
 

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ExtendedLoggingEvent.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ExtendedLoggingEvent.java?rev=965026&r1=965025&r2=965026&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ExtendedLoggingEvent.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ExtendedLoggingEvent.java
Sat Jul 17 07:51:38 2010
@@ -26,8 +26,12 @@ import org.apache.log4j.spi.LoggingEvent
 
 public class ExtendedLoggingEvent extends LoggingEvent
 {
+    private static final int DEFAULT_HEIGHT = -1;
+
     private Color colorRuleBackground = ChainsawConstants.COLOR_DEFAULT_BACKGROUND;
     private Color colorRuleForeground = ChainsawConstants.COLOR_DEFAULT_FOREGROUND;
+    private int markerHeight = DEFAULT_HEIGHT;
+    private int msgHeight = DEFAULT_HEIGHT;
 
     private boolean searchMatch = false;
     //a Map of event fields to Sets of string matches (can be used to render matches differently)
@@ -77,7 +81,30 @@ public class ExtendedLoggingEvent extend
         return searchMatch;
     }
 
+    public void setMarkerHeight(int markerHeight) {
+        this.markerHeight = markerHeight;
+    }
+
+    public int getMarkerHeight() {
+        return markerHeight;
+    }
+
+    public void setMsgHeight(int msgHeight) {
+        this.msgHeight = msgHeight;
+    }
+
+    public int getMsgHeight() {
+        return msgHeight;
+    }
+
+    public void setDisplayed(boolean b)
+    {
+        markerHeight = DEFAULT_HEIGHT;
+        msgHeight = DEFAULT_HEIGHT;
+    }
+
     public String toString() {
         return "ExtendedLoggingEvent - id: " + getProperty("log4jid") + " background: " +
getBackground() + ", foreground: " + getForeground() + ", msg: " + getMessage();
     }
+
 }

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java?rev=965026&r1=965025&r2=965026&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java (original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java Sat Jul 17
07:51:38 2010
@@ -715,33 +715,25 @@ public class LogPanel extends DockablePa
      */
     LogPanelLoggerTreeModel logTreeModel = new LogPanelLoggerTreeModel();
     logTreePanel = new LoggerNameTreePanel(logTreeModel, preferenceModel, this, colorizer,
filterModel);
-    logTreePanel.addPropertyChangeListener("searchExpression", new PropertyChangeListener()
+    logTreePanel.getLoggerVisibilityRule().addPropertyChangeListener(new PropertyChangeListener()
     {
         public void propertyChange(PropertyChangeEvent evt)
         {
-            findField.setText(evt.getNewValue().toString());
-            findNext();
+            if (evt.getPropertyName().equals("searchExpression")) {
+                findField.setText(evt.getNewValue().toString());
+                findNext();
+            }
         }
     });
       
     tableModel.addLoggerNameListener(logTreeModel);
-    ruleMediator.addPropertyChangeListener(new PropertyChangeListener()
-    {
-        public void propertyChange(PropertyChangeEvent evt)
-        {
-            //reset row height to default - logger rule or refinement rule changed the displayed
rows - when in multiline row mode,
-            //the table rows may not be the correct height (the row's height may be larger
than the preferred height)..
-            //updating all rows to the default height resolves this issue
-            table.setRowHeight(ChainsawConstants.DEFAULT_ROW_HEIGHT);
-        }
-    });
 
     /**
      * Set the LoggerRule to be the LoggerTreePanel, as this visual component
      * is a rule itself, and the RuleMediator will automatically listen when
      * it's rule state changes.
      */
-    ruleMediator.setLoggerRule(logTreePanel);
+    ruleMediator.setLoggerRule(logTreePanel.getLoggerVisibilityRule());
     colorizer.setLoggerRule(logTreePanel.getLoggerColorRule());
 
     /*

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java?rev=965026&r1=965025&r2=965026&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java
Sat Jul 17 07:51:38 2010
@@ -101,7 +101,7 @@ import org.apache.log4j.spi.LoggingEvent
  *
  * @author Paul Smith <psmith@apache.org>
  */
-final class LoggerNameTreePanel extends JPanel implements Rule
+final class LoggerNameTreePanel extends JPanel
 {
   //~ Static fields/initializers ==============================================
 
@@ -151,7 +151,7 @@ final class LoggerNameTreePanel extends 
   private final LogPanelLoggerTreeModel logTreeModel;
   private final PopupListener popupListener;
   private final LoggerTreePopupMenu popupMenu;
-  private final Rule ruleDelegate;
+  private final VisibilityRuleDelegate visibilityRuleDelegate;
   private Rule colorRuleDelegate; 
   private final JScrollPane scrollTree;
   private final JToolBar toolbar = new JToolBar();
@@ -180,28 +180,8 @@ final class LoggerNameTreePanel extends 
     ignoreExpressionEntryField.setPreferredSize(new Dimension(300, 150));
     JTextComponentFormatter.applySystemFontAndSize(ignoreExpressionEntryField);
 
-    ruleDelegate = new AbstractRule() {
-    	public boolean evaluate(LoggingEvent e, Map matches)
-        {
-          String currentlySelectedLoggerName = getCurrentlySelectedLoggerName();
-          boolean hiddenLogger = e.getLoggerName() != null && isHiddenLogger(e.getLoggerName());
-          boolean hiddenExpression = (ignoreExpressionRule != null && ignoreExpressionRule.evaluate(e,
null));
-          boolean hidden = hiddenLogger || hiddenExpression;
-          if (currentlySelectedLoggerName == null) {
-          	//if there is no selected logger, pass if not hidden
-          	return !hidden;
-          }
-          boolean result = (e.getLoggerName() != null) && !hidden;
-
-          if (result && isFocusOnSelected())
-          {
-            result = (e.getLoggerName() != null && (e.getLoggerName().startsWith(currentlySelectedLoggerName+".")
|| e.getLoggerName().endsWith(currentlySelectedLoggerName)));
-          }
 
-          return result;
-        }
-      };
-    
+    visibilityRuleDelegate = new VisibilityRuleDelegate();
     colorRuleDelegate = 
         new AbstractRule()
         {
@@ -439,7 +419,7 @@ final class LoggerNameTreePanel extends 
             } else {
                 ignoreExpressionRule = null;
             }
-            firePropertyChange("hiddenSet", null, null);
+            visibilityRuleDelegate.firePropertyChange("hiddenSet", null, null);
 
             updateAllIgnoreStuff();
             ignoreExpressionEntryField.setBackground(UIManager.getColor("TextField.background"));
@@ -464,27 +444,14 @@ final class LoggerNameTreePanel extends 
     listenerList.add(ChangeListener.class, l);
   }
 
-  /* (non-Javadoc)
-   * @see org.apache.log4j.chainsaw.rule.Rule#evaluate(org.apache.log4j.spi.LoggingEvent)
-   */
-  /**
-   * DOCUMENT ME!
-   *
-   * @param e DOCUMENT ME!
-   *
-   * @param matches
-   * @return DOCUMENT ME!
-   */
-  public boolean evaluate(LoggingEvent e, Map matches)
-  {
-    //no need for logger to build matches
-    return ruleDelegate.evaluate(e, null);
-  }
-  
   public Rule getLoggerColorRule() {
   	return colorRuleDelegate;
   }
 
+  public Rule getLoggerVisibilityRule() {
+      return visibilityRuleDelegate;
+  }
+
   /**
    * DOCUMENT ME!
    *
@@ -548,7 +515,7 @@ final class LoggerNameTreePanel extends 
       hiddenSet.remove(logger);
     }
 
-    firePropertyChange("hiddenSet", (Object) null, (Object) null);
+    visibilityRuleDelegate.firePropertyChange("hiddenSet", (Object) null, (Object) null);
   }
 
   /**
@@ -611,7 +578,7 @@ final class LoggerNameTreePanel extends 
   void ignore(Collection fqnLoggersToIgnore)
   {
     hiddenSet.addAll(fqnLoggersToIgnore);
-    firePropertyChange("hiddenSet", null, null);
+    visibilityRuleDelegate.firePropertyChange("hiddenSet", null, null);
     fireChangeEvent();
   }
 
@@ -1142,12 +1109,12 @@ final class LoggerNameTreePanel extends 
       {
         return;
       }
-      firePropertyChange("searchExpression", null, "logger like '^" + selectedLogger + ".*'");
+      visibilityRuleDelegate.firePropertyChange("searchExpression", null, "logger like '^"
+ selectedLogger + ".*'");
   }
 
   private void clearFindNext()
   {
-      firePropertyChange("searchExpression", null, "");
+      visibilityRuleDelegate.firePropertyChange("searchExpression", null, "");
   }
 
   private void clearRefineFocus()
@@ -1417,16 +1384,18 @@ final class LoggerNameTreePanel extends 
       {
         public void stateChanged(ChangeEvent evt)
         {
-          firePropertyChange("rule", null, null);
+          visibilityRuleDelegate.firePropertyChange("rule", null, null);
           updateAllIgnoreStuff();
         }
       });
 
-    addPropertyChangeListener("hiddenSet", new PropertyChangeListener()
+    visibilityRuleDelegate.addPropertyChangeListener(new PropertyChangeListener()
       {
-        public void propertyChange(PropertyChangeEvent arg0)
+        public void propertyChange(PropertyChangeEvent event)
         {
-          updateAllIgnoreStuff();
+          if (event.getPropertyName().equals("hiddenSet")) {
+            updateAllIgnoreStuff();
+          }
         }
       });
   }
@@ -1768,4 +1737,37 @@ final class LoggerNameTreePanel extends 
       }
     }
   }
+
+  class VisibilityRuleDelegate extends AbstractRule {
+    	public boolean evaluate(LoggingEvent e, Map matches)
+        {
+          String currentlySelectedLoggerName = getCurrentlySelectedLoggerName();
+          boolean hiddenLogger = e.getLoggerName() != null && isHiddenLogger(e.getLoggerName());
+          boolean hiddenExpression = (ignoreExpressionRule != null && ignoreExpressionRule.evaluate(e,
null));
+          boolean hidden = hiddenLogger || hiddenExpression;
+          if (currentlySelectedLoggerName == null) {
+          	//if there is no selected logger, pass if not hidden
+          	return !hidden;
+          }
+          boolean result = (e.getLoggerName() != null) && !hidden;
+
+          if (result && isFocusOnSelected())
+          {
+            result = (e.getLoggerName() != null && (e.getLoggerName().startsWith(currentlySelectedLoggerName+".")
|| e.getLoggerName().endsWith(currentlySelectedLoggerName)));
+          }
+
+          return result;
+        }
+
+        public void firePropertyChange(String propertyName, Object oldVal, Object newVal)
+        {
+            super.firePropertyChange(propertyName, oldVal, newVal);
+        }
+
+        public void firePropertyChange(PropertyChangeEvent evt)
+        {
+            super.firePropertyChange(evt);
+        }
+    }
+
 }

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java?rev=965026&r1=965025&r2=965026&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java
Sat Jul 17 07:51:38 2010
@@ -21,6 +21,7 @@ import java.awt.Color;
 import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.Insets;
+import java.awt.Toolkit;
 import java.awt.font.FontRenderContext;
 import java.awt.font.LineBreakMeasurer;
 import java.awt.font.TextAttribute;
@@ -118,6 +119,7 @@ public class TableColorizingRenderer ext
   private JTextPane multiLineTextPane;
   private MutableAttributeSet boldAttributeSet;
   private TabSet tabs;
+  private int maxHeight;
 
     /**
    * Creates a new TableColorizingRenderer object.
@@ -127,6 +129,7 @@ public class TableColorizingRenderer ext
     multiLinePanel.setLayout(new BoxLayout(multiLinePanel, BoxLayout.Y_AXIS));
     generalPanel.setLayout(new BoxLayout(generalPanel, BoxLayout.Y_AXIS));
     levelPanel.setLayout(new BoxLayout(levelPanel, BoxLayout.Y_AXIS));
+    maxHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
 
     //define the 'bold' attributeset
     boldAttributeSet = new SimpleAttributeSet();
@@ -276,22 +279,42 @@ public class TableColorizingRenderer ext
         } else {
             setHighlightAttributesInternal(matches.get(LoggingEventFieldResolver.MSG_FIELD),
(StyledDocument) multiLineTextPane.getDocument());
         }
-        int tableRowHeight = table.getRowHeight(row);
         multiLinePanel.removeAll();
         multiLinePanel.add(multiLineTextPane);
 
         if (wrap) {
+            /*
+            calculating the height -would- be the correct thing to do, but setting the size
to screen size works as well and
+            doesn't incur massive overhead, like calculateHeight does
             Map paramMap = new HashMap();
             paramMap.put(TextAttribute.FONT, multiLineTextPane.getFont());
 
             int calculatedHeight = calculateHeight(thisString, width, paramMap);
-            //set preferred size to default height
-            multiLineTextPane.setSize(new Dimension(width, calculatedHeight));
-
+             */
+            //instead, set size to max height
+            multiLineTextPane.setSize(new Dimension(width, maxHeight));
+            boolean setHeight = false;
             int multiLinePanelPrefHeight = multiLinePanel.getPreferredSize().height;
-            if(tableRowHeight < multiLinePanelPrefHeight) {
-                table.setRowHeight(row, Math.max(ChainsawConstants.DEFAULT_ROW_HEIGHT, multiLinePanelPrefHeight));
+            int newRowHeight = Math.max(ChainsawConstants.DEFAULT_ROW_HEIGHT, multiLinePanelPrefHeight);
+            if (colIndex == ChainsawColumns.INDEX_LOG4J_MARKER_COL_NAME) {
+                int currentMarkerHeight = loggingEvent.getMarkerHeight();
+                loggingEvent.setMarkerHeight(newRowHeight);
+                if (newRowHeight != currentMarkerHeight && newRowHeight >= loggingEvent.getMsgHeight())
{
+                    setHeight = true;
+                }
             }
+
+            if (colIndex == ChainsawColumns.INDEX_MESSAGE_COL_NAME) {
+                int currentMsgHeight = loggingEvent.getMsgHeight();
+                loggingEvent.setMsgHeight(newRowHeight);
+                if (newRowHeight != currentMsgHeight && newRowHeight >= loggingEvent.getMarkerHeight())
{
+                    setHeight = true;
+                }
+            }
+            if (setHeight) {
+                table.setRowHeight(row, newRowHeight);
+            }
+
         }
         component = multiLinePanel;
         break;



Mime
View raw message