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)
Project: http://git-wip-us.apache.org/repos/asf/logging-chainsaw/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-chainsaw/commit/66805db7 Tree: http://git-wip-us.apache.org/repos/asf/logging-chainsaw/tree/66805db7 Diff: http://git-wip-us.apache.org/repos/asf/logging-chainsaw/diff/66805db7 Branch: refs/heads/master Commit: 66805db79b459e159c01375645cc481bd6d61c63 Parents: f543275 Author: Scott Deboy <[email protected]> Authored: Fri Oct 22 07:36:35 2010 +0000 Committer: Scott Deboy <[email protected]> Committed: Fri Oct 22 07:36:35 2010 +0000 ---------------------------------------------------------------------- .../log4j/chainsaw/AbstractPreferencePanel.java | 2 +- .../java/org/apache/log4j/chainsaw/LogUI.java | 23 ++- .../chainsaw/ReceiverConfigurationPanel.java | 1 + .../log4j/chainsaw/TableColorizingRenderer.java | 197 +++++++++++++++---- .../plugins/PluginClassLoaderFactory.java | 14 +- 5 files changed, 181 insertions(+), 56 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/66805db7/src/main/java/org/apache/log4j/chainsaw/AbstractPreferencePanel.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/AbstractPreferencePanel.java b/src/main/java/org/apache/log4j/chainsaw/AbstractPreferencePanel.java index f7f1226..50adbc6 100644 --- a/src/main/java/org/apache/log4j/chainsaw/AbstractPreferencePanel.java +++ b/src/main/java/org/apache/log4j/chainsaw/AbstractPreferencePanel.java @@ -112,7 +112,7 @@ public abstract class AbstractPreferencePanel extends JPanel 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); http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/66805db7/src/main/java/org/apache/log4j/chainsaw/LogUI.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/LogUI.java b/src/main/java/org/apache/log4j/chainsaw/LogUI.java index 20c79f7..30a0abf 100644 --- a/src/main/java/org/apache/log4j/chainsaw/LogUI.java +++ b/src/main/java/org/apache/log4j/chainsaw/LogUI.java @@ -282,11 +282,11 @@ public class LogUI extends JFrame implements ChainsawViewer, SettingsListener { 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 implements ChainsawViewer, SettingsListener { 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 implements ChainsawViewer, SettingsListener { 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 implements ChainsawViewer, SettingsListener { UIManager.setLookAndFeel(lookAndFeelClassName); } catch (Exception e) { + e.printStackTrace(); } } @@ -2148,6 +2147,22 @@ public class LogUI extends JFrame implements ChainsawViewer, SettingsListener { 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. http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/66805db7/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java b/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java index 50c5934..fbd4c22 100644 --- a/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java +++ b/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java @@ -214,6 +214,7 @@ class ReceiverConfigurationPanel extends JPanel { 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); http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/66805db7/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java b/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java index 209204d..33d74d1 100644 --- a/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java +++ b/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java @@ -188,8 +188,16 @@ public class TableColorizingRenderer extends DefaultTableCellRenderer { 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 extends DefaultTableCellRenderer { 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 extends DefaultTableCellRenderer { } 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 extends DefaultTableCellRenderer { 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 extends DefaultTableCellRenderer { } 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 extends DefaultTableCellRenderer { } 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 extends DefaultTableCellRenderer { } 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 extends DefaultTableCellRenderer { 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 extends DefaultTableCellRenderer { 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(); http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/66805db7/src/main/java/org/apache/log4j/chainsaw/plugins/PluginClassLoaderFactory.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/plugins/PluginClassLoaderFactory.java b/src/main/java/org/apache/log4j/chainsaw/plugins/PluginClassLoaderFactory.java index 813e3a2..2ef492e 100644 --- a/src/main/java/org/apache/log4j/chainsaw/plugins/PluginClassLoaderFactory.java +++ b/src/main/java/org/apache/log4j/chainsaw/plugins/PluginClassLoaderFactory.java @@ -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.SettingsManager; */ 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()); }
