import java.awt.*;

/** Extensions of DrawImage,
 * override their draw () method to draw a Button face,
 * for use (instead of a fixed Image) with ImageButton.
 * They may draw a constant (never changing) image,
 * or they may have additional variables and methods,
 * by which an application may alter their appearance.
 * <IMG SRC="/cgi-bin/counter">
 *
 * Example
 * <PRE>
//import java.awt.*;
//
//// This example implements Runnable,
//// and uses a timer Thread to animate the image.
//
//public class WhiteBar extends DrawImage implements Runnable {
//
//    private int xx = 0;
//
//    public void draw (Graphics g, int xo, int yo, boolean enabled) {
//
//	Color Cgreen = Color.green;
//	Color Cyellow = Color.yellow;
//	Color Cred = Color.red;
//	Color Cwhite = Color.white;
//
//        if (!enabled) {
//	   Cgreen = BWFilter (Color.green);
//	   Cyellow = BWFilter (Color.yellow);
//	   Cred = BWFilter (Color.red);
//	   Cwhite = BWFilter (Color.white);
//	}
//
//	g.setColor (Cgreen);
//	g.fillRect (xo+0, yo+0, 32, 11);
//	g.setColor (Cyellow);
//	g.fillRect (xo+0, yo+11, 32, 11);
//	g.setColor (Cred);
//	g.fillRect (xo+0, yo+22, 32, 11);
//	g.setColor (Cwhite);
//	g.fillRect (xo+15, yo+3, 3, 28);
//
//	g.setColor (Color.black);
//	g.fillRect (xo+xx, yo, 3, 32);
//    }
//
//    public int getHeight () { return 32; }
//
//    public int getWidth () { return 32; }
//
//// Constructor creates and starts a thread,
//// with (this) as runnable target.
//
//    WhiteBar () { new Thread (this).start (); }
//
//// Animate the image and schedule repaints.
//
//    public void run () {
//	while (true) {
//	    try { Thread.sleep (1000); }
//	    catch (Exception exc) {}
//	    xx += 3;
//	    if (xx > 30)
//	        xx = 0;
//          repaint (10);
//      }
//   }
//}
 * </PRE>
 * @author Morris Hirsch IPD 1998
 */

public abstract class DrawImage {

    protected Component IB;

/** The ImageButton using this Drawing,
 * handle to be set by the ImageButton,
 * when it installs the Drawing.  */

    public void setButton (Component IB) {
	this.IB = IB;
    }

/** Callable directly by an application,
 * or by some additional method of an extension class,
 * which has been called by the application,
 * or as a Listener for some event,
 * when it determines that the appearance should change.
 * Scheduling repaint () through the DrawImage will in turn
 * schedule repaint () for the ImageButton,
 * which will cause draw () to be called. */

    public void repaint () {
	if (null != IB)
	    IB.repaint ();
    }

    public void repaint (int T) {
	if (null != IB)
	    IB.repaint (T);
    }

/** Called every time the Button is to be painted.
 * @param g, Graphics context in which to draw.
 * @param xo, offset x pixels.
 * @param yo, offset y pixels.
 * @param enabled, true for normal appearance,
 * false for disabled (grayed) appearance.
 * Extension classes will implement this method,
 * to draw their required Button appearance. */

    public abstract void draw (Graphics g, int xo, int yo, boolean enabled) ;

/** Extensions must provide a Height and Width for their Drawing.
 * These values will be read by the ImageButton only once,
 * and should remain valid. */

    public abstract int getHeight () ;

    public abstract int getWidth () ;

/* Called by a draw () method to gray out a given color,
 * for a disabled view of the Button. */

    public Color BWFilter (Color C) {
	int R = C.getRed ();
	int G = C.getGreen ();
	int B = C.getBlue ();

	int X = (400 + R + G + G + B) / 6;

	return new Color (X, X, X);
    }
}
/* <IMG SRC="/cgi-bin/counter">*/
