package cnp.ew.displayer;
import java.awt.*;
import cnp.ew.lightweight.*;

public abstract class CpAbstractTextDisplayer implements CpModelDisplayable
{
    Font font=null;

    public Font getFont()
    {
        return font;
    }

    public void setFont(Font newFont)
    {
        font = newFont;
    }

    public Object getModel()
    {
        return (Object)getText();
    }

    public void setModel(Object model)
    {
        setText((String)model);
    }

    /**
     * We may want to cache fontmetrics in the future
     * if it turns out to be an expensive operation.
     */
    public FontMetrics getFontMetrics(CpLightweightComponent component)
    {
        Font fontToUse;

        if (font == null) {
            fontToUse = component.getFont();
        } else {
            fontToUse = font;
        }
        return Toolkit.getDefaultToolkit().getFontMetrics(fontToUse);
    }

    abstract public void paintIn(CpLightweightComponent c, Graphics g, Rectangle r);
    abstract public void paintIn(CpLightweightComponent c, Graphics g, int x, int y, int w, int h);
    abstract public Dimension preferredSize(CpLightweightComponent c);
    abstract void setText(String text);
    abstract String getText();
}