FileDocCategorySizeDatePackage
ListenerList.javaAPI DocAndroid 1.5 API5816Wed May 06 22:41:54 BST 2009org.apache.harmony.awt

ListenerList

public class ListenerList extends Object implements Serializable
List of AWT listeners. It is for 3 purposes. 1. To support list modification from listeners 2. To ensure call for all listeners as atomic operation 3. To support system listeners that are needed for built-in AWT components

Fields Summary
private static final long
serialVersionUID
private transient ArrayList
systemList
private transient ArrayList
userList
Constructors Summary
public ListenerList()

    
      
        super();
    
Methods Summary
public voidaddSystemListener(T listener)
Adds system listener to this list.

param
listener - listener to be added.

        if (systemList == null) {
            systemList = new ArrayList<T>();
        }
        systemList.add(listener);
    
public voidaddUserListener(T listener)
Adds user (public) listener to this list.

param
listener - listener to be added.

        if (listener == null) {
            return;
        }
        // transactionally replace old list
        synchronized (this) {
            if (userList == null) {
                userList = new ArrayList<T>();
                userList.add(listener);
                return;
            }
            ArrayList<T> newList = new ArrayList<T>(userList);
            newList.add(listener);
            userList = newList;
        }
    
private static java.util.ArrayListgetOnlySerializable(java.util.ArrayList list)

        if (list == null) {
            return null;
        }

        ArrayList<Object> result = new ArrayList<Object>();
        for (Iterator<?> it = list.iterator(); it.hasNext();) {
            Object obj = it.next();
            if (obj instanceof Serializable) {
                result.add(obj);
            }
        }

        return (result.size() != 0) ? result : null;
    
public java.util.IteratorgetSystemIterator()
Gets iterator for system listeners.

return
iterator for system listeners.

        return systemList.iterator();
    
public java.util.ListgetSystemListeners()

        synchronized (this) {
            if (systemList == null || systemList.isEmpty()) {
                return Collections.emptyList();
            }
            return new ArrayList<T>(systemList);
        }
    
public java.util.IteratorgetUserIterator()
Gets iterator for user listeners.

return
iterator for user listeners.

        synchronized (this) {
            if (userList == null) {
                List<T> emptyList = Collections.emptyList();
                return emptyList.iterator();
            }
            return new ReadOnlyIterator<T>(userList.iterator());
        }
    
public AT[]getUserListeners(AT[] emptyArray)
Gets all user (public) listeners in one array.

param
emptyArray - empty array, it's for deriving particular listeners class.
return
array of all user listeners.

        synchronized (this) {
            return (userList != null ? userList.toArray(emptyArray) : emptyArray);

        }
    
public java.util.ListgetUserListeners()
Gets all user (public) listeners in one list.

return
list of all user listeners.

        synchronized (this) {
            if (userList == null || userList.isEmpty()) {
                return Collections.emptyList();
            }
            return new ArrayList<T>(userList);
        }
    
private voidreadObject(java.io.ObjectInputStream stream)


        stream.defaultReadObject();

        systemList = (ArrayList<T>)stream.readObject();
        userList = (ArrayList<T>)stream.readObject();
    
public voidremoveUserListener(java.lang.Object listener)
Removes user (public) listener to this list.

param
listener - listener to be removed.

        if (listener == null) {
            return;
        }
        // transactionally replace old list
        synchronized (this) {
            if (userList == null || !userList.contains(listener)) {
                return;
            }
            ArrayList<T> newList = new ArrayList<T>(userList);
            newList.remove(listener);
            userList = (newList.size() > 0 ? newList : null);
        }
    
private voidwriteObject(java.io.ObjectOutputStream stream)


        stream.defaultWriteObject();

        stream.writeObject(getOnlySerializable(systemList));
        stream.writeObject(getOnlySerializable(userList));