|
jfreechart example source code file (Series.java)
The jfreechart Series.java source code
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2008, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* -----------
* Series.java
* -----------
* (C) Copyright 2001-2008, by Object Refinery Limited.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): -;
*
* Changes
* -------
* 15-Nov-2001 : Version 1 (DG);
* 29-Nov-2001 : Added cloning and property change support (DG);
* 30-Jan-2002 : Added a description attribute and changed the constructors to
* protected (DG);
* 07-Oct-2002 : Fixed errors reported by Checkstyle (DG);
* 13-Mar-2003 : Implemented Serializable (DG);
* 01-May-2003 : Added equals() method (DG);
* 26-Jun-2003 : Changed listener list to use EventListenerList - see bug
* 757027 (DG);
* 15-Oct-2003 : Added a flag to control whether or not change events are sent
* to registered listeners (DG);
* 19-May-2005 : Made abstract (DG);
* ------------- JFREECHART 1.0.x ---------------------------------------------
* 04-May-2006 : Updated API docs (DG);
* 26-Sep-2007 : Added isEmpty() and getItemCount() methods (DG);
*
*/
package org.jfree.data.general;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import javax.swing.event.EventListenerList;
import org.jfree.util.ObjectUtilities;
/**
* Base class representing a data series. Subclasses are left to implement the
* actual data structures.
* <P>
* The series has two properties ("Key" and "Description") for which you can
* register a <code>PropertyChangeListener.
* <P>
* You can also register a {@link SeriesChangeListener} to receive notification
* of changes to the series data.
*/
public abstract class Series implements Cloneable, Serializable {
/** For serialization. */
private static final long serialVersionUID = -6906561437538683581L;
/** The key for the series. */
private Comparable key;
/** A description of the series. */
private String description;
/** Storage for registered change listeners. */
private EventListenerList listeners;
/** Object to support property change notification. */
private PropertyChangeSupport propertyChangeSupport;
/** A flag that controls whether or not changes are notified. */
private boolean notify;
/**
* Creates a new series with the specified key.
*
* @param key the series key (<code>null not permitted).
*/
protected Series(Comparable key) {
this(key, null);
}
/**
* Creates a new series with the specified key and description.
*
* @param key the series key (<code>null NOT permitted).
* @param description the series description (<code>null permitted).
*/
protected Series(Comparable key, String description) {
if (key == null) {
throw new IllegalArgumentException("Null 'key' argument.");
}
this.key = key;
this.description = description;
this.listeners = new EventListenerList();
this.propertyChangeSupport = new PropertyChangeSupport(this);
this.notify = true;
}
/**
* Returns the key for the series.
*
* @return The series key (never <code>null).
*
* @see #setKey(Comparable)
*/
public Comparable getKey() {
return this.key;
}
/**
* Sets the key for the series and sends a <code>PropertyChangeEvent
* (with the property name "Key") to all registered listeners.
*
* @param key the key (<code>null not permitted).
*
* @see #getKey()
*/
public void setKey(Comparable key) {
if (key == null) {
throw new IllegalArgumentException("Null 'key' argument.");
}
Comparable old = this.key;
this.key = key;
this.propertyChangeSupport.firePropertyChange("Key", old, key);
}
/**
* Returns a description of the series.
*
* @return The series description (possibly <code>null).
*
* @see #setDescription(String)
*/
public String getDescription() {
return this.description;
}
/**
* Sets the description of the series and sends a
* <code>PropertyChangeEvent to all registered listeners.
*
* @param description the description (<code>null permitted).
*
* @see #getDescription()
*/
public void setDescription(String description) {
String old = this.description;
this.description = description;
this.propertyChangeSupport.firePropertyChange("Description", old,
description);
}
/**
* Returns the flag that controls whether or not change events are sent to
* registered listeners.
*
* @return A boolean.
*
* @see #setNotify(boolean)
*/
public boolean getNotify() {
return this.notify;
}
/**
* Sets the flag that controls whether or not change events are sent to
* registered listeners.
*
* @param notify the new value of the flag.
*
* @see #getNotify()
*/
public void setNotify(boolean notify) {
if (this.notify != notify) {
this.notify = notify;
fireSeriesChanged();
}
}
/**
* Returns <code>true if the series contains no data items, and
* <code>false otherwise.
*
* @return A boolean.
*
* @since 1.0.7
*/
public boolean isEmpty() {
return (getItemCount() == 0);
}
/**
* Returns the number of data items in the series.
*
* @return The number of data items in the series.
*/
public abstract int getItemCount();
/**
* Returns a clone of the series.
* <P>
* Notes:
* <ul>
* <li>No need to clone the name or description, since String object is
* immutable.</li>
* <li>We set the listener list to empty, since the listeners did not
* register with the clone.</li>
* <li>Same applies to the PropertyChangeSupport instance.
* </ul>
*
* @return A clone of the series.
*
* @throws CloneNotSupportedException not thrown by this class, but
* subclasses may differ.
*/
public Object clone() throws CloneNotSupportedException {
Series clone = (Series) super.clone();
clone.listeners = new EventListenerList();
clone.propertyChangeSupport = new PropertyChangeSupport(clone);
return clone;
}
/**
* Tests the series for equality with another object.
*
* @param obj the object (<code>null permitted).
*
* @return <code>true or
Other jfreechart examples (source code examples)Here is a short list of links related to this jfreechart Series.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.