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


package oracle.jdeveloper.html;

import java.io.PrintWriter;
import java.util.Vector;

/**
 *
 * Represents an HTML SELECT field. The SELECT FIELD is used to present a selection list to the user. If the SELECT
 * field allows selection of multiple values, a comman delimited list is sent to the HTML FORM processor.
 *
 * @author  Juan Oropeza
 * @version PUBLIC
 *
 **/

public class HTMLSelect extends HTMLElement
{
   protected   Vector   Elements = new Vector();
   protected   String   theName;
   protected   boolean  bScroll = false;
   protected   String   sWidth = null;
   protected   String   sHeight = null;
   
   /**
   *	contructs the SELECT object providing the field's name.
   */
   public HTMLSelect(String sName)
   {
      theName = sName;
      setCSSClassName("vrSelectField");      
   }

   /**
   *	contructs the SELECT object providing the field's name and a boolean for enabling/disabling
   * multiple selection.
   */
   public HTMLSelect(String sName, boolean bMultiple)
   {
      theName = sName;
      bScroll = bMultiple;
      setCSSClassName("vrSelectField");            
   }

   /**
   *	contructs the SELECT object providing the field's name and the CSS class name.
   */
   public HTMLSelect(String sName, String sClass)
   {
      theName = sName;
      bScroll = false;

      setCSSClassName(sClass);      
   }   

   
   /*
   *	Enables multiple selection.
   */
   public void setMultiple()
   {
      bScroll = true;
   }

   /**
   *	Disables multiple selection.
   */
   public void clearMultiple()
   {
      bScroll = true;
   }
   
   /**
   *	Sets the field width
   */
   public void setWidth(String sWidth)
   {
      this.sWidth =  sWidth;
   }

   /**
   *	Sets the field height
   */
   
   public void setHeight(String sHeight)
   {
      this.sHeight =  sHeight;
   }

   /**
   *	Adds an option to the list.
   *
   *	@param sOption	string value of the new option
   */
   public void addOption(String sOption)
   {
      Elements.addElement("<OPTION VALUE=\"" + sOption + "\">" + sOption);
   }

   /**
   *	Adds a selected option to the list.
   *
   *	@param sOption	string value of the new option
   */   
   public void addSelectedOption(String sOption)
   {
      Elements.addElement("<OPTION SELECTED VALUE=\"" + sOption + "\" >" + sOption);
   }

   /**
   *	Adds an option to the list.
   *
   *	@param sOption	string value of the new option
   *	@param sValue	the value for the new option.
   */   
   public void addOption(String sOption, String sValue)
   {
     Elements.addElement("<OPTION VALUE=\"" + sValue + "\">" + sOption); 
   }

   /**
   *	Adds a selected option to the list.
   *
   *	@param sOption	string value of the new option
   *	@param sValue	the value for the new option.
   */      
   public void addSelectedOption(String sOption, String sValue)
   {
     Elements.addElement("<OPTION SELECTED VALUE=\"" + sValue + "\">" + sOption); 
   }

   public void render(PrintWriter out)
   {
      int nSize = Elements.size();

      out.println("<SELECT ");
      
      if(bScroll)
         out.print(" MULTIPLE ");

      out.print(" NAME=\"" + theName +  "\" CLASS=\"" + getCSSClassName() + "\" ");

      if(sWidth != null)
      {
         out.print(" WIDTH =\"" + sWidth + "\" ");
      }
      
      if(sHeight != null)
      {
         out.print(" HEIGHT =\"" + sHeight + "\" ");
      }
      
      out.println(">");
      
      for(int i = 0 ; i < nSize ; i++)
      {
         out.println(Elements.elementAt(i));
      }

      out.println("</SELECT>");      
   }


}