// HandGroup class, September/October 2001
//
// Designed for Brian's Superbly Incredible and Well-Commented Non-Functional
// Clock.
//
// Objects of this class are a collection of coordinated Hand objects. By
// placing a HandGroup object on an AnalogClockFace, you can get an AnalogClock.
// Woo hoo.

import aLibrary.AView;

public class HandGroup extends AView {
// A HandGroup is a collection of Hands, and so it makes sense to derive from
// an AView.

  /*
   * CLASS VARIABLES
   */

  private Hand hourHand, minuteHand, secondHand;
  // Our three hands for this group, appropriately named.

  public HandGroup(int x, int y, int w, int h) {
  // Creates a new HandGroup based on (x, y, w, h) coordinates.
  //
  // Preconditions:
  //   none
  //
  // Postconditions:
  //   A new HandGroup is instantiated with three hands: hourHand, minuteHand,
  //     and secondHand.
  //   hourHand is the shortest, and secondHand is the longest.
  //   secondHand controls minuteHand at a ratio of 1:60, and minuteHand
  //     controls hourHand at a ratio of 1:60.
  //   All three hands are placed in this.

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

    hourHand = new Hand(w / 2, h / 2,
      (w < h) ? (int)(w / 3) - 5 : (int)(h / 3) - 5, 12, this);
    minuteHand = new Hand(w / 2, h / 2,
      (w < h) ? (int)(w / 2.5) - 5 : (int)(h / 2.5) - 5, hourHand, 60, 60, this);
    secondHand = new Hand(w / 2, h / 2,
      (w < h) ? (int)(w / 2) - 5 : (int)(w / 2) - 5, minuteHand, 60, 60, this);
    // Instantiate and place these three hands. Note these really nifty
    // constructors that Hand offers. Hand is such a cool class. This is only
    // the tip of the iceberg of the things you can do with Hand. Here I haven't
    // even considered sweep versus tick, or initial and logical angles, or
    // moving a hand versus setting a hand... Wow. So cool. You should
    // definitely take a good look at the Hand class.

  }

  /*
   * UPDATE METHODS
   */

  public void setTime(double time) {
  // Sets the time that these hands point to and repaints.
  //
  // Precondition:
  //   time >= 0
  //
  // Postcondition:
  //   Hands point to the correct time.
  //   secondHand is moved, which in turn moves minuteHand, which then moves
  //     hourHand, so everything is taken care of.
  //   Hands are repainted.

    secondHand.moveTo(time);
    // Check this out in the Hand class. It's pretty cool how this is done.

    secondHand.repaint();
    minuteHand.repaint();
    hourHand.repaint();
    // Repaint the three hands

  }

}
