package cnp.ew.displayer;
import java.awt.*;
import cnp.ew.lightweight.*;

final public class Cp3DBorderDisplayer extends CpAbstractBorderDisplayer
{
    // Made these public for IE 3.0
    public boolean isRaised=true;
    public boolean isLight=false;
    // Ted added 10/4 because scrollbars have different 3D colors
    public boolean isReverse3D = false;

    public Cp3DBorderDisplayer(boolean raised, boolean light)
    {
        this(raised, light, false);
    }

    public Cp3DBorderDisplayer(boolean raised, boolean light, boolean reverse3D)
    {
        super();
        isRaised = raised;
        isLight = light;
        isReverse3D = reverse3D;
    }

    public void setRaised(boolean raised)
    {
        isRaised = raised;
    }

    public boolean getRaised()
    {
        return isRaised;
    }

    public void setReverse3D(boolean reverse3D)
    {
        isReverse3D = reverse3D;
    }

    /**
     * Display the borders in rect, using g.
     */
    public void paintBordersIn(CpLightweightComponent c, Graphics g, int x, int y, int w, int h)
    {
        Color leftAndTopOuterColor, rightAndBottomOuterColor;
        Color leftAndTopInnerColor, rightAndBottomInnerColor;

        if (isLight) {
            if (isRaised) {
                leftAndTopOuterColor = Color.white;
                rightAndBottomOuterColor = Color.gray;
            } else {
                leftAndTopOuterColor = Color.gray;
                rightAndBottomOuterColor = Color.white;
            }
            // shut the compiler up about initialization.
            leftAndTopInnerColor = Color.white;
            rightAndBottomInnerColor = Color.white;
        } else {
            if (isRaised) {
                if (isReverse3D) {
                    leftAndTopOuterColor = Color.lightGray;
                    leftAndTopInnerColor = Color.white;
                } else {
                    leftAndTopOuterColor = Color.white;
                    leftAndTopInnerColor = Color.lightGray;
                }
                rightAndBottomOuterColor = Color.black;
                rightAndBottomInnerColor = Color.gray;
            } else {
                if (isReverse3D) {
                    rightAndBottomOuterColor = Color.lightGray;
                    rightAndBottomInnerColor = Color.white;
                } else {
                    rightAndBottomOuterColor = Color.white;
                    rightAndBottomInnerColor = Color.lightGray;
                }
                leftAndTopOuterColor = Color.gray;
                leftAndTopInnerColor = Color.black;
            }
        }

        g.setColor(leftAndTopOuterColor);
        g.drawLine(x, y, x, (y + h - 2));
        g.drawLine(x, y, (x + w - 2), y);
        g.setColor(rightAndBottomOuterColor);
        g.drawLine(x, (y + h - 1), (x + w - 1), (y + h - 1));
        g.drawLine((x + w - 1), y, (x + w - 1), (y + h - 1));

        if (!isLight) {
            g.setColor(leftAndTopInnerColor);
            g.drawLine(x + 1, y + 1, x + 1, (y + h - 3));
            g.drawLine(x + 1, y + 1, (x + w - 3), y + 1);
            g.setColor(rightAndBottomInnerColor);
            g.drawLine(x + 1, (y + h - 2), (x + w - 2), (y + h - 2));
            g.drawLine((x + w - 2), y + 1, (x + w - 2), (y + h - 2));
        }
    }

    int borderThickness()
    {
        if (isLight) {
            return 1;
        } else {
            return 2;
        }
    }

    public int getLeftBorderThickness(CpLightweightComponent c)
    {
        return borderThickness();
    }

    public int getRightBorderThickness(CpLightweightComponent c)
    {
        return borderThickness();
    }

    public int getTopBorderThickness(CpLightweightComponent c)
    {
        return borderThickness();
    }

    public int getBottomBorderThickness(CpLightweightComponent c)
    {
        return borderThickness();
    }

}