package net.sf.jasperreports.charts.design;

import java.util.ArrayList;
import java.util.List;
import net.sf.jasperreports.charts.JRTimePeriodDataset;
import net.sf.jasperreports.charts.JRTimePeriodSeries;
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 JRDesignTimePeriodDataset extends JRDesignChartDataset implements JRTimePeriodDataset {
  public static final long serialVersionUID = 10200L;
  
  public static final String PROPERTY_TIME_PERIODS_SERIES = "timePeriodSeries";
  
  private List timePeriodSeriesList = new ArrayList();
  
  public JRDesignTimePeriodDataset(JRChartDataset dataset) {
    super(dataset);
  }
  
  public JRTimePeriodSeries[] getSeries() {
    JRTimePeriodSeries[] timePeriodSeriesArray = new JRTimePeriodSeries[this.timePeriodSeriesList.size()];
    this.timePeriodSeriesList.toArray((Object[])timePeriodSeriesArray);
    return timePeriodSeriesArray;
  }
  
  public List getSeriesList() {
    return this.timePeriodSeriesList;
  }
  
  public void addTimePeriodSeries(JRTimePeriodSeries timePeriodSeries) {
    this.timePeriodSeriesList.add(timePeriodSeries);
    getEventSupport().fireCollectionElementAddedEvent("timePeriodSeries", timePeriodSeries, this.timePeriodSeriesList.size() - 1);
  }
  
  public JRTimePeriodSeries removeTimePeriodSeries(JRTimePeriodSeries timePeriodSeries) {
    if (timePeriodSeries != null) {
      int idx = this.timePeriodSeriesList.indexOf(timePeriodSeries);
      if (idx >= 0) {
        this.timePeriodSeriesList.remove(idx);
        getEventSupport().fireCollectionElementRemovedEvent("timePeriodSeries", timePeriodSeries, idx);
      } 
    } 
    return timePeriodSeries;
  }
  
  public byte getDatasetType() {
    return 5;
  }
  
  public void collectExpressions(JRExpressionCollector collector) {
    collector.collect(this);
  }
  
  public void validate(JRVerifier verifier) {
    verifier.verify(this);
  }
  
  public Object clone() {
    JRDesignTimePeriodDataset clone = (JRDesignTimePeriodDataset)super.clone();
    if (this.timePeriodSeriesList != null) {
      clone.timePeriodSeriesList = new ArrayList(this.timePeriodSeriesList.size());
      for (int i = 0; i < this.timePeriodSeriesList.size(); i++)
        clone.timePeriodSeriesList.add(((JRTimePeriodSeries)this.timePeriodSeriesList.get(i)).clone()); 
    } 
    return clone;
  }
}
