package net.sf.jasperreports.engine.design;

import net.sf.jasperreports.engine.JRCommonRectangle;
import net.sf.jasperreports.engine.JRDefaultStyleProvider;
import net.sf.jasperreports.engine.JRExpressionCollector;
import net.sf.jasperreports.engine.JRRectangle;
import net.sf.jasperreports.engine.JRVisitor;
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 JRDesignRectangle extends JRDesignGraphicElement implements JRRectangle, JRChangeEventsSupport {
  private static final long serialVersionUID = 10200L;
  
  protected Integer radius;
  
  private transient JRPropertyChangeSupport eventSupport;
  
  public JRDesignRectangle() {
    super(null);
  }
  
  public JRDesignRectangle(JRDefaultStyleProvider defaultStyleProvider) {
    super(defaultStyleProvider);
  }
  
  public int getRadius() {
    return JRStyleResolver.getRadius((JRCommonRectangle)this);
  }
  
  public Integer getOwnRadius() {
    return this.radius;
  }
  
  public void setRadius(int radius) {
    setRadius(new Integer(radius));
  }
  
  public void setRadius(Integer radius) {
    Object old = this.radius;
    this.radius = radius;
    getEventSupport().firePropertyChange("radius", old, this.radius);
  }
  
  public void visit(JRVisitor visitor) {
    visitor.visitRectangle(this);
  }
  
  public void collectExpressions(JRExpressionCollector collector) {
    collector.collect(this);
  }
  
  public JRPropertyChangeSupport getEventSupport() {
    synchronized (this) {
      if (this.eventSupport == null)
        this.eventSupport = new JRPropertyChangeSupport(this); 
    } 
    return this.eventSupport;
  }
}
