Package net.xoetrope.html

Source Code of net.xoetrope.html.XTextArea

package net.xoetrope.html;

import net.xoetrope.xui.XTextHolder;
import netscape.javascript.JSObject;
import org.w3c.dom.Node;
import org.w3c.dom.html.HTMLFormElement;
import org.w3c.dom.html.HTMLTextAreaElement;

/**
* <p>
* A wrapper for the AWT TextField class
* </p>
* <p>
* Copyright (c) Xoetrope Ltd., 1998-2004<br>
* License: see license.txt $Revision: 2.2 $
*/
public class XTextArea extends XHtmlWidget implements XTextHolder
{

  protected JSObject obj;

  /**
   * Create a new text area
   */
  public XTextArea()
  {
    super();
    HTMLTextAreaElement textarea = (HTMLTextAreaElement)htmlDoc.createElement( "TEXTAREA" );
    Node text = htmlDoc.getBody().getFirstChild().cloneNode( true );
    textarea.appendChild( text );
    textareaElement = textarea;
  }

  /**
   * Create a new XTextArea with an id and a specific value
   *
   * @param value
   *          the value of the text area
   * @param id
   *          the id of the text area
   */
  public XTextArea( String value, String id )
  {
    super();
    HTMLTextAreaElement textarea = (HTMLTextAreaElement)htmlDoc.createElement( "TEXTAREA" );
    Node text = htmlDoc.getBody().getFirstChild().cloneNode( true );
    textarea.appendChild( text );
    textarea.setId( id );
    textarea.setValue( value );
    textareaElement = textarea;
  }

  /**
   * Create a new XTextArea based on an existing HTML text area.
   *
   * @param textareaElement
   *          the HTML input tag the XTextArea refers to
   */
  public XTextArea( HTMLTextAreaElement textareaElement )
  {
    super( textareaElement );
  }

  /**
   * Lose focus on the current text area.
   */
  public void blur()
  {
    textareaElement.blur();
  }

  /**
   * Focus on the current text area.
   */
  public void focus()
  {
    textareaElement.focus();
  }

  /**
   * Select all the content of the current text area.
   */
  public void select()
  {
    textareaElement.select();
  }

  /**
   * Set the default value of the XTextArea.
   *
   * @param value
   *          the default value
   */
  public void setDefaultValue( String value )
  {
    textareaElement.setDefaultValue( value );
  }

  /**
   * Get the default value of the XTextArea.
   *
   * @return the default value
   */
  public String getDefaultValue()
  {
    return textareaElement.getDefaultValue();
  }

  /**
   * Get the text content of the current text area.
   *
   * @return the content of the text area
   */
  public String getText()
  {
    return (String)getValue();
  }

  /**
   * Set the text content of the current text area.
   *
   * @param text
   *          the new text value of the text area
   */
  public void setText( String text )
  {
    setValue( text );
  }

  /**
   * Get the Object value of the text field
   *
   * @return the Object value for this field
   */
  public Object getValue()
  {
    return textareaElement.getValue();
  }

  /**
   * Set the Object value for the text field
   *
   * @param value
   *          the new object value
   */
  public void setValue( Object value )
  {
    textareaElement.setValue( value.toString() );
  }

  /**
   * Set the number of columns of the text area
   *
   * @param cols
   *          the number of columns
   */
  public void setCols( int cols )
  {
    textareaElement.setCols( cols );
  }

  /**
   * Set the number of rows of the text area
   *
   * @param rows
   *          the number of rows
   */
  public void setRows( int rows )
  {
    textareaElement.setRows( rows );
  }

  /**
   * Set both the number of rows and columns of the text area
   *
   * @param cols
   *          the number of columns
   * @param rows
   *          the number of rows
   */
  public void setColsAndRows( int cols, int rows )
  {
    textareaElement.setCols( cols );
    textareaElement.setRows( rows );
  }

  /**
   * Get the number of columns of the text area
   *
   * @return the number of columns
   */
  public int getCols()
  {
    return textareaElement.getCols();
  }

  /**
   * Get the number of rows of the text area
   *
   * @return the number of rows
   */
  public int getRows()
  {
    return textareaElement.getRows();
  }

  /**
   * Get both the number of rows and columns of the text area
   *
   * @return a String representation of the number of rows and columns
   */
  public String getColsAndRows()
  {
    return "Columns : " + textareaElement.getCols() + " ; Rows : " + textareaElement.getRows();
  }

  /**
   * Set the XTextArea visible or invisible.
   *
   * @param visible
   *          true if visible, false otherwise
   */
  public void setVisible( boolean visible )
  {
    obj = JSObject.getWindow( XApplet.getApplet() );
    String status = "";
    if ( !visible ) {
      status = "hidden";
    }
    else {
      status = "visible";
    }
    obj.eval( "document.all." + textareaElement.getId() + ".style.visibility = \"" + status + "\"" );
  }

  /**
   * Set the XTextArea enabled or disabled.
   *
   * @param enabled
   *          true if enabled, false otherwise
   * @todo fix this method
   */
  public void setEnabled( boolean enabled )
  {
    obj = JSObject.getWindow( XApplet.getApplet() );
    if ( !enabled ) {
      textareaElement.setDisabled( enabled );
    }
    else {
      /**
       * Methods getAttributeNode( String nodeName ) and removeAttribute( String
       * attribName ) not supported in FireFox.
       *
       * @todo remove the disabled attribute without using JavaScript
       */
      obj.eval( "document.all." + textareaElement.getId() + ".disabled = false" );
    }
  }

  /**
   * Set one or more attributes of the component.
   *
   * @param attribName
   *          the name of the attribute
   * @param attribValue
   *          the value of the attribute
   */
  public void setAttribute( String attribName, Object attribValue )
  {
    textareaElement.setAttribute( attribName, (String)attribValue );
  }

  /**
   * Get an attribute value
   *
   * @param attribName
   *          the attribute which value is requested
   * @return the value of this attribute
   */
  public String getAttribute( String attribName )
  {
    return textareaElement.getAttribute( attribName );
  }

  /**
   * Get the form this XTextArea belongs to.
   *
   * @return the HTML Form element
   */
  public HTMLFormElement getForm()
  {
    return textareaElement.getForm();
  }

  /**
   * Set whether the text area is read only
   *
   * @param readOnly
   *          true if the text area is read only, false otherwise
   */
  public void setReadOnly( boolean readOnly )
  {
    textareaElement.setReadOnly( readOnly );
  }

  /**
   * Get whether the text area is read only
   *
   * @return true if read only, false otherwise
   */
  public boolean getReadOnly()
  {
    return textareaElement.getReadOnly();
  }

  /**
   * Get the size of the XTextArea's text.
   *
   * @return the int value of the font size
   */
  public int getFontSize()
  {
    obj = JSObject.getWindow( XApplet.getApplet() );
    return Integer.parseInt( (String)obj.eval( "document.all." + textareaElement.getId() + ".style.fontSize" ) );
  }

  /**
   * Set the size of the XTextArea's text.
   *
   * @param fontsize
   *          the int value of the font size
   */
  public void setFontSize( int fontsize )
  {
    obj = JSObject.getWindow( XApplet.getApplet() );
    obj.eval( "document.all." + textareaElement.getId() + ".style.fontSize = \"" + fontsize + "\"" );
  }

  /**
   * Get the background color of the XTextArea.
   *
   * @return the hexadecimal value of the background color
   */
  public String getBackgroundColor()
  {
    obj = JSObject.getWindow( XApplet.getApplet() );
    return (String)obj.eval( "document.all." + textareaElement.getId() + ".style.background" );
  }

  /**
   * Set the background color of the XTextArea.
   *
   * @param hexColor
   *          the hexadecimal value of the background color
   */
  public void setBackgroundColor( String hexColor )
  {
    obj = JSObject.getWindow( XApplet.getApplet() );
    obj.eval( "document.all." + textareaElement.getId() + ".style.background = \"" + hexColor + "\"" );
  }

  /**
   * Get the font color of the XTextArea's elements.
   *
   * @return the hexadecimal value of the font color
   */
  public String getFontColor()
  {
    obj = JSObject.getWindow( XApplet.getApplet() );
    return (String)obj.eval( "document.all." + textareaElement.getId() + ".style.color" );
  }

  /**
   * Set the font color of the XTextArea's elements.
   *
   * @param hexColor
   *          the hexadecimal value of the font color
   */
  public void setFontColor( String hexColor )
  {
    obj = JSObject.getWindow( XApplet.getApplet() );
    obj.eval( "document.all." + textareaElement.getId() + ".style.color = \"" + hexColor + "\"" );
  }

  /**
   * Get the HTML element at which refers the XTextArea.
   *
   * @return the HTML element.
   */
  public HTMLTextAreaElement getHTMLElement()
  {
    return textareaElement;
  }

}
TOP

Related Classes of net.xoetrope.html.XTextArea

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.