psmith 2003/09/10 20:35:05 Modified: src/java/org/apache/log4j/chainsaw LogPanel.java ChainsawCyclicBufferTableModel.java TableColorizingRenderer.java Added: src/java/org/apache/log4j/chainsaw ThrowableRenderPanel.java Log: Modifications so that the Throwable Column can be "edited", and by that I mean that selected a Throwable cell entry displays a non-editable label, with an associated "..." button that can be clicked. This mechanism will be used to display a Popup containing the display of the full stack trace, in standard format. Eventually this class will be refactored somewhat to share functionality to be used for NDC, MDC, and Properties. Revision Changes Path 1.4 +19 -1 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- LogPanel.java 10 Sep 2003 23:03:07 -0000 1.3 +++ LogPanel.java 11 Sep 2003 03:35:05 -0000 1.4 @@ -151,6 +151,7 @@ import javax.swing.event.TableColumnModelEvent; import javax.swing.event.TableColumnModelListener; import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableCellEditor; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; import javax.swing.table.TableModel; @@ -765,6 +766,9 @@ externalPanel.setLayout(new BorderLayout()); undockedFrame.getContentPane().add(externalPanel); + // TODO undocked toolbar is broken + // f.getContentPane().add( + // logUI.getToolBarAndMenus().createDockwindowToolbar(f, this), BorderLayout.NORTH); dockingAction = new AbstractAction("Undock") { public void actionPerformed(ActionEvent evt) { @@ -1696,13 +1700,27 @@ //sort column name class ChainsawTableColumnModelListener implements TableColumnModelListener { private JSortTable table; + private TableCellEditor throwableRenderPanel ; public ChainsawTableColumnModelListener(JSortTable table) { this.table = table; + throwableRenderPanel = new ThrowableRenderPanel(table); } public void columnAdded(TableColumnModelEvent e) { - LogLog.debug("Detected columnAdded" + e); +// LogLog.debug("Detected columnAdded" + e); + + TableColumnModel columnModel = (TableColumnModel) e.getSource(); + Enumeration enum = table.getColumnModel().getColumns(); + + while (enum.hasMoreElements()) { + TableColumn column = (TableColumn) enum.nextElement(); + + if ( + (column.getModelIndex() + 1) == ChainsawColumns.INDEX_THROWABLE_COL_NAME) { + column.setCellEditor(throwableRenderPanel); + } + } } public void columnRemoved(TableColumnModelEvent e) { 1.7 +11 -0 jakarta-log4j/src/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java Index: ChainsawCyclicBufferTableModel.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ChainsawCyclicBufferTableModel.java 10 Sep 2003 23:03:07 -0000 1.6 +++ ChainsawCyclicBufferTableModel.java 11 Sep 2003 03:35:05 -0000 1.7 @@ -607,4 +607,15 @@ }); } } + /* (non-Javadoc) + * @see javax.swing.table.TableModel#isCellEditable(int, int) + */ + public boolean isCellEditable(int rowIndex, int columnIndex) { + switch(columnIndex+1){ + case ChainsawColumns.INDEX_THROWABLE_COL_NAME: + return true; + } + return super.isCellEditable(rowIndex, columnIndex); + } + } 1.4 +17 -2 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TableColorizingRenderer.java 5 Sep 2003 06:07:26 -0000 1.3 +++ TableColorizingRenderer.java 11 Sep 2003 03:35:05 -0000 1.4 @@ -49,17 +49,22 @@ 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; @@ -70,6 +75,7 @@ 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; /** @@ -147,8 +153,8 @@ Color color = 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) { @@ -159,6 +165,15 @@ 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; case ChainsawColumns.INDEX_LEVEL_COL_NAME: 1.1 jakarta-log4j/src/java/org/apache/log4j/chainsaw/ThrowableRenderPanel.java Index: ThrowableRenderPanel.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/>. * */ /* * Created on 11/09/2003 * * To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */ package org.apache.log4j.chainsaw; import org.apache.log4j.helpers.LogLog; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.AbstractCellEditor; import javax.swing.Action; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.table.TableCellEditor; /** * An "editor" that doesn't allow editing, but allows the user to press a "..." for more detail about this * Column. * * @author Paul Smith <[EMAIL PROTECTED]> * */ class ThrowableRenderPanel extends AbstractCellEditor implements TableCellEditor { private final SmallButton btn = new SmallButton(); private final JLabel lbl = new JLabel(""); private final JPanel panel = new JPanel(); private Color background = new Color(255, 255, 254); private final Color COLOR_ODD = new Color(230, 230, 230); private final Action showStackTraceAction; private JTable table; ThrowableRenderPanel(JTable table) { panel.setLayout(new BorderLayout()); panel.add(lbl, BorderLayout.CENTER); panel.add(btn, BorderLayout.EAST); lbl.setOpaque(false); btn.setOpaque(false); showStackTraceAction = new AbstractAction("...") { public void actionPerformed(ActionEvent e) { displaySelectedEntry(); } }; this.table = table; showStackTraceAction.putValue( Action.SHORT_DESCRIPTION, "Display the full stack trace in a popup"); btn.setAction(showStackTraceAction); } private void displaySelectedEntry() { Object object = table.getModel().getValueAt( table.getSelectedRow(), table.getSelectedColumn() - 1); LogLog.debug("Would hae displayed " + object); } private void setText(String text) { lbl.setText(text); } /* (non-Javadoc) * @see javax.swing.table.TableCellEditor#getTableCellEditorComponent(javax.swing.JTable, java.lang.Object, boolean, int, int) */ public Component getTableCellEditorComponent( JTable table, Object value, boolean isSelected, int row, int column) { lbl.setText(((String[]) value)[0]); if (isSelected) { panel.setBackground(table.getSelectionBackground()); panel.setForeground(table.getSelectionForeground()); } else if ((row % 2) != 0) { panel.setBackground(COLOR_ODD); } else { panel.setBackground(background); } return panel; } /* (non-Javadoc) * @see javax.swing.CellEditor#getCellEditorValue() */ public Object getCellEditorValue() { return lbl.getText(); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]