package cnp.ew.misc;
import cnp.ew.util.*;
import cnp.ew.displayer.*;
import java.awt.*;
import cnp.ew.lightweight.*;

public class CpComponentLc extends CpAbstractLc
{
    Component realComponent;

    public CpComponentLc(Component realComponent)
    {
        this.realComponent = realComponent;
    }

    public void reshape(int x, int y, int width, int height)
    {
        CpLightweightComponent parent;

        if ((parent = getParent()) == null) {
            return;
        }

        Rectangle boundsGlobal = parent.boundsGlobal();
        Insets insets = insets();
        Insets parentInsets = parent.insets();

        boundingBox = new Rectangle(boundsGlobal.x + x + parentInsets.left, boundsGlobal.y + y + parentInsets.top, width, height);
        realComponent.reshape(boundingBox.x + insets.left, boundingBox.y + insets.top, boundingBox.width - insets.left - insets.right, boundingBox.height - insets.top - insets.bottom);
    }

    public void move(int x, int y)
    {
        reshape(x, y, size().width, size().height);
    }

    public void size(int width, int height)
    {
        Rectangle bounds = bounds();
        reshape(bounds.x, bounds.y, width, height);
    }

    public void setParent(CpLightweightComponent newParent)
    {
        super.setParent(newParent);
        getComponent().addRealComponent(realComponent, this);
    }

    public Dimension preferredSize()
    {
        return realComponent.preferredSize();
    }

    public void setIsDisabled(boolean disable)
    {
        super.setIsDisabled(disable);
        realComponent.enable(!disable);
    }

    public boolean handleEvent(Event e)
    {
        return false;
    }

    public void setBackground(Color color)
    {
        super.setBackground(color);
        realComponent.setBackground(color);
    }

    public void setForeground(Color color)
    {
        super.setForeground(color);
        realComponent.setForeground(color);
    }
}

