package net.sf.jasperreports.engine.fill;

import net.sf.jasperreports.engine.JREllipse;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExpressionCollector;
import net.sf.jasperreports.engine.JRGraphicElement;
import net.sf.jasperreports.engine.JRPrintElement;
import net.sf.jasperreports.engine.JRStyle;
import net.sf.jasperreports.engine.JRVisitor;

public class JRFillEllipse extends JRFillGraphicElement implements JREllipse {
  protected JRFillEllipse(JRBaseFiller filler, JREllipse ellipse, JRFillObjectFactory factory) {
    super(filler, (JRGraphicElement)ellipse, factory);
  }
  
  protected JRFillEllipse(JRFillEllipse ellipse, JRFillCloneFactory factory) {
    super(ellipse, factory);
  }
  
  protected JRTemplateEllipse getJRTemplateEllipse() {
    JRStyle style = getStyle();
    JRTemplateEllipse template = (JRTemplateEllipse)getTemplate(style);
    if (template == null) {
      template = new JRTemplateEllipse((this.band == null) ? null : this.band.getOrigin(), this.filler.getJasperPrint().getDefaultStyleProvider(), this);
      transferProperties(template);
      registerTemplate(style, template);
    } 
    return template;
  }
  
  protected void evaluate(byte evaluation) throws JRException {
    reset();
    evaluatePrintWhenExpression(evaluation);
    evaluateProperties(evaluation);
    setValueRepeating(true);
  }
  
  protected JRPrintElement fill() {
    JRTemplatePrintEllipse printEllipse = new JRTemplatePrintEllipse(getJRTemplateEllipse());
    printEllipse.setX(getX());
    printEllipse.setY(getRelativeY());
    printEllipse.setWidth(getWidth());
    printEllipse.setHeight(getStretchHeight());
    transferProperties(printEllipse);
    return printEllipse;
  }
  
  public void collectExpressions(JRExpressionCollector collector) {
    collector.collect(this);
  }
  
  public void visit(JRVisitor visitor) {
    visitor.visitEllipse(this);
  }
  
  protected void resolveElement(JRPrintElement element, byte evaluation) {}
  
  public JRFillCloneable createClone(JRFillCloneFactory factory) {
    return new JRFillEllipse(this, factory);
  }
}
