1
2
3
4
5
6
7
8
9
10
11 package edu.uci.ics.jung.visualization.util;
12
13 import javax.swing.event.ChangeEvent;
14 import javax.swing.event.ChangeListener;
15 import javax.swing.event.EventListenerList;
16
17
18
19
20
21
22
23
24 public class DefaultChangeEventSupport implements ChangeEventSupport {
25
26 Object eventSource;
27
28
29
30 protected EventListenerList listenerList = new EventListenerList();
31
32
33
34
35
36
37
38 protected transient ChangeEvent changeEvent;
39
40 public DefaultChangeEventSupport(Object eventSource) {
41 this.eventSource = eventSource;
42 }
43
44 public void addChangeListener(ChangeListener l) {
45 listenerList.add(ChangeListener.class, l);
46 }
47
48 public void removeChangeListener(ChangeListener l) {
49 listenerList.remove(ChangeListener.class, l);
50 }
51
52 public ChangeListener[] getChangeListeners() {
53 return listenerList.getListeners(ChangeListener.class);
54 }
55
56
57
58
59
60
61
62
63
64 public void fireStateChanged() {
65
66 Object[] listeners = listenerList.getListenerList();
67
68
69 for (int i = listeners.length-2; i>=0; i-=2) {
70 if (listeners[i]==ChangeListener.class) {
71
72 if (changeEvent == null)
73 changeEvent = new ChangeEvent(eventSource);
74 ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
75 }
76 }
77 }
78
79 }