1 55 56 package org.jfree.data.general; 57 58 import java.beans.PropertyChangeListener ; 59 import java.beans.PropertyChangeSupport ; 60 import java.io.Serializable ; 61 62 import javax.swing.event.EventListenerList ; 63 64 import org.jfree.util.ObjectUtilities; 65 66 76 public abstract class Series implements Cloneable , Serializable { 77 78 79 private static final long serialVersionUID = -6906561437538683581L; 80 81 82 private Comparable key; 83 84 85 private String description; 86 87 88 private EventListenerList listeners; 89 90 91 private PropertyChangeSupport propertyChangeSupport; 92 93 94 private boolean notify; 95 96 101 protected Series(Comparable key) { 102 this(key, null); 103 } 104 105 111 protected Series(Comparable key, String description) { 112 if (key == null) { 113 throw new IllegalArgumentException ("Null 'key' argument."); 114 } 115 this.key = key; 116 this.description = description; 117 this.listeners = new EventListenerList (); 118 this.propertyChangeSupport = new PropertyChangeSupport (this); 119 this.notify = true; 120 } 121 122 129 public Comparable getKey() { 130 return this.key; 131 } 132 133 141 public void setKey(Comparable key) { 142 if (key == null) { 143 throw new IllegalArgumentException ("Null 'key' argument."); 144 } 145 Comparable old = this.key; 146 this.key = key; 147 this.propertyChangeSupport.firePropertyChange("Key", old, key); 148 } 149 150 157 public String getDescription() { 158 return this.description; 159 } 160 161 169 public void setDescription(String description) { 170 String old = this.description; 171 this.description = description; 172 this.propertyChangeSupport.firePropertyChange("Description", old, 173 description); 174 } 175 176 184 public boolean getNotify() { 185 return this.notify; 186 } 187 188 196 public void setNotify(boolean notify) { 197 if (this.notify != notify) { 198 this.notify = notify; 199 fireSeriesChanged(); 200 } 201 } 202 203 220 public Object clone() throws CloneNotSupportedException { 221 222 Series clone = (Series) super.clone(); 223 clone.listeners = new EventListenerList (); 224 clone.propertyChangeSupport = new PropertyChangeSupport (clone); 225 return clone; 226 227 } 228 229 236 public boolean equals(Object obj) { 237 if (obj == this) { 238 return true; 239 } 240 if (!(obj instanceof Series)) { 241 return false; 242 } 243 Series that = (Series) obj; 244 if (!getKey().equals(that.getKey())) { 245 return false; 246 } 247 if (!ObjectUtilities.equal(getDescription(), that.getDescription())) { 248 return false; 249 } 250 return true; 251 } 252 253 258 public int hashCode() { 259 int result; 260 result = this.key.hashCode(); 261 result = 29 * result + (this.description != null 262 ? this.description.hashCode() : 0); 263 return result; 264 } 265 266 275 public void addChangeListener(SeriesChangeListener listener) { 276 this.listeners.add(SeriesChangeListener.class, listener); 277 } 278 279 285 public void removeChangeListener(SeriesChangeListener listener) { 286 this.listeners.remove(SeriesChangeListener.class, listener); 287 } 288 289 293 public void fireSeriesChanged() { 294 if (this.notify) { 295 notifyListeners(new SeriesChangeEvent(this)); 296 } 297 } 298 299 305 protected void notifyListeners(SeriesChangeEvent event) { 306 307 Object [] listenerList = this.listeners.getListenerList(); 308 for (int i = listenerList.length - 2; i >= 0; i -= 2) { 309 if (listenerList[i] == SeriesChangeListener.class) { 310 ((SeriesChangeListener) listenerList[i + 1]).seriesChanged( 311 event); 312 } 313 } 314 315 } 316 317 322 public void addPropertyChangeListener(PropertyChangeListener listener) { 323 this.propertyChangeSupport.addPropertyChangeListener(listener); 324 } 325 326 331 public void removePropertyChangeListener(PropertyChangeListener listener) { 332 this.propertyChangeSupport.removePropertyChangeListener(listener); 333 } 334 335 342 protected void firePropertyChange(String property, Object oldValue, 343 Object newValue) { 344 this.propertyChangeSupport.firePropertyChange(property, oldValue, 345 newValue); 346 } 347 348 } 349 | Popular Tags |