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.JComponent;
    18
    19  import org.apache.log4j.spi.LoggingEvent;
    20
    21  import com.eviware.soapui.support.components.Inspector;
    22  import com.eviware.soapui.support.components.JComponentInspector;
    23  import com.eviware.soapui.support.components.JInspectorPanel;
    24
    25  /***
    26   * JTabbedPane that displays Log4J output in different tabs
    27   *
    28   * @author Ole.Matzura
    29   */
    30
    31  public class InspectorLog4JMonitor extends JInspectorPanel implements Log4JMonitor
    32  {
    33  	private JLogList defaultLogArea;
    34
    35  	public InspectorLog4JMonitor( JComponent content )
    36  	{
    37  		super( content );
    38
    39  		setResizeWeight( 0.9F );
    40  	}
    41
    42  	public JLogList addLogArea( String title, String loggerName, boolean isDefault )
    43  	{
    44  		JLogList logArea = new JLogList( title );
    45  		logArea.addLogger( loggerName, !isDefault );
    46  		JComponentInspector inspector = new JComponentInspector(logArea,  title, null, true);
    47  		addInspector( inspector);
    48
    49  		if( isDefault )
    50  		{
    51  			defaultLogArea = logArea;
    52  			activate( inspector );
    53  			setDividerLocation( 500 );
    54  		}
    55
    56  		return logArea;
    57  	}
    58
    59  	public void logEvent(Object msg)
    60  	{
    61  		if( msg instanceof LoggingEvent )
    62  		{
    63  			LoggingEvent event = (LoggingEvent) msg;
    64  			String loggerName = event.getLoggerName();
    65
    66  			for( Inspector inspector : getInspectors() )
    67  			{
    68  				Component tabComponent = inspector.getComponent();
    69  				if( tabComponent instanceof JLogList )
    70  				{
    71  					JLogList logArea = (JLogList) tabComponent;
    72  					if( logArea.monitors( loggerName ))
    73  					{
    74  						logArea.addLine( msg );
    75  					}
    76  				}
    77  			}
    78  		}
    79  		else if( defaultLogArea != null )
    80  		{
    81  			defaultLogArea.addLine( msg );
    82  		}
    83  	}
    84
    85  	public JLogList getLogArea( String title )
    86  	{
    87  		Inspector inspector = getInspectorByTitle( title );
    88  		return ( JLogList ) ( title == null ? null : inspector.getComponent() );
    89  	}
    90
    91  	public boolean hasLogArea(String loggerName)
    92  	{
    93  		for( Inspector inspector : getInspectors() )
    94  		{
    95  			Component tabComponent = inspector.getComponent();
    96  			if( tabComponent instanceof JLogList )
    97  			{
    98  				JLogList logArea = (JLogList) tabComponent;
    99  				if( logArea.monitors( loggerName ))
    100 				{
    101 					return true;
    102 				}
    103 			}
    104 		}
    105
    106 		return false;
    107 	}
    108
    109 	public JComponent getComponent()
    110 	{
    111 		return this;
    112 	}
    113
    114 	public void setCurrentLog( JLogList lastLog )
    115 	{
    116 		for( Inspector inspector : getInspectors() )
    117 		{
    118 			Component tabComponent = inspector.getComponent();
    119 			if( tabComponent == lastLog )
    120 			{
    121 				activate( inspector );
    122 				return;
    123 			}
    124 		}
    125
    126 		deactivate();
    127 	}
    128
    129 	public JLogList getCurrentLog()
    130 	{
    131 		return ( JLogList ) ( getCurrentInspector() == null ? null : getCurrentInspector().getComponent() );
    132 	}
    133 }