1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.log4j.varia; 19 20 import org.apache.log4j.AppenderSkeleton; 21 import org.apache.log4j.spi.LoggingEvent; 22 23 import javax.swing.DefaultListModel; 24 import javax.swing.ListModel; 25 26 27 /** 28 * A very basic appender that takes the events and stores them in to a 29 * ListModel for late retrieval. 30 * 31 * 32 * @author Paul Smith (psmith@apache.org) 33 * 34 */ 35 public final class ListModelAppender extends AppenderSkeleton { 36 /** 37 * Default list model. 38 */ 39 private final DefaultListModel model = new DefaultListModel(); 40 41 /** 42 * Constructs a ListModelAppender. 43 */ 44 public ListModelAppender() { 45 super(true); 46 } 47 /** 48 * Returns a reference to the ListModel that contains all the LoggingEvents 49 * that have been appended to this class. 50 * 51 * @return the list model 52 */ 53 public ListModel getModel() { 54 return model; 55 } 56 57 /** {@inheritDoc} */ 58 protected void append(final LoggingEvent event) { 59 model.addElement(event); 60 } 61 62 /** {@inheritDoc} */ 63 public void close() { 64 clearModel(); 65 } 66 67 /** 68 * Removes all the Events from the model. 69 */ 70 public void clearModel() { 71 model.clear(); 72 } 73 74 /** {@inheritDoc} */ 75 public boolean requiresLayout() { 76 return false; 77 } 78 79 }