import java.applet.Applet;
import java.awt.*;

// This appears in Core Web Programming from
// Prentice Hall Publishers, and may be freely used
// or adapted. 1997 Marty Hall, hall@apl.jhu.edu.

/** Tries out the ColorPopUp pseudo-menu class. */

public class ColorPopupTest extends Applet {
  private ColorPopup popup;

  public void init() {
    popup = new ColorPopup(getFrame());
    setBackground(Color.lightGray);
  }

  /** Pop up "menu" when right mouse button clicked. */
  
  public boolean mouseDown(Event event, int x, int y) {
    if ((event.modifiers & Event.META_MASK) != 0) {
      String[] colorNames = { "White", "Light Gray",
                              "Gray", "Dark Gray",
                              "Black" };
      Color[] colors = { Color.white, Color.lightGray,
                         Color.gray, Color.darkGray,
                         Color.black };
      popup.display(this, colorNames, colors, x, y);
      return(true);
    } else
      return(false);
  }

  private Frame frame = null;
  
  private Frame getFrame() {
    if (frame == null) {
      Container containingWin = getParent();
      while (containingWin != null) {
        if (containingWin instanceof Frame) {
          frame = (Frame)containingWin;
          break;
        } else
          containingWin = containingWin.getParent();
      }
    }
    return(frame);
  }
}
