package net.sf.jasperreports.engine.fill;

import java.awt.Color;
import net.sf.jasperreports.engine.JRCommonGraphicElement;
import net.sf.jasperreports.engine.JRElement;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRGraphicElement;
import net.sf.jasperreports.engine.JRPen;
import net.sf.jasperreports.engine.util.JRPenUtil;
import net.sf.jasperreports.engine.util.JRStyleResolver;

public abstract class JRFillGraphicElement extends JRFillElement implements JRGraphicElement {
  protected JRFillGraphicElement(JRBaseFiller filler, JRGraphicElement graphicElement, JRFillObjectFactory factory) {
    super(filler, (JRElement)graphicElement, factory);
  }
  
  protected JRFillGraphicElement(JRFillGraphicElement graphicElement, JRFillCloneFactory factory) {
    super(graphicElement, factory);
  }
  
  public JRPen getLinePen() {
    return ((JRGraphicElement)this.parent).getLinePen();
  }
  
  public byte getPen() {
    return JRPenUtil.getPenFromLinePen(getLinePen());
  }
  
  public Byte getOwnPen() {
    return JRPenUtil.getOwnPenFromLinePen(getLinePen());
  }
  
  public void setPen(byte pen) {}
  
  public void setPen(Byte pen) {}
  
  public byte getFill() {
    return JRStyleResolver.getFill((JRCommonGraphicElement)this);
  }
  
  public Byte getOwnFill() {
    return ((JRGraphicElement)this.parent).getOwnFill();
  }
  
  public void setFill(byte fill) {}
  
  public void setFill(Byte fill) {}
  
  public Float getDefaultLineWidth() {
    return ((JRGraphicElement)this.parent).getDefaultLineWidth();
  }
  
  public Color getDefaultLineColor() {
    return getForecolor();
  }
  
  public void rewind() {}
  
  protected boolean prepare(int availableStretchHeight, boolean isOverflow) throws JRException {
    boolean willOverflow = false;
    super.prepare(availableStretchHeight, isOverflow);
    if (!isToPrint())
      return willOverflow; 
    boolean isToPrint = true;
    boolean isReprinted = false;
    if (isOverflow && isAlreadyPrinted() && !isPrintWhenDetailOverflows())
      isToPrint = false; 
    if (isToPrint && isPrintWhenExpressionNull() && !isPrintRepeatedValues())
      if ((!isPrintInFirstWholeBand() || !getBand().isFirstWholeOnPageColumn()) && (getPrintWhenGroupChanges() == null || !getBand().isNewGroup(getPrintWhenGroupChanges())) && (!isOverflow || !isPrintWhenDetailOverflows()))
        isToPrint = false;  
    if (isToPrint && availableStretchHeight < getRelativeY() - getY() - getBandBottomY()) {
      isToPrint = false;
      willOverflow = true;
    } 
    if (isToPrint && isOverflow && isPrintWhenDetailOverflows() && (isAlreadyPrinted() || (!isAlreadyPrinted() && !isPrintRepeatedValues())))
      isReprinted = true; 
    setToPrint(isToPrint);
    setReprinted(isReprinted);
    return willOverflow;
  }
}
