// AnalogClock class, September/October 2001
//
// Designed for Brian's Superbly Incredible and Well-Commented Non-Functional
// Clock.
//
// Objects of this class are analog clocks (that is, clocks with hands). This
// class instantiates objects of class AnalogClockFace and Hand.

import aLibrary.*;
// Since it would really be nice to be able to refer to classes and methods in
// aLibrary without having to type their fully qualified names over and over
// and over again, we'll import it. That will fix all of our problems.

import java.awt.*;
// The same thing goes for our good buddy java.awt over here.

import java.lang.*;
// Well, we run into the same "stupid line" issue as we did in Director.java,
// but it's a good thing to clarify what we already know to be true. It's sort
// of like an assert. But not really. No, actually, it's nothing like an assert
// at all. I lied. Ha ha ha.

public class AnalogClock extends Clock {
// An AnalogClock is inherited from Clock.

  /*
   * CLASS VARIABLES
   */

  protected AnalogClockFace face;  // the clock face (that square thing)
  protected HandGroup hands;       // a group of coordinated clock hands

  /*
   * CONSTRUCTOR
   */

  public AnalogClock(int x, int y, int w, int h, Color c) {
  // Constructs a new AnalogClock.
  //
  // Preconditions:
  //   0 < x < containerWidth
  //   0 < y < containerWidth
  //   c != null
  //
  // Postconditions:
  //   face is instantiated as a new AnalogClockFace.
  //   hands is instantiated as a new HandGroup.
  //   Both are placed in this AnalogClock.

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

    face = new AnalogClockFace(0, 0, w, h, c);
    face.place(this);
    // instantiate face and place it here

    hands = new HandGroup((int)(face.innerBounds().getX()),
                          (int)(face.innerBounds().getY()),
                          (int)(face.innerBounds().getWidth()),
                          (int)(face.innerBounds().getHeight()));
    hands.place(this);
    // instantiate hands and place it here

    setDescription("analog clock");
    // set a default description

  }

  /*
   * UPDATE METHODS
   */

  public void setColor(Color c) {
  // Changes the color of the face of this AnalogClock.
  //
  // Precondition:
  //   c != null
  //
  // Postcondition:
  //   The face is set to the new color.

    face.setColor(c);

  }

  public void showTime(double time) {
  // Sets the hands to display the time passed as an argument. We must override
  // this method to inherit from Clock.
  //
  // Preconditions:
  //   time >= 0
  //
  // Postconditions:
  //   hands are set (but not repainted) to new time.

    hands.setTime(time);

  }

}
