package net.sf.jasperreports.charts.base;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.sf.jasperreports.charts.JRChartAxis;
import net.sf.jasperreports.charts.JRMultiAxisPlot;
import net.sf.jasperreports.engine.JRChart;
import net.sf.jasperreports.engine.JRChartPlot;
import net.sf.jasperreports.engine.JRExpressionCollector;
import net.sf.jasperreports.engine.base.JRBaseChartPlot;
import net.sf.jasperreports.engine.base.JRBaseObjectFactory;

public class JRBaseMultiAxisPlot extends JRBaseChartPlot implements JRMultiAxisPlot {
  private static final long serialVersionUID = 10200L;
  
  protected List axes = new ArrayList();
  
  public JRBaseMultiAxisPlot(JRChartPlot multiAxisPlot, JRChart chart) {
    super(multiAxisPlot, chart);
  }
  
  public JRBaseMultiAxisPlot(JRMultiAxisPlot multiAxisPlot, JRBaseObjectFactory factory) {
    super((JRChartPlot)multiAxisPlot, factory);
    List origAxes = multiAxisPlot.getAxes();
    this.axes.clear();
    if (origAxes != null) {
      Iterator iter = origAxes.iterator();
      while (iter.hasNext()) {
        JRChartAxis axis = iter.next();
        this.axes.add(factory.getChartAxis(axis));
      } 
    } 
  }
  
  public List getAxes() {
    return this.axes;
  }
  
  public void collectExpressions(JRExpressionCollector collector) {
    Iterator iter = this.axes.iterator();
    while (iter.hasNext()) {
      JRChartAxis axis = iter.next();
      collector.collect(axis.getChart());
    } 
  }
  
  public Object clone(JRChart parentChart) {
    JRBaseMultiAxisPlot clone = (JRBaseMultiAxisPlot)super.clone(parentChart);
    if (this.axes != null) {
      clone.axes = new ArrayList(this.axes.size());
      for (int i = 0; i < this.axes.size(); i++)
        clone.axes.add(((JRChartAxis)this.axes.get(i)).clone(parentChart)); 
    } 
    return clone;
  }
}
