You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ecs-dev@jakarta.apache.org by sn...@apache.org on 2001/07/11 23:06:52 UTC

cvs commit: jakarta-ecs/src/java/org/apache/ecs/html Option.java Select.java

snagy       01/07/11 14:06:50

  Modified:    src/java/org/apache/ecs/html Option.java Select.java
  Log:
  Added methods to make things a little easier with options and selects.
  
  Revision  Changes    Path
  1.5       +45 -45    jakarta-ecs/src/java/org/apache/ecs/html/Option.java
  
  Index: Option.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ecs/src/java/org/apache/ecs/html/Option.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Option.java	2001/04/07 13:15:10	1.4
  +++ Option.java	2001/07/11 21:06:42	1.5
  @@ -15,23 +15,23 @@
    *
    * 3. All advertising materials mentioning features or use of this
    *    software must display the following acknowledgment:
  - *    "This product includes software developed by the Java Apache 
  + *    "This product includes software developed by the Java Apache
    *    Project. <http://java.apache.org/>"
    *
  - * 4. The names "Java Apache Element Construction Set", "Java Apache ECS" and 
  - *    "Java Apache Project" must not be used to endorse or promote products 
  + * 4. The names "Java Apache Element Construction Set", "Java Apache ECS" and
  + *    "Java Apache Project" must not be used to endorse or promote products
    *    derived from this software without prior written permission.
    *
  - * 5. Products derived from this software may not be called 
  - *    "Java Apache Element Construction Set" nor "Java Apache ECS" appear 
  - *    in their names without prior written permission of the 
  + * 5. Products derived from this software may not be called
  + *    "Java Apache Element Construction Set" nor "Java Apache ECS" appear
  + *    in their names without prior written permission of the
    *    Java Apache Project.
    *
    * 6. Redistributions of any form whatsoever must retain the following
    *    acknowledgment:
  - *    "This product includes software developed by the Java Apache 
  + *    "This product includes software developed by the Java Apache
    *    Project. <http://java.apache.org/>"
  - *    
  + *
    * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY
    * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  @@ -70,7 +70,7 @@
           .addElement(new option("value2").addElement("text2"))
   </pre>
   </code>
  -rather than 
  +rather than
   <code>
   <pre>
       new org.apache.ecs.html.Select
  @@ -78,7 +78,7 @@
           .addElement(new option("value2").addElement("text2")))
   </pre>
   </code>
  -(this change should not break existing code too badly since browsers generally display 
  +(this change should not break existing code too badly since browsers generally display
   the output from the above correctly).
   </p><p>
   Alternatively, you could use the new option constructor and do something like
  @@ -98,7 +98,7 @@
   </pre>
   </code>
   </p><p>
  -    @version $Id: Option.java,v 1.4 2001/04/07 13:15:10 rdonkin Exp $
  +    @version $Id: Option.java,v 1.5 2001/07/11 21:06:42 snagy Exp $
       @author <a href="mailto:snagy@servletapi.com">Stephan Nagy</a>
       @author <a href="mailto:jon@clearink.com">Jon S. Stevens</a>
   */
  @@ -113,21 +113,21 @@
           setElementType("option");
           setNeedClosingTag(true);
       }
  -    
  +
       /**
  -        Basic constructor. 
  +        Basic constructor.
           Use the set* methods to set the values
           of the attributes.
       */
       public Option()
       {
       }
  -    
  +
       /**
  -        Constructor sets the value attribute. 
  +        Constructor sets the value attribute.
           Use the set* methods to set the values
           of the other attributes.
  -        
  +
           @param value sets the attribute VALUE=""
       */
       public Option(String value)
  @@ -136,10 +136,10 @@
       }
   
       /**
  -        Constructor sets the value and label attributes. 
  +        Constructor sets the value and label attributes.
           Use the set* methods to set the values
           of the other attributes.
  -        
  +
           @param label sets the attribute LABEL=""
           @param value sets the attribute VALUE=""
       */
  @@ -150,10 +150,10 @@
       }
   
       /**
  -        Constructor sets the value and label attributes. 
  +        Constructor sets the value and label attributes.
           Use the set* methods to set the values
           of the other attributes.
  -        
  +
           @param label sets the attribute LABEL=""
           @param value sets the attribute VALUE=""
       */
  @@ -164,10 +164,10 @@
       }
   
       /**
  -        Constructor sets the value and label attributes. 
  +        Constructor sets the value and label attributes.
           Use the set* methods to set the values
           of the other attributes.
  -        
  +
           @param label sets the attribute LABEL=""
           @param value sets the attribute VALUE=""
       */
  @@ -178,10 +178,10 @@
       }
   
       /**
  -        Same as Option(label,value).addElement(text).  
  +        Same as Option(label,value).addElement(text).
           Use the set* methods to set the values
           of the other attributes.
  -        
  +
           @param label sets the attribute LABEL=""
           @param value sets the attribute VALUE=""
           @param text is added as an element
  @@ -193,10 +193,10 @@
       }
   
       /**
  -        Same as Option(label,value).addElement(text). 
  +        Same as Option(label,value).addElement(text).
           Use the set* methods to set the values
           of the other attributes.
  -        
  +
           @param label sets the attribute LABEL=""
           @param value sets the attribute VALUE=""
           @param text is added as an element
  @@ -208,10 +208,10 @@
       }
   
       /**
  -        Same as Option(label,value).addElement(text). 
  +        Same as Option(label,value).addElement(text).
           Use the set* methods to set the values
           of the other attributes.
  -        
  +
           @param label sets the attribute LABEL=""
           @param value sets the attribute VALUE=""
           @param text is added as an element
  @@ -231,7 +231,7 @@
           addAttribute("label",label);
           return this;
       }
  -    
  +
       /**
           Gets the LABEL attribute.
       */
  @@ -277,7 +277,7 @@
       {
           return getAttribute("value");
       }
  -    
  +
       /**
           Sets the selected value
           @param   selected  true or false
  @@ -288,7 +288,7 @@
               addAttribute("selected", NO_ATTRIBUTE_VALUE);
           else
               removeAttribute("selected");
  -            
  +
           return(this);
       }
   
  @@ -316,7 +316,7 @@
               addAttribute("disabled", NO_ATTRIBUTE_VALUE);
           else
               removeAttribute("disabled");
  -            
  +
           return(this);
       }
   
  @@ -333,7 +333,7 @@
               return false;
           }
       }
  -    
  +
       /**
           Adds an Element to the element.
           @param  hashcode name of element for hash table
  @@ -365,7 +365,7 @@
           addElementToRegistry(element);
           return(this);
       }
  -    
  +
       /**
           Adds an Element to the element.
           @param  element Adds an Element to the element.
  @@ -389,7 +389,7 @@
           }
           return(option);
       }
  -    
  +
       /**
           Removes an Element from the element.
           @param hashcode the name of the element to be removed.
  @@ -405,7 +405,7 @@
           pointing device or by tabbing navigation. This attribute may be used
           with the following elements: LABEL, INPUT, SELECT, TEXTAREA, and
           BUTTON.
  -        
  +
           @param The script
       */
       public void setOnFocus(String script)
  @@ -417,7 +417,7 @@
           The onblur event occurs when an element loses focus either by the
           pointing device or by tabbing navigation. It may be used with the same
           elements as onfocus.
  -        
  +
           @param The script
       */
       public void setOnBlur(String script)
  @@ -428,7 +428,7 @@
       /**
           The onsubmit event occurs when a form is submitted. It only applies to
           the FORM element.
  -        
  +
           @param The script
       */
       public void setOnSubmit(String script)
  @@ -439,7 +439,7 @@
       /**
           The onreset event occurs when a form is reset. It only applies to the
           FORM element.
  -        
  +
           @param The script
       */
       public void setOnReset(String script)
  @@ -450,7 +450,7 @@
       /**
           The onselect event occurs when a user selects some text in a text
           field. This attribute may be used with the INPUT and TEXTAREA elements.
  -        
  +
           @param The script
       */
       public void setOnSelect(String script)
  @@ -462,7 +462,7 @@
           The onchange event occurs when a control loses the input focus and its
           value has been modified since gaining focus. This attribute applies to
           the following elements: INPUT, SELECT, and TEXTAREA.
  -        
  +
           @param The script
       */
       public void setOnChange(String script)
  @@ -473,7 +473,7 @@
       /**
           The onclick event occurs when the pointing device button is clicked
           over an element. This attribute may be used with most elements.
  -        
  +
           @param The script
       */
       public void setOnClick(String script)
  @@ -544,7 +544,7 @@
       /**
           The onkeypress event occurs when a key is pressed and released over an
           element. This attribute may be used with most elements.
  -        
  +
           @param The script
       */
       public void setOnKeyPress(String script)
  @@ -555,7 +555,7 @@
       /**
           The onkeydown event occurs when a key is pressed down over an element.
           This attribute may be used with most elements.
  -        
  +
           @param The script
       */
       public void setOnKeyDown(String script)
  @@ -566,7 +566,7 @@
       /**
           The onkeyup event occurs when a key is released over an element. This
           attribute may be used with most elements.
  -        
  +
           @param The script
       */
       public void setOnKeyUp(String script)
  
  
  
  1.6       +60 -44    jakarta-ecs/src/java/org/apache/ecs/html/Select.java
  
  Index: Select.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ecs/src/java/org/apache/ecs/html/Select.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Select.java	2001/04/07 13:16:22	1.5
  +++ Select.java	2001/07/11 21:06:44	1.6
  @@ -15,23 +15,23 @@
    *
    * 3. All advertising materials mentioning features or use of this
    *    software must display the following acknowledgment:
  - *    "This product includes software developed by the Java Apache 
  + *    "This product includes software developed by the Java Apache
    *    Project. <http://java.apache.org/>"
    *
  - * 4. The names "Java Apache Element Construction Set", "Java Apache ECS" and 
  - *    "Java Apache Project" must not be used to endorse or promote products 
  + * 4. The names "Java Apache Element Construction Set", "Java Apache ECS" and
  + *    "Java Apache Project" must not be used to endorse or promote products
    *    derived from this software without prior written permission.
    *
  - * 5. Products derived from this software may not be called 
  - *    "Java Apache Element Construction Set" nor "Java Apache ECS" appear 
  - *    in their names without prior written permission of the 
  + * 5. Products derived from this software may not be called
  + *    "Java Apache Element Construction Set" nor "Java Apache ECS" appear
  + *    in their names without prior written permission of the
    *    Java Apache Project.
    *
    * 6. Redistributions of any form whatsoever must retain the following
    *    acknowledgment:
  - *    "This product includes software developed by the Java Apache 
  + *    "This product includes software developed by the Java Apache
    *    Project. <http://java.apache.org/>"
  - *    
  + *
    * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY
    * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  @@ -53,6 +53,7 @@
   package org.apache.ecs.html;
   
   import org.apache.ecs.*;
  +import java.util.Enumeration;
   
   /**
       <p>
  @@ -61,11 +62,11 @@
       <strong>Please note</strong> that the {@link Option} element now defaults
       to add a closing tag (as is now required by the specification).
       </p>
  -    @version $Id: Select.java,v 1.5 2001/04/07 13:16:22 rdonkin Exp $
  +    @version $Id: Select.java,v 1.6 2001/07/11 21:06:44 snagy Exp $
       @author <a href="mailto:snagy@servletapi.com">Stephan Nagy</a>
       @author <a href="mailto:jon@clearink.com">Jon S. Stevens</a>
   */
  -public class Select extends MultiPartElement implements 
  +public class Select extends MultiPartElement implements
       Printable, PageEvents, FormEvents, MouseEvents, KeyEvents, FocusEvents
   {
       /**
  @@ -75,7 +76,7 @@
           setElementType("select");
       }
       /**
  -        Basic constructor. 
  +        Basic constructor.
           Use the set* methods to set attributes.
       */
       public Select()
  @@ -85,7 +86,7 @@
       /**
           Constructor sets the name attribute.
           Use the set* methods to set the other attributes.
  -        
  +
           @param name  set the NAME="" attribute
       */
       public Select(String name)
  @@ -96,7 +97,7 @@
       /**
           Constructor sets the name and size attribute.
           Use the set* methods to set the other attributes.
  -         
  +
           @param name  set the NAME="" attribute
           @param name  set the SIZE="" attribute
       */
  @@ -109,7 +110,7 @@
       /**
           Constructor sets the name and size attribute.
           Use the set* methods to set the other attributes.
  -         
  +
           @param name  set the NAME="" attribute
           @param name  set the SIZE="" attribute
       */
  @@ -122,7 +123,7 @@
       /**
           Constructor sets the name attribute and adds all the elements in the array.
           Use the set* methods to set the other attributes.
  -        
  +
           @param name set the NAME="" attribute
           @param element provide a group of strings to be converted to options elements.
       */
  @@ -135,7 +136,7 @@
       /**
           Constructor sets the name attribute and adds all the option elements in the array.
           Use the set* methods to set the other attributes.
  -        
  +
           @param name set the NAME="" attribute
           @param element provide a group of strings to be converted to options elements.
       */
  @@ -211,6 +212,21 @@
           return(this);
       }
   
  +    public Select selectOption(int option)
  +    {
  +        Enumeration enum = keys();
  +        for(int x = 0; enum.hasMoreElements(); x++)
  +        {
  +            ConcreteElement element = (ConcreteElement)getElement((String)enum.nextElement());
  +            if(x == option)
  +            {
  +                ((Option)element).setSelected(true);
  +                break;
  +            }
  +        }
  +        return this;
  +    }
  +
       /**
           <p>
           Creates and appends an option element.
  @@ -218,7 +234,7 @@
           Same as addElement(new org.apache.ecs.html.Option(value)).
           </p>
           @param     value creates an option with value attribute set.
  -    */    
  +    */
       public Select appendOption(String value)
       {
           return addElement(new org.apache.ecs.html.Option(value));
  @@ -232,7 +248,7 @@
           </p>
           @param     label creates an option with label attribute set.
           @param     value creates an option with value attribute set.
  -    */    
  +    */
       public Select appendOption(String label,String value)
       {
           return addElement(new org.apache.ecs.html.Option(label,value));
  @@ -246,12 +262,12 @@
           </p>
           @param     label creates an option with label attribute set.
           @param     value creates an option with value attribute set.
  -    */    
  +    */
       public Select appendOption(String label,int value)
       {
           return addElement(new org.apache.ecs.html.Option(label,value));
       }
  -    
  +
       /**
           <p>
           Creates and appends an option element.
  @@ -260,12 +276,12 @@
           </p>
           @param     label creates an option with label attribute set.
           @param     value creates an option with value attribute set.
  -    */    
  +    */
       public Select appendOption(String label,double value)
       {
           return addElement(new org.apache.ecs.html.Option(label,value));
       }
  -    
  +
       /**
           <p>
           Creates and appends an option element.
  @@ -275,7 +291,7 @@
           @param     label creates an option with label attribute set.
           @param     value creates an option with value attribute set.
           @param     text added to the option as a text element.
  -    */    
  +    */
       public Select appendOption(String label,String value,String text)
       {
           return addElement(new org.apache.ecs.html.Option(label,value,text));
  @@ -290,12 +306,12 @@
           @param     label creates an option with label attribute set.
           @param     value creates an option with value attribute set.
           @param     text added to the option as a text element.
  -    */    
  +    */
       public Select appendOption(String label,int value,String text)
       {
           return addElement(new org.apache.ecs.html.Option(label,value,text));
       }
  -    
  +
       /**
           <p>
           Creates and appends an option element.
  @@ -305,7 +321,7 @@
           @param     label creates an option with label attribute set.
           @param     value creates an option with value attribute set.
           @param     text added to the option as a text element.
  -    */    
  +    */
       public Select appendOption(String label,double value,String text)
       {
           return addElement(new org.apache.ecs.html.Option(label,value,text));
  @@ -330,7 +346,7 @@
           addAttribute("size",size);
           return this;
       }
  -    
  +
       /**
           Sets the SIZE="" attribute
           @param   size  the SIZE="" attribute
  @@ -351,7 +367,7 @@
               addAttribute("multiple", NO_ATTRIBUTE_VALUE);
           else
               removeAttribute("multiple");
  -            
  +
           return(this);
       }
   
  @@ -364,7 +380,7 @@
           addAttribute("tabindex",index);
           return this;
       }
  -    
  +
       /**
           Sets the TABINDEX="" attribute
           @param   alt  the TABINDEX="" attribute
  @@ -374,7 +390,7 @@
           setTabindex(Integer.toString(index));
           return this;
       }
  -    
  +
       /**
           Sets the disabled value
           @param   disabled  true or false
  @@ -385,7 +401,7 @@
               addAttribute("disabled", NO_ATTRIBUTE_VALUE);
           else
               removeAttribute("disabled");
  -            
  +
           return(this);
       }
       /**
  @@ -402,7 +418,7 @@
           The onload event occurs when the user agent finishes loading a window
           or all frames within a FRAMESET. This attribute may be used with BODY
           and FRAMESET elements.
  -        
  +
           @param The script
       */
       public void setOnLoad(String script)
  @@ -414,7 +430,7 @@
           The onunload event occurs when the user agent removes a document from a
           window or frame. This attribute may be used with BODY and FRAMESET
           elements.
  -        
  +
           @param The script
       */
       public void setOnUnload(String script)
  @@ -425,7 +441,7 @@
       /**
           The onsubmit event occurs when a form is submitted. It only applies to
           the FORM element.
  -        
  +
           @param The script
       */
       public void setOnSubmit(String script)
  @@ -436,7 +452,7 @@
       /**
           The onreset event occurs when a form is reset. It only applies to the
           FORM element.
  -        
  +
           @param The script
       */
       public void setOnReset(String script)
  @@ -447,7 +463,7 @@
       /**
           The onselect event occurs when a user selects some text in a text
           field. This attribute may be used with the INPUT and TEXTAREA elements.
  -        
  +
           @param The script
       */
       public void setOnSelect(String script)
  @@ -459,7 +475,7 @@
           The onchange event occurs when a control loses the input focus and its
           value has been modified since gaining focus. This attribute applies to
           the following elements: INPUT, SELECT, and TEXTAREA.
  -        
  +
           @param The script
       */
       public void setOnChange(String script)
  @@ -470,7 +486,7 @@
       /**
           The onclick event occurs when the pointing device button is clicked
           over an element. This attribute may be used with most elements.
  -        
  +
           @param The script
       */
       public void setOnClick(String script)
  @@ -541,7 +557,7 @@
       /**
           The onkeypress event occurs when a key is pressed and released over an
           element. This attribute may be used with most elements.
  -        
  +
           @param The script
       */
       public void setOnKeyPress(String script)
  @@ -552,7 +568,7 @@
       /**
           The onkeydown event occurs when a key is pressed down over an element.
           This attribute may be used with most elements.
  -        
  +
           @param The script
       */
       public void setOnKeyDown(String script)
  @@ -563,7 +579,7 @@
       /**
           The onkeyup event occurs when a key is released over an element. This
           attribute may be used with most elements.
  -        
  +
           @param The script
       */
       public void setOnKeyUp(String script)
  @@ -576,7 +592,7 @@
           pointing device or by tabbing navigation. This attribute may be used
           with the following elements: LABEL, INPUT, SELECT, TEXTAREA, and
           BUTTON.
  -        
  +
           @param The script
       */
       public void setOnFocus(String script)
  @@ -588,7 +604,7 @@
           The onblur event occurs when an element loses focus either by the
           pointing device or by tabbing navigation. It may be used with the same
           elements as onfocus.
  -        
  +
           @param The script
       */
       public void setOnBlur(String script)
  @@ -596,4 +612,4 @@
           addAttribute ( "onBlur", script );
       }
   
  -} 
  +}
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ecs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ecs-dev-help@jakarta.apache.org