package net.sf.jasperreports.engine.fill;

import net.sf.jasperreports.engine.JRCommonRectangle;
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.JRPrintRectangle;
import net.sf.jasperreports.engine.JRRectangle;
import net.sf.jasperreports.engine.JRStyle;
import net.sf.jasperreports.engine.JRVisitor;
import net.sf.jasperreports.engine.util.JRStyleResolver;

public class JRFillRectangle extends JRFillGraphicElement implements JRRectangle {
  protected JRFillRectangle(JRBaseFiller filler, JRRectangle rectangle, JRFillObjectFactory factory) {
    super(filler, (JRGraphicElement)rectangle, factory);
  }
  
  protected JRFillRectangle(JRFillRectangle rectangle, JRFillCloneFactory factory) {
    super(rectangle, factory);
  }
  
  public int getRadius() {
    return JRStyleResolver.getRadius((JRCommonRectangle)this);
  }
  
  public Integer getOwnRadius() {
    return ((JRRectangle)this.parent).getOwnRadius();
  }
  
  public void setRadius(int radius) {}
  
  public void setRadius(Integer radius) {}
  
  protected JRTemplateRectangle getJRTemplateRectangle() {
    JRStyle style = getStyle();
    JRTemplateRectangle template = (JRTemplateRectangle)getTemplate(style);
    if (template == null) {
      template = new JRTemplateRectangle((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() {
    JRPrintRectangle printRectangle = null;
    printRectangle = new JRTemplatePrintRectangle(getJRTemplateRectangle());
    printRectangle.setX(getX());
    printRectangle.setY(getRelativeY());
    printRectangle.setWidth(getWidth());
    printRectangle.setHeight(getStretchHeight());
    transferProperties((JRPrintElement)printRectangle);
    return (JRPrintElement)printRectangle;
  }
  
  public void collectExpressions(JRExpressionCollector collector) {
    collector.collect(this);
  }
  
  public void visit(JRVisitor visitor) {
    visitor.visitRectangle(this);
  }
  
  protected void resolveElement(JRPrintElement element, byte evaluation) {}
  
  public JRFillCloneable createClone(JRFillCloneFactory factory) {
    return new JRFillRectangle(this, factory);
  }
}
