psmith      2004/10/18 15:16:35

  Modified:    src/java/org/apache/log4j/chainsaw/messages
                        MessageCenter.java
  Added:       src/java/org/apache/log4j/varia ListAppender.java
                        ListModelAppender.java
  Removed:     src/java/org/apache/log4j/chainsaw/messages
                        MessageCenterAppender.java
  Log:
  Moved out the MessageCenterAppender into a better named ListModelAppender, and moved
  it into the log4j core via the varia package.
  
  Also added a ListAppender on suggestion from a member of the log4j-dev list (no full 
name supplied).
  
  Revision  Changes    Path
  1.7       +2 -1      
logging-log4j/src/java/org/apache/log4j/chainsaw/messages/MessageCenter.java
  
  Index: MessageCenter.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/messages/MessageCenter.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MessageCenter.java        20 May 2004 23:09:57 -0000      1.6
  +++ MessageCenter.java        18 Oct 2004 22:16:34 -0000      1.7
  @@ -48,6 +48,7 @@
   import org.apache.log4j.chainsaw.SmallButton;
   import org.apache.log4j.chainsaw.icons.ChainsawIcons;
   import org.apache.log4j.spi.LoggingEvent;
  +import org.apache.log4j.varia.ListModelAppender;
   
   
   /**
  @@ -74,7 +75,7 @@
     private final Logger logger = Logger.getLogger(MessageCenter.class);
     private Layout layout = new TTCCLayout();
     private final JList messageList = new JList();
  -  private final MessageCenterAppender appender = new MessageCenterAppender();
  +  private final ListModelAppender appender = new ListModelAppender();
     private ListCellRenderer listCellRenderer =
       new LayoutListCellRenderer(layout);
     private PropertyChangeSupport propertySupport =
  
  
  
  1.1                  logging-log4j/src/java/org/apache/log4j/varia/ListAppender.java
  
  Index: ListAppender.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"); you may
   * not use this file except in compliance with the License. You may obtain a
   * copy of the License at
   * 
   * http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   * License for the specific language governing permissions and limitations
   * under the License.
   */
  package org.apache.log4j.varia;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.log4j.AppenderSkeleton;
  import org.apache.log4j.spi.LoggingEvent;
  
  /**
   * A very basic appender that takes the events and stores them in to a
   * java.util.List for late retrieval.
   * 
   * Note:  This implemenation intentionally does not allow direct modification
   * of the internal List model to reduce the synchronization complexity that this 
would
   * require.  
   * 
   * @see org.apache.log4j.varia.ListModelAppender
   * 
   * @author Paul Smith <[EMAIL PROTECTED]>
   *  
   */
  public final class ListAppender extends AppenderSkeleton {
        private final List model = new ArrayList();
  
        /**
         * Returns a writeable, BUT cloned List of all the LoggingEvents that are 
contained 
         * in the internal model.  You are free to modify this list without 
       * worry of synchronization, but note that any modifications to the returned list
       * that you do will have NO impact on the internal model of this Appender.
         * 
         * @return Modifiable List
         */
        public final List getModel() {
          synchronized(model) {
                return new ArrayList(model); 
          }
        }
  
        /*
         * (non-Javadoc)
         * 
         * @see 
org.apache.log4j.AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent)
         */
        protected void append(LoggingEvent event) {
          synchronized(model) {
                model.add(event);
          }
        }
  
        /*
         * (non-Javadoc)
         * 
         * @see org.apache.log4j.Appender#close()
         */
        public void close() {
                clearModel();
        }
  
        /*
         * (non-Javadoc)
         * 
         * @see org.apache.log4j.Appender#requiresLayout()
         */
        public boolean requiresLayout() {
                return false;
        }
  
        /**
         * Removes all the Events from the model
         */
        public void clearModel() {
                synchronized (model) {
                        model.clear();
                }
        }
  }
  
  
  
  
  1.1                  
logging-log4j/src/java/org/apache/log4j/varia/ListModelAppender.java
  
  Index: ListModelAppender.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.log4j.varia;
  
  import org.apache.log4j.AppenderSkeleton;
  import org.apache.log4j.spi.LoggingEvent;
  
  import javax.swing.DefaultListModel;
  import javax.swing.ListModel;
  
  
  /**
   * A very basic appender that takes the events and stores them in to a
   * ListModel for late retrieval.
   *
   * @author Paul Smith <[EMAIL PROTECTED]>
   *
   */
  public final class ListModelAppender extends AppenderSkeleton {
    private final DefaultListModel model = new DefaultListModel();
  
    /**
     * Returns a reference to the ListModel that contains all the LoggingEvents
     * that have been appended to this class.
     * 
     * @return
     */
    public final ListModel getModel() {
      return model;
    }
  
    /* (non-Javadoc)
     * @see org.apache.log4j.AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent)
     */
    protected void append(LoggingEvent event) {
      model.addElement(event);
    }
  
    /* (non-Javadoc)
     * @see org.apache.log4j.Appender#close()
     */
    public void close() {
      clearModel();
    }
  
    /* (non-Javadoc)
     * @see org.apache.log4j.Appender#requiresLayout()
     */
    public boolean requiresLayout() {
      return false;
    }
  
    /**
     * Removes all the Events from the model
     */
    public void clearModel() {
      model.clear();
    }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to