1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.event;
21
22 import java.util.List;
23 import java.util.Vector;
24
25 /***
26 * This is a utility class that can be used by data containers to notify
27 * <code>StateEvent</code> listeners.
28 */
29 public class StateSupport {
30
31
32
33 private Object source;
34 private List listeners = new Vector();
35
36
37
38 /***
39 * Constructs a StateSupport object.
40 *
41 * @param source the object to be given as the source for any events
42 */
43 public StateSupport(Object source)
44 {
45 this.source = source;
46 }
47
48
49
50 public void addStateListener(StateListener listener)
51 {
52 listeners.add(listener);
53 }
54
55 public void removeStateListener(StateListener listener)
56 {
57 listeners.remove(listener);
58 }
59
60 public void fireStateChanged()
61 {
62 Object[] l = listeners.toArray();
63
64 if (l != null) {
65 StateEvent event = new StateEvent(source);
66
67 for (int i = l.length - 1; i >= 0; i--) {
68 ((StateListener)l[i]).stateChanged(event);
69 }
70 }
71 }
72
73 }