01: /* AbstractChartModel.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Thu Aug 03 11:50:19 2006, Created by henrichen
10: }}IS_NOTE
11:
12: Copyright (C) 2006 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.zul;
20:
21: import java.util.List;
22: import java.util.LinkedList;
23: import java.util.Iterator;
24:
25: import org.zkoss.io.Serializables;
26:
27: import org.zkoss.zk.ui.UiException;
28:
29: import org.zkoss.zul.event.ChartDataEvent;
30: import org.zkoss.zul.event.ChartDataListener;
31:
32: /**
33: * A skeletal implementation for {@link ChartModel}.
34: *
35: * @author henrichen
36: */
37: abstract public class AbstractChartModel implements ChartModel,
38: java.io.Serializable {
39: private transient List _listeners = new LinkedList();
40:
41: /** Fires a {@link ChartDataEvent} for all registered listener
42: * (thru {@link #addChartDataListener}.
43: *
44: * <p>Note: you can invoke this method only in an event listener.
45: */
46: protected void fireEvent(int type, Comparable series, Object data) {
47: final ChartDataEvent evt = new ChartDataEvent(this , type,
48: series, data);
49: for (Iterator it = _listeners.iterator(); it.hasNext();)
50: ((ChartDataListener) it.next()).onChange(evt);
51: }
52:
53: //-- ChartModel --//
54: public void addChartDataListener(ChartDataListener l) {
55: if (l == null)
56: throw new NullPointerException();
57: _listeners.add(l);
58: }
59:
60: public void removeChartDataListener(ChartDataListener l) {
61: _listeners.remove(l);
62: }
63:
64: //Serializable//
65: private synchronized void writeObject(java.io.ObjectOutputStream s)
66: throws java.io.IOException {
67: s.defaultWriteObject();
68:
69: Serializables.smartWrite(s, _listeners);
70: }
71:
72: private synchronized void readObject(java.io.ObjectInputStream s)
73: throws java.io.IOException, ClassNotFoundException {
74: s.defaultReadObject();
75:
76: _listeners = new LinkedList();
77: Serializables.smartRead(s, _listeners);
78: }
79: }
|