|
jfreechart example source code file (XYSeriesCollection.java)
The jfreechart XYSeriesCollection.java source code
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2009, 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.]
*
* -----------------------
* XYSeriesCollection.java
* -----------------------
* (C) Copyright 2001-2009, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): Aaron Metzger;
*
* Changes
* -------
* 15-Nov-2001 : Version 1 (DG);
* 03-Apr-2002 : Added change listener code (DG);
* 29-Apr-2002 : Added removeSeries, removeAllSeries methods (ARM);
* 07-Oct-2002 : Fixed errors reported by Checkstyle (DG);
* 26-Mar-2003 : Implemented Serializable (DG);
* 04-Aug-2003 : Added getSeries() method (DG);
* 31-Mar-2004 : Modified to use an XYIntervalDelegate.
* 05-May-2004 : Now extends AbstractIntervalXYDataset (DG);
* 18-Aug-2004 : Moved from org.jfree.data --> org.jfree.data.xy (DG);
* 17-Nov-2004 : Updated for changes to DomainInfo interface (DG);
* 11-Jan-2005 : Removed deprecated code in preparation for 1.0.0 release (DG);
* 28-Mar-2005 : Fixed bug in getSeries(int) method (1170825) (DG);
* 05-Oct-2005 : Made the interval delegate a dataset listener (DG);
* ------------- JFREECHART 1.0.x ---------------------------------------------
* 27-Nov-2006 : Added clone() override (DG);
* 08-May-2007 : Added indexOf(XYSeries) method (DG);
* 03-Dec-2007 : Added getSeries(Comparable) method (DG);
* 22-Apr-2008 : Implemented PublicCloneable (DG);
* 27-Feb-2009 : Overridden getDomainOrder() to detect when all series are
* sorted in ascending order (DG);
* 06-Mar-2009 : Implemented RangeInfo (DG);
* 06-Mar-2009 : Fixed equals() implementation (DG);
*
*/
package org.jfree.data.xy;
import java.io.Serializable;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.jfree.chart.HashUtilities;
import org.jfree.data.DomainInfo;
import org.jfree.data.DomainOrder;
import org.jfree.data.Range;
import org.jfree.data.RangeInfo;
import org.jfree.data.UnknownKeyException;
import org.jfree.data.general.DatasetChangeEvent;
import org.jfree.util.ObjectUtilities;
import org.jfree.util.PublicCloneable;
/**
* Represents a collection of {@link XYSeries} objects that can be used as a
* dataset.
*/
public class XYSeriesCollection extends AbstractIntervalXYDataset
implements IntervalXYDataset, DomainInfo, RangeInfo, PublicCloneable,
Serializable {
/** For serialization. */
private static final long serialVersionUID = -7590013825931496766L;
/** The series that are included in the collection. */
private List data;
/** The interval delegate (used to calculate the start and end x-values). */
private IntervalXYDelegate intervalDelegate;
/**
* Constructs an empty dataset.
*/
public XYSeriesCollection() {
this(null);
}
/**
* Constructs a dataset and populates it with a single series.
*
* @param series the series (<code>null ignored).
*/
public XYSeriesCollection(XYSeries series) {
this.data = new java.util.ArrayList();
this.intervalDelegate = new IntervalXYDelegate(this, false);
addChangeListener(this.intervalDelegate);
if (series != null) {
this.data.add(series);
series.addChangeListener(this);
}
}
/**
* Returns the order of the domain (X) values, if this is known.
*
* @return The domain order.
*/
public DomainOrder getDomainOrder() {
int seriesCount = getSeriesCount();
for (int i = 0; i < seriesCount; i++) {
XYSeries s = getSeries(i);
if (!s.getAutoSort()) {
return DomainOrder.NONE; // we can't be sure of the order
}
}
return DomainOrder.ASCENDING;
}
/**
* Adds a series to the collection and sends a {@link DatasetChangeEvent}
* to all registered listeners.
*
* @param series the series (<code>null not permitted).
*/
public void addSeries(XYSeries series) {
if (series == null) {
throw new IllegalArgumentException("Null 'series' argument.");
}
this.data.add(series);
series.addChangeListener(this);
fireDatasetChanged();
}
/**
* Removes a series from the collection and sends a
* {@link DatasetChangeEvent} to all registered listeners.
*
* @param series the series index (zero-based).
*/
public void removeSeries(int series) {
if ((series < 0) || (series >= getSeriesCount())) {
throw new IllegalArgumentException("Series index out of bounds.");
}
// fetch the series, remove the change listener, then remove the series.
XYSeries ts = (XYSeries) this.data.get(series);
ts.removeChangeListener(this);
this.data.remove(series);
fireDatasetChanged();
}
/**
* Removes a series from the collection and sends a
* {@link DatasetChangeEvent} to all registered listeners.
*
* @param series the series (<code>null not permitted).
*/
public void removeSeries(XYSeries series) {
if (series == null) {
throw new IllegalArgumentException("Null 'series' argument.");
}
if (this.data.contains(series)) {
series.removeChangeListener(this);
this.data.remove(series);
fireDatasetChanged();
}
}
/**
* Removes all the series from the collection and sends a
* {@link DatasetChangeEvent} to all registered listeners.
*/
public void removeAllSeries() {
// Unregister the collection as a change listener to each series in
// the collection.
for (int i = 0; i < this.data.size(); i++) {
XYSeries series = (XYSeries) this.data.get(i);
series.removeChangeListener(this);
}
// Remove all the series from the collection and notify listeners.
this.data.clear();
fireDatasetChanged();
}
/**
* Returns the number of series in the collection.
*
* @return The series count.
*/
public int getSeriesCount() {
return this.data.size();
}
/**
* Returns a list of all the series in the collection.
*
* @return The list (which is unmodifiable).
*/
public List getSeries() {
return Collections.unmodifiableList(this.data);
}
/**
* Returns the index of the specified series, or -1 if that series is not
* present in the dataset.
*
* @param series the series (<code>null not permitted).
*
* @return The series index.
*
* @since 1.0.6
*/
public int indexOf(XYSeries series) {
if (series == null) {
throw new IllegalArgumentException("Null 'series' argument.");
}
return this.data.indexOf(series);
}
/**
* Returns a series from the collection.
*
* @param series the series index (zero-based).
*
* @return The series.
*
* @throws IllegalArgumentException if <code>series is not in the
* range <code>0 to
Other jfreechart examples (source code examples)Here is a short list of links related to this jfreechart XYSeriesCollection.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.