/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* 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 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
* <code>HTMLDocument.HTMLReader.FormAction</code>. If there are
* multiple views mapped over the document, they will share the
* embedded component models.
* <p>
* The following table shows what components get built
* by this view.
* <table summary="shows what components get built by this view">
* <tr>
* <th>Element Type</th>
* <th>Component built</th>
* </tr>
* <tr>
* <td>input, type button</td>
* <td>JButton</td>
* </tr>
* <tr>
* <td>input, type checkbox</td>
* <td>JCheckBox</td>
* </tr>
* <tr>
* <td>input, type image</td>
* <td>JButton</td>
* </tr>
* <tr>
* <td>input, type password</td>
* <td>JPasswordField</td>
* </tr>
* <tr>
* <td>input, type radio</td>
* <td>JRadioButton</td>
* </tr>
* <tr>
* <td>input, type reset</td>
* <td>JButton</td>
* </tr>
* <tr>
* <td>input, type submit</td>
* <td>JButton</td>
* </tr>
* <tr>
* <td>input, type text</td>
* <td>JTextField</td>
* </tr>
* <tr>
* <td>select, size > 1 or multiple attribute defined</td>
* <td>JList in a JScrollPane</td>
* </tr>
* <tr>
* <td>select, size unspecified or 1</td>
* <td>JComboBox</td>
* </tr>
* <tr>
* <td>textarea</td>
* <td>JTextArea in a JScrollPane</td>
* </tr>
* <tr>
* <td>input, type file</td>
* <td>JTextField</td>
* </tr>
* </table>
*
* @author Timothy Prinzing
* @author Sunita Mani
*/
/**
* If a value attribute is not specified for a FORM input element
* of type "submit", then this default string is used.
*
* @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 "reset", then this default string is used.
*
* @deprecated As of 1.3, value comes from UIManager UIManager property
* FormView.resetButtonText
*/
/**
* Document attribute name for storing POST data. JEditorPane.getPostData()
* uses the same name, should be kept in sync.
*/
/**
* 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.
*/
private short maxIsPreferred;
/**
* Creates a new FormView object.
*
* @param elem the element to decorate
*/
super(elem);
}
/**
* Create the component. This is basically a
* big switch statement based upon the tag type
* and html attributes of the associated element.
*/
JComponent c = null;
// Remove listeners previously registered in shared model
// when a new UI component is replaced. See bug 8008289.
if (model instanceof OptionListModel) {
1);
c = new JScrollPane(list);
} else {
maxIsPreferred = 3;
}
1);
20);
maxIsPreferred = 3;
c = new JScrollPane(area,
}
if (c != null) {
c.setAlignmentY(1.0f);
}
return c;
}
/**
* Creates a component for an <INPUT> element based on the
* value of the "type" attribute.
*
* @param set of attributes associated with the <INPUT> element.
* @param model the value of the StyleConstants.ModelAttribute
* @return the component.
*/
JComponent c = null;
} else {
}
}
button.addActionListener(this);
}
c = button;
maxIsPreferred = 3;
try {
} catch (MalformedURLException e) {
}
}
c = button;
maxIsPreferred = 3;
c = new JCheckBox();
}
maxIsPreferred = 3;
c = new JRadioButton();
}
maxIsPreferred = 3;
-1);
if (size > 0) {
field = new JTextField();
}
else {
field = new JTextField();
}
c = field;
}
field.addActionListener(this);
maxIsPreferred = 3;
c = field;
}
-1);
field.addActionListener(this);
maxIsPreferred = 3;
}
-1);
("FormView.browseFileButtonText"));
c = box;
maxIsPreferred = 3;
}
return c;
}
if (model instanceof DefaultButtonModel) {
// case of JButton whose model is DefaultButtonModel
// Need to remove stale ActionListener, ChangeListener and
// ItemListener that are instance of AbstractButton$Handler.
}
}
}
}
}
}
} else if (model instanceof AbstractListModel) {
// case of JComboBox and JList
// For JList, the stale ListDataListener is instance
// BasicListUI$Handler.
// For JComboBox, there are 2 stale ListDataListeners, which are
// BasicListUI$Handler and BasicComboBoxUI$Handler.
"javax.swing.plaf.basic.BasicListUI$Handler";
"javax.swing.plaf.basic.BasicComboBoxUI$Handler";
{
}
}
} else if (model instanceof AbstractDocument) {
// case of JPasswordField, JTextField and JTextArea
// All have 2 stale DocumentListeners.
"javax.swing.plaf.basic.BasicTextUI$UpdateHandler";
"javax.swing.text.DefaultCaret$Handler";
{
}
}
}
}
/**
* 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.
*
* @param axis may be either View.X_AXIS or View.Y_AXIS
* @return 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.
* @exception IllegalArgumentException for an invalid axis
*/
switch (axis) {
super.getMaximumSpan(axis);
return getPreferredSpan(axis);
}
return super.getMaximumSpan(axis);
super.getMaximumSpan(axis);
return getPreferredSpan(axis);
}
return super.getMaximumSpan(axis);
default:
break;
}
return super.getMaximumSpan(axis);
}
/**
* 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.
*
* @param evt the ActionEvent.
*/
resetForm();
if (isLastTextOrPasswordField()) {
} else {
}
}
}
/**
* This method is responsible for submitting the form data.
* A thread is forked to undertake the submission.
*/
target = "_self";
}
method = "GET";
}
if (isPostMethod) {
}
try {
if (!isPostMethod) {
}
} catch (MalformedURLException e) {
}
formEvent = new FormSubmitEvent(
}
// setPage() may take significant time so schedule it to run later.
public void run() {
} else {
try {
} catch (IOException e) {
}
}
}
});
}
/* POST data is stored into the document property named by constant
* PostDataProperty from where it is later retrieved by method
* JEditorPane.getPostData(). If the current document is in a frame,
* the data is initially put into the toplevel (frameset) document
* property (named <PostDataProperty>.<Target frame name>). It is the
* responsibility of FrameView which updates the target frame
* to move data from the frameset document property into the frame
* document property.
*/
if (doc.isFrameDocument()) {
// find the top-most JEditorPane holding the frameset view.
FrameView v = p.getFrameView();
JEditorPane c = v.getOutermostJEditorPane();
if (c != null) {
propDoc = c.getDocument();
}
}
}
/**
* 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.
*/
}
}
/**
* This method is called to submit a form in response
* to a click on an image -- an <INPUT> form
* element of type "image".
*
* @param imageData the mouse click coordinates.
*/
}
return;
}
/**
* 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
*
* @param point associated with the mouse click.
* @return the image data.
*/
} else {
}
return data;
}
/**
* The following methods provide functionality required to
* iterate over a the elements of the form and in the case
* of a form submission, extract the data from each model
* that is associated with each form element, and in the
* case of reset, reinitialize the each model to its
* initial state.
*/
/**
* Returns the Element representing the <code>FORM</code>.
*/
return elem;
}
}
return null;
}
/**
* 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.
*
* @param buffer the buffer that contains that data to submit
* @param targetElement the element that triggered the
* form submission
*/
next != getElement()) {
// do nothing - this submit isnt the trigger
// images only result in data if they triggered
// the submit and they require that the mouse click
// coords be appended to the data. Hence its
// processing is handled by the view.
}
}
}
}
}
/**
* 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
*
*/
return;
}
}
}
}
/**
* 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.
*/
try {
} catch (BadLocationException e) {
}
value = "";
}
if (m.isSelected()) {
value = "on";
}
}
try {
} catch (BadLocationException e) {
}
}
}
return value;
}
/**
* Returns the data associated with the <TEXTAREA> form
* element. This is done by getting the text stored in the
* Document model.
*/
try {
} catch (BadLocationException e) {
return null;
}
}
/**
* 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.
*/
return;
}
if (m instanceof OptionListModel) {
if (model.isSelectedIndex(i)) {
}
}
} else if (m instanceof ComboBoxModel) {
}
}
}
/**
* Appends name / value pairs into the
* buffer. Both names and values are encoded using the
* URLEncoder.encode() method before being added to the
* buffer.
*/
}
}
/**
* Returns true if the Element <code>elem</code> represents a control.
*/
}
/**
* 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.
*/
boolean isLastTextOrPasswordField() {
boolean found = false;
found = true;
}
return false;
}
}
}
}
}
return true;
}
/**
* 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
*/
void resetForm() {
if (m instanceof TextAreaDocument) {
} else if (m instanceof PlainDocument) {
try {
}
}
} catch (BadLocationException e) {
}
} else if (m instanceof OptionListModel) {
for (int i = 0; i < size; i++) {
model.removeIndexInterval(i, i);
}
if (selectionRange.get(i)) {
model.addSelectionInterval(i, i);
}
}
} else if (m instanceof OptionComboBoxModel) {
}
} else if (m instanceof JToggleButton.ToggleButtonModel) {
}
}
}
}
}
/**
* 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).
*/
}
// PENDING: When mime support is added to JFileChooser use the
// accept value of attrs.
fc.setMultiSelectionEnabled(false);
try {
}
} catch (BadLocationException ble) {}
}
}
}
}
}