01: package JSci.awt;
02:
03: import javax.swing.event.EventListenerList;
04:
05: /**
06: * The AbstractGraphModel class handles the dispatching of
07: * GraphDataEvents to interested listeners.
08: * @version 1.2
09: * @author Mark Hale
10: */
11: public abstract class AbstractGraphModel extends Object {
12: private final EventListenerList listenerList = new EventListenerList();
13: private final GraphDataEvent dataChangedEvent = new GraphDataEvent(
14: this );
15:
16: /**
17: * Notifies all listeners that the graph data may have changed.
18: */
19: protected final void fireGraphDataChanged() {
20: fireGraphChanged(dataChangedEvent);
21: }
22:
23: /**
24: * Notifies all listeners that a series may have changed.
25: */
26: protected final void fireGraphSeriesUpdated(int series) {
27: final GraphDataEvent event = new GraphDataEvent(this , series);
28: fireGraphChanged(event);
29: }
30:
31: /**
32: * Notifies all listeners of a given graph data event.
33: */
34: protected final void fireGraphChanged(GraphDataEvent event) {
35: final Object listeners[] = listenerList.getListenerList();
36: for (int i = listeners.length - 2; i >= 0; i -= 2) {
37: if (listeners[i] == GraphDataListener.class)
38: ((GraphDataListener) listeners[i + 1])
39: .dataChanged(event);
40: }
41: }
42:
43: /**
44: * Adds a listener to the list that's notified each time a change to the graph data occurs.
45: */
46: public final void addGraphDataListener(GraphDataListener l) {
47: listenerList.add(GraphDataListener.class, l);
48: }
49:
50: /**
51: * Removes a listener from the list that's notified each time a change to the graph data occurs.
52: */
53: public final void removeGraphDataListener(GraphDataListener l) {
54: listenerList.remove(GraphDataListener.class, l);
55: }
56: }
|