FileDocCategorySizeDatePackage
DetailPanel.javaAPI DocApache log4j 1.2.155663Sat Aug 25 00:09:40 BST 2007org.apache.log4j.chainsaw

DetailPanel

public class DetailPanel extends JPanel implements ListSelectionListener
A panel for showing a stack trace.
author
Oliver Burn

Fields Summary
private static final Logger
LOG
used to log events
private static final MessageFormat
FORMATTER
used to format the logging event
private final MyTableModel
mModel
the model for the data to render
private final JEditorPane
mDetails
pane for rendering detail
Constructors Summary
DetailPanel(JTable aTable, MyTableModel aModel)
Creates a new DetailPanel instance.

param
aTable the table to listen for selections on
param
aModel the model backing the table


                              
         
        mModel = aModel;
        setLayout(new BorderLayout());
        setBorder(BorderFactory.createTitledBorder("Details: "));

        mDetails = new JEditorPane();
        mDetails.setEditable(false);
        mDetails.setContentType("text/html");
        add(new JScrollPane(mDetails), BorderLayout.CENTER);

        final ListSelectionModel rowSM = aTable.getSelectionModel();
        rowSM.addListSelectionListener(this);
    
Methods Summary
private java.lang.Stringescape(java.lang.String aStr)
Escape <, > & and " as their entities. It is very dumb about & handling.

param
aStr the String to escape.
return
the escaped String

        if (aStr == null) {
            return null;
        }

        final StringBuffer buf = new StringBuffer();
        for (int i = 0; i < aStr.length(); i++) {
            char c = aStr.charAt(i);
            switch (c) {
            case '<":
                buf.append("<");
                break;
            case '>":
                buf.append(">");
                break;
            case '\"":
                buf.append(""");
                break;
            case '&":
                buf.append("&");
                break;
            default:
                buf.append(c);
                break;
            }
        }
        return buf.toString();
    
private static java.lang.StringgetThrowableStrRep(org.apache.log4j.chainsaw.EventDetails aEvent)
Returns a string representation of a throwable.

param
aEvent contains the throwable information
return
a String value

        final String[] strs = aEvent.getThrowableStrRep();
        if (strs == null) {
            return null;
        }

        final StringBuffer sb = new StringBuffer();
        for (int i = 0; i < strs.length; i++) {
            sb.append(strs[i]).append("\n");
        }

        return sb.toString();
    
public voidvalueChanged(javax.swing.event.ListSelectionEvent aEvent)

see
ListSelectionListener

        //Ignore extra messages.
        if (aEvent.getValueIsAdjusting()) {
            return;
        }

        final ListSelectionModel lsm = (ListSelectionModel) aEvent.getSource();
        if (lsm.isSelectionEmpty()) {
            mDetails.setText("Nothing selected");
        } else {
            final int selectedRow = lsm.getMinSelectionIndex();
            final EventDetails e = mModel.getEventDetails(selectedRow);
            final Object[] args =
            {
                new Date(e.getTimeStamp()),
                e.getPriority(),
                escape(e.getThreadName()),
                escape(e.getNDC()),
                escape(e.getCategoryName()),
                escape(e.getLocationDetails()),
                escape(e.getMessage()),
                escape(getThrowableStrRep(e))
            };
            mDetails.setText(FORMATTER.format(args));
            mDetails.setCaretPosition(0);
        }