View Javadoc

1   /**************************************************************************
2   Copyright 2005 Webstersmalley
3   
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7   
8       http://www.apache.org/licenses/LICENSE-2.0
9   
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  *************************************************************************/
16  /*
17   * Created on 04-Jun-2005
18   */
19  package com.webstersmalley.statuslog;
20  
21  import java.io.File;
22  
23  import javax.swing.JFrame;
24  import javax.swing.JTable;
25  
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  import org.apache.log4j.spi.LoggingEvent;
29  import org.swixml.SwingEngine;
30  
31  import ca.odell.glazedlists.BasicEventList;
32  import ca.odell.glazedlists.EventList;
33  import ca.odell.glazedlists.SortedList;
34  import ca.odell.glazedlists.swing.EventTableModel;
35  import ca.odell.glazedlists.swing.TableComparatorChooser;
36  
37  /***
38   * @author Matthew Smalley
39   */
40  public class StatusFrame
41  {
42  	/*** Logger for the class. */
43  	private static Log log = LogFactory.getLog(StatusFrame.class);
44  	
45  	/***
46  	 * Constructs a new StatusFrame based on a SwiXML configuration file
47  	 *
48  	 */
49  	public StatusFrame()
50  	{
51  		String filename = this.getClass().getName() + ".xml";
52  		File uiFile = new File("src/xml" + File.separator + filename);
53  
54  		try
55  		{
56  			frame = (JFrame) new SwingEngine(this).render(uiFile);
57  			frame.setVisible(true);
58  		}
59  		catch (Exception e)
60  		{
61  			log.error("Error launching UI", e);
62  		}
63  		
64  		SortedList sortedList = new SortedList(list, new StatusBeanComparator(false, 0));
65  		EventTableModel model = new EventTableModel(sortedList, new StatusBeanTableFormat());
66  		logTable.setModel(model);
67  		TableComparatorChooser tableSorter = new TableComparatorChooser(logTable, sortedList, true);
68  	}
69  	
70  	private JFrame frame;
71  	public JTable logTable;
72  	private EventList list = new BasicEventList();
73  
74  	public void addLoggingEntry(LoggingEvent le)
75  	{
76  		StatusBean bean = StatusBean.fromLoggingEvent(le);
77  		list.add(bean);
78  	}
79  	
80  }