View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 eviware.com
    3    *
    4    *  soapUI is free software; you can redistribute it and/or modify it under the
    5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
    6    *  the Free Software Foundation.
    7    *
    8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
    9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    10   *  See the GNU Lesser General Public License for more details at gnu.org.
    11   */
    12
    13  package com.eviware.soapui.support.log;
    14
    15  import java.awt.Component;
    16
    17  import javax.swing.JTabbedPane;
    18
    19  import org.apache.log4j.spi.LoggingEvent;
    20
    21  /***
    22   * JTabbedPane that displays Log4J output in different tabs
    23   *
    24   * @author Ole.Matzura
    25   */
    26
    27  public class Log4JMonitor extends JTabbedPane
    28  {
    29  	private JLogList defaultLogArea;
    30
    31  	public Log4JMonitor()
    32  	{
    33  		super( JTabbedPane.BOTTOM, JTabbedPane.SCROLL_TAB_LAYOUT );
    34  	}
    35
    36  	public JLogList addLogArea( String title, String loggerName, boolean isDefault )
    37  	{
    38  		JLogList logArea = new JLogList( title );
    39  		logArea.addLogger( loggerName, !isDefault );
    40  		addTab( title, logArea);
    41
    42  		if( isDefault )
    43  			defaultLogArea = logArea;
    44
    45  		return logArea;
    46  	}
    47
    48  	public void logEvent(Object msg)
    49  	{
    50  		if( msg instanceof LoggingEvent )
    51  		{
    52  			LoggingEvent event = (LoggingEvent) msg;
    53  			String loggerName = event.getLoggerName();
    54
    55  			for( int c = 0; c < getTabCount(); c++ )
    56  			{
    57  				Component tabComponent = getComponentAt( c );
    58  				if( tabComponent instanceof JLogList )
    59  				{
    60  					JLogList logArea = (JLogList) tabComponent;
    61  					if( logArea.monitors( loggerName ))
    62  					{
    63  						logArea.addLine( msg );
    64  					}
    65  				}
    66  			}
    67  		}
    68  		else if( defaultLogArea != null )
    69  		{
    70  			defaultLogArea.addLine( msg );
    71  		}
    72  	}
    73
    74  	public JLogList getLogArea( String title )
    75  	{
    76  		int ix = indexOfTab( title );
    77  		return ( JLogList ) ( ix == -1 ? null : getComponentAt( ix ) );
    78  	}
    79
    80  	public boolean hasLogArea(String loggerName)
    81  	{
    82  		for( int c = 0; c < getTabCount(); c++ )
    83  		{
    84  			Component tabComponent = getComponentAt( c );
    85  			if( tabComponent instanceof JLogList )
    86  			{
    87  				JLogList logArea = (JLogList) tabComponent;
    88  				if( logArea.monitors( loggerName ))
    89  				{
    90  					return true;
    91  				}
    92  			}
    93  		}
    94
    95  		return false;
    96  	}
    97  }