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

/** BorderPanel extends Panel,
 * providing a shaded Border,
 * drawn either Raised or Lowered.
 *
 * Optionally,
 * a shaded Border may be drawn around each visible Child Component,
 * instead of inside of the Panel itself.
 * (Doing both at once is possible, but ugly.)
 *
 * @author Morris Hirsch IPD
 * @see Panel
 */

public class BorderPanel extends Panel {

    public String getVersion () { 
        return "$Id: BorderPanel.java,v 1.8 1998/10/07 13:02:15 mhirsch Exp $"; 
    }

    public BorderPanel () { 
        super (); 
    }

    public BorderPanel (LayoutManager LM) { 
        super (); 
        setLayout (LM); 
	setBorderThickness (0);
    }

    private Color borderColor = null;

/** If no BorderColor is specified,
 * brighter and darker shades of the Background Color will be used.
 * @param BC the BorderColor. */

    public void setBorderColor (Color BC) {
        borderColor = BC;

        if (isShowing ()) {
            repaint ();
        }
    }

    private int borderThickness = 2;

/** Set the Border Thickness.
 * @param BT -- the Border Thickness in pixels,
 * zero for no Border. */

    public void setBorderThickness (int BT) {
        borderThickness = BT;

        if (isShowing ()) {
            invalidate ();
            getParent ().validate();
        }
    }

    private boolean Raised = false;

/** If Raised vs Lowered is not specified,
 * a default is used. */

    public void setRaised (boolean R) {
        Raised = R;

        if (isShowing ()) {
            repaint ();
        }
    }

    private boolean BorderEachChild = false;

/** Optionally,
 * a shaded Border may be drawn around each Child Component,
 * instead of the Panel itself.
 * (Doing both at once is possible, but ugly.) */

    public void setBorderEachChild (boolean B) {
        BorderEachChild = B;

        if (isShowing ()) {
            repaint ();
        }
    }

    private Insets myInsets = null;

/** Set the Insets for this Panel.
 * @param myInsets -- the Insets for this Panel.
 * While Insets (0, 0, 0, 0) is legal,
 * null is not.
 *
 * Note:
 * insets of at least Border Thickness will be needed for either,
 * a border around the inside of the Panel,
 * or borders around the outside of each child.
 * @see Insets */

    public void setInsets (Insets myInsets) {
        this.myInsets = myInsets;

        if (isShowing ()) {
            invalidate ();
            getParent ().validate();
        }
    }

/** Set the Insets for this Panel.
 * @param top -- the top inset.
 * @param left -- the left inset.
 * @param bottom -- the bottom inset.
 * @param right -- the right inset.
 * Insets (0, 0, 0, 0) is legal. */

    public void setInsets (int top, int left, int bottom, int right) {
        setInsets (new Insets (top, left, bottom, right));
    }

/** Can return all-zero insets but not null */

    public Insets getInsets () {
        if (null != myInsets)
            return myInsets;

        int edge = borderThickness;
        return new Insets (edge, edge, edge, edge);
    }

/** Deprecated */

    public Insets insets () {
        if (null != myInsets)
            return myInsets;

        int edge = borderThickness;
        return new Insets (edge, edge, edge, edge);
    }

    public void paint (Graphics g) {

        if (0 < borderThickness) {

            Color BC = getBackground ();
            if (null != borderColor)
                BC = borderColor;

/* Borders outside the space allocated for each visible child */

            if (BorderEachChild) {
                Component [] cc = getComponents ();

                for (int ii = 0; ii < cc.length; ii++) {
                    if (cc[ii].isVisible ()) {
                        Point cl = cc[ii].getLocation ();
                        Dimension cs = cc[ii].getSize ();

                        Util.paint3DRect (g, BC,
                            cl.x, cl.y, cs.width, cs.height,
                            borderThickness,
                            true, Raised);
                    }
                }
            }

/* Border inside the Panel using insets space */

            else {
                Dimension S = getSize ();

                Util.paint3DRect (g, BC,
                     0, 0, S.width, S.height,
                     borderThickness,
                     false, Raised);
            }
        }

/* Let super paint all the children. */

        super.paint (g);
    }

}
/* <IMG SRC="/cgi-bin/counter">*/
