01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jface.util;
11:
12: /**
13: * This class is used to maintain a list of listeners, and is used in the
14: * implementations of several classes within JFace which allow you to register
15: * listeners of various kinds. It is a fairly lightweight object, occupying
16: * minimal space when no listeners are registered.
17: * <p>
18: * Note that the <code>add</code> method checks for and eliminates duplicates
19: * based on identity (not equality). Likewise, the <code>remove</code> method
20: * compares based on identity.
21: * </p>
22: * <p>
23: * Use the <code>getListeners</code> method when notifying listeners. Note
24: * that no garbage is created if no listeners are registered. The recommended
25: * code sequence for notifying all registered listeners of say,
26: * <code>FooListener.eventHappened</code>, is:
27: *
28: * <pre>
29: * Object[] listeners = myListenerList.getListeners();
30: * for (int i = 0; i < listeners.length; ++i) {
31: * ((FooListener) listeners[i]).eventHappened(event);
32: * }
33: * </pre>
34: *
35: * </p>
36: *
37: * @deprecated Please use {@link org.eclipse.core.runtime.ListenerList} instead.
38: * Please note that the {@link #ListenerList(int)} and
39: * {@link org.eclipse.core.runtime.ListenerList#ListenerList(int)}
40: * constructors have different semantics. Please read the javadoc
41: * carefully. Also note that the equivalent of
42: * {@link #ListenerList()} is actually
43: * {@link org.eclipse.core.runtime.ListenerList#ListenerList(int)}
44: * with {@link org.eclipse.core.runtime.ListenerList#IDENTITY} as
45: * the argument.
46: */
47: public class ListenerList extends org.eclipse.core.runtime.ListenerList {
48:
49: /**
50: * Creates a listener list with an initial capacity of 1.
51: */
52: public ListenerList() {
53: super (IDENTITY);
54: }
55:
56: /**
57: * Creates a listener list with the given initial capacity.
58: *
59: * @param capacity
60: * the number of listeners which this list can initially accept
61: * without growing its internal representation; must be at least
62: * 1
63: */
64: public ListenerList(int capacity) {
65: // the runtime ListenerList does not support capacity
66: this();
67: }
68: }
|