2 * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
\r
4 * The program is provided "as is" without any warranty express or
\r
5 * implied, including the warranty of non-infringement and the implied
\r
6 * warranties of merchantibility and fitness for a particular purpose.
\r
7 * IBM will not be liable for any damages suffered by you as a result
\r
8 * of using the Program. In no event will IBM be liable for any
\r
9 * special, indirect or consequential damages or lost profits even if
\r
10 * IBM has been advised of the possibility of their occurrence. IBM
\r
11 * will not be liable for any third party claims against you.
\r
13 package com.ibm.richtext.textpanel;
\r
15 import java.util.Vector;
\r
18 * This class listens for text state change notifications
\r
19 * and broadcasts them to all of its listeners.
\r
21 final class PanelEventBroadcaster {
\r
23 static final String COPYRIGHT =
\r
24 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
\r
25 private static final int FIRST = TextPanelEvent.TEXT_PANEL_FIRST;
\r
27 private final Vector[] fListeners;
\r
28 private final TextPanelEvent[] fEvents;
\r
31 * Construct a new PanelEventBroadcaster.
\r
32 * @param panel the TextPanel for which events are broadcasted
\r
34 public PanelEventBroadcaster(MTextPanel panel) {
\r
36 int count = TextPanelEvent.TEXT_PANEL_LAST - FIRST + 1;
\r
38 fEvents = new TextPanelEvent[count];
\r
39 fListeners = new Vector[count];
\r
41 for (int i=0; i < fListeners.length; i++) {
\r
42 fEvents[i] = new TextPanelEvent(panel, i+FIRST);
\r
43 fListeners[i] = new Vector();
\r
48 * Add the given TextPanelListener to the TextPanelListeners to
\r
49 * which notifications are forwarded.
\r
50 * @param listener the listener to add
\r
52 public synchronized void addListener(TextPanelListener listener) {
\r
54 for (int i=FIRST; i <= TextPanelEvent.TEXT_PANEL_LAST; i++) {
\r
55 Vector listeners = fListeners[i-FIRST];
\r
56 if (listener.respondsToEventType(i)) {
\r
57 if (!listeners.contains(listener)) {
\r
58 listeners.addElement(listener);
\r
65 * Remove the given TextPanelListener from the TextPanelListeners to
\r
66 * which notifications are forwarded.
\r
67 * @param listener the listener to remove
\r
69 public synchronized void removeListener(TextPanelListener listener) {
\r
71 for (int i=FIRST; i <= TextPanelEvent.TEXT_PANEL_LAST; i++) {
\r
72 Vector listeners = fListeners[i-FIRST];
\r
73 if (listener.respondsToEventType(i)) {
\r
74 listeners.removeElement(listener);
\r
80 * Receive a notification and forward it to all listeners.
\r
81 * @changeCode one of the constants in the TextPanelListener class
\r
83 public synchronized void textStateChanged(int id) {
\r
85 int index = id-FIRST;
\r
86 TextPanelEvent event = fEvents[index];
\r
87 Vector listeners = fListeners[index];
\r
89 int size = listeners.size();
\r
91 for (int i=0; i < size; i++) {
\r
93 TextPanelListener listener =
\r
94 (TextPanelListener) listeners.elementAt(i);
\r
95 listener.textEventOccurred(event);
\r