1 49 50 package org.jfree.data; 51 52 import java.io.IOException ; 53 import java.io.InvalidObjectException ; 54 import java.io.ObjectInputStream ; 55 import java.io.ObjectInputValidation ; 56 import java.io.ObjectOutputStream ; 57 import java.io.Serializable ; 58 59 import javax.swing.event.EventListenerList ; 60 61 67 public abstract class AbstractDataset implements Dataset, 68 Cloneable , 69 Serializable , 70 ObjectInputValidation { 71 72 73 private DatasetGroup group; 74 75 76 private transient EventListenerList listenerList; 77 78 83 protected AbstractDataset() { 84 this.group = new DatasetGroup(); 85 this.listenerList = new EventListenerList (); 86 } 87 88 93 public DatasetGroup getGroup() { 94 return this.group; 95 } 96 97 102 public void setGroup(DatasetGroup group) { 103 this.group = group; 104 } 105 106 111 public void addChangeListener(DatasetChangeListener listener) { 112 listenerList.add(DatasetChangeListener.class, listener); 113 } 114 115 120 public void removeChangeListener(DatasetChangeListener listener) { 121 listenerList.remove(DatasetChangeListener.class, listener); 122 } 123 124 127 protected void fireDatasetChanged() { 128 notifyListeners(new DatasetChangeEvent(this, this )); 131 } 132 133 138 protected void notifyListeners(DatasetChangeEvent event) { 139 140 Object [] listeners = listenerList.getListenerList(); 141 for (int i = listeners.length - 2; i >= 0; i -= 2) { 142 if (listeners[i] == DatasetChangeListener.class) { 143 ((DatasetChangeListener) listeners[i + 1]).datasetChanged(event); 144 } 145 } 146 147 } 148 149 159 public Object clone() throws CloneNotSupportedException { 160 AbstractDataset clone = (AbstractDataset) super.clone(); 161 clone.listenerList = new EventListenerList (); 162 return clone; 163 } 164 165 172 private void writeObject(ObjectOutputStream stream) throws IOException { 173 stream.defaultWriteObject(); 174 } 175 176 184 private void readObject(ObjectInputStream stream) throws IOException , ClassNotFoundException { 185 stream.defaultReadObject(); 186 this.listenerList = new EventListenerList (); 187 stream.registerValidation(this, 10); } 190 191 205 public void validateObject() throws InvalidObjectException { 206 fireDatasetChanged(); 207 } 208 209 } 210 211 212 213 214 215 216 | Popular Tags |