package net.sf.jasperreports.engine.fill;

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

public class JRFillLine extends JRFillGraphicElement implements JRLine {
  protected JRFillLine(JRBaseFiller filler, JRLine line, JRFillObjectFactory factory) {
    super(filler, (JRGraphicElement)line, factory);
  }
  
  protected JRFillLine(JRFillLine line, JRFillCloneFactory factory) {
    super(line, factory);
  }
  
  public byte getDirection() {
    return ((JRLine)this.parent).getDirection();
  }
  
  public void setDirection(byte direction) {}
  
  protected JRTemplateLine getJRTemplateLine() {
    JRStyle style = getStyle();
    JRTemplateLine template = (JRTemplateLine)getTemplate(style);
    if (template == null) {
      template = new JRTemplateLine((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() {
    JRTemplatePrintLine printLine = new JRTemplatePrintLine(getJRTemplateLine());
    printLine.setX(getX());
    printLine.setY(getRelativeY());
    printLine.setWidth(getWidth());
    printLine.setHeight(getStretchHeight());
    transferProperties(printLine);
    return printLine;
  }
  
  public void collectExpressions(JRExpressionCollector collector) {
    collector.collect(this);
  }
  
  public void visit(JRVisitor visitor) {
    visitor.visitLine(this);
  }
  
  protected void resolveElement(JRPrintElement element, byte evaluation) {}
  
  public JRFillCloneable createClone(JRFillCloneFactory factory) {
    return new JRFillLine(this, factory);
  }
}
