1 45 46 package org.jfree.data; 47 48 import java.beans.PropertyChangeListener ; 49 import java.beans.PropertyChangeSupport ; 50 import java.io.Serializable ; 51 52 import javax.swing.event.EventListenerList ; 53 54 import org.jfree.util.ObjectUtils; 55 56 68 public class Series implements Cloneable , Serializable { 69 70 71 private String name; 72 73 74 private String description; 75 76 77 private EventListenerList listeners; 78 79 80 private PropertyChangeSupport propertyChangeSupport; 81 82 83 private boolean notify; 84 85 90 protected Series(String name) { 91 this(name, null); 92 } 93 94 100 protected Series(String name, String description) { 101 102 this.name = name; 103 this.description = description; 104 this.listeners = new EventListenerList (); 105 this.propertyChangeSupport = new PropertyChangeSupport (this); 106 this.notify = true; 107 108 } 109 110 115 public String getName() { 116 return this.name; 117 } 118 119 124 public void setName(String name) { 125 126 String old = this.name; 127 this.name = name; 128 propertyChangeSupport.firePropertyChange("Name", old, name); 129 130 } 131 132 137 public String getDescription() { 138 return this.description; 139 } 140 141 146 public void setDescription(String description) { 147 148 String old = this.description; 149 this.description = description; 150 this.propertyChangeSupport.firePropertyChange("Description", old, description); 151 152 } 153 154 160 public boolean getNotify() { 161 return this.notify; 162 } 163 164 170 public void setNotify(boolean notify) { 171 if (this.notify != notify) { 172 this.notify = notify; 173 fireSeriesChanged(); 174 } 175 } 176 177 187 public Object clone() { 188 189 Object obj = null; 190 191 try { 192 obj = super.clone(); 193 } 194 catch (CloneNotSupportedException e) { System.err.println("Series.clone(): unexpected exception."); 196 } 197 198 Series clone = (Series) obj; 199 clone.listeners = new EventListenerList (); 200 clone.propertyChangeSupport = new PropertyChangeSupport (clone); 201 202 return clone; 203 204 } 205 206 213 public boolean equals(Object object) { 214 215 if (object == null) { 216 return false; 217 } 218 219 if (object == this) { 220 return true; 221 } 222 223 boolean result = false; 224 225 if (object instanceof Series) { 226 Series s = (Series) object; 227 boolean b1 = getName().equals(s.getName()); 228 boolean b2 = ObjectUtils.equal(getDescription(), s.getDescription()); 229 result = b1 && b2; 230 } 231 232 return result; 233 234 } 235 236 243 public void addChangeListener(SeriesChangeListener listener) { 244 this.listeners.add(SeriesChangeListener.class, listener); 245 } 246 247 253 public void removeChangeListener(SeriesChangeListener listener) { 254 this.listeners.remove(SeriesChangeListener.class, listener); 255 } 256 257 261 public void fireSeriesChanged() { 262 if (this.notify) { 263 notifyListeners(new SeriesChangeEvent(this)); 264 } 265 } 266 267 272 protected void notifyListeners(SeriesChangeEvent event) { 273 274 Object [] listenerList = this.listeners.getListenerList(); 275 for (int i = listenerList.length - 2; i >= 0; i -= 2) { 276 if (listenerList[i] == SeriesChangeListener.class) { 277 ((SeriesChangeListener) listenerList[i + 1]).seriesChanged(event); 278 } 279 } 280 281 } 282 283 288 public void addPropertyChangeListener(PropertyChangeListener listener) { 289 this.propertyChangeSupport.addPropertyChangeListener(listener); 290 } 291 292 297 public void removePropertyChangeListener(PropertyChangeListener listener) { 298 this.propertyChangeSupport.removePropertyChangeListener(listener); 299 } 300 301 308 protected void firePropertyChange(String property, Object oldValue, Object newValue) { 309 this.propertyChangeSupport.firePropertyChange(property, oldValue, newValue); 310 } 311 312 } 313 | Popular Tags |