import  java.awt.*;
import  java.io.*;
import java.util.*;
import cnp.ew.util.*;
import cnp.ew.layout.*;
import cnp.ew.misc.*;
import cnp.ew.lightweight.*;
import cnp.ew.calendar.*;
import cnp.ew.spin.*;
import cnp.ew.image.*;
import cnp.ew.text.*;
import cnp.ew.kdemo.*;
import cnp.ew.diagram.*;
import cnp.ew.displayer.*;

public class CpAttachmentsDemo extends CpLcApplet
{

    CpEyeballLc leftEye, rightEye;
    CpPanelLc rootLc;

	public void init()
	{
	    super.init();

		CpAttachmentsLayout layout;
		CpAttachments attachments;

		rootLc = new CpPanelLc();
		rootLc.setLayout(layout = new CpAttachmentsLayout());
        rootLc.setDrawOffscreen(true);
		setLc(rootLc);

        CpPanelLc panelLc = new CpPanelLc(CpAbstractLc.BORDER_LABELED_RAISED);
        attachments = new CpAttachments(10, 10, 10, 10);
        layout.setAttachments(panelLc, attachments);
        panelLc.setLayout(layout = new CpAttachmentsLayout());
        rootLc.add(panelLc);

        CpDiagramLc diagramFrame = new CpDiagramLc(false, false);
        CpDiagram diagram = diagramFrame.getDiagram();
        panelLc.add(diagramFrame);
        attachments = new CpAttachments(10, 10, 10, 10);
        layout.setAttachments(diagramFrame, attachments);

        CpAttachmentsExampleLc head = new CpAttachmentsExampleLc();
        attachments = new CpAttachments(5, 5, -1, -1);
        attachments.setRightAttachment(CpAttachments.ATTACH_SELF, 300);
        attachments.setBottomAttachment(CpAttachments.ATTACH_SELF, 200);
        layout.setAttachments(head, attachments);
        head.setLayout(layout = new CpAttachmentsLayout());
        diagram.add(head);
        Vector selectedLcs = new Vector(1);
        selectedLcs.addElement(head);
        diagram.selectLcs(selectedLcs);

        leftEye = new CpEyeballLc();
        rightEye = new CpEyeballLc();
        CpShapeLc nose = new CpShapeLc(CpShapeLc.OVAL, Color.blue);
        CpShapeLc mouth = new CpShapeLc(CpShapeLc.OVAL, Color.green);

        attachments = new CpAttachments(-1, -1, -1, 10);
        attachments.setLeftAttachment(CpAttachments.ATTACH_POSITION, 25);
        attachments.setRightAttachment(CpAttachments.ATTACH_POSITION, 75);
        attachments.setTopAttachment(CpAttachments.ATTACH_POSITION, 70);
        layout.setAttachments(mouth, attachments);
        head.add(mouth);

        attachments = new CpAttachments(-1, -1, -1, -1);
        attachments.setWidth(30);
        attachments.setHorizontalCentering();
        attachments.setBottomAttachment(10, mouth);
        attachments.setTopAttachment(CpAttachments.ATTACH_POSITION, 40);
        layout.setAttachments(nose, attachments);
        head.add(nose);

        attachments = new CpAttachments(10, 10, -1, -1);
        attachments.setRightAttachment(5, nose);
        attachments.setBottomAttachment(5, nose);
        layout.setAttachments(leftEye, attachments);
        head.add(leftEye);

        attachments = new CpAttachments(-1, 10, 10, -1);
        attachments.setLeftAttachment(5, nose);
        attachments.setBottomAttachment(5, nose);
        layout.setAttachments(rightEye, attachments);
        head.add(rightEye);

        mouth.setLayout(layout = new CpAttachmentsLayout());
        CpShapeLc tooth = new CpShapeLc(CpShapeLc.RECTANGLE);
        attachments = new CpAttachments(-1, -1, -1, 0);
        attachments.setTopAttachment(CpAttachments.ATTACH_POSITION, 90);
        attachments.setLeftAttachment(CpAttachments.ATTACH_POSITION, 47);
        attachments.setRightAttachment(CpAttachments.ATTACH_POSITION, 53);
        layout.setAttachments(tooth, attachments);
        mouth.add(tooth);

        layout();
	}



	public boolean mouseMove(Event e, int x, int y)
	{
	    leftEye.damage();
	    rightEye.damage();
	    rootLc.repairDamage();
	    return super.mouseMove(e, x, y);
	}
}



