package net.sf.jasperreports.charts.design;

import java.util.ArrayList;
import java.util.List;
import net.sf.jasperreports.charts.JRCategoryDataset;
import net.sf.jasperreports.charts.JRCategorySeries;
import net.sf.jasperreports.engine.JRChartDataset;
import net.sf.jasperreports.engine.JRExpressionCollector;
import net.sf.jasperreports.engine.design.JRDesignChartDataset;
import net.sf.jasperreports.engine.design.JRVerifier;

public class JRDesignCategoryDataset extends JRDesignChartDataset implements JRCategoryDataset {
  private static final long serialVersionUID = 10200L;
  
  public static final String PROPERTY_CATEGORY_SERIES = "categorySeries";
  
  private List categorySeriesList = new ArrayList();
  
  public JRDesignCategoryDataset(JRChartDataset dataset) {
    super(dataset);
  }
  
  public JRCategorySeries[] getSeries() {
    JRCategorySeries[] categorySeriesArray = new JRCategorySeries[this.categorySeriesList.size()];
    this.categorySeriesList.toArray((Object[])categorySeriesArray);
    return categorySeriesArray;
  }
  
  public List getSeriesList() {
    return this.categorySeriesList;
  }
  
  public void addCategorySeries(JRCategorySeries categorySeries) {
    this.categorySeriesList.add(categorySeries);
    getEventSupport().fireCollectionElementAddedEvent("categorySeries", categorySeries, this.categorySeriesList.size() - 1);
  }
  
  public JRCategorySeries removeCategorySeries(JRCategorySeries categorySeries) {
    if (categorySeries != null) {
      int idx = this.categorySeriesList.indexOf(categorySeries);
      if (idx >= 0) {
        this.categorySeriesList.remove(idx);
        getEventSupport().fireCollectionElementRemovedEvent("categorySeries", categorySeries, idx);
      } 
    } 
    return categorySeries;
  }
  
  public byte getDatasetType() {
    return 2;
  }
  
  public void collectExpressions(JRExpressionCollector collector) {
    collector.collect(this);
  }
  
  public void validate(JRVerifier verifier) {
    verifier.verify(this);
  }
  
  public Object clone() {
    JRDesignCategoryDataset clone = (JRDesignCategoryDataset)super.clone();
    if (this.categorySeriesList != null) {
      clone.categorySeriesList = new ArrayList(this.categorySeriesList.size());
      for (int i = 0; i < this.categorySeriesList.size(); i++)
        clone.categorySeriesList.add(((JRCategorySeries)this.categorySeriesList.get(i)).clone()); 
    } 
    return clone;
  }
}
