KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > awt > AbstractGraphModel


1 package JSci.awt;
2
3 import javax.swing.event.EventListenerList JavaDoc;
4
5 /**
6 * The AbstractGraphModel class handles the dispatching of
7 * GraphDataEvents to interested listeners.
8 * @version 1.2
9 * @author Mark Hale
10 */

11 public abstract class AbstractGraphModel extends Object JavaDoc {
12         private final EventListenerList JavaDoc listenerList = new EventListenerList JavaDoc();
13         private final GraphDataEvent dataChangedEvent = new GraphDataEvent(this);
14
15         /**
16         * Notifies all listeners that the graph data may have changed.
17         */

18         protected final void fireGraphDataChanged() {
19                 fireGraphChanged(dataChangedEvent);
20         }
21         /**
22         * Notifies all listeners that a series may have changed.
23         */

24         protected final void fireGraphSeriesUpdated(int series) {
25                 final GraphDataEvent event = new GraphDataEvent(this, series);
26                 fireGraphChanged(event);
27         }
28         /**
29         * Notifies all listeners of a given graph data event.
30         */

31         protected final void fireGraphChanged(GraphDataEvent event) {
32                 final Object JavaDoc listeners[] = listenerList.getListenerList();
33                 for(int i=listeners.length-2; i>=0; i-=2) {
34                         if(listeners[i] == GraphDataListener.class)
35                                 ((GraphDataListener)listeners[i+1]).dataChanged(event);
36                 }
37         }
38         /**
39         * Adds a listener to the list that's notified each time a change to the graph data occurs.
40         */

41         public final void addGraphDataListener(GraphDataListener l) {
42                 listenerList.add(GraphDataListener.class, l);
43         }
44         /**
45         * Removes a listener from the list that's notified each time a change to the graph data occurs.
46         */

47         public final void removeGraphDataListener(GraphDataListener l) {
48                 listenerList.remove(GraphDataListener.class, l);
49         }
50 }
51
52
Popular Tags