package cnp.ew.notebook;
import cnp.ew.displayer.*;
import java.awt.*;
import cnp.ew.lightweight.*;
import cnp.ew.util.*;

public class CpBeveledTabDisplayer extends CpAbstractBorderDisplayer
implements CpTabDisplayable
{
    static final int insetWidth = 8;
    boolean hasFocus=false;

    public void paintIn(CpLightweightComponent lc, Graphics g, int x, int y, int width, int height, CpDisplayable innerDisplayer, boolean isSelected)
    {
        Rectangle clientRect = new Rectangle(
            x + getLeftBorderThickness(lc),
            y + getTopBorderThickness(lc),
            width - getLeftBorderThickness(lc) - getRightBorderThickness(lc),
            height - getTopBorderThickness(lc) - getBottomBorderThickness(lc)
        );

        paintBordersIn(lc, g, x, y, width, height, isSelected);
        innerDisplayer.paintIn(lc, g,clientRect);
        if (hasFocus) {
            // TBD: fix the bug where it clips the right and left pixels off the focus rect.
           // CpFocusRect.drawFocusRect(g, clientRect);
        }
    }
    void paintBordersIn(CpLightweightComponent lc, Graphics g, int x, int y, int width, int height)
    {
        // GET RID OF THIS
    }

    void paintBordersIn(CpLightweightComponent lc, Graphics g, int x, int y, int width, int height, boolean isSelected)
    {
        int [] xPoints = new int[5];
        int [] yPoints = new int[5];
        xPoints[0] = x; yPoints[0] = y;
        xPoints[1] = x + insetWidth; yPoints[1] = y + height;
        xPoints[2] = x + width - insetWidth; yPoints[2] = y + height;
        xPoints[3] = x + width; yPoints[3] = y;
        xPoints[4] = xPoints[0]; yPoints[4] = yPoints[0];

        if (isSelected) {
            g.setColor(Color.white);
        } else {
            g.setColor(Color.lightGray);
        }
        g.fillPolygon(xPoints, yPoints, 5);

        if (!isSelected) {
            g.setColor(Color.white);
            g.drawLine(xPoints[0] + 1, yPoints[0], xPoints[1] + 1, yPoints[1]);
            g.setColor(Color.gray);
            g.drawLine(xPoints[2] - 1, yPoints[2], xPoints[3] - 1, yPoints[3]);
        }

        g.setColor(Color.black);
        g.drawLine(xPoints[0], yPoints[0], xPoints[1], yPoints[1]);
        g.drawLine(xPoints[2], yPoints[2], xPoints[3], yPoints[3]);
        g.setColor(Color.gray);
        g.drawLine(xPoints[1], yPoints[1] - 1, xPoints[2], yPoints[2] - 1);

    }

    public int getLeftBorderThickness(CpLightweightComponent lc)
    {
        return insetWidth + 2;
    }

    public int getRightBorderThickness(CpLightweightComponent lc)
    {
        return insetWidth + 2;
    }

    public int getTopBorderThickness(CpLightweightComponent lc)
    {
        return 1;
    }

    public int getBottomBorderThickness(CpLightweightComponent lc)
    {
        return 2;
    }


    public int horizontalOverlap()
    {
        return insetWidth;
    }

    public Insets expansion(boolean isSelected)
    {
        if (isSelected) {
            return new Insets(1, 0, 0, 0);
        } else {
            return new Insets(0, 0, 0, 0);
        }
    }

    public Insets maxExpansion()
    {
        return new Insets(1, 0, 0, 0);
    }

    public void setHasFocus(boolean hasFocus)
    {
        this.hasFocus = hasFocus;
    }
}

