package cnp.ew.richtext;

import java.awt.*;
import java.util.*;
import java.io.*;

import cnp.ew.util.*;
import cnp.ew.lightweight.*;

public class CpLcFormat extends CpCharFormat
{
    CpLightweightComponent lc;
    CpRichTextPane richpane;

    public CpLcFormat(CpLcFormat charFormat)
    {
        super(charFormat);
    }

    public CpLcFormat(CpRichTextPane rich, CpLightweightComponent newLc)
    {
    	super(0, null, false, false, false, 0, null);
    	lc = newLc;
    	//lc.reshape(0, 0, 100, 50);
    	lc.hide(true);
    	rich.add(lc);
    	richpane = rich;
    }

    public void setRichAndLc(CpRichTextPane rich, CpLightweightComponent newLc)
    {
        richpane = rich;
        lc = newLc;
    	lc.hide(true);
    	rich.add(lc);
    }

    public void aboutToDelete()
    {
        richpane.remove(lc);
    }

    public int paint(Graphics g, int curOffset, int charsToDraw, CpLine line, CpTextModel text, int x, int y)
    {
     /*   System.out.println("In lc format paint, lc parent = " + lc.getParent());
        System.out.println("rich children " + richpane.getChildren());
        System.out.println("Contained? = " + richpane.getChildren().contains(lc));
        System.out.println("Boudns = " + lc.boundsGlobal());
        */
          setupGraphics(g);
          richpane.enableDamageRepair(false);
          lc.move(x, y);
          lc.hide(false);
          lc.setFont(g.getFont());
          lc.setForeground(g.getColor());
          richpane.enableDamageRepair(true);
          lc.clearDamagedRect();
          return lc.size().width;
    }

    public int[] getWidths()
    {
        int[] widths = new int[1];
        widths[0] = lc.size().width;
        return widths;
    }

    public int getHeight()
    {
        return lc.size().height;
    }


    public Object getCopy()
    {
        CpLcFormat f = new CpLcFormat(this);
        f.setRichAndLc(richpane, (CpLightweightComponent)lc.getCopy());
        return f;
    }


    public int getDescent()
    {
        return 0;
    }
}