// DigitalClockFace 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 DigitalClocks.

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

public class DigitalClockFace extends AView {
// DigitalClockFace is_an AView (ooh, ahh)

  /*
   * CLASS VARIABLES
   */

  private ARectangle outerSquare, innerSquare; // to form the actual clock
  private ARectangle snooze; // the large snooze button on the left
  private ARectangle[] button; // the three other buttons on the right
  private int x_, y_, w_, h_; // these store the arguments (x, y, w, h)

  /*
   * CONSTRUCTOR
   */

  public DigitalClockFace(int x, int y, int w, int h) {
  // Instantiates a new DigitalClockFace
  //
  // Preconditions:
  //   none
  //
  // Postconditions:
  //   A new DigitalClockFace is instantiated.

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

    x_ = x;
    y_ = y;
    w_ = w;
    h_ = h;
    // preserve our arguments for later

    outerSquare = new ARectangle(0, (int)((h_ / 50d) + 0.5), w_, h_);
    outerSquare.setToFill();
    outerSquare.setColor(Color.black);
    outerSquare.place(this);
    // draw and place outer black box

    innerSquare = new ARectangle((int)(((w_ + h_) / 20d) + 0.5),
      (int)(((w_ + h_) / 20d) + 0.5),
      (int)(w_ - ((w_ + h_) / 10d) + 0.5),
      (int)(h_ - ((w_ + h_) / 10d) + 0.5));
    innerSquare.setToFill();
    innerSquare.setColor(Color.darkGray);
    innerSquare.place(this);
    // draw and place inner gray box, where the digits are

    snooze = new ARectangle((int)((w_ / 50d) + 0.5), 0,
      (int)(((2d / 5d) * w_) + 0.5), (int)((h_ / 50d) + 0.5));
    snooze.setToFill();
    snooze.setColor(Color.black);
    snooze.place(this);
    // create and place snooze button

    button = new ARectangle[3];
    // create array for other buttons

    for (int i = 0; i < 3; i++) {
      button[i] = new ARectangle(
        (int)((((11d / 25d) + ((1d / 6d) + (1d / 50d)) * i) * w_) + 0.5), 0,
        (int)((w_ / 6d) + 0.5), (int)((h_ / 50d) + 0.5)); // sorry about this :(
      button[i].setToFill();
      button[i].setColor(Color.black);
      button[i].place(this);
    }
    // draw and place other buttons

  }

  /*
   * QUERY METHODS
   */

  public Rectangle innerBounds() {
  // Returns a Rectangle indicating the bounds of the inner part of the
  // DigitalClockFace. Useful for placing digits.
  //
  // Preconditions:
  //   none
  //
  // Postconditions:
  //   Returns a Rectangle bounded by the same bounds as innerSquare.

    return new Rectangle((int)(((w_ + h_) / 20d) + 0.5),
      (int)(((w_ + h_) / 20d) + 0.5),
      (int)(w_ - ((w_ + h_) / 10d) + 0.5),
      (int)(h_ - ((w_ + h_) / 10d) + 0.5));

  }

}