APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing.text.html

public Class FormView

extends ComponentView
implements ActionListener
Class Inheritance
All Implemented Interfaces
java.awt.event.ActionListener, java.util.EventListener
Imports
java.awt.Component, .MediaTracker, .Point, java.awt.event.ActionEvent, .ActionListener, .ItemListener, .MouseAdapter, .MouseEvent, java.io.File, .IOException, java.net.MalformedURLException, .URL, .URLEncoder, java.util.BitSet, javax.swing.AbstractListModel, .Box, .ButtonModel, .ComboBoxModel, .DefaultButtonModel, .ImageIcon, .JButton, .JCheckBox, .JComboBox, .JComponent, .JEditorPane, .JFileChooser, .JList, .JPasswordField, .JRadioButton, .JScrollPane, .JTextArea, .JTextField, .JToggleButton, .ListModel, .ListSelectionModel, .SwingUtilities, .UIManager, javax.swing.event.ChangeListener, .DocumentListener, .HyperlinkEvent, .ListDataListener, javax.swing.text.AbstractDocument, .AttributeSet, .BadLocationException, .ComponentView, .Document, .Element, .ElementIterator, .PlainDocument, .StyleConstants, .View

Component decorator that implements the view interface for form elements, <input>, <textarea>, and <select>. The model for the component is stored as an attribute of the element (using StyleConstants.ModelAttribute), and is used to build the component of the view. The type of the model is assumed to of the type that would be set by HTMLDocument.HTMLReader.FormAction. If there are multiple views mapped over the document, they will share the embedded component models.

The following table shows what components get built by this view.

Shows what components get built by this view
Element Type Component built
input, type button JButton
input, type checkbox JCheckBox
input, type image JButton
input, type password JPasswordField
input, type radio JRadioButton
input, type reset JButton
input, type submit JButton
input, type text JTextField
select, size > 1 or multiple attribute defined JList in a JScrollPane
select, size unspecified or 1 JComboBox
textarea JTextArea in a JScrollPane
input, type file JTextField
Authors
Timothy Prinzing, Sunita Mani

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
FormView.BrowseFileAction

BrowseFileAction is used for input type == file.

protected class
FormView.MouseEventListener

MouseEventListener class to handle form submissions when an input with type equal to image is clicked on.

Field Summary

Modifier and TypeField and Description
private short
maxIsPreferred

Used to indicate if the maximum span should be the same as the preferred span.

pack-priv static final String
PostDataProperty

Document attribute name for storing POST data.

public static final String
RESET

Deprecated As of 1.3, value comes from UIManager UIManager property FormView.resetButtonText
If a value attribute is not specified for a FORM input element of type "reset", then this default string is used.
public static final String
SUBMIT

Deprecated As of 1.3, value now comes from UIManager property FormView.submitButtonText
If a value attribute is not specified for a FORM input element of type "submit", then this default string is used.

Constructor Summary

AccessConstructor and Description
public
FormView(Element
the element to decorate
elem
)

Creates a new FormView object.

Method Summary

Modifier and TypeMethod and Description
public void
actionPerformed(ActionEvent
the ActionEvent.
evt
)

Implements java.awt.event.ActionListener.actionPerformed.

Responsible for processing the ActionEvent.

private void
appendBuffer(StringBuilder buffer, String name, String value)

Appends name / value pairs into the buffer.

protected Component
private JComponent

Returns:

the component.
createInputComponent
(AttributeSet
set of attributes associated with the <INPUT> element.
attr
,
Object
the value of the StyleConstants.ModelAttribute
model
)

Creates a component for an <INPUT> element based on the value of the "type" attribute.

private void
getFormData(StringBuilder
the buffer that contains that data to submit
buffer
)

Iterates over the element hierarchy, extracting data from the models associated with the relevant form elements.

private Element
getFormElement()

Returns the Element representing the FORM.

private String

Returns:

the image data.
getImageData
(Point
associated with the mouse click.
point
)

Extracts the value of the name attribute associated with the input element of type image.

private String
getInputElementData(AttributeSet attr)

Returns the data associated with an <INPUT> form element.

public float

Returns:

the span the view would like to be rendered into >= 0. Typically the view is told to render into the span that is returned, although there is no guarantee. The parent may choose to resize or break the view.
getMaximumSpan
(int
may be either View.X_AXIS or View.Y_AXIS
axis
)

Overrides javax.swing.text.ComponentView.getMaximumSpan.

Determines the maximum span for this view along an axis.

private String
getTextAreaData(AttributeSet attr)

Returns the data associated with the <TEXTAREA> form element.

protected void
imageSubmit(String
the mouse click coordinates.
imageData
)

This method is called to submit a form in response to a click on an image -- an <INPUT> form element of type "image".

private boolean
isControl(Element elem)

Returns true if the Element elem represents a control.

pack-priv boolean
isLastTextOrPasswordField()

Iterates over the element hierarchy to determine if the element parameter, which is assumed to be an <INPUT> element of type password or text, is the last one of either kind, in the form to which it belongs.

private void
loadElementDataIntoBuffer(Element elem, StringBuilder buffer)

Loads the data associated with the element into the buffer.

private void
loadSelectData(AttributeSet attr, StringBuilder buffer)

Loads the buffer with the data associated with the Select form element.

private void
pack-priv void
resetForm()

Resets the form to its initial state by reinitializing the models associated with each form element to their initial values.

private void
protected void
submitData(String
data to submit
data
)

This method is responsible for submitting the form data.

Inherited from javax.swing.text.ComponentView:
getAlignmentgetComponentgetMinimumSpangetPreferredSpanmodelToViewpaintsetParentviewToModel

Field Detail

maxIsPreferredback to summary
private short maxIsPreferred

Used to indicate if the maximum span should be the same as the preferred span. This is used so that the Component's size doesn't change if there is extra room on a line. The first bit is used for the X direction, and the second for the y direction.

PostDataPropertyback to summary
pack-priv static final String PostDataProperty

Document attribute name for storing POST data. JEditorPane.getPostData() uses the same name, should be kept in sync.

RESETback to summary
public static final String RESET

Deprecated

As of 1.3, value comes from UIManager UIManager property FormView.resetButtonText

If a value attribute is not specified for a FORM input element of type "reset", then this default string is used.

Annotations
@Deprecated
SUBMITback to summary
public static final String SUBMIT

Deprecated

As of 1.3, value now comes from UIManager property FormView.submitButtonText

If a value attribute is not specified for a FORM input element of type "submit", then this default string is used.

Annotations
@Deprecated

Constructor Detail

FormViewback to summary
public FormView(Element elem)

Creates a new FormView object.

Parameters
elem:Element

the element to decorate

Method Detail

actionPerformedback to summary
public void actionPerformed(ActionEvent evt)

Implements java.awt.event.ActionListener.actionPerformed.

Responsible for processing the ActionEvent. If the element associated with the FormView, has a type of "submit", "reset", "text" or "password" then the action is processed. In the case of a "submit" the form is submitted. In the case of a "reset" the form is reset to its original state. In the case of "text" or "password", if the element is the last one of type "text" or "password", the form is submitted. Otherwise, focus is transferred to the next component in the form.

Parameters
evt:ActionEvent

the ActionEvent.

appendBufferback to summary
private void appendBuffer(StringBuilder buffer, String name, String value)

Appends name / value pairs into the buffer. Both names and values are encoded using the URLEncoder.encode() method before being added to the buffer.

Annotations
@SuppressWarnings:deprecation
createComponentback to summary
protected Component createComponent()

Overrides javax.swing.text.ComponentView.createComponent.

Create the component. This is basically a big switch statement based upon the tag type and html attributes of the associated element.

createInputComponentback to summary
private JComponent createInputComponent(AttributeSet attr, Object model)

Creates a component for an <INPUT> element based on the value of the "type" attribute.

Parameters
attr:AttributeSet

set of attributes associated with the <INPUT> element.

model:Object

the value of the StyleConstants.ModelAttribute

Returns:JComponent

the component.

getFormDataback to summary
private void getFormData(StringBuilder buffer)

Iterates over the element hierarchy, extracting data from the models associated with the relevant form elements. "Relevant" means the form elements that are part of the same form whose element triggered the submit action.

Parameters
buffer:StringBuilder

the buffer that contains that data to submit

getFormElementback to summary
private Element getFormElement()

Returns the Element representing the FORM.

getImageDataback to summary
private String getImageData(Point point)

Extracts the value of the name attribute associated with the input element of type image. If name is defined it is encoded using the URLEncoder.encode() method and the image data is returned in the following format: name + ".x" +"="+ x +"&"+ name +".y"+"="+ y otherwise, "x="+ x +"&y="+ y

Parameters
point:Point

associated with the mouse click.

Returns:String

the image data.

Annotations
@SuppressWarnings:deprecation
getInputElementDataback to summary
private String getInputElementData(AttributeSet attr)

Returns the data associated with an <INPUT> form element. The value of "type" attributes is used to determine the type of the model associated with the element and then the relevant data is extracted.

getMaximumSpanback to summary
public float getMaximumSpan(int axis)

Overrides javax.swing.text.ComponentView.getMaximumSpan.

Determines the maximum span for this view along an axis. For certain components, the maximum and preferred span are the same. For others this will return the value returned by Component.getMaximumSize along the axis of interest.

Parameters
axis:int

may be either View.X_AXIS or View.Y_AXIS

Returns:float

the span the view would like to be rendered into >= 0. Typically the view is told to render into the span that is returned, although there is no guarantee. The parent may choose to resize or break the view.

Exceptions
IllegalArgumentException:
for an invalid axis
getTextAreaDataback to summary
private String getTextAreaData(AttributeSet attr)

Returns the data associated with the <TEXTAREA> form element. This is done by getting the text stored in the Document model.

imageSubmitback to summary
protected void imageSubmit(String imageData)

This method is called to submit a form in response to a click on an image -- an <INPUT> form element of type "image".

Parameters
imageData:String

the mouse click coordinates.

isControlback to summary
private boolean isControl(Element elem)

Returns true if the Element elem represents a control.

isLastTextOrPasswordFieldback to summary
pack-priv boolean isLastTextOrPasswordField()

Iterates over the element hierarchy to determine if the element parameter, which is assumed to be an <INPUT> element of type password or text, is the last one of either kind, in the form to which it belongs.

loadElementDataIntoBufferback to summary
private void loadElementDataIntoBuffer(Element elem, StringBuilder buffer)

Loads the data associated with the element into the buffer. The format in which data is appended depends on the type of the form element. Essentially data is loaded in name/value pairs.

loadSelectDataback to summary
private void loadSelectData(AttributeSet attr, StringBuilder buffer)

Loads the buffer with the data associated with the Select form element. Basically, only items that are selected and have their name attribute set are added to the buffer.

removeStaleListenerForModelback to summary
private void removeStaleListenerForModel(Object model)
resetFormback to summary
pack-priv void resetForm()

Resets the form to its initial state by reinitializing the models associated with each form element to their initial values. param elem the element that triggered the reset

storePostDataback to summary
private void storePostData(HTMLDocument doc, String target, String data)
submitDataback to summary
protected void submitData(String data)

This method is responsible for submitting the form data. A thread is forked to undertake the submission.

Parameters
data:String

data to submit

javax.swing.text.html back to summary

private Class FormView.BrowseFileAction

extends Object
implements ActionListener
Class Inheritance
All Implemented Interfaces
java.awt.event.ActionListener, java.util.EventListener

BrowseFileAction is used for input type == file. When the user clicks the button a JFileChooser is brought up allowing the user to select a file in the file system. The resulting path to the selected file is set in the text field (actually an instance of Document).

Field Summary

Modifier and TypeField and Description
private AttributeSet
private Document

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
actionPerformed(ActionEvent ae)

Implements java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attrsback to summary
private AttributeSet attrs
modelback to summary
private Document model

Constructor Detail

BrowseFileActionback to summary
pack-priv BrowseFileAction(AttributeSet attrs, Document model)

Method Detail

actionPerformedback to summary
public void actionPerformed(ActionEvent ae)

Implements java.awt.event.ActionListener.actionPerformed.

Doc from java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.

javax.swing.text.html back to summary

protected Class FormView.MouseEventListener

extends MouseAdapter
Class Inheritance

MouseEventListener class to handle form submissions when an input with type equal to image is clicked on. A MouseListener is necessary since along with the image data the coordinates associated with the mouse click need to be submitted.

Constructor Summary

AccessConstructor and Description
protected
MouseEventListener()

Constructs a MouseEventListener.

Method Summary

Modifier and TypeMethod and Description
public void
mouseReleased(MouseEvent evt)

Overrides java.awt.event.MouseAdapter.mouseReleased.

Implements java.awt.event.MouseListener.mouseReleased.

Invoked when a mouse button has been released on a component.

Inherited from java.awt.event.MouseAdapter:
mouseClickedmouseDraggedmouseEnteredmouseExitedmouseMovedmousePressedmouseWheelMoved

Constructor Detail

MouseEventListenerback to summary
protected MouseEventListener()

Constructs a MouseEventListener.

Method Detail

mouseReleasedback to summary
public void mouseReleased(MouseEvent evt)

Overrides java.awt.event.MouseAdapter.mouseReleased.

Implements java.awt.event.MouseListener.mouseReleased.

Doc from java.awt.event.MouseAdapter.mouseReleased.

Invoked when a mouse button has been released on a component.