Codebase list libonemind-commons-java-java / 5c42640 src / java / org / onemind / commons / java / event / EventListenerList.java
5c42640

Tree @5c42640 (Download .tar.gz)

EventListenerList.java @5c42640raw · history · blame

/*
 * Copyright (C) 2004 TiongHiang Lee
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not,  write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Email: thlee@onemindsoft.org
 */

package org.onemind.commons.java.event;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EventObject;
import java.util.Iterator;
import java.util.List;
/**
 * A listener list contains listeners and fire events
 * @author TiongHiang Lee (thlee@onemindsoft.org)
 * @version $Id: EventListenerList.java,v 1.2 2004/08/26 12:33:16 thlee Exp $ $Name:  $
 */
public class EventListenerList
{

    /** the listeners * */
    private List _eventListeners = new ArrayList();

    /**
     * {@inheritDoc}
     */
    public EventListenerList()
    {
    }

    /**
     * Get the listeners
     * @return the listeners
     */
    public Collection getListeners()
    {
        return Collections.unmodifiableCollection(_eventListeners);
    }

    /**
     * Fire an event to all listeneres
     * @param firer the firer
     * @param obj the event object
     */
    public void fireEvent(EventFirer firer, EventObject obj)
    {
        Iterator it = _eventListeners.iterator();
        while (it.hasNext())
        {
            EventListener listener = (EventListener) it.next();
            firer.fireEvent(listener, obj);
        }
    }

    /**
     * Add a listener
     * @param listener the listener
     */
    public void addListener(EventListener listener)
    {
        _eventListeners.add(listener);
    }

    /**
     * Remove a listener
     * @param listener the listener
     */
    public void removeListener(EventListener listener)
    {
        _eventListeners.remove(listener);
    }
}