01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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: private JLogList defaultLogArea;
29:
30: public Log4JMonitor() {
31: super (JTabbedPane.BOTTOM, JTabbedPane.SCROLL_TAB_LAYOUT);
32: }
33:
34: public JLogList addLogArea(String title, String loggerName,
35: boolean isDefault) {
36: JLogList logArea = new JLogList(title);
37: logArea.addLogger(loggerName, !isDefault);
38: addTab(title, logArea);
39:
40: if (isDefault)
41: defaultLogArea = logArea;
42:
43: return logArea;
44: }
45:
46: public void logEvent(Object msg) {
47: if (msg instanceof LoggingEvent) {
48: LoggingEvent event = (LoggingEvent) msg;
49: String loggerName = event.getLoggerName();
50:
51: for (int c = 0; c < getTabCount(); c++) {
52: Component tabComponent = getComponentAt(c);
53: if (tabComponent instanceof JLogList) {
54: JLogList logArea = (JLogList) tabComponent;
55: if (logArea.monitors(loggerName)) {
56: logArea.addLine(msg);
57: }
58: }
59: }
60: } else if (defaultLogArea != null) {
61: defaultLogArea.addLine(msg);
62: }
63: }
64:
65: public JLogList getLogArea(String title) {
66: int ix = indexOfTab(title);
67: return (JLogList) (ix == -1 ? null : getComponentAt(ix));
68: }
69:
70: public boolean hasLogArea(String loggerName) {
71: for (int c = 0; c < getTabCount(); c++) {
72: Component tabComponent = getComponentAt(c);
73: if (tabComponent instanceof JLogList) {
74: JLogList logArea = (JLogList) tabComponent;
75: if (logArea.monitors(loggerName)) {
76: return true;
77: }
78: }
79: }
80:
81: return false;
82: }
83: }
|