lapisx.swing
Class HTMLFormAccess

java.lang.Object
  extended bylapisx.swing.HTMLFormAccess

public class HTMLFormAccess
extends Object

This class provides access to the form fields of an HTML document displayed by a JEditorPane, so that an HTML form can be used for input in a Java program.

Only certain types of form fields can be accessed by the get* and set* methods in this class:

Other form fields (such as buttons and multiple-selection lists) can be accessed by calling getFieldModel() to obtain the field's model object and accessing it directly.

Warning: form fields are not accessible until JEditorPane has finished loading the HTML page. To initialize form fields, you should use a PropertyChangeListener that listens for the "page" property to change:

 final JEditorPane editor = new JEditorPane (myURL);
 editor.addPropertyChangeListener (new PropertyChangeListener () {
     public void propertyChange (PropertyChangeEvent event) {
         if ("page".equals (event.getPropertyName ()))
             HTMLFormAccess access = new HTMLFormAccess (editor);
             access.setStringValue (name, value); // etc.
         }
     });
 


Constructor Summary
HTMLFormAccess(JEditorPane editor)
          Make an HTMLFormAccess object.
 
Method Summary
 boolean getBooleanValue(String name)
          Gets value of a checkbox or radio button.
 Object getFieldModel(String name)
          Get the model for a form field.
 String getStringValue(String name)
          Get value of a text field or single-selection list.
 void setBooleanValue(String name, boolean value)
          Set value of a checkbox or radio button.
 void setStringValue(String name, String value)
          Set value of a text field or single-selection list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTMLFormAccess

public HTMLFormAccess(JEditorPane editor)
Make an HTMLFormAccess object.

Parameters:
editor - JEditorPane containing an HTML form to access.
Method Detail

getStringValue

public String getStringValue(String name)
Get value of a text field or single-selection list.

Parameters:
name - name attribute of form field to access (case-sensitive)
Returns:
value of form field (empty string if it's a list with no selection).
Throws:
IllegalArgumentException - if no field by that name is found
ClassCastException - if the field is found but is not a text field or single-selection list

setStringValue

public void setStringValue(String name,
                           String value)
Set value of a text field or single-selection list.

Parameters:
name - name attribute of form field to access (case-sensitive)
value - value to store in form field
Throws:
IllegalArgumentException - if no field by that name is found, or if the field is a single-selection list and the value is not one of the choices
ClassCastException - if the field is found but is not a text field or single-selection list

getBooleanValue

public boolean getBooleanValue(String name)
Gets value of a checkbox or radio button.

Parameters:
name - name attribute of form field to access (case-sensitive)
Returns:
true if form field is checked, false if not
Throws:
IllegalArgumentException - if no field by that name is found
ClassCastException - if the field is found but is not a checkbox or radio button

setBooleanValue

public void setBooleanValue(String name,
                            boolean value)
Set value of a checkbox or radio button.

Parameters:
name - name attribute of form field to access (case-sensitive)
value - value to set in form field
Throws:
IllegalArgumentException - if no field by that name is found
ClassCastException - if the field is found but is not a checkbox or radio button

getFieldModel

public Object getFieldModel(String name)
Get the model for a form field.

Parameters:
name - name attribute of form field to access (case-sensitive)
Returns:
object representing the form field's model. For text fields, the model is a Document. For buttons, checkboxes, and radio buttons, it is a ButtonModel. For lists, it is a ListModel and a ListSelectionModel (implements both).
Throws:
IllegalArgumentException - if no field by that name is found