psmith 2003/09/11 05:32:52 Modified: src/java/org/apache/log4j/chainsaw/filter FilterModel.java Added: src/java/org/apache/log4j/chainsaw/filter EventTypeEntryContainer.java FilterColorPreferences.java Log: A basic shell of a potential replacement "Medium" filtering panel. As new unique elements of LoggingEvents arrive, ListModels are built up to represent them, so the user may tick what events must have to qualify for viewing. Very much WIP. Revision Changes Path 1.2 +33 -47 jakarta-log4j/src/java/org/apache/log4j/chainsaw/filter/FilterModel.java Index: FilterModel.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/filter/FilterModel.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- FilterModel.java 10 Sep 2003 03:12:20 -0000 1.1 +++ FilterModel.java 11 Sep 2003 12:32:52 -0000 1.2 @@ -52,72 +52,58 @@ import org.apache.log4j.spi.LocationInfo; import org.apache.log4j.spi.LoggingEvent; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import javax.swing.event.EventListenerList; /** - * This class is used as a Model for Filtering, and retains the unique entries that + * This class is used as a Model for Filtering, and retains the unique entries that * come through over a set of LoggingEvents - * + * * @author Paul Smith <[EMAIL PROTECTED]> * @author Scott Deboy <[EMAIL PROTECTED]> */ public class FilterModel { - private Map eventTypeMap = new HashMap(); + // private Map eventTypeMap = new HashMap(); + private EventTypeEntryContainer eventContainer = + new EventTypeEntryContainer(); + private EventListenerList eventListenerList = new EventListenerList(); public void processNewLoggingEvent(String eventType, LoggingEvent event) { - /** - * we update the Entry maps for this identifier, - * - */ EventTypeEntryContainer container = getContainer(eventType); - container.Levels.add(event.getLevel()); - container.Loggers.add(event.getLoggerName()); - container.Threads.add(event.getThreadName()); - container.NDCs.add(event.getNDC()); - container.MDCKeys.addAll(event.getMDCKeySet()); + container.addLevel(event.getLevel()); + container.addLogger(event.getLoggerName()); + container.addThread(event.getThreadName()); + container.addNDC(event.getNDC()); + container.addMDCKeys(event.getMDCKeySet()); if (event.getLocationInformation() != null) { LocationInfo info = event.getLocationInformation(); - container.Classes.add(info.getClassName()); - container.Methods.add(info.getMethodName()); - container.FileNames.add(info.getFileName()); + container.addClass(info.getClassName()); + container.addMethod(info.getMethodName()); + container.addFileName(info.getFileName()); } } - /** - * @param eventType - * @return - */ - private EventTypeEntryContainer getContainer(String eventType) { - EventTypeEntryContainer container = null; - - if (eventTypeMap.containsKey(eventType)) { - container = (EventTypeEntryContainer) eventTypeMap.get(eventType); - } else { - container = new EventTypeEntryContainer(); - eventTypeMap.put(eventType, container); - } - - return container; + EventTypeEntryContainer getContainer() { + // if(eventTypeMap.size()>0){ + // return (EventTypeEntryContainer) eventTypeMap.values().iterator().next(); + // } + return eventContainer; } - private static class EventTypeEntryContainer { - List LeveList = new ArrayList(); - Set ColumnNames = new HashSet(); - Set Methods = new HashSet(); - Set Classes = new HashSet(); - Set MDCKeys = new HashSet(); - Set NDCs = new HashSet(); - Set Levels = new HashSet(); - Set Loggers = new HashSet(); - Set Threads = new HashSet(); - Set FileNames = new HashSet(); + EventTypeEntryContainer getContainer(String eventType) { + return this.eventContainer; + + // EventTypeEntryContainer container = null; + // + // if (eventTypeMap.containsKey(eventType)) { + // container = (EventTypeEntryContainer) eventTypeMap.get(eventType); + // } else { + // container = new EventTypeEntryContainer(); + // eventTypeMap.put(eventType, container); + // } + // + // return container; } } 1.1 jakarta-log4j/src/java/org/apache/log4j/chainsaw/filter/EventTypeEntryContainer.java Index: EventTypeEntryContainer.java =================================================================== /* * ============================================================================ * The Apache Software License, Version 1.1 * ============================================================================ * * Copyright (C) 1999 The Apache Software Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. The end-user documentation included with the redistribution, if any, must * include the following acknowledgment: "This product includes software * developed by the Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, if * and wherever such third-party acknowledgments normally appear. * * 4. The names "log4j" and "Apache Software Foundation" must not be used to * endorse or promote products derived from this software without prior * written permission. For written permission, please contact * [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", nor may * "Apache" appear in their name, without prior written permission of the * Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals * on behalf of the Apache Software Foundation. For more information on the * Apache Software Foundation, please see <http://www.apache.org/>. * */ /* */ package org.apache.log4j.chainsaw.filter; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import javax.swing.DefaultListModel; import javax.swing.ListModel; /** * A Container class used to hold unique LoggingEvent values * and provide them as unique ListModels. * * @author Paul Smith * */ class EventTypeEntryContainer { private Set ColumnNames = new HashSet(); private Set Methods = new HashSet(); private Set Classes = new HashSet(); private Set MDCKeys = new HashSet(); private Set NDCs = new HashSet(); private Set Levels = new HashSet(); private Set Loggers = new HashSet(); private Set Threads = new HashSet(); private Set FileNames = new HashSet(); private DefaultListModel columnNameListModel = new DefaultListModel(); private DefaultListModel methodListModel = new DefaultListModel(); private DefaultListModel classesListModel = new DefaultListModel(); private DefaultListModel mdcListModel = new DefaultListModel(); private DefaultListModel ndcListModel = new DefaultListModel(); private DefaultListModel levelListModel = new DefaultListModel(); private DefaultListModel loggerListModel = new DefaultListModel(); private DefaultListModel threadListModel = new DefaultListModel(); private DefaultListModel fileNameListModel = new DefaultListModel(); void addLevel(Object level) { if (Levels.add(level)) { levelListModel.addElement(level); } } void addLogger(String logger) { if (Loggers.add(logger)) { loggerListModel.addElement(logger); } } void addFileName(String filename) { if (FileNames.add(filename)) { fileNameListModel.addElement(filename); } } void addThread(String thread) { if (Threads.add(thread)) { threadListModel.addElement(thread); } } void addNDC(String ndc) { if (NDCs.add(ndc)) { ndcListModel.addElement(ndc); } } void addColumnName(String name) { if (ColumnNames.add(name)) { columnNameListModel.addElement(name); } } void addMethod(String method) { if (Methods.add(method)) { methodListModel.addElement(method); } } void addClass(String className) { if (Classes.add(className)) { classesListModel.addElement(className); } } void addMDCKeys(Set keySet) { if (MDCKeys.addAll(keySet)) { for (Iterator iter = keySet.iterator(); iter.hasNext();) { Object element = (Object) iter.next(); mdcListModel.addElement(element); } } } ListModel getColumnListModel() { return columnNameListModel; } /** * @return */ DefaultListModel getClassesListModel() { return classesListModel; } /** * @return */ DefaultListModel getColumnNameListModel() { return columnNameListModel; } /** * @return */ DefaultListModel getFileNameListModel() { return fileNameListModel; } /** * @return */ DefaultListModel getLevelListModel() { return levelListModel; } /** * @return */ DefaultListModel getLoggerListModel() { return loggerListModel; } /** * @return */ DefaultListModel getMdcListModel() { return mdcListModel; } /** * @return */ DefaultListModel getMethodListModel() { return methodListModel; } /** * @return */ DefaultListModel getNdcListModel() { return ndcListModel; } /** * @return */ DefaultListModel getThreadListModel() { return threadListModel; } } 1.1 jakarta-log4j/src/java/org/apache/log4j/chainsaw/filter/FilterColorPreferences.java Index: FilterColorPreferences.java =================================================================== /* * ============================================================================ * The Apache Software License, Version 1.1 * ============================================================================ * * Copyright (C) 1999 The Apache Software Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. The end-user documentation included with the redistribution, if any, must * include the following acknowledgment: "This product includes software * developed by the Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, if * and wherever such third-party acknowledgments normally appear. * * 4. The names "log4j" and "Apache Software Foundation" must not be used to * endorse or promote products derived from this software without prior * written permission. For written permission, please contact * [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", nor may * "Apache" appear in their name, without prior written permission of the * Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals * on behalf of the Apache Software Foundation. For more information on the * Apache Software Foundation, please see <http://www.apache.org/>. * */ package org.apache.log4j.chainsaw.filter; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; import java.util.Date; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; import javax.swing.ListModel; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.spi.LoggingEvent; /** * A Panel that is used for configuring which unique Event elements determine * what events to display. * * @author Paul Smith */ class FilterColorPreferences extends JPanel { private final FilterModel filterModel; private JTabbedPane tabbedPane = new JTabbedPane(); FilterColorPreferences(FilterModel filterModel) { this.filterModel = filterModel; initComponents(); } /** * */ private void initComponents() { setLayout(new BorderLayout()); EventTypeEntryContainer container = filterModel.getContainer(); ListModel[] models = new ListModel[] { container.getLevelListModel(), container.getLoggerListModel(), }; String[] tabNames = new String[] { "Levels", "Loggers", }; for (int i = 0; i < tabNames.length; i++) { tabbedPane.add(tabNames[i], createTabPanel(tabNames[i], models[i])); } add(tabbedPane, BorderLayout.CENTER); } /** * @param string * @param collection * @return */ private Component createTabPanel(String tabName, ListModel listModel) { JPanel c = new JPanel(); c.setLayout(new BorderLayout()); JList list = new JList(listModel); list.setVisibleRowCount(25); c.add(new JScrollPane(list), BorderLayout.CENTER); return c; } public static void main(String[] args) { JFrame frame = new JFrame("test bed"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); FilterModel model = new FilterModel(); LoggingEvent e = new LoggingEvent( "org.blah.blah", Logger.getLogger("org.blah.blah"), new Date().getTime(), Level.DEBUG, "Hello World", null); model.processNewLoggingEvent(null, e); frame.getContentPane().add(new FilterColorPreferences(model)); frame.pack(); frame.setSize(new Dimension(320, 240)); frame.setVisible(true); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]