package cnp.ew.notebook;

import cnp.ew.displayer.*;
import java.awt.*;
import cnp.ew.lightweight.*;

public class Cp3Sided3DBorderDisplayer extends CpAbstractBorderDisplayer
{
    public static final int HIDE_TOP=0;
    public static final int HIDE_BOTTOM=1;
    public static final int HIDE_LEFT=2;
    public static final int HIDE_RIGHT=3;

    boolean isRaised=false;
    boolean isLight=false;
    int sideToHide=HIDE_TOP;

    public Cp3Sided3DBorderDisplayer(boolean raised, boolean light, int newSideToHide)
    {
        super();
        isRaised = raised;
        isLight = light;
        sideToHide = newSideToHide;
    }

    public void setRaised(boolean raised)
    {
        isRaised = raised;
    }

    public boolean getRaised()
    {
        return isRaised;
    }

    public void paintBordersIn(CpLightweightComponent lc, 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) {
                leftAndTopOuterColor = Color.white;
                rightAndBottomOuterColor = Color.black;
                leftAndTopInnerColor = Color.lightGray;
                rightAndBottomInnerColor = Color.gray;
            } else {
                leftAndTopOuterColor = Color.gray;
                rightAndBottomOuterColor = Color.lightGray;
                leftAndTopInnerColor = Color.black;
                rightAndBottomInnerColor = Color.white;
            }
        }

        // expand the rect on the side that is hidden, so the lines will
        // draw in the entire space
        switch (sideToHide) {
        case HIDE_LEFT:
            x -= 2;
            w -= 2;
            break;
        case HIDE_TOP:
            y -= 2;
            h += 2;
            break;
        case HIDE_RIGHT:
            w += 2;
            break;
        case HIDE_BOTTOM:
            h += 2;
            break;
        }

        g.setColor(leftAndTopOuterColor);

        if (sideToHide != HIDE_LEFT) {
            g.drawLine(x, y, x, (y + h - 2));
        }
        if (sideToHide != HIDE_TOP) {
            g.drawLine(x, y, (x + w - 2), y);
        }

        g.setColor(rightAndBottomOuterColor);

        if (sideToHide != HIDE_BOTTOM) {
            g.drawLine(x, (y + h - 1), (x + w - 1), (y + h - 1));
        }
        if (sideToHide != HIDE_RIGHT) {
            g.drawLine((x + w - 1), y, (x + w - 1), (y + h - 1));
        }

        if (!isLight) {

            g.setColor(leftAndTopInnerColor);

            if (sideToHide != HIDE_LEFT) {
                g.drawLine(x + 1, y + 1, x + 1, (y + h - 3));
            }
            if (sideToHide != HIDE_TOP) {
                g.drawLine(x + 1, y + 1, (x + w - 3), y + 1);
            }

            g.setColor(rightAndBottomInnerColor);

            if (sideToHide != HIDE_BOTTOM) {
                g.drawLine(x + 1, (y + h - 2), (x + w - 2), (y + h - 2));
            }
            if (sideToHide != HIDE_RIGHT) {
                g.drawLine((x + w - 2), y + 1, (x + w - 2), (y + h - 2));
            }
        }
    }

    int borderThickness(int sideToShow)
    {
        if (sideToShow == sideToHide) {
            return 0;
        }

        if (isLight) {
            return 1;
        } else {
            return 2;
        }
    }

    public int getLeftBorderThickness(CpLightweightComponent lc)
    {
        return borderThickness(HIDE_LEFT);
    }

    public int getRightBorderThickness(CpLightweightComponent lc)
    {
        return borderThickness(HIDE_RIGHT);
    }

    public int getTopBorderThickness(CpLightweightComponent lc)
    {
        return borderThickness(HIDE_TOP);
    }

    public int getBottomBorderThickness(CpLightweightComponent lc)
    {
        return borderThickness(HIDE_BOTTOM);
    }

}