< prev index next >

src/java.desktop/share/classes/javax/swing/text/html/FormView.java

Print this page




  23  * questions.
  24  */
  25 package javax.swing.text.html;
  26 
  27 import java.net.*;
  28 import java.io.*;
  29 import java.awt.*;
  30 import java.awt.event.*;
  31 import java.util.*;
  32 import javax.swing.*;
  33 import javax.swing.event.*;
  34 import javax.swing.text.*;
  35 
  36 /**
  37  * Component decorator that implements the view interface
  38  * for form elements, &lt;input&gt;, &lt;textarea&gt;,
  39  * and &lt;select&gt;.  The model for the component is stored
  40  * as an attribute of the element (using StyleConstants.ModelAttribute),
  41  * and is used to build the component of the view.  The type
  42  * of the model is assumed to of the type that would be set by
  43  * <code>HTMLDocument.HTMLReader.FormAction</code>.  If there are
  44  * multiple views mapped over the document, they will share the
  45  * embedded component models.
  46  * <p>
  47  * The following table shows what components get built
  48  * by this view.
  49  * <table summary="shows what components get built by this view">
  50  * <tr>
  51  *   <th>Element Type</th>
  52  *   <th>Component built</th>
  53  * </tr>
  54  * <tr>
  55  *   <td>input, type button</td>
  56  *   <td>JButton</td>
  57  * </tr>
  58  * <tr>
  59  *   <td>input, type checkbox</td>
  60  *   <td>JCheckBox</td>
  61  * </tr>
  62  * <tr>
  63  *   <td>input, type image</td>


 613             data = "x="+ x +"&y="+ y;
 614         } else {
 615             name = URLEncoder.encode(name);
 616             data = name + ".x" +"="+ x +"&"+ name +".y"+"="+ y;
 617         }
 618         return data;
 619     }
 620 
 621 
 622     /**
 623      * The following methods provide functionality required to
 624      * iterate over a the elements of the form and in the case
 625      * of a form submission, extract the data from each model
 626      * that is associated with each form element, and in the
 627      * case of reset, reinitialize the each model to its
 628      * initial state.
 629      */
 630 
 631 
 632     /**
 633      * Returns the Element representing the <code>FORM</code>.
 634      */
 635     private Element getFormElement() {
 636         Element elem = getElement();
 637         while (elem != null) {
 638             if (elem.getAttributes().getAttribute
 639                 (StyleConstants.NameAttribute) == HTML.Tag.FORM) {
 640                 return elem;
 641             }
 642             elem = elem.getParentElement();
 643         }
 644         return null;
 645     }
 646 
 647     /**
 648      * Iterates over the
 649      * element hierarchy, extracting data from the
 650      * models associated with the relevant form elements.
 651      * "Relevant" means the form elements that are part
 652      * of the same form whose element triggered the submit
 653      * action.


 813 
 814     /**
 815      * Appends name / value pairs into the
 816      * buffer.  Both names and values are encoded using the
 817      * URLEncoder.encode() method before being added to the
 818      * buffer.
 819      */
 820     @SuppressWarnings("deprecation")
 821     private void appendBuffer(StringBuilder buffer, String name, String value) {
 822         if (buffer.length() > 0) {
 823             buffer.append('&');
 824         }
 825         String encodedName = URLEncoder.encode(name);
 826         buffer.append(encodedName);
 827         buffer.append('=');
 828         String encodedValue = URLEncoder.encode(value);
 829         buffer.append(encodedValue);
 830     }
 831 
 832     /**
 833      * Returns true if the Element <code>elem</code> represents a control.
 834      */
 835     private boolean isControl(Element elem) {
 836         return elem.isLeaf();
 837     }
 838 
 839     /**
 840      * Iterates over the element hierarchy to determine if
 841      * the element parameter, which is assumed to be an
 842      * &lt;INPUT&gt; element of type password or text, is the last
 843      * one of either kind, in the form to which it belongs.
 844      */
 845     boolean isLastTextOrPasswordField() {
 846         Element parent = getFormElement();
 847         Element elem = getElement();
 848 
 849         if (parent != null) {
 850             ElementIterator it = new ElementIterator(parent);
 851             Element next;
 852             boolean found = false;
 853 




  23  * questions.
  24  */
  25 package javax.swing.text.html;
  26 
  27 import java.net.*;
  28 import java.io.*;
  29 import java.awt.*;
  30 import java.awt.event.*;
  31 import java.util.*;
  32 import javax.swing.*;
  33 import javax.swing.event.*;
  34 import javax.swing.text.*;
  35 
  36 /**
  37  * Component decorator that implements the view interface
  38  * for form elements, &lt;input&gt;, &lt;textarea&gt;,
  39  * and &lt;select&gt;.  The model for the component is stored
  40  * as an attribute of the element (using StyleConstants.ModelAttribute),
  41  * and is used to build the component of the view.  The type
  42  * of the model is assumed to of the type that would be set by
  43  * {@code HTMLDocument.HTMLReader.FormAction}.  If there are
  44  * multiple views mapped over the document, they will share the
  45  * embedded component models.
  46  * <p>
  47  * The following table shows what components get built
  48  * by this view.
  49  * <table summary="shows what components get built by this view">
  50  * <tr>
  51  *   <th>Element Type</th>
  52  *   <th>Component built</th>
  53  * </tr>
  54  * <tr>
  55  *   <td>input, type button</td>
  56  *   <td>JButton</td>
  57  * </tr>
  58  * <tr>
  59  *   <td>input, type checkbox</td>
  60  *   <td>JCheckBox</td>
  61  * </tr>
  62  * <tr>
  63  *   <td>input, type image</td>


 613             data = "x="+ x +"&y="+ y;
 614         } else {
 615             name = URLEncoder.encode(name);
 616             data = name + ".x" +"="+ x +"&"+ name +".y"+"="+ y;
 617         }
 618         return data;
 619     }
 620 
 621 
 622     /**
 623      * The following methods provide functionality required to
 624      * iterate over a the elements of the form and in the case
 625      * of a form submission, extract the data from each model
 626      * that is associated with each form element, and in the
 627      * case of reset, reinitialize the each model to its
 628      * initial state.
 629      */
 630 
 631 
 632     /**
 633      * Returns the Element representing the {@code FORM}.
 634      */
 635     private Element getFormElement() {
 636         Element elem = getElement();
 637         while (elem != null) {
 638             if (elem.getAttributes().getAttribute
 639                 (StyleConstants.NameAttribute) == HTML.Tag.FORM) {
 640                 return elem;
 641             }
 642             elem = elem.getParentElement();
 643         }
 644         return null;
 645     }
 646 
 647     /**
 648      * Iterates over the
 649      * element hierarchy, extracting data from the
 650      * models associated with the relevant form elements.
 651      * "Relevant" means the form elements that are part
 652      * of the same form whose element triggered the submit
 653      * action.


 813 
 814     /**
 815      * Appends name / value pairs into the
 816      * buffer.  Both names and values are encoded using the
 817      * URLEncoder.encode() method before being added to the
 818      * buffer.
 819      */
 820     @SuppressWarnings("deprecation")
 821     private void appendBuffer(StringBuilder buffer, String name, String value) {
 822         if (buffer.length() > 0) {
 823             buffer.append('&');
 824         }
 825         String encodedName = URLEncoder.encode(name);
 826         buffer.append(encodedName);
 827         buffer.append('=');
 828         String encodedValue = URLEncoder.encode(value);
 829         buffer.append(encodedValue);
 830     }
 831 
 832     /**
 833      * Returns true if the Element {@code elem} represents a control.
 834      */
 835     private boolean isControl(Element elem) {
 836         return elem.isLeaf();
 837     }
 838 
 839     /**
 840      * Iterates over the element hierarchy to determine if
 841      * the element parameter, which is assumed to be an
 842      * &lt;INPUT&gt; element of type password or text, is the last
 843      * one of either kind, in the form to which it belongs.
 844      */
 845     boolean isLastTextOrPasswordField() {
 846         Element parent = getFormElement();
 847         Element elem = getElement();
 848 
 849         if (parent != null) {
 850             ElementIterator it = new ElementIterator(parent);
 851             Element next;
 852             boolean found = false;
 853 


< prev index next >