import  java.awt.*;
import  java.io.*;
import java.util.*;
import java.applet.*;
import cnp.ew.util.*;
import cnp.ew.layout.*;
import cnp.ew.misc.*;
import cnp.ew.lightweight.*;
import cnp.ew.button.*;
import cnp.ew.text.*;
import cnp.ew.list.*;

public class CpBorderedPanelDemo extends CpLcApplet
implements CpObserver
{
    CpPanelLc panelLc, mainPanelLc;
    CpDropDownListLc styleChoice;
    CpEntryFieldLc labelTextField;

	public void init()
	{
        CpReadOnlyTextAreaLc label1, label2;
	    CpAttachmentsLayout layout, mainLayout;
	    CpAttachments attachments;

	    super.init();

	    setLc(mainPanelLc = new CpPanelLc());
	    mainPanelLc.setLayout(mainLayout = new CpAttachmentsLayout());
	    mainPanelLc.setDrawOffscreen(true);
	    mainPanelLc.setBackground(Color.lightGray);

	    panelLc = new CpPanelLc(CpAbstractLc.BORDER_INWARD3D);
	    layout = new CpAttachmentsLayout();
	    panelLc.setLayout(layout);
	    attachments = new CpAttachments(-1, 10, 10, 10);
	    attachments.setWidth(160);
	    mainLayout.setAttachments(panelLc, attachments);
	    mainPanelLc.add(panelLc);

	    CpLabeledImageButtonLc button = new CpLabeledImageButtonLc("A Button");
	    button.setBorderMargin(4);
	    attachments = new CpAttachments();
	    attachments.setHorizontalCentering(CpAttachments.CENTER_PARENT, 0);
	    attachments.setVerticalCentering(CpAttachments.CENTER_PARENT, 0);
	    layout.setAttachments(button, attachments);
	    panelLc.add(button);


        styleChoice = new CpDropDownListLc();
        styleChoice.addObserver(this);
        styleChoice.addItem("No Border");
        styleChoice.addItem("Single Line Border");
        styleChoice.addItem("Sunken 3D Border");
        styleChoice.addItem("Raised 3D Border");
        styleChoice.addItem("Labeled Etched Border");
        styleChoice.addItem("Light Sunken 3D Border");
        styleChoice.addItem("Light Raised 3D Border");
        styleChoice.addItem("Labeled Embossed Border");
        styleChoice.addItem("Drop Shadow Border");
        styleChoice.select(2);
        styleChoice.setIsTabStop(true);
        attachments = new CpAttachments();
        attachments.setRightAttachment(20, panelLc);
        attachments.setTopAttachment(CpAttachments.ATTACH_SIBLING_OPPOSITE, 0, panelLc);
        mainLayout.setAttachments(styleChoice, attachments);
        mainPanelLc.add(styleChoice);

        labelTextField = new CpEntryFieldLc();
        labelTextField.addObserver(this);
        labelTextField.setIsTabStop(true);
        labelTextField.setBorderStyle(CpAbstractLc.BORDER_LINE);
        labelTextField.setBorderMargin(1);
        labelTextField.setBackground(Color.white);
        labelTextField.setSelectAllOnGettingFocus(true);
        attachments = new CpAttachments();
        attachments.setLeftAttachment(CpAttachments.ATTACH_SIBLING_OPPOSITE, 0, styleChoice);
        attachments.setRightAttachment(CpAttachments.ATTACH_SIBLING_OPPOSITE, 0, styleChoice);
        attachments.setTopAttachment(10, styleChoice);
        mainLayout.setAttachments(labelTextField, attachments);
        mainPanelLc.add(labelTextField);

        label1 = new CpReadOnlyTextAreaLc("Style");
        attachments = new CpAttachments();
        attachments.setVerticalCentering(styleChoice);
        attachments.setRightAttachment(10, styleChoice);
        mainLayout.setAttachments(label1, attachments);
        mainPanelLc.add(label1);

        label1 = new CpReadOnlyTextAreaLc("Label");
        attachments = new CpAttachments();
        attachments.setVerticalCentering(labelTextField);
        attachments.setRightAttachment(10, labelTextField);
        mainLayout.setAttachments(label1, attachments);
        mainPanelLc.add(label1);

        layout();
	}

    public void update(CpObservable target, int facet, Object arg)
    {
        if (target == styleChoice  && facet == OBJECT_CHANGED) {
            panelLc.enableDamageRepair(false);
            panelLc.setBorderStyle(styleChoice.getSelectedIndex());
            panelLc.setText(labelTextField.getText());
            panelLc.enableDamageRepair(true);
            panelLc.repaint();
        }

        if (target == labelTextField && facet == OBJECT_CHANGING) {
            panelLc.setText(labelTextField.getText());
        }
    }
}



