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


package oracle.jdeveloper.html;

import java.io.PrintWriter;

/**
 *
 * Represents a text element. This is an element you can add to a page when no tag is necessary.
 * @author  Charles Gayraud
 * @version PUBLIC
 *
 **/

public class HTMLInputElement extends HTMLElement
{
   protected   String   name;
   protected   String   type;
   protected   int      maxLength = -1;
   protected   String   size;
   protected   String   value;
   protected   String   className;
   protected   String   label;
   protected   boolean  checked;
   protected   int      tabIndex = -1;
   protected   String   onFocus;
   protected   String   onChange;
   protected   String   onBlur;
   protected   String   onSelect;

   public HTMLInputElement()
   {
   }

   public void setName(String name)
   {
      this.name = name;
   }
   
   public String getName()
   {
      return name;
   }

   public void setType(String type)
   {
      this.type = type;
   }
   
   public String getType()
   {
      return type;
   }

   
   public void setMaxLength(String smaxLength)
   {
      try
      {
         this.maxLength = Integer.parseInt(smaxLength);
      }
      catch (NumberFormatException ex)
      {

      }
   }
   
   public String getMaxLengthAsString()
   {
      return Integer.toString(maxLength);
   }
   
   public void setMaxLength(int maxLength)
   {
      this.maxLength = maxLength;
   }
   
   public int getMaxLength()
   {
      return maxLength;
   }

   public void setSize(String size)
   {
      this.size = size;
   }
   
   public String getSize()
   {
      return size;
   }

   public void setSize(int size)
   {
      this.size = Integer.toString(size);
   }
   
   public void setValue(String value)
   {
      this.value = value;
   }
   
   public String getValue()
   {
      return value;
   }
   
   public void setClassName(String className)
   {
      this.className = className;
   }
   
   public String getClassName()
   {
      return className;
   }
   
   public void setLabel(String label)
   {
      this.label = label;
   }
   
   public String getLabel()
   {
      return label;
   }

   public void setChecked(boolean checked)
   {
      this.checked = checked;
   }
   
   public boolean getChecked()
   {
      return checked;
   }

   public void setTabIndex(int tabIndex)
   {
      this.tabIndex = tabIndex;
   }
   
   public int getTabIndex()
   {
      return tabIndex;
   }

   public void setOnFocus(String onFocus)
   {
      this.onFocus = onFocus;
   }
   
   public String getOnFocus()
   {
      return onFocus;
   }
   
   public void setOnChange(String onChange)
   {
      this.onChange = onChange;
   }
   
   public String getOnChange()
   {
      return onChange;
   }
   
   public void setOnSelect(String onSelect)
   {
      this.onSelect = onSelect;
   }
   
   public String getOnSelect()
   {
      return onSelect;
   }
   
   public void setOnBlur(String onBlur)
   {
      this.onBlur = onBlur;
   }
   
   public String getOnBlur()
   {
      return onBlur;
   }
   
   public void render(PrintWriter out) throws Exception
   {
      out.print("<INPUT TYPE=\"");
      out.print(type);
      out.print("\"");
      
      if (checked)
      {
         out.print(" CHECKED");
      }
      
      if (tabIndex >= 0)
      {
         out.print(" TABINDEX=\"");
         out.print(Integer.toString(tabIndex));
         out.print("\"");
      }

      
      if (size != null && size.length() > 0)
      {
         out.print(" SIZE=\"");
         out.print(size);
         out.print("\"");
      }

      if (maxLength >= 0)
      {
         out.print(" MAXLENGTH=\"");
         out.print(getMaxLengthAsString());
         out.print("\"");
      }

      if (name != null && name.length() > 0)
      {
         out.print(" NAME=\"");
         out.print(name);
         out.print("\"");
      }

      if (className != null && className.length() > 0)
      {
         out.print(" CLASS=\"");
         out.print(className);
         out.print("\"");
      }
      
      if (value != null && value.length() > 0)
      {
         out.print(" VALUE=\"");
         out.print(value);
         out.print("\"");
      }
      
      if (onChange != null)
      {
         out.print(" onchange=\"");
         out.print(onChange);
         out.print("\"");
      }
      
      if (onChange != null)
      {
         out.print(" onselect=\"");
         out.print(onSelect);
         out.print("\"");
      }
      
      if (onFocus != null)
      {
         out.print(" onfocus=\"");
         out.print(onFocus);
         out.print("\"");
      }
      
      if (onBlur != null)
      {
         out.print(" onblur=\"");
         out.print(onBlur);
         out.print("\"");
      }
      
      out.print(">");
      
      if (label != null && label.length() > 0)
      {
         out.print(label);
      }
   }

}