// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) space 
// Source File Name:   TextLabel.java

package lt.monarch.awt;

import java.awt.*;

public class TextLabel extends Canvas
{

    public TextLabel()
    {
        this(2);
    }

    public TextLabel(int i)
    {
        text = new String[0];
        alignment = i;
    }

    public TextLabel(String s)
    {
        this(s, 2);
    }

    public TextLabel(String s, int i)
    {
        alignment = i;
        setText(s);
    }

    public TextLabel(String as[])
    {
        this(as, 2);
    }

    public TextLabel(String as[], int i)
    {
        alignment = i;
        text = as;
    }

    public void paint(Graphics g)
    {
        Rectangle rectangle = bounds();
        g.setColor(getForeground());
        FontMetrics fontmetrics = g.getFontMetrics();
        int i = fontmetrics.stringWidth(" ");
        for (int j = 0; j < text.length; j++)
            switch (alignment)
            {
            case 3: // '\003'
                g.drawString(text[j], rectangle.width - fontmetrics.stringWidth(text[j]) - i, j * fontmetrics.getHeight() + fontmetrics.getAscent());
                break;

            case 2: // '\002'
                g.drawString(text[j], i, j * fontmetrics.getHeight() + fontmetrics.getAscent());
                break;

            case 1: // '\001'
                g.drawString(text[j], (rectangle.width - fontmetrics.stringWidth(text[j])) / 2, j * fontmetrics.getHeight() + fontmetrics.getAscent());
                break;
            }

    }

    public Dimension preferredSize()
    {
        Graphics g = getGraphics();
        FontMetrics fontmetrics = g.getFontMetrics();
        int i = 0;
        for (int j = 0; j < text.length; j++)
        {
            int k = fontmetrics.stringWidth(text[j]);
            if (i < k)
                i = k;
        }

        int l = fontmetrics.stringWidth(" ");
        return new Dimension(i + l * 2, text.length * fontmetrics.getHeight());
    }

    public void setText(String s)
    {
        int i = 1;
        for (int j = 0; j < s.length(); j++)
            if (s.charAt(j) == '\n')
                i++;

        text = new String[i];
        for (int k = 0; k < i; k++)
            text[k] = new String();

        i = 0;
        for (int l = 0; l < s.length(); l++)
            switch (s.charAt(l))
            {
            case 10: // '\n'
                i++;
                break;

            case 11: // '\013'
            case 12: // '\f'
            default:
                text[i] += s.charAt(l);
                break;

            case 13: // '\r'
                break;
            }

    }

    public void update(Graphics g)
    {
        paint(g);
    }

    public static final int CENTER = 1;
    public static final int LEFT = 2;
    public static final int RIGHT = 3;
    protected String text[];
    protected int alignment;
}
