package cnp.ew.lightweight;

import java.awt.*;
import java.applet.*;
import java.util.*;
import cnp.ew.util.*;
import cnp.ew.text.*;
import cnp.ew.image.*;

public class CpLcApplet extends Applet implements CpEvent, CpObserver
{
    CpLcPanel lcPanel;

    public void init()
    {
        CpImageGetter.getDefault().setApplet(this);
        CpToolkit.setDefaultComponent(this);
        super.init();
        setLayout(null);
        lcPanel = new CpLcPanel();
        add(lcPanel);
        layout();
    }

    public void layout()
    {
        if (lcPanel != null) {
            lcPanel.reshape(0, 0, size().width, size().height);
        }
    }

    public CpLcPanel getRootPanel()
    {
        return lcPanel;
    }

    public void setLc(CpLightweightComponent lc)
    {
        lcPanel.setLc(lc);
    }

    public void update(CpObservable target, int facet, Object arg)
    {
    }

    public Frame getFrame()
    {
        Container parent = getParent();

        while (parent != null) {
            if (parent instanceof Frame) {
                return (Frame)parent;
            }
            parent = parent.getParent();
        }
        return null;
    }

    /**
     * TBD: hack to deal with browsers not adequately handling gotFocus
     */
    public void start()
    {
        getRootPanel().gotFocus(new Event(null, 0, null), null);
        getRootPanel().requestFocus();
    }
}

