View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
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 boolean hasLogArea(String loggerName)
75  	{
76  		for( int c = 0; c < getTabCount(); c++ )
77  		{
78  			Component tabComponent = getComponentAt( c );
79  			if( tabComponent instanceof JLogList )
80  			{
81  				JLogList logArea = (JLogList) tabComponent;
82  				if( logArea.monitors( loggerName ))
83  				{
84  					return true;
85  				}
86  			}
87  		}
88  		
89  		return false;
90  	}
91  }