package net.sf.jasperreports.engine.base;

import java.awt.Color;
import java.io.Serializable;
import net.sf.jasperreports.engine.JRPen;
import net.sf.jasperreports.engine.JRPenContainer;
import net.sf.jasperreports.engine.JRRuntimeException;
import net.sf.jasperreports.engine.JRStyleContainer;
import net.sf.jasperreports.engine.design.events.JRChangeEventsSupport;
import net.sf.jasperreports.engine.design.events.JRPropertyChangeSupport;
import net.sf.jasperreports.engine.util.JRStyleResolver;

public class JRBasePen implements JRPen, Serializable, Cloneable, JRChangeEventsSupport {
  private static final long serialVersionUID = 10200L;
  
  public static final String PROPERTY_LINE_WIDTH = "lineWidth";
  
  public static final String PROPERTY_LINE_STYLE = "lineStyle";
  
  public static final String PROPERTY_LINE_COLOR = "lineColor";
  
  protected JRPenContainer penContainer = null;
  
  protected Float lineWidth = null;
  
  protected Byte lineStyle = null;
  
  protected Color lineColor = null;
  
  private transient JRPropertyChangeSupport eventSupport;
  
  public JRBasePen(JRPenContainer penContainer) {
    this.penContainer = penContainer;
  }
  
  public JRStyleContainer getStyleContainer() {
    return (JRStyleContainer)this.penContainer;
  }
  
  public Float getLineWidth() {
    return JRStyleResolver.getLineWidth(this, this.penContainer.getDefaultLineWidth());
  }
  
  public Float getOwnLineWidth() {
    return this.lineWidth;
  }
  
  public void setLineWidth(float lineWidth) {
    setLineWidth(new Float(lineWidth));
  }
  
  public void setLineWidth(Float lineWidth) {
    Object old = this.lineWidth;
    this.lineWidth = lineWidth;
    getEventSupport().firePropertyChange("lineWidth", old, this.lineWidth);
  }
  
  public Byte getLineStyle() {
    return JRStyleResolver.getLineStyle(this);
  }
  
  public Byte getOwnLineStyle() {
    return this.lineStyle;
  }
  
  public void setLineStyle(byte lineStyle) {
    setLineStyle(new Byte(lineStyle));
  }
  
  public void setLineStyle(Byte lineStyle) {
    Object old = this.lineStyle;
    this.lineStyle = lineStyle;
    getEventSupport().firePropertyChange("lineStyle", old, this.lineStyle);
  }
  
  public Color getLineColor() {
    return JRStyleResolver.getLineColor(this, this.penContainer.getDefaultLineColor());
  }
  
  public Color getOwnLineColor() {
    return this.lineColor;
  }
  
  public void setLineColor(Color lineColor) {
    Object old = this.lineColor;
    this.lineColor = lineColor;
    getEventSupport().firePropertyChange("lineColor", old, this.lineColor);
  }
  
  public String getStyleNameReference() {
    return null;
  }
  
  public JRPen clone(JRPenContainer penContainer) {
    JRBasePen clone = null;
    try {
      clone = (JRBasePen)clone();
    } catch (CloneNotSupportedException e) {
      throw new JRRuntimeException(e);
    } 
    clone.penContainer = penContainer;
    return clone;
  }
  
  public JRPropertyChangeSupport getEventSupport() {
    synchronized (this) {
      if (this.eventSupport == null)
        this.eventSupport = new JRPropertyChangeSupport(this); 
    } 
    return this.eventSupport;
  }
}
