1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.support.log;
14
15 import com.eviware.soapui.support.components.Inspector;
16 import com.eviware.soapui.support.components.JComponentInspector;
17 import com.eviware.soapui.support.components.JInspectorPanel;
18 import com.eviware.soapui.support.components.JInspectorPanelFactory;
19 import org.apache.log4j.spi.LoggingEvent;
20
21 import javax.swing.*;
22 import java.awt.*;
23 import java.util.List;
24
25 /***
26 * JTabbedPane that displays Log4J output in different tabs
27 *
28 * @author Ole.Matzura
29 */
30
31 public class InspectorLog4JMonitor implements JInspectorPanel, Log4JMonitor
32 {
33 private JLogList defaultLogArea;
34 private JInspectorPanel inspectorPanel;
35
36 public InspectorLog4JMonitor( JComponent content )
37 {
38 inspectorPanel = JInspectorPanelFactory.build( content );
39
40 setResizeWeight( 0.9F );
41 }
42
43 public JLogList addLogArea( String title, String loggerName, boolean isDefault )
44 {
45 JLogList logArea = new JLogList( title );
46 logArea.addLogger( loggerName, !isDefault );
47 JComponentInspector<JLogList> inspector = new JComponentInspector<JLogList>(logArea, title, null, true);
48 addInspector( inspector);
49
50 if( isDefault )
51 {
52 defaultLogArea = logArea;
53 activate( inspector );
54 setDividerLocation( 500 );
55 }
56
57 return logArea;
58 }
59
60 public void logEvent(Object msg)
61 {
62 if( msg instanceof LoggingEvent )
63 {
64 LoggingEvent event = (LoggingEvent) msg;
65 String loggerName = event.getLoggerName();
66
67 for( Inspector inspector : inspectorPanel.getInspectors() )
68 {
69 Component tabComponent = inspector.getComponent();
70 if( tabComponent instanceof JLogList )
71 {
72 JLogList logArea = (JLogList) tabComponent;
73 if( logArea.monitors( loggerName ))
74 {
75 logArea.addLine( msg );
76 }
77 }
78 }
79 }
80 else if( defaultLogArea != null )
81 {
82 defaultLogArea.addLine( msg );
83 }
84 }
85
86 public JLogList getLogArea( String title )
87 {
88 Inspector inspector = inspectorPanel.getInspectorByTitle( title );
89 return ( JLogList ) ( title == null ? null : inspector.getComponent() );
90 }
91
92 public boolean hasLogArea(String loggerName)
93 {
94 for( Inspector inspector : getInspectors() )
95 {
96 Component tabComponent = inspector.getComponent();
97 if( tabComponent instanceof JLogList )
98 {
99 JLogList logArea = (JLogList) tabComponent;
100 if( logArea.monitors( loggerName ))
101 {
102 return true;
103 }
104 }
105 }
106
107 return false;
108 }
109
110 public JComponent getComponent()
111 {
112 return inspectorPanel.getComponent();
113 }
114
115 public Inspector getCurrentInspector() {
116 return inspectorPanel.getCurrentInspector();
117 }
118
119 public Inspector getInspectorByTitle(String title) {
120 return inspectorPanel.getInspectorByTitle(title);
121 }
122
123 public List<Inspector> getInspectors() {
124 return inspectorPanel.getInspectors();
125 }
126
127 public void setCurrentInspector(String s) {
128 inspectorPanel.setCurrentInspector(s);
129 }
130
131 public void setDefaultDividerLocation(float v) {
132 inspectorPanel.setDefaultDividerLocation(v);
133 }
134
135 public void setDividerLocation(int i) {
136 inspectorPanel.setDividerLocation(i);
137 }
138
139 public void setResizeWeight(double v) {
140 inspectorPanel.setResizeWeight(v);
141 }
142
143 public void setCurrentLog( JLogList lastLog )
144 {
145 for( Inspector inspector : getInspectors() )
146 {
147 Component tabComponent = inspector.getComponent();
148 if( tabComponent == lastLog )
149 {
150 activate( inspector );
151 return;
152 }
153 }
154
155 inspectorPanel.deactivate();
156 }
157
158 public void activate(Inspector inspector) {
159 inspectorPanel.activate(inspector);
160 }
161
162 public <T extends Inspector> T addInspector(T inspector) {
163 return inspectorPanel.addInspector(inspector);
164 }
165
166 public void deactivate() {
167 inspectorPanel.deactivate();
168 }
169
170 public void removeInspector(Inspector inspector) {
171 inspectorPanel.removeInspector(inspector);
172 }
173
174 public JLogList getCurrentLog()
175 {
176 return ( JLogList ) ( inspectorPanel.getCurrentInspector() == null ? null : inspectorPanel.getCurrentInspector().getComponent() );
177 }
178
179
180 public boolean removeLogArea( String loggerName )
181 {
182 for( Inspector inspector : getInspectors())
183 {
184 JLogList logList = ((JLogList)((JComponentInspector<?>)inspector).getComponent());
185 if( logList.getLogger( loggerName ) != null )
186 {
187 logList.removeLogger( loggerName );
188 inspectorPanel.removeInspector( inspector );
189
190 return true;
191 }
192 }
193
194 return false;
195 }
196
197 public int getDividerLocation() {
198 return inspectorPanel.getDividerLocation();
199 }
200
201 public void setContentComponent(JComponent component) {
202 inspectorPanel.setContentComponent( component );
203 }
204
205 public void release() {
206 inspectorPanel.release();
207 }
208
209 public void setResetDividerLocation() {
210 inspectorPanel.setResetDividerLocation();
211 }
212
213 public void setInspectorVisible(Inspector inspector, boolean b) {
214 inspectorPanel.setInspectorVisible(inspector, b);
215 }
216
217 public Inspector getInspector(String inspectorId) {
218 return inspectorPanel.getInspector(inspectorId);
219 }
220 }