package wheels.users;

import java.awt.Color;
import java.awt.Dimension;

/**
 * A subclass of Ellispe with equal width and height.
 *
 * @author Zach Tomaszewski
 * @version Oct 5, 2007
 */
public class Circle extends Ellipse {


  /**
   * Creates a default circle, which matches a default ellipse.
   */
  public Circle() {
    super();
    //even if Ellipse's defaults are changed, this will always be a circle
    this.setSize(this.getWidth(), this.getWidth());
  }

  /**
   * Creates a circle of default size at the given location.
   *
   * @param x  The horizontal coordinate
   * @param y  The vertical coordinate
   */
  public Circle(int x, int y) {
    this();
    this.setLocation(x, y);
  }

  /**
   * Creates a circle with the given details.
   *
   * @param x         Horiz position
   * @param y         Vert position
   * @param diameter  Equals both width and height of a Circle
   * @param c         Color of this new Circle
   */
  public Circle(int x, int y, int diameter, Color c) {
    this(x, y);
    this.setColor(c);
    this.setDiameter(diameter);
  }


  /**
   * Set's this Circle's diameter, which equals both its width and its height.
   */
  public void setDiameter(int d) {
    this.setSize(d, d);
  }

  /**
   * Overrides Ellipse's setSize to preserve a Circle's shape.
   * This Circle's diameter is set equal to the width part of the
   * given size; the height is ignored.
   */
  public void setSize(int width, int height) {
    int diameter = Math.min(width, height);
    super.setSize(diameter, diameter);
  }

  /**
   * Overrides Ellipse's setSize to preserve a Circle's shape.
   * This Circle's diameter is set equal to the width part of the
   * given size Dimension; the height is ignored.
   */
  public void setSize(Dimension d) {
    Dimension sizeDim = new Dimension(d);
    double diam = Math.min(sizeDim.getWidth(), sizeDim.getHeight());
    sizeDim.setSize(diam, diam);
    super.setSize(sizeDim);
  }

  /**
   * Tests a Circle.
   */
  public static void main(String[] args) {
    Frame window = new Frame();
    final int START_X = 235;

    Ellipse red = new Circle();
    Circle yellow = new Circle(325, 280);
    yellow.setColor(Color.yellow);

    Ellipse green = new Circle(315, 335, 70, Color.green);
    green.setFrameThickness(5);
    green.setFrameColor(Color.green.darker());

    //test size methods
    Circle blueOne = new Circle(START_X, 100, 5, Color.blue);
    blueOne.setDiameter(30);

    Ellipse blueTwo = new Circle(START_X + 50, 100, 5, Color.blue);
    blueTwo.setSize(30, 90); //should be set to 30

    Rectangle rect = new Rectangle(START_X + 100, 70);
    rect.setColor(new Color(90, 0, 90));

    Ellipse blueThree = new Circle(START_X + 150, 100, 5, Color.blue);
    blueThree.setSize(90, 30); //should be set to 30

    Dimension dim = new Dimension(30, 90);
    Ellipse blueFour = new Circle(START_X + 200, 100, 5, Color.blue);
    blueFour.setSize(dim);
    //making sure Circle's setSize doesn't mess up the Dimension object
    rect.setSize(dim);
    //and that it takes the min of the two
    blueFour.setSize(new Dimension(90, 30));

  }

}
