1 59 60 package org.jfree.data.general; 61 62 import java.io.IOException ; 63 import java.io.InvalidObjectException ; 64 import java.io.ObjectInputStream ; 65 import java.io.ObjectInputValidation ; 66 import java.io.ObjectOutputStream ; 67 import java.io.Serializable ; 68 import java.util.Arrays ; 69 import java.util.EventListener ; 70 import java.util.List ; 71 72 import javax.swing.event.EventListenerList ; 73 74 78 public abstract class AbstractDataset implements Dataset, 79 Cloneable , 80 Serializable , 81 ObjectInputValidation { 82 83 84 private static final long serialVersionUID = 1918768939869230744L; 85 86 87 private DatasetGroup group; 88 89 90 private transient EventListenerList listenerList; 91 92 96 protected AbstractDataset() { 97 this.group = new DatasetGroup(); 98 this.listenerList = new EventListenerList (); 99 } 100 101 106 public DatasetGroup getGroup() { 107 return this.group; 108 } 109 110 115 public void setGroup(DatasetGroup group) { 116 if (group == null) { 117 throw new IllegalArgumentException ("Null 'group' argument."); 118 } 119 this.group = group; 120 } 121 122 127 public void addChangeListener(DatasetChangeListener listener) { 128 this.listenerList.add(DatasetChangeListener.class, listener); 129 } 130 131 137 public void removeChangeListener(DatasetChangeListener listener) { 138 this.listenerList.remove(DatasetChangeListener.class, listener); 139 } 140 141 150 public boolean hasListener(EventListener listener) { 151 List list = Arrays.asList(this.listenerList.getListenerList()); 152 return list.contains(listener); 153 } 154 155 158 protected void fireDatasetChanged() { 159 notifyListeners(new DatasetChangeEvent(this, this)); 160 } 161 162 168 protected void notifyListeners(DatasetChangeEvent event) { 169 170 Object [] listeners = this.listenerList.getListenerList(); 171 for (int i = listeners.length - 2; i >= 0; i -= 2) { 172 if (listeners[i] == DatasetChangeListener.class) { 173 ((DatasetChangeListener) listeners[i + 1]).datasetChanged( 174 event 175 ); 176 } 177 } 178 179 } 180 181 191 public Object clone() throws CloneNotSupportedException { 192 AbstractDataset clone = (AbstractDataset) super.clone(); 193 clone.listenerList = new EventListenerList (); 194 return clone; 195 } 196 197 204 private void writeObject(ObjectOutputStream stream) throws IOException { 205 stream.defaultWriteObject(); 206 } 207 208 216 private void readObject(ObjectInputStream stream) 217 throws IOException , ClassNotFoundException { 218 stream.defaultReadObject(); 219 this.listenerList = new EventListenerList (); 220 stream.registerValidation(this, 10); } 223 224 241 public void validateObject() throws InvalidObjectException { 242 fireDatasetChanged(); 243 } 244 245 } 246 | Popular Tags |