package cnp.ew.text;

import cnp.ew.lightweight.*;
import cnp.ew.util.*;
import cnp.ew.displayer.*;
import java.awt.*;
import java.lang.*;
import java.util.*;

public class CpReadOnlyTextAreaLc extends CpAbstractLc implements CpAlignable
{
    Object contents;
    CpGeneralStringDisplayer textDisplayer = new CpGeneralStringDisplayer();
    String text;


    public static final int SELECT_NONE = CpGeneralStringDisplayer.SELECT_NONE;
    public static final int SELECT_TEXT = CpGeneralStringDisplayer.SELECT_TEXT;
    public static final int SELECT_CELL = CpGeneralStringDisplayer.SELECT_CELL;

    public CpReadOnlyTextAreaLc(String string)
    {
        super();
        setText(string);
    }

    public CpReadOnlyTextAreaLc()
    {
        this("Empty Label");
    }

    public int getHorizontalAlignment()
    {
        return textDisplayer.horizontalAlignment;
    }

    public void setHorizontalAlignment(int alignmentStyle)
    {
        textDisplayer.horizontalAlignment = alignmentStyle;
        repaint();
    }

    public int getVerticalAlignment()
    {
        return textDisplayer.verticalAlignment;
    }

    public void setVerticalAlignment(int alignmentStyle)
    {
        textDisplayer.verticalAlignment = alignmentStyle;
        repaint();
    }

    public void setShouldWrap(boolean shouldWrap)
    {
        textDisplayer.setShouldWrap(shouldWrap);
        if (shouldWrap) {
            textDisplayer.setWrapWidth(getClientRect().width);
        }
        repaint();
    }

    public void setShouldDisplayDisabled(boolean shouldDisplay)
    {
        textDisplayer.setShouldDisplayDisabled(shouldDisplay);
    }

    public void setCharsPerLineToNumLinesRatio(int ratio)
    {
        textDisplayer.charsPerLineToNumLinesRatio = 5;
    }

    public void setForeground(Color color)
    {
        super.setForeground(color);
        textDisplayer.foreColor = color;
        repaint();
    }

    public void setBackground(Color color)
    {
        super.setBackground(color);
        textDisplayer.backColor = color;
        repaint();
    }

    public void setSelectionForeColor(Color color)
    {
        textDisplayer.selectionForeColor = color;
        repaint();
    }

    public void setSelectionBackColor(Color color)
    {
        textDisplayer.selectionBackColor = color;
        repaint();
    }

    public void setShowFocus(boolean drawFocusRect)
    {
        textDisplayer.setShowFocus(drawFocusRect);
        repaint();
    }

    public Dimension preferredSize()
    {
        return borderedPreferredSize(textDisplayer.preferredSize(this));
    }


    public void setTextList(Vector textList)
    {
        textDisplayer.setTextList(textList);
        repaint();
    }

    public void setText(String text)
    {
        // Ted added test. 10/23
        if (text.equals(this.text)) {
            return;
        }
	    this.text = text;
	    Vector stringList = new Vector();
	    StringTokenizer tokenizer = new StringTokenizer(text, "\r\n");
	    while (tokenizer.hasMoreTokens()) {
	        stringList.addElement(tokenizer.nextToken());
	    }
	    setTextList(stringList);
    }

    public String getText()
    {
        return text;
    }

    public int wrappedPreferredHeightFor(int width)
    {
        return textDisplayer.wrappedPreferredHeightFor(this, width);
    }

    public void paint(Graphics g, Rectangle clipRect)
    {
        Rectangle clientRect = getClientRect();
        g.setColor(getBackground());
        g.fillRect(0, 0, size().width, size().height);
	  textDisplayer.foreColor = getForeground();
        textDisplayer.paintIn(this, g, clientRect);
    }

    public void setSelectionExpansion(int expansion)
    {
        textDisplayer.setSelectionExpansion(expansion);
    }

    public void setSelectionStyle(int selectionStyle)
    {
        textDisplayer.selectionDisplayStyle = selectionStyle;
    }

    public void layout()
    {
        super.layout();
        textDisplayer.setWrapWidth(getClientRect().width);
    }

    public void setIsSelected(boolean isSelected)
    {
        textDisplayer.setIsSelected(isSelected);
    }


}