// AnalogClockFace class, September/October 2001
//
// Designed for Brian's Superbly Incredible and Well-Commented Non-Functional
// Clock.
//
// This class defines objects to be used as faces for AnalogClocks.

import aLibrary.*;
import java.awt.*;

public class AnalogClockFace extends AView {
// Inherits from AView, so it has a lot of nice qualities.

  /*
   * CLASS VARIABLES
   */

  private ARoundRectangle outerSquare, innerSquare; // to make the face border
  private AOval[] dot;    // twelve dots around edge
  private int outerW, outerH;  // outer width and height of clock
  private int innerX, innerY, innerW, innerH; // inner width and height (used
                                              // especially when making hands)

  /*
   * CONSTRUCTOR
   */

  public AnalogClockFace(int x, int y, int w, int h, Color c) {
  // Creates a new AnalogClockFace based on coordinates and color passed in.
  //
  // Precondition:
  //   c != null
  //
  // Postconditions:
  //   A new AView (this AnalogClockFace) is created at (x, y) with width w and
  //     height h.
  //   The outer border is set to color c.
  //   Twelve dots are placed around the outside of the clock face.

    super(x, y, w, h); // call AView constructor

    outerW = w;
    outerH = h;
    // keep these values so we can work with them later

    outerSquare = new ARoundRectangle(0, 0, outerW, outerH);
    outerSquare.setToFill();
    outerSquare.setColor(c);
    outerSquare.place(this);
    // create and place outer ARoundRectangle

    innerX = (int)((outerW + outerH) / 30d);
    innerY = (int)((outerW + outerH) / 30d);
    innerW = (int)(outerW - ((outerW + outerH) / 15d));
    innerH = (int)(outerH - ((outerW + outerH) / 15d));
    // calculate coordinates of inner ARoundRectangle

    innerSquare = new ARoundRectangle(innerX, innerY, innerW, innerH);
    innerSquare.setToFill();
    innerSquare.setColor(Color.white);
    innerSquare.place(this);
    // instantiate and place inner ARoundRectangle

    dot = new AOval[12];
    // set up array

    for (int i = 0; i < 12; i++) {
      // loop through array, instantiating each object

      dot[i] = new AOval(
        (int)((outerW / 2d) + (0.4 * innerW * Math.cos(i * Math.PI / 6)) - 4),
        (int)((outerH / 2d) + (0.4 * innerH * Math.sin(i * Math.PI / 6)) - 4),
        8, 8); // complicated formula... sorry about that
      dot[i].setToFill();
      dot[i].setColor(Color.black);
      dot[i].place(this);
      // instantiate and place the twelve dots

    }

  }

  /*
   * QUERY METHODS
   */

  public Rectangle innerBounds() {
  // Returns a Rectangle which is the inner bounds of the border. This is
  // useful when figuring out how large to make the clock hands.
  //
  // Preconditions:
  //   none
  //
  // Postconditions:
  //   Returns a Rectangle corresponding to the (x, y, w, h) coordinates of the
  //   inner ARoundRectangle.

    return new Rectangle(innerX, innerY, innerW, innerH);

  }

  /*
   * UPDATE METHODS
   */

  public void setColor (Color c) {
  // Changes the color of the outer square, i.e., the outside of the face.
  //
  // Preconditions:
  //   c != null
  //
  // Postcondition:
  //   The color of the face is c.

    outerSquare.setColor(c);

  }
}
