import java.awt.*;
import cnp.ew.misc.*;
import cnp.ew.util.*;
import cnp.ew.layout.*;
import cnp.ew.notebook.*;
import cnp.ew.image.*;
import cnp.ew.lightweight.*;

public class CpGaugeDemo extends CpLcApplet
implements Runnable
{
    CpValueViewerLc vert1, vert2, vert3, horz1, horz2, horz3;
    CpPanelLc panelLc;
    Thread thread;
    int value;

    public void init()
    {
        super.init();

        CpAttachments attachments;
        CpAttachmentsLayout layout;

        panelLc = new CpPanelLc();
        setLc(panelLc);
        panelLc.setDrawOffscreen(true);
        panelLc.setLayout(layout = new CpAttachmentsLayout());
        panelLc.setBackground(Color.lightGray);


        vert1 = new CpValueViewerLc(CpValueViewerLc.STYLE_BOXED);
        vert1.setOrientation(CpValueViewerLc.ORIENT_VERT);
        panelLc.add(vert1);
        attachments = new CpAttachments(20, 10, -1, 20);
        layout.setAttachments(vert1, attachments);

        vert2 = new CpValueViewerLc(CpValueViewerLc.STYLE_SOLID);
        vert2.setOrientation(CpValueViewerLc.ORIENT_VERT);
        panelLc.add(vert2);
        attachments = new CpAttachments();
        attachments.setLeftAttachment(10, vert1);
        attachments.setTopAttachment(CpAttachments.ATTACH_SIBLING_OPPOSITE, 0, vert1);
        attachments.setBottomAttachment(CpAttachments.ATTACH_SIBLING_OPPOSITE, 0, vert1);
        layout.setAttachments(vert2, attachments);

        vert3 = new CpValueViewerLc(CpValueViewerLc.STYLE_LABELED_SOLID);
        vert3.setOrientation(CpValueViewerLc.ORIENT_VERT);
        panelLc.add(vert3);
        attachments = new CpAttachments();
        attachments.setLeftAttachment(10, vert2);
        attachments.setTopAttachment(CpAttachments.ATTACH_SIBLING_OPPOSITE, 0, vert1);
        attachments.setBottomAttachment(CpAttachments.ATTACH_SIBLING_OPPOSITE, 0, vert1);
        layout.setAttachments(vert3, attachments);

        horz1 = new CpValueViewerLc(CpValueViewerLc.STYLE_BOXED);
        horz1.setOrientation(CpValueViewerLc.ORIENT_HORZ);
        panelLc.add(horz1);
        attachments = new CpAttachments();
        attachments.setLeftAttachment(10, vert3);
        attachments.setTopAttachment(CpAttachments.ATTACH_SIBLING_OPPOSITE, 0, vert1);
        attachments.setRightAttachment(20);
        layout.setAttachments(horz1, attachments);

        horz2 = new CpValueViewerLc(CpValueViewerLc.STYLE_SOLID);
        horz2.setOrientation(CpValueViewerLc.ORIENT_HORZ);
        panelLc.add(horz2);
        attachments = new CpAttachments();
        attachments.setLeftAttachment(CpAttachments.ATTACH_SIBLING_OPPOSITE, 0, horz1);
        attachments.setTopAttachment(10, horz1);
        attachments.setRightAttachment(CpAttachments.ATTACH_SIBLING_OPPOSITE, 0, horz1);
        layout.setAttachments(horz2, attachments);

        horz3 = new CpValueViewerLc(CpValueViewerLc.STYLE_LABELED_SOLID);
        horz3.setOrientation(CpValueViewerLc.ORIENT_HORZ);
        panelLc.add(horz3);
        attachments = new CpAttachments();
        attachments.setLeftAttachment(CpAttachments.ATTACH_SIBLING_OPPOSITE, 0, horz1);
        attachments.setTopAttachment(10, horz2);
        attachments.setRightAttachment(CpAttachments.ATTACH_SIBLING_OPPOSITE, 0, horz1);
        layout.setAttachments(horz3, attachments);
    }

    public void run()
    {
        while (true) {
            panelLc.enableDamageRepair(false);
            vert1.setValue(value);
            vert2.setValue(value);
            vert3.setValue(value);
            horz1.setValue(value);
            horz2.setValue(value);
            horz3.setValue(value);
            panelLc.enableDamageRepair(true);
            panelLc.repairDamage();
            try {
                thread.sleep(1);
            }
            catch (InterruptedException e) {}
            value = (value + 1) % 101;
        }
    }

    public void start()
    {
        if (thread == null) {
            value = 0;
            vert1.setValue(value);
            vert2.setValue(value);
            vert3.setValue(value);
            horz1.setValue(value);
            horz2.setValue(value);
            horz3.setValue(value);
            thread = new Thread(this);
            thread.start();
        }
    }

    public void stop()
    {
        if (thread != null) {
            thread.stop();
            thread = null;
        }
    }
}

