/********************************************************************
 *  Oracle JDeveloper
 *  Copyright (c) 1997, 1999, Oracle Corporation. All rights reserved.
 ********************************************************************/

package oracle.jdeveloper.html;

import oracle.jdeveloper.html.*;
import oracle.jbo.*;

/**
 *
 *	Represents a textarea field renderer.
 *
 * @author  Juan Oropeza
 * @version PUBLIC
 *
 **/
 
public class TextArea extends HTMLFieldRendererImpl
{
  public TextArea()
  {
   this.setDisplayHeight(10);
   this.setDisplayWidth(60);
  }

  /**
   *	Adds a textarea text field with a target number of rows.
   *
   *	@param	sLabel		The label for the field.
   *	@param	sName		The field name.
   *	@param	sValue		The field value.
   *	@param	rows		Number of rows
   */
   public String createMultilineTextField(String sName , String sValue)
   {
      String sText;

      if(this.getDisplayWidth() <= 0)
      {
         this.setDisplayWidth(20);
      }

      sText = "<TEXTAREA NAME=\""+ sName + "\" ROWS=" + this.getDisplayHeight() + " COLS="
                  + this.getDisplayWidth() + ">" + sValue + "</TEXTAREA>";
      sText += "<INPUT TYPE=\"HIDDEN\" NAME=\"_"+ sName + "\" VALUE=\"" + sValue + "\"/>";

      return sText;
  }

  public String renderToString(HTMLRenderingContext ctx , RowSet rs, Row row , String sAttribute)
   {
      String sText;

      Object obj = row.getAttribute(sAttribute);

      if(obj == null)
      {
         sText = createMultilineTextField(sAttribute , "&nbsp;");
      }
      else
      {
         sText = createMultilineTextField(sAttribute , obj.toString());
      }
      return sText;
   }
}

