package cnp.ew.notebook;
import cnp.ew.displayer.*;
import java.awt.*;
import cnp.ew.lightweight.*;
import cnp.ew.util.*;

public class Cp3DRoundedTabDisplayer extends CpAbstractBorderDisplayer
implements CpTabDisplayable
{
    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)
        );
        g.setColor(Color.lightGray);
        g.fillRect(x, y, width, height);
        innerDisplayer.paintIn(lc, g,clientRect);
        if (hasFocus) {
            CpFocusRect.drawFocusRect(g, clientRect.x - 1, clientRect.y - 1, clientRect.width + 2, clientRect.height + 2);
        }
        paintBordersIn(lc, g, x, y, width, height);
    }

    void paintBordersIn(CpLightweightComponent lc, Graphics g, int x, int y, int width, int height)
    {
        g.setColor(Color.white);
        g.drawLine(x, y + 2, x, y + height);
        g.drawLine(x + 1, y + 1, x + 1, y + 1);
        g.drawLine(x + 2, y, x + width - 2, y);

        g.setColor(Color.gray);
        g.drawLine(x + width - 2, y + 1, x + width - 2, y + height);

        g.setColor(Color.black);
        g.drawLine(x + width - 1, y + 2, x + width - 1, y + height);
    }

    public int getLeftBorderThickness(CpLightweightComponent lc)
    {
        return 4;
    }

    public int getRightBorderThickness(CpLightweightComponent lc)
    {
        return 4;
    }

    public int getTopBorderThickness(CpLightweightComponent lc)
    {
        return 4;
    }

    public int getBottomBorderThickness(CpLightweightComponent lc)
    {
        return 2;
    }


    public int horizontalOverlap()
    {
        return 0;
    }

    public Insets expansion(boolean isSelected)
    {
        if (isSelected) {
            return new Insets(2, 2, 1, 2);
        } else {
            return new Insets(0, 0, 0, 0);
        }
    }

    public Insets maxExpansion()
    {
        return expansion(true);
    }

    public void setHasFocus(boolean hasFocus)
    {
        this.hasFocus = hasFocus;
    }
}

