KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > util > ListenerList


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jface.util;
12
13 /**
14  * This class is used to maintain a list of listeners, and is used in the
15  * implementations of several classes within JFace which allow you to register
16  * listeners of various kinds. It is a fairly lightweight object, occupying
17  * minimal space when no listeners are registered.
18  * <p>
19  * Note that the <code>add</code> method checks for and eliminates duplicates
20  * based on identity (not equality). Likewise, the <code>remove</code> method
21  * compares based on identity.
22  * </p>
23  * <p>
24  * Use the <code>getListeners</code> method when notifying listeners. Note
25  * that no garbage is created if no listeners are registered. The recommended
26  * code sequence for notifying all registered listeners of say,
27  * <code>FooListener.eventHappened</code>, is:
28  *
29  * <pre>
30  * Object[] listeners = myListenerList.getListeners();
31  * for (int i = 0; i &lt; listeners.length; ++i) {
32  * ((FooListener) listeners[i]).eventHappened(event);
33  * }
34  * </pre>
35  *
36  * </p>
37  *
38  * @deprecated Please use {@link org.eclipse.core.runtime.ListenerList} instead.
39  * Please note that the {@link #ListenerList(int)} and
40  * {@link org.eclipse.core.runtime.ListenerList#ListenerList(int)}
41  * constructors have different semantics. Please read the javadoc
42  * carefully. Also note that the equivalent of
43  * {@link #ListenerList()} is actually
44  * {@link org.eclipse.core.runtime.ListenerList#ListenerList(int)}
45  * with {@link org.eclipse.core.runtime.ListenerList#IDENTITY} as
46  * the argument.
47  */

48 public class ListenerList extends org.eclipse.core.runtime.ListenerList {
49
50     /**
51      * Creates a listener list with an initial capacity of 1.
52      */

53     public ListenerList() {
54         super(IDENTITY);
55     }
56
57     /**
58      * Creates a listener list with the given initial capacity.
59      *
60      * @param capacity
61      * the number of listeners which this list can initially accept
62      * without growing its internal representation; must be at least
63      * 1
64      */

65     public ListenerList(int capacity) {
66         // the runtime ListenerList does not support capacity
67
this();
68     }
69 }
70
Popular Tags