logging-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sde...@apache.org
Subject svn commit: r1026230 - in /logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw: AbstractPreferencePanel.java LogUI.java ReceiverConfigurationPanel.java TableColorizingRenderer.java plugins/PluginClassLoaderFactory.java
Date Fri, 22 Oct 2010 07:36:35 GMT
Author: sdeboy
Date: Fri Oct 22 07:36:35 2010
New Revision: 1026230

URL: http://svn.apache.org/viewvc?rev=1026230&view=rev
Log:
Minor button layout updates, changes to support third party look & feels (copy jars to
$USERHOME/.chainsaw/plugins and update   <lookAndFeelClassName>fully-qualified-class-name</lookAndFeelClassName>
in $USERHOME/.chainsaw/chainsaw.settings.xml
Also updated the TableCellRenderer to use a basic JLabel renderer if highlighted search, wrap
and time delta rendering aren't enabled (still supports border display & color rules)

Modified:
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/AbstractPreferencePanel.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/plugins/PluginClassLoaderFactory.java

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/AbstractPreferencePanel.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/AbstractPreferencePanel.java?rev=1026230&r1=1026229&r2=1026230&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/AbstractPreferencePanel.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/AbstractPreferencePanel.java
Fri Oct 22 07:36:35 2010
@@ -112,7 +112,7 @@ public abstract class AbstractPreference
     Box buttonBox = Box.createHorizontalBox();
     buttonBox.add(Box.createHorizontalGlue());
     buttonBox.add(okButton);
-    buttonBox.add(Box.createHorizontalStrut(5));
+    buttonBox.add(Box.createHorizontalStrut(10));
     buttonBox.add(cancelButton);
   
     add(buttonBox, BorderLayout.SOUTH);

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java?rev=1026230&r1=1026229&r2=1026230&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java (original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java Fri Oct 22 07:36:35
2010
@@ -282,11 +282,11 @@ public class LogUI extends JFrame implem
         model.setBypassConfigurationURL(configurationURLAppArg);
     }
 
-    applyLookAndFeel(model.getLookAndFeelClassName());
     EventQueue.invokeLater(new Runnable()
     {
         public void run()
         {
+            loadLookAndFeelUsingPluginClassLoader(model.getLookAndFeelClassName());
             createChainsawGUI(model, null);
         }
     });
@@ -484,7 +484,6 @@ public class LogUI extends JFrame implem
     SettingsManager.getInstance().configure(new ApplicationPreferenceModelSaver(model));
 
     cyclicBufferSize = model.getCyclicBufferSize();
-    applyLookAndFeel(model.getLookAndFeelClassName());
 
     handler = new ChainsawAppenderHandler(appender);
     handler.addEventBatchListener(new NewTabEventBatchReceiver());
@@ -501,12 +500,11 @@ public class LogUI extends JFrame implem
 
     SettingsManager.getInstance().configure(new ApplicationPreferenceModelSaver(model));
 
-    applyLookAndFeel(model.getLookAndFeelClassName());
-
     EventQueue.invokeLater(new Runnable()
     {
         public void run()
         {
+            loadLookAndFeelUsingPluginClassLoader(model.getLookAndFeelClassName());
             createChainsawGUI(model, null);
             getApplicationPreferenceModel().apply(model);
             activateViewer();
@@ -1853,6 +1851,7 @@ public class LogUI extends JFrame implem
       UIManager.setLookAndFeel(lookAndFeelClassName);
 
     } catch (Exception e) {
+      e.printStackTrace();
     }
   }
 
@@ -2148,6 +2147,22 @@ public class LogUI extends JFrame implem
         ensureChainsawAppenderHandlerAdded();
     }
 
+  private static void loadLookAndFeelUsingPluginClassLoader(String lookAndFeelClassName)
{
+      ClassLoader classLoader = PluginClassLoaderFactory.getInstance().getClassLoader();
+      ClassLoader previousTCCL = Thread.currentThread().getContextClassLoader();
+          try {
+            // we temporarily swap the TCCL so that plugins can find resources
+            Thread.currentThread().setContextClassLoader(classLoader);
+            UIManager.setLookAndFeel(lookAndFeelClassName);
+            UIManager.getLookAndFeelDefaults().put("ClassLoader", classLoader);
+          } catch (Exception e) {
+            e.printStackTrace();
+          } finally{
+              // now switch it back...
+              Thread.currentThread().setContextClassLoader(previousTCCL);
+          }
+  }
+
     /**
      * Makes sure that the LoggerRepository has the ChainsawAppenderHandler
      * added to the root logger so Chainsaw can receive all the events.  

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java?rev=1026230&r1=1026229&r2=1026230&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java
Fri Oct 22 07:36:35 2010
@@ -214,6 +214,7 @@ class ReceiverConfigurationPanel extends
         c.fill = GridBagConstraints.HORIZONTAL;
         c.gridx = 1;
         c.gridy = 0;
+        c.insets = new Insets(0, 0, 0, 10);
         okButton = new JButton(" OK ");
         panel.add(okButton, c);
 

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=1026230&r1=1026229&r2=1026230&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
Fri Oct 22 07:36:35 2010
@@ -188,8 +188,16 @@ public class TableColorizingRenderer ext
     int colIndex = tableColumn.getModelIndex() + 1;
 
     //no event, use default renderer
-    if (loggingEventWrapper == null) {
-        return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
col);
+
+    JLabel basicComponent = null;
+    boolean basic = (!wrap && !highlightSearchMatchText && !logPanelPreferenceModel.isShowMillisDeltaAsGap());
+    if (basic || loggingEventWrapper == null) {
+      Component rendererComponent = super.getTableCellRendererComponent(table, value, false,
false, row, col);
+      if (!(rendererComponent instanceof JLabel) || loggingEventWrapper == null) {
+        return rendererComponent;
+      }
+      basicComponent = (JLabel)rendererComponent;
+      setBasicComponentBorder(basicComponent, isSelected, table, col);
     }
     long delta = 0;
     if (row > 0) {
@@ -203,6 +211,9 @@ public class TableColorizingRenderer ext
     switch (colIndex) {
     case ChainsawColumns.INDEX_THROWABLE_COL_NAME:
       if (value instanceof String[] && ((String[])value).length > 0){
+        if (basic) {
+          basicComponent.setText(((String[])value)[0]);
+        } else {
           Style tabStyle = singleLineTextPane.getLogicalStyle();
           StyleConstants.setTabSet(tabStyle, tabs);
           //set the 1st tab at position 3
@@ -215,11 +226,20 @@ public class TableColorizingRenderer ext
           } else {
               singleLineTextPane.setText(((String[])value)[0]);
           }
+        }
       } else {
-        singleLineTextPane.setText("");
+        if (basic) {
+          basicComponent.setText("");
+        } else {
+          singleLineTextPane.setText("");
+        }
+      }
+      if (basic) {
+        component = basicComponent;
+      } else {
+        layoutRenderingPanel(generalPanel, singleLineTextPane, delta, isSelected, width,
col, table);
+        component = generalPanel;
       }
-      layoutRenderingPanel(generalPanel, singleLineTextPane, delta, isSelected, width, col,
table);
-      component = generalPanel;
       break;
     case ChainsawColumns.INDEX_LOGGER_COL_NAME:
       String logger = value.toString();
@@ -231,49 +251,88 @@ public class TableColorizingRenderer ext
           break;
         }
       }
+      if (basic) {
+        basicComponent.setText(logger.substring(startPos + 1));
+        component = basicComponent;
+      } else {
         singleLineTextPane.setText(logger.substring(startPos + 1));
         setHighlightAttributesInternal(matches.get(LoggingEventFieldResolver.LOGGER_FIELD),
(StyledDocument) singleLineTextPane.getDocument());
         layoutRenderingPanel(generalPanel, singleLineTextPane, delta, isSelected, width,
col, table);
         component = generalPanel;
+      }
       break;
     case ChainsawColumns.INDEX_ID_COL_NAME:
+      if (basic) {
+        basicComponent.setText(value.toString());
+        component = basicComponent;
+      } else {
         singleLineTextPane.setText(value.toString());
         setHighlightAttributesInternal(matches.get(LoggingEventFieldResolver.PROP_FIELD +
"LOG4JID"), (StyledDocument) singleLineTextPane.getDocument());
         layoutRenderingPanel(generalPanel, singleLineTextPane, delta, isSelected, width,
col, table);
         component = generalPanel;
+      }
         break;
     case ChainsawColumns.INDEX_CLASS_COL_NAME:
+      if (basic) {
+        basicComponent.setText(value.toString());
+        component = basicComponent;
+      } else {
         singleLineTextPane.setText(value.toString());
         setHighlightAttributesInternal(matches.get(LoggingEventFieldResolver.CLASS_FIELD),
(StyledDocument) singleLineTextPane.getDocument());
         layoutRenderingPanel(generalPanel, singleLineTextPane, delta, isSelected, width,
col, table);
         component = generalPanel;
+      }
         break;
     case ChainsawColumns.INDEX_FILE_COL_NAME:
+      if (basic) {
+        basicComponent.setText(value.toString());
+        component = basicComponent;
+      } else {
         singleLineTextPane.setText(value.toString());
         setHighlightAttributesInternal(matches.get(LoggingEventFieldResolver.FILE_FIELD),
(StyledDocument) singleLineTextPane.getDocument());
         layoutRenderingPanel(generalPanel, singleLineTextPane, delta, isSelected, width,
col, table);
         component = generalPanel;
+      }
         break;
     case ChainsawColumns.INDEX_LINE_COL_NAME:
+      if (basic) {
+        basicComponent.setText(value.toString());
+        component = basicComponent;
+      } else {
         singleLineTextPane.setText(value.toString());
         setHighlightAttributesInternal(matches.get(LoggingEventFieldResolver.LINE_FIELD),
(StyledDocument) singleLineTextPane.getDocument());
         layoutRenderingPanel(generalPanel, singleLineTextPane, delta, isSelected, width,
col, table);
         component = generalPanel;
+      }
         break;
     case ChainsawColumns.INDEX_NDC_COL_NAME:
+      if (basic) {
+        basicComponent.setText(value.toString());
+        component = basicComponent;
+      } else {
         singleLineTextPane.setText(value.toString());
         setHighlightAttributesInternal(matches.get(LoggingEventFieldResolver.NDC_FIELD),
(StyledDocument) singleLineTextPane.getDocument());
         layoutRenderingPanel(generalPanel, singleLineTextPane, delta, isSelected, width,
col, table);
         component = generalPanel;
+      }
         break;
     case ChainsawColumns.INDEX_THREAD_COL_NAME:
+      if (basic) {
+        basicComponent.setText(value.toString());
+        component = basicComponent;
+      } else {
         singleLineTextPane.setText(value.toString());
         setHighlightAttributesInternal(matches.get(LoggingEventFieldResolver.THREAD_FIELD),
(StyledDocument) singleLineTextPane.getDocument());
         layoutRenderingPanel(generalPanel, singleLineTextPane, delta, isSelected, width,
col, table);
         component = generalPanel;
+      }
         break;
     case ChainsawColumns.INDEX_TIMESTAMP_COL_NAME:
         //timestamp matches contain the millis..not the display text..just highlight if we
have a match for the timestamp field
+      if (basic) {
+        basicComponent.setText(value.toString());
+        component = basicComponent;
+      } else {
         Set timestampMatches = (Set)matches.get(LoggingEventFieldResolver.TIMESTAMP_FIELD);
         if (timestampMatches != null && timestampMatches.size() > 0) {
             singleLineTextPane.setText(value.toString());
@@ -283,16 +342,26 @@ public class TableColorizingRenderer ext
         }
         layoutRenderingPanel(generalPanel, singleLineTextPane, delta, isSelected, width,
col, table);
         component = generalPanel;
+      }
         break;
     case ChainsawColumns.INDEX_METHOD_COL_NAME:
+      if (basic) {
+        basicComponent.setText(value.toString());
+        component = basicComponent;
+      } else {
         singleLineTextPane.setText(value.toString());
         setHighlightAttributesInternal(matches.get(LoggingEventFieldResolver.METHOD_FIELD),
(StyledDocument) singleLineTextPane.getDocument());
         layoutRenderingPanel(generalPanel, singleLineTextPane, delta, isSelected, width,
col, table);
         component = generalPanel;
+      }
         break;
     case ChainsawColumns.INDEX_LOG4J_MARKER_COL_NAME:
     case ChainsawColumns.INDEX_MESSAGE_COL_NAME:
         String thisString = value.toString().trim();
+      if (basic) {
+        basicComponent.setText(thisString);
+        component = basicComponent;
+      } else {
         JTextPane textPane = wrap ? multiLineTextPane : singleLineTextPane;
         JComponent textPaneContainer = wrap ? multiLinePanel : generalPanel;
         textPane.setText(thisString);
@@ -313,23 +382,6 @@ public class TableColorizingRenderer ext
         }
         textPaneContainer.add(textPane, BorderLayout.SOUTH);
 
-        if (delta == 0 || !logPanelPreferenceModel.isShowMillisDeltaAsGap()) {
-          if (col == 0) {
-            textPane.setBorder(getLeftBorder(isSelected, delta));
-          } else if (col == table.getColumnCount() - 1) {
-            textPane.setBorder(getRightBorder(isSelected, delta));
-          } else {
-            textPane.setBorder(getMiddleBorder(isSelected, delta));
-          }
-        } else {
-            if (col == 0) {
-              textPane.setBorder(getLeftBorder(isSelected, 0));
-            } else if (col == table.getColumnCount() - 1) {
-              textPane.setBorder(getRightBorder(isSelected, 0));
-            } else {
-              textPane.setBorder(getMiddleBorder(isSelected, 0));
-            }
-        }
         int currentMarkerHeight = loggingEventWrapper.getMarkerHeight();
         int currentMsgHeight = loggingEventWrapper.getMsgHeight();
         int newRowHeight = ChainsawConstants.DEFAULT_ROW_HEIGHT;
@@ -373,28 +425,54 @@ public class TableColorizingRenderer ext
         }
 
         component = textPaneContainer;
+        setComponentBorder(component, isSelected, table, col, delta);
+      }
         break;
     case ChainsawColumns.INDEX_LEVEL_COL_NAME:
       if (levelUseIcons) {
-        levelTextPane.setText("");
-        levelTextPane.insertIcon((Icon) iconMap.get(value.toString()));
-        if (!toolTipsVisible) {
-          levelTextPane.setToolTipText(value.toString());
+        if (basic) {
+          basicComponent.setText("");
+          if (!toolTipsVisible) {
+            basicComponent.setToolTipText(value.toString());
+          }
+        } else {
+          levelTextPane.setText("");
+          levelTextPane.insertIcon((Icon) iconMap.get(value.toString()));
+          if (!toolTipsVisible) {
+            levelTextPane.setToolTipText(value.toString());
+          }
         }
       } else {
-        levelTextPane.setText(value.toString());
-        setHighlightAttributesInternal(matches.get(LoggingEventFieldResolver.LEVEL_FIELD),
(StyledDocument) levelTextPane.getDocument());
-        if (!toolTipsVisible) {
-            levelTextPane.setToolTipText(null);
+        if (basic) {
+          basicComponent.setText(value.toString());
+          if (!toolTipsVisible) {
+              basicComponent.setToolTipText(null);
+          }
+        } else {
+          levelTextPane.setText(value.toString());
+          setHighlightAttributesInternal(matches.get(LoggingEventFieldResolver.LEVEL_FIELD),
(StyledDocument) levelTextPane.getDocument());
+          if (!toolTipsVisible) {
+              levelTextPane.setToolTipText(null);
+          }
         }
       }
       if (toolTipsVisible) {
+        if (basic) {
+          basicComponent.setToolTipText(label.getToolTipText());
+        } else {
           levelTextPane.setToolTipText(label.getToolTipText());
+        }
+      }
+      if (basic) {
+        basicComponent.setForeground(label.getForeground());
+        basicComponent.setBackground(label.getBackground());
+        component = basicComponent;
+      } else {
+        levelTextPane.setForeground(label.getForeground());
+        levelTextPane.setBackground(label.getBackground());
+        layoutRenderingPanel(levelPanel, levelTextPane, delta, isSelected, width, col, table);
+        component = levelPanel;
       }
-      levelTextPane.setForeground(label.getForeground());
-      levelTextPane.setBackground(label.getBackground());
-      layoutRenderingPanel(levelPanel, levelTextPane, delta, isSelected, width, col, table);
-      component = levelPanel;
       break;
 
     //remaining entries are properties
@@ -413,13 +491,26 @@ public class TableColorizingRenderer ext
         if (thisProp != null) {
             String propKey = LoggingEventFieldResolver.PROP_FIELD + thisProp.toUpperCase();
             Set propKeyMatches = (Set)matches.get(propKey);
-            singleLineTextPane.setText(loggingEventWrapper.getLoggingEvent().getProperty(thisProp));
+            String propertyValue = loggingEventWrapper.getLoggingEvent().getProperty(thisProp);
+          if (basic) {
+            basicComponent.setText(propertyValue);
+          } else {
+            singleLineTextPane.setText(propertyValue);
             setHighlightAttributesInternal(propKeyMatches, (StyledDocument) singleLineTextPane.getDocument());
+          }
         } else {
+          if (basic) {
+            basicComponent.setText("");
+          } else {
             singleLineTextPane.setText("");
+          }
         }
+      if (basic) {
+        component = basicComponent;
+      } else {
         layoutRenderingPanel(generalPanel, singleLineTextPane, delta, isSelected, width,
col, table);
         component = generalPanel;
+      }
         break;
     }
 
@@ -454,16 +545,40 @@ public class TableColorizingRenderer ext
     component.setForeground(foreground);
 
     //update the background & foreground of the jtextpane using styles
-    if (multiLineTextPane != null)
-    {
-        updateColors(multiLineTextPane, background, foreground);
+    if (!basic) {
+      if (multiLineTextPane != null)
+      {
+          updateColors(multiLineTextPane, background, foreground);
+      }
+      updateColors(levelTextPane, background, foreground);
+      updateColors(singleLineTextPane, background, foreground);
     }
-    updateColors(levelTextPane, background, foreground);
-    updateColors(singleLineTextPane, background, foreground);
-
     return component;
   }
 
+  private void setBasicComponentBorder(JComponent component, boolean isSelected, JTable table,
int col) {
+    setComponentBorder(component, isSelected, table, col, 0);
+  }
+
+  private void setComponentBorder(JComponent component, boolean isSelected, JTable table,
int col, long delta) {
+    if (delta == 0 || !logPanelPreferenceModel.isShowMillisDeltaAsGap()) {
+      if (col == 0) {
+        component.setBorder(getLeftBorder(isSelected, delta));
+      } else if (col == table.getColumnCount() - 1) {
+        component.setBorder(getRightBorder(isSelected, delta));
+      } else {
+        component.setBorder(getMiddleBorder(isSelected, delta));
+      }
+    } else {
+        if (col == 0) {
+          component.setBorder(getLeftBorder(isSelected, 0));
+        } else if (col == table.getColumnCount() - 1) {
+          component.setBorder(getRightBorder(isSelected, 0));
+        } else {
+          component.setBorder(getMiddleBorder(isSelected, 0));
+        }
+      }
+  }
     private void layoutRenderingPanel(JComponent container, JComponent bottomComponent, long
delta, boolean isSelected,
                                       int width, int col, JTable table) {
         container.removeAll();

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/plugins/PluginClassLoaderFactory.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/plugins/PluginClassLoaderFactory.java?rev=1026230&r1=1026229&r2=1026230&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/plugins/PluginClassLoaderFactory.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/plugins/PluginClassLoaderFactory.java
Fri Oct 22 07:36:35 2010
@@ -23,8 +23,6 @@ import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
 import org.apache.log4j.chainsaw.prefs.SettingsManager;
 
 /**
@@ -40,13 +38,9 @@ import org.apache.log4j.chainsaw.prefs.S
  */
 public class PluginClassLoaderFactory {
 	private final ClassLoader pluginClassLoader;
-	private static final Logger logger = LogManager.getLogger(PluginClassLoaderFactory.class);
-    
+
     private static final PluginClassLoaderFactory instance = new PluginClassLoaderFactory();
     
-	/**
-	 * @param urls
-	 */
 	private PluginClassLoaderFactory() {
         this.pluginClassLoader= PluginClassLoaderFactory.create(new File(SettingsManager.getInstance().getSettingsDirectory()
+ File.separator + "plugins"));
 
@@ -73,7 +67,7 @@ public class PluginClassLoaderFactory {
      */
     private static final ClassLoader create(File pluginDirectory) {
         if(pluginDirectory == null || !pluginDirectory.exists() || !pluginDirectory.canRead())
{
-         logger.error("pluginDirectory cannot be null, and it must exist and must be readable,
using the normal Classloader");
+         System.err.println("pluginDirectory cannot be null, and it must exist and must be
readable, using the normal Classloader");
          return PluginClassLoaderFactory.class.getClassLoader();
         }
         
@@ -97,10 +91,10 @@ public class PluginClassLoaderFactory {
 				File file = new File(pluginDirectory, name);
 				try {
 					list.add(file.toURI().toURL());
-					logger.info("Added " + file.getAbsolutePath()
+					System.out.println("Added " + file.getAbsolutePath()
 							+ " to Plugin class loader list");
 				} catch (Exception e) {
-					logger.error("Failed to retrieve the URL for file: "
+					System.err.println("Failed to retrieve the URL for file: "
 							+ file.getAbsolutePath());
 					throw new RuntimeException(e.getMessage());
 				}



Mime
View raw message