package cnp.ew.richtext;

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

import cnp.ew.util.*;

public class CpImageFormat extends CpCharFormat
{
    Image image;
    int imageId;

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

    public CpImageFormat(int id)
    {
        super(0, null, false, false, false, 0, null);
        imageId = id;
    }

    public void setIdAndImage(int newId, Image im)
    {
        imageId = newId;
        image = im;
    }

    public CpImageFormat(Image newImage)
    {
    	super(0, null, false, false, false, 0, null);
    	image = newImage;
    }

    public void getImage()
    {
        if (image == null) {
            image = CpToolkit.getImage(imageId);
        }
    }

    public int paint(Graphics g, int curOffset, int charsToDraw, CpLine line, CpTextModel text, int x, int y)
    {
        getImage();
        g.drawImage(image, x, y, CpToolkit.defaultComponent());
        return image.getWidth(CpToolkit.defaultComponent());
    }

    public int[] getWidths()
    {
        getImage();
        int[] widths = new int[1];
        widths[0] = image.getWidth(CpToolkit.defaultComponent());
        return widths;
    }

    public int getHeight()
    {
        getImage();
        return image.getHeight(CpToolkit.defaultComponent());
    }


    public Object getCopy()
    {
        CpImageFormat f = new CpImageFormat(this);
        f.setIdAndImage(imageId, image);
        return f;
    }


    public int getDescent()
    {
        return 0;
    }
}