harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r427121 [14/29] - in /incubator/harmony/enhanced/classlib/trunk/modules/swing: make/ src/main/java/common/javax/swing/ src/main/java/common/javax/swing/text/ src/main/java/common/javax/swing/text/html/ src/main/java/common/javax/swing/text/...
Date Mon, 31 Jul 2006 14:08:55 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/FormViewTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/FormViewTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/FormViewTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/FormViewTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,1048 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Roman I. Chernyatchik
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.io.StringReader;
+
+import javax.swing.Box;
+import javax.swing.ButtonModel;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JEditorPane;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JPasswordField;
+import javax.swing.JRadioButton;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.JViewport;
+import javax.swing.SwingTestCase;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.Document;
+import javax.swing.text.Element;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.PlainDocument;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.View;
+
+import org.apache.harmony.x.swing.text.html.form.FormAttributes;
+
+public class FormViewTest extends SwingTestCase {
+
+    private HTMLDocument doc;
+
+    private HTMLEditorKit htmlEditorKit;
+
+    private JEditorPane editorPane;
+
+    private Element elem;
+
+    private FormView formView;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        setIgnoreNotImplemented(true);
+        
+        htmlEditorKit = new HTMLEditorKit();
+        editorPane = new JEditorPane();
+        editorPane.setEditorKit(htmlEditorKit);
+        doc = (HTMLDocument) editorPane.getDocument();
+
+        StringBuffer src = new StringBuffer();
+        src.append("<HTML>");
+        src.append("<HEAD></HEAD>");
+        src.append("<BODY>");
+        src.append("   Hello word!");
+        src.append("<FORM ACTION = \"\">");
+        src.append("    <INPUT TYPE = \"button\" NAME =\"button_name\" "
+                   + "VALUE = \"button:JButton\" ID=\"button\">");
+        src.append("    <INPUT TYPE = \"checkbox\" NAME =\"checkbox_name\" "
+                   + "VALUE = \"checkbox:JCheckBox\" ID=\"checkbox\">");
+        src.append("    <INPUT TYPE = \"checkbox\" NAME =\"checked "
+                   + "checkbox_name\" VALUE = \"checked checkbox:JCheckBox\" "
+                   + "CHECKED ID=\"checked checkbox\">");
+        src.append("    <INPUT TYPE = \"image\" NAME =\"image_name\" "
+                   + "VALUE = \"image:JButton\" ID=\"image\">");
+        src.append("    <INPUT TYPE = \"password\" NAME =\"password_name\" "
+                   + "VALUE = \"password:JPasswordField\" ID=\"password\">");
+        src.append("    <INPUT TYPE = \"radio\" NAME =\"radio1_name\" "
+                   + "value = \"radio:JRadioButton\" ID=\"radio\">");
+        src.append("    <INPUT TYPE = \"radio\" NAME =\"radio2_name\" "
+                   + "value = \"radio:JRadioButton\" ID=\"radio2\">");
+        src.append("    <INPUT TYPE = \"radio\" NAME =\"checked radio_name\" "
+                   + "value = \"checked radio:JRadioButton\" CHECKED "
+                   + "ID=\"checked radio\">");
+        src.append("    <INPUT TYPE = \"reset\" NAME =\"reset_name\" "
+                   + "VALUE = \"reset:JButton\" ID=\"reset\">");
+        src.append("    <INPUT TYPE = \"submit\" NAME =\"submit_name\" "
+                   + "VALUE = \"submit:JButton\" ID=\"submit\">");
+        src.append("    <INPUT TYPE = \"text\" NAME =\"text_name\" "
+                   + "VALUE = \"text:JTextField\" ID=\"text\">");
+        src.append("    <INPUT TYPE = \"text\" "
+                   + "NAME =\"disabled_text_name\" disabled VALUE = "
+                   + "\"disabled_text:JTextField\" ID=\"disabled_text\">");
+        src.append("    <INPUT TYPE = \"file\" NAME =\"file_name\" "
+                   + "VALUE = \"file:JTextField\" ID=\"file\">");
+        src.append("    <SELECT NAME = \"select_name\" ID=\"select_0\">");
+        src.append("    </SELECT>");
+        src.append("    <SELECT NAME = \"select_name\" ID=\"select\">");
+        src.append("        <OPTION VALUE = \"case1\" SELECTED> case1");
+        src.append("    </SELECT>");
+        src.append("    <SELECT NAME = \"select_name\" ID=\"select_many\">");
+        src.append("        <OPTION VALUE = \"case1\"> case1");
+        src.append("        <OPTION VALUE = \"case2\" SELECTED> case2");
+        src.append("        <OPTION VALUE = \"case3\" SELECTED> case3");
+        src.append("    </SELECT>");
+        src.append("    <SELECT NAME = \"select_name\" MULTIPLE "
+                   + "ID=\"select_multiple\">");
+        src.append("        <OPTION VALUE = \"case1\"> case1");
+        src.append("    </SELECT>");
+        src.append("    <SELECT NAME = \"select_name\" MULTIPLE "
+                   + "ID=\"select_multiple_many\">");
+        src.append("        <OPTION VALUE = \"case1\"> case1");
+        src.append("        <OPTION VALUE = \"case2\" SELECTED> case2");
+        src.append("        <OPTION VALUE = \"case3\" SELECTED> case3");
+        src.append("    </SELECT>");
+        src.append("    <TEXTAREA NAME = \"textarea_name\" WRAP=\"virtual\" "
+                   + "COLS=\"50\" ROWS=\"5\" ID=\"textArea\">");
+        src.append("         JTextArea in a JScrollPane");
+        src.append("    </TEXTAREA>");
+        src.append("    <INPUT TYPE = \"text\" NAME =\"text_maxlength\" "
+                   + "MAXLENGTH = \"10\" VALUE = \"text:JTextField\" "
+                   + "ID=\"text_maxlength\">");
+        src.append("    <INPUT TYPE = \"submit\" NAME =\"submit3_name\" "
+                   + "VALUE = \"submit2:JButton\" ID=\"submit2\">");
+        src.append("</FORM>");
+        src.append("    <INPUT TYPE = \"submit\" NAME =\"submit3_name\" "
+                   + "VALUE = \"submit3:JButton\" ID=\"submit3\">");
+        src.append("</BODY>");
+        src.append("</HTML>");
+        StringReader reader = new StringReader(src.toString());
+        htmlEditorKit.read(reader, doc, 0);
+    }
+
+    public void testFormView() throws Exception {
+
+        // Wrong element
+        elem = createElement();
+        formView = new FormView(elem);
+        assertNull(formView.getComponent());
+        assertSame(elem, formView.getElement());
+        assertSame(elem.getAttributes(), formView.getAttributes());
+        assertNull(formView.createComponent());
+        assertNull(formView.getComponent());
+        assertNull(getModelAttribute(elem));
+        assertNull(StyleConstants.getComponent(elem.getAttributes()));
+
+        formView.setParent(editorPane.getUI().getRootView(editorPane));
+        assertNull(StyleConstants.getComponent(elem.getAttributes()));
+        assertNull(formView.createComponent());
+        assertNull(formView.getComponent());
+        assertNull(getModelAttribute(elem));
+
+        // Wrong element type name
+        createFormView(FormAttributes.INPUT_TYPE_SUBMIT);
+        MutableAttributeSet attrs = new SimpleAttributeSet();
+        attrs.addAttribute(HTML.Attribute.TYPE, "my_type");
+        doc.setCharacterAttributes(22, 1, attrs, false);
+        assertEquals("my_type",
+                     elem.getAttributes().getAttribute(HTML.Attribute.TYPE));
+        assertNull(formView.createComponent());
+        assertNull(formView.getComponent());
+        assertNotNull(getModelAttribute(elem));
+        assertNull(StyleConstants.getComponent(elem.getAttributes()));
+
+        formView.setParent(editorPane.getUI().getRootView(editorPane));
+        assertNull(StyleConstants.getComponent(elem.getAttributes()));
+        assertNull(formView.createComponent());
+        assertNull(formView.getComponent());
+        assertNotNull(getModelAttribute(elem));
+
+        // Element type "password"
+        createFormView(FormAttributes.INPUT_TYPE_PASSWORD);
+        assertNull(StyleConstants.getComponent(elem.getAttributes()));
+        assertNull(StyleConstants.getComponent(elem.getAttributes()));
+        Object modelAttribute = getModelAttribute(elem);
+        assertNull(formView.getComponent());
+        assertSame(elem, formView.getElement());
+        assertSame(elem.getAttributes(), formView.getAttributes());
+        Component component = formView.createComponent();
+        assertNotNull(component);
+        assertNull(formView.getComponent());
+        assertSame(modelAttribute, getModelAttribute(elem));
+        assertNotSame(component, formView.createComponent());
+        component = formView.createComponent();
+
+        formView.setParent(editorPane.getUI().getRootView(editorPane));
+        assertNotNull(component);
+        Component cashedComponent = formView.getComponent();
+        assertNotNull(cashedComponent);
+        assertSame(cashedComponent, formView.getComponent());
+        assertNotSame(component, cashedComponent);
+        assertNotSame(component, formView.createComponent());
+        assertNotSame(formView.getComponent(), formView.createComponent());
+        assertSame(modelAttribute, getModelAttribute(elem));
+        assertSame(cashedComponent, formView.getComponent());
+
+        // Check component attribute
+        createFormView(FormAttributes.INPUT_TYPE_TEXT);
+        assertNull(StyleConstants.getComponent(elem.getAttributes()));
+        JButton button = new JButton();
+        attrs = new SimpleAttributeSet();
+        StyleConstants.setComponent(attrs, button);
+        doc.setCharacterAttributes(23, 1, attrs, false);
+        assertNotNull(StyleConstants.getComponent(elem.getAttributes()));
+        assertNull(formView.getComponent());
+
+        formView.setParent(editorPane.getUI().getRootView(editorPane));
+        component = formView.getComponent();
+        assertNotSame(button, component);
+        assertTrue(component instanceof JTextField);
+        assertNotSame(component,
+                      StyleConstants.getComponent(elem.getAttributes()));
+
+        formView.setParent(null);
+        assertSame(component, formView.getComponent());
+        formView.setParent(editorPane.getUI().getRootView(editorPane));
+        assertSame(component, formView.getComponent());
+    }
+
+    public void testFormView_Models() throws Exception {
+        createFormView(FormAttributes.INPUT_TYPE_BUTTON);
+        if (isHarmony()) {
+            //TODO uncomment when HTMLDocument would be implemented
+            /*
+             *  assertNotNull(getModelAttribute(elem));
+             */
+        } else {
+            assertNull(getModelAttribute(elem));
+        }
+
+        testModel(FormAttributes.INPUT_TYPE_CHECKBOX);
+        testModel(FormAttributes.INPUT_TYPE_IMAGE);
+        testModel(FormAttributes.INPUT_TYPE_PASSWORD);
+        testModel(FormAttributes.INPUT_TYPE_RADIO);
+        testModel(FormAttributes.INPUT_TYPE_RESET);
+        testModel(FormAttributes.INPUT_TYPE_SUBMIT);
+        testModel(FormAttributes.INPUT_TYPE_TEXT);
+        testModel(FormAttributes.INPUT_TYPE_FILE);
+        testModel("textArea");
+        testModel("select_0");
+        testModel("select");
+        testModel("select_many");
+        testModel("select_multiple");
+        testModel("select_multiple_many");
+
+        //HTML 4.0 innovations
+        if (isHarmony()) {
+            //TODO Button
+            //TODO Select with option groups
+        }
+    }
+
+    public void testCreateComponent() throws Exception {
+        Component component;
+
+        createFormView(FormAttributes.INPUT_TYPE_BUTTON);
+        if (isHarmony()) {
+            component = formView.createComponent();
+            assertTrue(component instanceof JButton);
+            checkCreateComponent(formView, component);
+        } else {
+            assertNull(formView.createComponent());
+            formView.setParent(editorPane.getUI().getRootView(editorPane));
+            assertNull(formView.createComponent());
+        }
+
+        createFormView(FormAttributes.INPUT_TYPE_CHECKBOX);
+        component = formView.createComponent();
+        assertTrue(component instanceof JCheckBox);
+        checkCreateComponent(formView, component);
+
+        createFormView(FormAttributes.INPUT_TYPE_IMAGE);
+        component = formView.createComponent();
+        assertTrue(component instanceof JButton);
+        checkCreateComponent(formView, component);
+
+        createFormView(FormAttributes.INPUT_TYPE_PASSWORD);
+        component = formView.createComponent();
+        assertTrue(component instanceof JPasswordField);
+        checkCreateComponent(formView, component);
+
+        createFormView(FormAttributes.INPUT_TYPE_RADIO);
+        component = formView.createComponent();
+        assertTrue(component instanceof JRadioButton);
+        checkCreateComponent(formView, component);
+
+        createFormView(FormAttributes.INPUT_TYPE_RESET);
+        component = formView.createComponent();
+        assertTrue(component instanceof JButton);
+        checkCreateComponent(formView, component);
+
+        createFormView(FormAttributes.INPUT_TYPE_SUBMIT);
+        component = formView.createComponent();
+        assertTrue(component instanceof JButton);
+        checkCreateComponent(formView, component);
+
+        createFormView(FormAttributes.INPUT_TYPE_TEXT);
+        component = formView.createComponent();
+        assertTrue(component instanceof JTextField);
+        checkCreateComponent(formView, component);
+
+        createFormView("text_maxlength");
+        component = formView.createComponent();
+        assertTrue(component instanceof JTextField);
+        assertTrue(getModelAttribute(elem) instanceof PlainDocument);
+
+        createFormView(FormAttributes.INPUT_TYPE_FILE);
+        Container container = (Container) formView.createComponent();
+        assertTrue(container instanceof Box);
+        assertEquals(container.getComponentCount(), 3);
+        assertTrue(container.getComponent(0) instanceof JTextField);
+        assertTrue(container.getComponent(2) instanceof JButton);
+        checkCreateComponent(formView, container);
+
+        createFormView("textArea");
+        container = (Container) formView.createComponent();
+        assertTrue(container instanceof JScrollPane);
+        assertEquals(container.getComponentCount(), 3);
+        assertTrue(container.getComponent(0) instanceof JViewport);
+        assertTrue(((JViewport) container.getComponent(0)).getComponent(0)
+                   instanceof JTextArea);
+        checkCreateComponent(formView, container);
+
+        createFormView("select_0");
+        component = formView.createComponent();
+        assertTrue(component instanceof JComboBox);
+        checkCreateComponent(formView, component);
+
+        createFormView("select");
+        component = formView.createComponent();
+        assertTrue(component instanceof JComboBox);
+        checkCreateComponent(formView, component);
+
+        createFormView("select_many");
+        component = formView.createComponent();
+        assertTrue(component instanceof JComboBox);
+        checkCreateComponent(formView, component);
+
+        createFormView("select_multiple");
+        container = (Container) formView.createComponent();
+        assertTrue(container instanceof JScrollPane);
+        assertEquals(container.getComponentCount(), 3);
+
+        assertTrue(container.getComponent(0) instanceof JViewport);
+        assertTrue(((JViewport) container.getComponent(0)).getComponent(0)
+                   instanceof JList);
+        checkCreateComponent(formView, container);
+
+        createFormView("select_multiple_many");
+        container = (Container) formView.createComponent();
+        assertTrue(container instanceof JScrollPane);
+        assertEquals(container.getComponentCount(), 3);
+
+        assertTrue(container.getComponent(0) instanceof JViewport);
+        assertTrue(((JViewport) container.getComponent(0)).getComponent(0)
+                   instanceof JList);
+        checkCreateComponent(formView, container);
+    }
+
+    public void testCreateComponent_Models() throws Exception {
+        Component component;
+
+        createFormView(FormAttributes.INPUT_TYPE_BUTTON);
+        component = formView.createComponent();
+        if (isHarmony()) {
+            assertSame(getModelAttribute(elem),
+                      ((JButton) component).getModel());
+             
+        } else {
+            assertNull(component);
+        }
+
+        createFormView(FormAttributes.INPUT_TYPE_CHECKBOX);
+        component = formView.createComponent();
+        assertSame(getModelAttribute(elem), ((JCheckBox) component).getModel());
+        checkWithoutlModel(14,
+                           FormAttributes.INPUT_TYPE_CHECKBOX);
+        assertNotNull(((JCheckBox)formView.createComponent()).getModel());
+
+
+        createFormView(FormAttributes.INPUT_TYPE_IMAGE);
+        component = formView.createComponent();
+        assertSame(getModelAttribute(elem), ((JButton) component).getModel());
+        checkWithoutlModel(16,
+                           FormAttributes.INPUT_TYPE_IMAGE);
+        assertNotNull(((JButton)formView.createComponent()).getModel());
+
+
+        createFormView(FormAttributes.INPUT_TYPE_PASSWORD);
+        component = formView.createComponent();
+        assertSame(getModelAttribute(elem), ((JTextField) component)
+                .getDocument());
+        checkWithoutlModel(17,
+                           FormAttributes.INPUT_TYPE_PASSWORD);
+        assertNotNull(((JTextField)formView.createComponent()).getDocument());
+
+
+        createFormView(FormAttributes.INPUT_TYPE_RADIO);
+        component = formView.createComponent();
+        assertSame(getModelAttribute(elem), ((JRadioButton) component)
+                .getModel());
+        checkWithoutlModel(18,
+                           FormAttributes.INPUT_TYPE_RADIO);
+        assertNotNull(((JRadioButton)formView.createComponent()).getModel());
+
+
+        createFormView(FormAttributes.INPUT_TYPE_RESET);
+        component = formView.createComponent();
+        assertSame(getModelAttribute(elem), ((JButton) component).getModel());
+        checkWithoutlModel(21,
+                           FormAttributes.INPUT_TYPE_RESET);
+        assertNotNull(((JButton)formView.createComponent()).getModel());
+
+
+        createFormView(FormAttributes.INPUT_TYPE_SUBMIT);
+        component = formView.createComponent();
+        assertSame(getModelAttribute(elem), ((JButton) component).getModel());
+        checkWithoutlModel(22,
+                           FormAttributes.INPUT_TYPE_SUBMIT);
+        assertNotNull(((JButton)formView.createComponent()).getModel());
+
+
+        createFormView(FormAttributes.INPUT_TYPE_TEXT);
+        component = formView.createComponent();
+        assertSame(getModelAttribute(elem), ((JTextField) component)
+                .getDocument());
+        checkWithoutlModel(23,
+                FormAttributes.INPUT_TYPE_TEXT);
+        assertNotNull(((JTextField)formView.createComponent()).getDocument());
+
+        createFormView(FormAttributes.INPUT_TYPE_FILE);
+        component = formView.createComponent();
+        assertSame(getModelAttribute(elem),
+                ((JTextField) ((Container) component).getComponent(0))
+                        .getDocument());
+        checkWithoutlModel(25,
+                FormAttributes.INPUT_TYPE_FILE);
+        Component c = ((Box)formView.createComponent()).getComponent(0);
+        assertNotNull(((JTextField)c).getDocument());
+
+        createFormView("textArea");
+        component = formView.createComponent();
+        assertSame(getModelAttribute(elem),
+                ((JTextArea) ((Container) ((Container) component)
+                        .getComponent(0)).getComponent(0)).getDocument());
+        checkWithoutlModel(31, "textArea", "textarea");
+        JViewport viewPort = ((JScrollPane)formView.createComponent()).getViewport();
+        assertNotNull(((JTextArea)viewPort.getComponent(0)).getDocument());
+
+        createFormView("select_0");
+        component = formView.createComponent();
+        assertSame(getModelAttribute(elem), ((JComboBox) component).getModel());
+        if (isHarmony()) {
+            checkWithoutlModel(26, "select_0", "select");
+        } else {
+            testExceptionalCase(new NullPointerCase() {
+                public void exceptionalAction() throws Exception {
+                    checkWithoutlModel(26, "select_0", "select");
+                }
+            });
+        }
+
+        createFormView("select");
+        component = formView.createComponent();
+        assertSame(getModelAttribute(elem), ((JComboBox) component).getModel());
+
+        createFormView("select_many");
+        component = formView.createComponent();
+        assertSame(getModelAttribute(elem), ((JComboBox) component).getModel());
+
+        createFormView("select_multiple");
+        formView = new FormView(elem);
+        component = formView.createComponent();
+        assertSame(getModelAttribute(elem),
+                ((JList) ((Container) ((Container) component).getComponent(0))
+                        .getComponent(0)).getModel());
+
+        createFormView("select_multiple_many");
+        component = formView.createComponent();
+        assertSame(getModelAttribute(elem),
+                ((JList) ((Container) ((Container) component).getComponent(0))
+                        .getComponent(0)).getModel());
+    }
+
+    public void testGetMaximumSpan() throws Exception {
+
+        elem = doc.getElement(FormAttributes.INPUT_TYPE_TEXT);
+        formView = new FormView(elem) {
+            protected Component createComponent() {
+                return null;
+            }
+        };
+        assertNull(formView.createComponent());
+        checkFormViewSpans(0, 0, 0, 0);
+
+
+        final Marker getPrefferdSpanCalled = new Marker();
+        elem = doc.getElement(FormAttributes.INPUT_TYPE_RESET);
+        formView = new FormView(elem) {
+            protected Component createComponent() {
+                Component component = new JCheckBox();
+                ((JCheckBox) component).setModel((ButtonModel) elem
+                        .getAttributes().getAttribute(
+                                StyleConstants.ModelAttribute));
+                component.setMinimumSize(new Dimension(10, 10));
+                component.setPreferredSize(new Dimension(20, 20));
+                component.setMaximumSize(new Dimension(30, 30));
+                return component;
+            }
+
+            public float getPreferredSpan(int axis) {
+                getPrefferdSpanCalled.setOccurred();
+                return super.getPreferredSpan(axis);
+            }
+        };
+        assertFalse(getPrefferdSpanCalled.isOccurred());
+        checkFormViewSpans(0, 0, 30, 30);
+
+
+        // Wrong element type
+        elem = doc.getElement(FormAttributes.INPUT_TYPE_SUBMIT);
+        formView = new FormView(elem) {
+            protected Component createComponent() {
+                Component component = super.getComponent();
+                if (component == null) {
+                    return null;
+                }
+                component.setMinimumSize(new Dimension(10, 10));
+                component.setPreferredSize(new Dimension(20, 20));
+                component.setMaximumSize(new Dimension(30, 30));
+                return component;
+            };
+        };
+        MutableAttributeSet attrs = new SimpleAttributeSet();
+        attrs.addAttribute(HTML.Attribute.TYPE, "my_type");
+        doc.setCharacterAttributes(22, 1, attrs, false);
+        assertEquals("my_type",
+                     elem.getAttributes().getAttribute(HTML.Attribute.TYPE));
+        checkFormViewSpans(0, 0, 0, 0);
+
+
+        elem = doc.getElement(FormAttributes.INPUT_TYPE_RESET);
+        formView = new FormView(elem) {
+            private boolean called;
+
+            protected Component createComponent() {
+                Component component;
+                if (!called) {
+                    component = super.createComponent();
+                    called = true;
+                    component.setMinimumSize(new Dimension(100, 100));
+                    component.setPreferredSize(new Dimension(2000, 2000));
+                    component.setMaximumSize(new Dimension(3000, 3000));
+                } else {
+                    component = new JPanel();
+                    component.setMinimumSize(new Dimension(10, 10));
+                    component.setPreferredSize(new Dimension(20, 20));
+                    component.setMaximumSize(new Dimension(30, 30));
+                }
+                return component;
+            }
+        };
+        checkFormViewSpans(0, 0, 2000, 2000);
+        formView.setParent(null);
+        checkFormViewSpans(0, 0, 2000, 2000);
+
+        // Wrong element
+        elem = createElement();
+        formView = new FormView(elem) {
+            protected Component createComponent() {
+                Component component = new JPanel();
+                component.setMinimumSize(new Dimension(10, 10));
+                component.setPreferredSize(new Dimension(20, 20));
+                component.setMaximumSize(new Dimension(30, 30));
+                return component;
+            }
+        };
+        checkFormViewSpans(0, 0, 30, 30);
+    }
+
+    public void testGetMaximumSpan_WithValidElements() throws Exception {
+        createFormView(FormAttributes.INPUT_TYPE_BUTTON);
+        checkMaxSpan(formView);
+
+        createFormView(FormAttributes.INPUT_TYPE_CHECKBOX);
+        checkMaxSpan(formView);
+
+        createFormView(FormAttributes.INPUT_TYPE_IMAGE);
+        checkMaxSpan(formView);
+
+        createFormView(FormAttributes.INPUT_TYPE_PASSWORD);
+        checkMaxSpan(formView);
+
+        createFormView(FormAttributes.INPUT_TYPE_RADIO);
+        checkMaxSpan(formView);
+
+        createFormView(FormAttributes.INPUT_TYPE_RESET);
+        checkMaxSpan(formView);
+
+        createFormView(FormAttributes.INPUT_TYPE_SUBMIT);
+        checkMaxSpan(formView);
+
+        createFormView(FormAttributes.INPUT_TYPE_TEXT);
+        checkMaxSpan(formView);
+
+        createFormView(FormAttributes.INPUT_TYPE_FILE);
+        checkMaxSpan(formView);
+
+        createFormView("textArea");
+        checkMaxSpan(formView);
+
+        createFormView("select_0");
+        checkMaxSpan(formView);
+
+        createFormView("select");
+        checkMaxSpan(formView);
+
+        createFormView("select_many");
+        checkMaxSpan(formView);
+
+        createFormView("select_multiple");
+        // getPreferred span doesn't handle
+        checkFormViewSpans(0, 0);
+        formView.setParent(editorPane.getUI().getRootView(editorPane));
+        
+        boolean notEqual = Math.abs(formView.getPreferredSpan(View.X_AXIS)
+                                    - formView.getMaximumSpan(View.X_AXIS))
+                           > 0.00001;
+        if (isHarmony()) {
+            assertFalse(notEqual);
+        } else {
+            assertTrue(notEqual);
+        }
+        notEqual = Math.abs(formView.getPreferredSpan(View.Y_AXIS)
+                            - formView.getMaximumSpan(View.Y_AXIS))
+                   > 0.00001;
+        if (isHarmony()) {
+            assertFalse(notEqual);
+        } else {
+            assertTrue(notEqual);
+        }
+
+        createFormView("select_multiple_many");
+        // getPreferred span doesn't handle
+        checkFormViewSpans(0, 0);
+        formView.setParent(editorPane.getUI().getRootView(editorPane));
+        notEqual = Math.abs(formView.getPreferredSpan(View.X_AXIS)
+                            - formView.getMaximumSpan(View.X_AXIS))
+                   > 0.00001;
+        if (isHarmony()) {
+            assertFalse(notEqual);
+        } else {
+            assertTrue(notEqual);
+        }
+        notEqual = Math.abs(formView.getPreferredSpan(View.Y_AXIS)
+                            - formView.getMaximumSpan(View.Y_AXIS))
+                   > 0.00001;
+        if (isHarmony()) {
+            assertFalse(notEqual);
+        } else {
+            assertTrue(notEqual);
+        }
+    }
+
+    public void testImageSubmit() throws Exception {
+        throw new UnsupportedOperationException("Not implemented");
+    }
+
+    public void testSubmitData() throws Exception {
+        throw new UnsupportedOperationException("Not implemented");
+    }
+
+    public void testActionPerformed() throws Exception {
+        Component component;
+
+        elem = doc.getElement("submit2");
+        formView = new FormView(elem) {
+            public void actionPerformed(ActionEvent event) {
+                super.actionPerformed(event);
+            }
+
+            protected void submitData(String data) {
+                super.submitData(data);
+            }
+        };
+        component = formView.createComponent();
+        JPanel panel = new JPanel() {
+            public int getComponentCount() {
+                return super.getComponentCount();
+            }
+        };
+        panel.add(component);
+        ((JButton) component).doClick();
+        
+        throw new UnsupportedOperationException("Not implemented");
+    }
+
+    public void testIsElementSuccessfull() throws Exception {
+        StringBuffer src = new StringBuffer();
+        src.append("<HTML><HEAD></HEAD><BODY> Test");
+        src.append("<FORM ACTION = \"\">");
+        src.append("    <INPUT TYPE = \"checkbox\" NAME =\"checkbox_name\" "
+                   + "VALUE = \"checkbox:JCheckBox\" ID=\"checkbox\">");
+        src.append("    <INPUT TYPE = \"checkbox\" NAME =\"checked "
+                   + "checkbox_name\" VALUE = \"checked checkbox:JCheckBox\" "
+                   + "CHECKED ID=\"checked checkbox\">");
+        src.append("</FORM></BODY></HTML>");
+        StringReader reader = new StringReader(src.toString());
+        doc = new HTMLDocument();
+        editorPane.setDocument(doc);
+        htmlEditorKit.read(reader, doc, 0);
+        // 1. Test checkbox button. Succsessful should be only checked buttons.
+
+        src = new StringBuffer();
+        src.append("<HTML><HEAD></HEAD><BODY> Test");
+        src.append("<FORM ACTION = \"\">");
+        src.append("    <INPUT TYPE = \"submit\" disabled NAME =\"submit_name\""
+                   + " VALUE = \"submit:JButton\" ID=\"submit\">");
+        src.append("    <INPUT TYPE = \"checkbox\" disabled NAME =\"checked "
+                   + "checkbox_name\" VALUE = \"checked checkbox:JCheckBox\" "
+                   + "CHECKED ID=\"checked checkbox\">");
+        src.append("    <INPUT TYPE = \"button\" disabled NAME =\"button_name\""
+                   + " VALUE = \"button:JButton\" ID=\"button\">");
+        src.append("    <INPUT TYPE = \"file\" disabled NAME =\"file_name\" "
+                   + "VALUE = \"file:JTextField\" ID=\"file\">");
+        src.append("    <SELECT NAME = \"select_name\" disabled MULTIPLE "
+                   + "ID=\"select_multiple_many\">");
+        src.append("       <OPTION VALUE = \"case1\"> case1");
+        src.append("       <OPTION VALUE = \"case2\" SELECTED> case2");
+        src.append("       <OPTION VALUE = \"case3\" SELECTED> case3");
+        src.append("    </SELECT>");
+        src.append("    <SELECT NAME = \"select_name\" MULTIPLE "
+                   + "ID=\"select_multiple_many\">");
+        src.append("       <OPTION VALUE = \"case1\"> case1");
+        src.append("       <OPTION VALUE = \"case2\" disabled SELECTED> case2");
+        src.append("    </SELECT>");
+        src.append("    <TEXTAREA NAME = \"textarea_name\" disabled WRAP="
+                   + "\"virtual\" COLS=\"50\" ROWS=\"5\" ID=\"textArea\">");
+        src.append("         JTextArea in a JScrollPane");
+        src.append("    </TEXTAREA>");
+        src.append("</FORM></BODY></HTML>");
+        reader = new StringReader(src.toString());
+        doc = new HTMLDocument();
+        editorPane.setDocument(doc);
+        htmlEditorKit.read(reader, doc, 0);
+        // TODO
+        // 1. Test disable attribute in
+        // a) INPUT
+        // b) SELECT
+        // d) OPTION
+        // c) TEXTAREA
+
+        src = new StringBuffer();
+        src.append("<HTML><HEAD></HEAD><BODY> Test");
+        src.append("<FORM ACTION = \"\">");
+        src.append("    <INPUT TYPE = \"submit\" NAME =\"submit_name1\" "
+                   + "VALUE = \"submi1t:JButton\" ID=\"submit1\">");
+        src.append("    <INPUT TYPE = \"submit\" NAME =\"submit_name2\" "
+                   + "VALUE = \"submit2:JButton\" ID=\"submit2\">");
+        src.append("</FORM></BODY></HTML>");
+        reader = new StringReader(src.toString());
+        doc = new HTMLDocument();
+        editorPane.setDocument(doc);
+        htmlEditorKit.read(reader, doc, 0);
+        // 1. Test submit button. Succsessful should be only armed button.
+
+        if (isHarmony()) {
+            /**
+             * HTML 4.0 specific tags
+             */
+            src = new StringBuffer();
+            src.append("<HTML><HEAD></HEAD><BODY> Test");
+            src.append("<FORM ACTION = \"\">");
+            src.append("    <BUTTON TYPE = \"submit1\" disabled "
+                       + "NAME=\"button_submit1_name\" value=\"submit1:JButton\">");
+            src.append("       Send");
+            src.append("       <IMG src=\"\" alt=\"alt\">");
+            src.append("    </BUTTON>");
+            src .append("    <SELECT NAME = \"select_name\" MULTIPLE "
+                        + "ID=\"select_multiple_many\">");
+            src.append("        <OPTGROUP disabled label=\"Option gr1\">");
+            src.append("            <OPTION VALUE = \"case1\"> case1");
+            src.append("            <OPTION VALUE = \"case2\" disabled "
+                       + "SELECTED> case2");
+            src.append("        </OPTGROUP>");
+            src.append("        <OPTGROUP label=\"Option gr2\">");
+            src.append("            <OPTION VALUE = \"case1\"> case1");
+            src.append("            <OPTION VALUE = \"case2\" disabled "
+                       + "SELECTED> case2");
+            src.append("        </OPTGROUP>");
+            src.append("    </SELECT>");
+            src.append("    <INPUT TYPE = \"submit\" NAME =\"submit_name2\" "
+                       + "VALUE = \"submit2:JButton\" ID=\"submit2\">");
+            src.append("</FORM></BODY></HTML>");
+            reader = new StringReader(src.toString());
+            doc = new HTMLDocument();
+            editorPane.setDocument(doc);
+            htmlEditorKit.read(reader, doc, 0);
+            // TODO
+            // 1. Test disable attribute in
+            // a) BUTTON
+            // b) OPTGROUP
+            // 2. Test submit button. Succsessful should be only armed button.
+        }
+
+        src = new StringBuffer();
+        src.append("<HTML><HEAD></HEAD><BODY> Test");
+        src.append("<FORM ACTION = \"\">");
+        src.append("    <INPUT TYPE = \"checkbox\" NAME =\"checkbox_name\" "
+                   + "VALUE = \"checkbox:JCheckBox\" ID=\"checkbox\">");
+        src.append("    <INPUT TYPE = \"checkbox\" NAME =\"checked "
+                   + "checkbox_name\" VALUE = \"checked checkbox:JCheckBox\" "
+                   + "CHECKED ID=\"checked checkbox\">");
+        src.append("</FORM></BODY></HTML>");
+        reader = new StringReader(src.toString());
+        doc = new HTMLDocument();
+        editorPane.setDocument(doc);
+        htmlEditorKit.read(reader, doc, 0);
+        // TODO
+        // 1. Test checkbox button. Succsessful should be only checked buttons.
+
+        src = new StringBuffer();
+        src.append("<HTML><HEAD></HEAD><BODY> Test");
+        src.append("<FORM ACTION = \"\">");
+        src.append("    <INPUT TYPE = \"radio\" NAME =\"radio_name\" "
+                   + "value = \"radio:JRadioButton\" ID=\"radio\">");
+        src.append("    <INPUT TYPE = \"radio\" NAME =\"radio_name\" "
+                   + "value = \"radio:JRadioButton\" CHECKED ID=\"radio\">");
+        src.append("    <INPUT TYPE = \"radio\" NAME =\"checked radio_name\" "
+                   + "value = \"checked radio:JRadioButton\" ID=\"checked "
+                   + "radio\">");
+        src.append("</FORM></BODY></HTML>");
+        reader = new StringReader(src.toString());
+        doc = new HTMLDocument();
+        editorPane.setDocument(doc);
+        htmlEditorKit.read(reader, doc, 0);
+        // TODO
+        // 1. Test radioButton.
+        // a) For buttons with the same name succsessful should be only selected
+        // button.
+        // b) Test Unchecked buttons
+
+        src = new StringBuffer();
+        src.append("<HTML><HEAD></HEAD><BODY> Test");
+        src.append("<FORM ACTION = \"\">");
+        src.append("    <SELECT NAME = \"select_name\" MULTIPLE "
+                   + "ID=\"select_multiple_many\">");
+        src.append("       <OPTION VALUE = \"case1\"> case1");
+        src.append("       <OPTION VALUE = \"case1\"> SELECTED case2");
+        src.append("       <OPTION VALUE = \"case1\"> SELECTED case2");
+        src.append("       <OPTION VALUE = \"case2\" disabled SELECTED> case3");
+        src.append("    </SELECT>");
+        src.append("</FORM></BODY></HTML>");
+        reader = new StringReader(src.toString());
+        doc = new HTMLDocument();
+        editorPane.setDocument(doc);
+        htmlEditorKit.read(reader, doc, 0);
+        // TODO
+        // 1. Succsessful should be only selected items.
+
+        src = new StringBuffer();
+        src.append("<HTML><HEAD></HEAD><BODY> Test");
+        src.append("<FORM ACTION = \"\">");
+        src.append("    <INPUT TYPE = \"file\" NAME =\"file_name\" "
+                   + "VALUE = \"file:JTextField\" ID=\"file\">");
+        src.append("</FORM></BODY></HTML>");
+        reader = new StringReader(src.toString());
+        doc = new HTMLDocument();
+        editorPane.setDocument(doc);
+        htmlEditorKit.read(reader, doc, 0);
+        // TODO
+        // 1. File is succsessful element
+
+        // TODO
+        // 1. If current value of element is unset, element may considered as
+        // not successfull
+
+        src = new StringBuffer();
+        src.append("<HTML><HEAD></HEAD><BODY> Test");
+        src.append("<FORM ACTION = \"\">");
+        src.append("    <INPUT TYPE = \"reset\" NAME =\"reset_name\" "
+                   + "VALUE = \"reset:JButton\" ID=\"reset\">");
+        src.append("</FORM></BODY></HTML>");
+        reader = new StringReader(src.toString());
+        doc = new HTMLDocument();
+        editorPane.setDocument(doc);
+        htmlEditorKit.read(reader, doc, 0);
+        // TODO
+        // 1. Reset isn't succsessful element
+
+        src = new StringBuffer();
+        src.append("<HTML><HEAD></HEAD><BODY> Test");
+        src.append("<FORM ACTION = \"\">");
+        src.append("    <INPUT TYPE = \"reset\" NAME =\"reset_name\" "
+                   + "VALUE = \"reset:JButton\" ID=\"reset\">");
+        src.append("</FORM></BODY></HTML>");
+        reader = new StringReader(src.toString());
+        doc = new HTMLDocument();
+        editorPane.setDocument(doc);
+        htmlEditorKit.read(reader, doc, 0);
+        // TODO
+        // 1. OBJECT with attrubute "declare" isn't succsessful element.
+
+        // TODO
+        // 1. Tests on invisible elements.
+        throw new UnsupportedOperationException("Not implemented");
+    }
+
+    private void checkCreateComponent(final FormView formView,
+                                      final Component component) {
+
+        Component comp = component;
+        assertNotSame(comp, formView.createComponent());
+        formView.setParent(editorPane.getUI().getRootView(editorPane));
+        assertNotNull(formView.getComponent());
+        comp = formView.createComponent();
+        assertNotSame(comp, formView.getComponent());
+        assertNotSame(formView.getComponent(),
+                      StyleConstants.getComponent(elem.getAttributes()));
+        assertNotSame(comp,
+                      StyleConstants.getComponent(formView.getElement()
+                      .getAttributes()));
+        assertNull(formView.createComponent().getParent());
+        assertNotNull(formView.getComponent().getParent());
+    }
+
+    private void checkFormViewSpans(final double x1, final double y1) {
+        assertEquals(x1, y1, 0.0001);
+    }
+
+    private void checkFormViewSpans(final double x1, final double y1,
+                final double x2, final double y2) {
+        checkFormViewSpans(x1, y1);
+        formView.setParent(editorPane.getUI().getRootView(editorPane));
+        checkFormViewSpans(x2, y2);
+    }
+
+    private void checkMaxSpan(final FormView formView) {
+        checkFormViewSpans(formView.getPreferredSpan(View.X_AXIS),
+                           formView.getPreferredSpan(View.X_AXIS));
+        checkFormViewSpans(formView.getPreferredSpan(View.Y_AXIS),
+                           formView.getPreferredSpan(View.Y_AXIS));
+
+        formView.setParent(editorPane.getUI().getRootView(editorPane));
+
+        checkFormViewSpans(formView.getPreferredSpan(View.X_AXIS),
+                           formView.getPreferredSpan(View.X_AXIS));
+        checkFormViewSpans(formView.getPreferredSpan(View.Y_AXIS),
+                           formView.getPreferredSpan(View.Y_AXIS));
+    }
+
+    private void checkWithoutlModel(final int offset, final String id) {
+        checkWithoutlModel(offset, id, id);
+    }
+
+    private void checkWithoutlModel(final int offset, final String id,
+                                    final String type) {
+        elem = doc.getElement(id);
+        MutableAttributeSet attrs = new SimpleAttributeSet();
+        attrs.addAttributes(elem.getAttributes());
+        attrs.removeAttribute(StyleConstants.ModelAttribute);
+        doc.setCharacterAttributes(offset, 1, attrs, true);
+    
+        assertNull(elem.getAttributes().getAttribute(StyleConstants
+                                                     .ModelAttribute));
+        createFormView(id);
+        assertNotNull(formView.createComponent());
+        assertNull(elem.getAttributes().getAttribute(StyleConstants
+                  .ModelAttribute));
+    }
+
+    private Element createElement() {
+        return new Element() {
+
+            private MutableAttributeSet attrs = new SimpleAttributeSet();
+
+            public AttributeSet getAttributes() {
+                return attrs;
+            }
+
+            public Document getDocument() {
+                return null;
+            }
+
+            public Element getElement(int index) {
+                return null;
+            }
+
+            public int getElementCount() {
+                return 0;
+            }
+
+            public int getElementIndex(int offset) {
+                return 0;
+            }
+
+            public int getEndOffset() {
+                return 2;
+            }
+
+            public String getName() {
+                return "element";
+            }
+
+            public Element getParentElement() {
+                return null;
+            }
+
+            public int getStartOffset() {
+                return 0;
+            }
+
+            public boolean isLeaf() {
+                return true;
+            }
+        };
+    }
+
+    private void createFormView(final String id) {
+        elem = doc.getElement(id);
+        formView = new FormView(elem);
+    }
+
+    private Object getModelAttribute(final Element element) {
+        return element.getAttributes().getAttribute(
+                StyleConstants.ModelAttribute);
+    }
+
+    private void testModel(String id) {
+        createFormView(id);
+        assertNotNull(getModelAttribute(elem));
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/FormView_FormInputElementTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/FormView_FormInputElementTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/FormView_FormInputElementTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/FormView_FormInputElementTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,744 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Roman I. Chernyatchik
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import java.awt.ComponentOrientation;
+import java.awt.Dimension;
+import java.awt.FontMetrics;
+import java.io.StringReader;
+
+import javax.swing.AbstractButton;
+import javax.swing.Box;
+import javax.swing.DefaultButtonModel;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComponent;
+import javax.swing.JEditorPane;
+import javax.swing.JPasswordField;
+import javax.swing.JRadioButton;
+import javax.swing.JTextField;
+import javax.swing.JToggleButton;
+import javax.swing.SwingTestCase;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.Element;
+import javax.swing.text.JTextComponent;
+import javax.swing.text.StyleConstants;
+
+import org.apache.harmony.x.swing.Utilities;
+
+public class FormView_FormInputElementTest extends SwingTestCase {
+
+    private static final char MEAN_CHAR = 'z';
+    private static final int DEFAULT_TEXTFIELD_SIZE = 20;
+    private static final String BROWSE_BUTTON_DEFAULT_TEXT = "Browse...";
+    private static final String SUBMIT_DEFAULT_TEXT = "Submit Query";
+    private static final String RESET_DEFAULT_TEXT = "Reset";
+
+    private HTMLDocument document;
+    private HTMLEditorKit htmlEditorKit;
+    private JEditorPane editorPane;
+
+    private Element elem;
+
+    private FormView formView;
+
+    protected void setUp() throws Exception {
+       super.setUp();
+       
+       setIgnoreNotImplemented(true);
+
+       htmlEditorKit = new HTMLEditorKit();
+       editorPane = new JEditorPane();
+       editorPane.setEditorKit(htmlEditorKit);
+       document = (HTMLDocument) editorPane.getDocument();
+    }
+
+    public void testCreateButtonComponent() throws Exception {
+        createHTMLSample("button");
+        JButton button;
+
+        if (isHarmony()) {
+            // VALUE
+            createFormViewWithParent("button_default");
+            button = (JButton) formView.createComponent();
+            assertEquals("button_default", button.getText());
+            assertNull(button.getToolTipText());
+            assertEquals(button.getPreferredSize(),
+                    button.getMaximumSize());
+            assertEquals(button.getPreferredSize(),
+                    button.getMinimumSize());
+
+            //ACCESSKEY
+            checkButtonAccessKey("button_accesskey");
+
+            //TITLE
+            checkTitle("button_title");
+
+            // SIZE
+            checkButtonSize("button_size");
+
+            // ALIGN
+            checkButtonAligns("button");
+
+            // DISABLED
+            checkDisabled("button_disabled");
+        }
+    }
+
+    public void testCreateCheckBoxComponent() throws Exception {
+        createHTMLSample("checkbox");
+        JCheckBox checkBox;
+
+        // VALUE
+        createFormViewWithParent("checkbox_default");
+        checkBox = (JCheckBox) formView.createComponent();
+        assertEquals("", checkBox.getText());
+        assertEquals(checkBox.getPreferredSize(),
+                checkBox.getMaximumSize());
+        assertEquals(checkBox.getPreferredSize(),
+                checkBox.getMinimumSize());
+        assertNull(checkBox.getToolTipText());
+
+        // CHECKED
+        checkChecked("checkbox_checked");
+
+        // ACCESSKEY
+        checkButtonAccessKey("checkbox_accesskey");
+
+        // TITLE
+        checkTitle("checkbox_title");
+
+        // SIZE
+        checkButtonSize("checkbox_size");
+
+        // ALIGN
+        checkButtonAligns("checkbox");
+
+        // DISABLED
+        checkDisabled("checkbox_disabled");
+
+    }
+
+    public void testCreateImageComponent() throws Exception {
+        createHTMLSample("image");
+        JButton image;
+
+        // VALUE
+        createFormViewWithParent("image_src");
+        image = (JButton) formView.createComponent();
+        assertEquals("", image.getText());
+
+        createFormViewWithParent("image_default");
+        image = (JButton) formView.createComponent();
+        assertEquals("", image.getText());
+
+        // ACCESSKEY
+        checkButtonAccessKey("image_accesskey");
+
+        // TITLE
+        checkTitle("image_title");
+        createFormViewWithParent("image_alt");
+        image = (JButton) formView.createComponent();
+        if (isHarmony()) {
+            assertEquals("alt_attribute", image.getToolTipText());
+        } else {
+            assertNull(image.getToolTipText());
+        }
+        createFormViewWithParent("image_alt_title");
+        image = (JButton) formView.createComponent();
+        if (isHarmony()) {
+            assertEquals("title_attribute", image.getToolTipText());
+        } else {
+            assertNull(image.getToolTipText());
+        }
+
+        // ALT
+        createFormViewWithParent("image_alt");
+        image = (JButton) formView.createComponent();
+        if (isHarmony()) {
+            assertEquals("alt_attribute", image.getText());
+        } else {
+            assertEquals("", image.getText());
+        }
+
+        // SIZE
+        checkButtonSize("image_size");
+
+
+        // SRC
+        createFormViewWithParent("image_src");
+        image = (JButton) formView.createComponent();
+        if (isHarmony()) {
+           assertNotNull(image.getIcon());
+        } else {
+           assertNull(image.getIcon());
+        }
+        createFormViewWithParent("image_alt");
+        if (isHarmony()) {
+            assertNotNull(image.getIcon());
+        } else {
+            assertNull(image.getIcon());
+        }
+
+        // ALIGN
+        checkButtonAligns("image");
+
+        // DISABLED
+        checkDisabled("image_disabled");
+    }
+
+    public void testCreatePasswordComponent() throws Exception {
+        JPasswordField passwordField;
+        createHTMLSample("password");
+
+        // VALUE
+        createFormViewWithParent("password_default");
+        passwordField = (JPasswordField) formView.createComponent();
+        assertEquals("password_default", passwordField.getText());
+        assertNull(passwordField.getToolTipText());
+
+        // READONLY
+        checkTextReadonly("password_readonly");
+
+        createFormViewWithParent("password_accesskey");
+        passwordField = (JPasswordField) formView.createComponent();
+
+        // TITLE
+        checkTitle("password_title");
+
+        //SIZE
+        checkTextSize("password", passwordField.getEchoChar());
+
+        //DIR
+        checkTextDir("password_rtl");
+
+        // ALIGN
+        checkTextAligns("password");
+
+        // DISABLED
+        checkDisabled("password_disabled");
+    }
+
+    public void testCreateRadioComponent() throws Exception {
+        createHTMLSample("radio");
+        JRadioButton radioButton;
+
+        // VALUE
+        createFormViewWithParent("radio_default");
+        radioButton = (JRadioButton) formView.createComponent();
+        assertEquals("", radioButton.getText());
+        assertNull(radioButton.getToolTipText());
+
+        // CHECKED
+        checkChecked("radio_checked");
+
+        // ACCESSKEY
+        checkButtonAccessKey("radio_accesskey");
+
+        // SIZE
+        checkButtonSize("radio_size");
+
+        //TITLE
+        checkTitle("radio_title");
+
+        // ALIGN
+        checkButtonAligns("radio");
+
+        // DISABLED
+        checkDisabled("radio_disabled");
+    }
+
+    public void testRadioGroups() throws Exception {
+        StringBuffer htmlSrc = new StringBuffer();
+        htmlSrc.append("<HTML> <HEAD></HEAD><BODY>");
+        htmlSrc.append("   Hello word!");
+        htmlSrc.append("<FORM ACTION = \"\">");
+        htmlSrc.append("    <INPUT TYPE = \"radio\" NAME =\"name\" ID=\"1\">");
+        htmlSrc.append("    <INPUT TYPE = \"radio\" NAME =\"name\" ID=\"2\">");
+        htmlSrc.append("    <INPUT TYPE = \"radio\" NAME =\"name\" ID=\"3\">");
+        htmlSrc.append("</FORM></BODY></HTML>");
+        StringReader reader = new StringReader(htmlSrc.toString());
+        htmlEditorKit.read(reader, document, 0);
+
+        AttributeSet attrs = document.getElement("1").getAttributes();
+        DefaultButtonModel sourceModel1;
+        sourceModel1 = (DefaultButtonModel) attrs.getAttribute(StyleConstants
+                .ModelAttribute);
+        assertEquals(0, sourceModel1.getGroup().getButtonCount());
+        attrs = document.getElement("2").getAttributes();
+        DefaultButtonModel sourceModel2;
+        sourceModel2 = (DefaultButtonModel) attrs.getAttribute(StyleConstants
+                .ModelAttribute);
+        assertEquals(0, sourceModel2.getGroup().getButtonCount());
+
+        createFormViewWithParent("1");
+        assertEquals(0, sourceModel1.getGroup().getButtonCount());
+    }
+
+    public void testCreateResetComponent() throws Exception {
+        createHTMLSample("reset");
+        JButton resetButton;
+
+        //Default VALUE
+        createFormViewWithParent("reset");
+        resetButton = (JButton) formView.createComponent();
+        assertEquals(RESET_DEFAULT_TEXT,  resetButton.getText());
+
+        // VALUE
+        createFormViewWithParent("reset_default");
+        resetButton = (JButton) formView.createComponent();
+        assertEquals("reset_default", resetButton.getText());
+        assertNull(resetButton.getToolTipText());
+
+        // ACCESSKEY
+        checkButtonAccessKey("reset_accesskey");
+
+        // SIZE
+        checkButtonSize("reset_size");
+
+        //TITLE
+        checkTitle("reset_title");
+
+        // ALIGN
+        checkButtonAligns("reset");
+
+        // DISABLED
+        checkDisabled("reset_disabled");
+    }
+
+    public void testCreateSubmitComponent() throws Exception {
+        createHTMLSample("submit");
+        JButton submitButton;
+
+        //Default VALUE
+        createFormViewWithParent("submit");
+        submitButton = (JButton) formView.createComponent();
+        assertEquals(SUBMIT_DEFAULT_TEXT,  submitButton.getText());
+
+        // VALUE
+        createFormViewWithParent("submit_default");
+        submitButton = (JButton) formView.createComponent();
+        assertEquals("submit_default", submitButton.getText());
+        assertNull(submitButton.getToolTipText());
+
+        // ACCESSKEY
+        checkButtonAccessKey("submit_accesskey");
+
+        // SIZE
+        checkButtonSize("submit_size");
+
+        //TITLE
+        checkTitle("submit_title");
+
+        // ALIGN
+        checkButtonAlign("submit");
+
+        // DISABLED
+        checkDisabled("submit_disabled");
+    }
+
+    public void testCreateTextComponent() throws Exception {
+        JTextField textField;
+        createHTMLSample("text");
+
+        // VALUE
+        createFormViewWithParent("text_default");
+        textField = (JTextField) formView.createComponent();
+        assertEquals("text_default", textField.getText());
+        assertNull(textField.getToolTipText());
+
+        // DISABLED
+        checkDisabled("text_disabled");
+
+        // READONLY
+        checkTextReadonly("text_readonly");
+
+        //SIZE
+        checkTextSize("text", MEAN_CHAR);
+
+        // TITLE
+        checkTitle("text_title");
+
+        // ALIGN
+        checkTextAligns("text");
+
+        //DIR
+        checkTextDir("text_rtl");
+    }
+
+    public void testCreateFileComponent() throws Exception {
+        createHTMLSample("file");
+
+        //Default VALUE
+        createFormViewWithParent("file");
+        Box box = (Box)formView.createComponent();;
+        JTextField filePath = (JTextField)box.getComponent(0);
+        JButton browseButton = (JButton)box.getComponent(2);
+        assertEquals("", filePath.getText());
+        assertEquals(BROWSE_BUTTON_DEFAULT_TEXT,  browseButton.getText());
+
+        //VALUE
+        createFormViewWithParent("file_default");
+        box = (Box)formView.createComponent();;
+        filePath = (JTextField)box.getComponent(0);
+        browseButton = (JButton)box.getComponent(2);
+        checkTextSize(filePath, MEAN_CHAR, false);
+        assertEquals(BROWSE_BUTTON_DEFAULT_TEXT,  browseButton.getText());
+
+        // SIZE
+        createFormViewWithParent("file_size");
+        box = (Box)formView.createComponent();;
+        filePath = (JTextField)box.getComponent(0);
+        Box.Filler filler = (Box.Filler)box.getComponent(1);
+        browseButton = (JButton)box.getComponent(2);
+        assertEquals(new Dimension(5, 0), filler.getMinimumSize());
+        assertEquals(new Dimension(5, 0), filler.getPreferredSize());
+        assertEquals(new Dimension(5, 32767), filler.getMaximumSize());
+        checkTextSize(filePath, MEAN_CHAR, true);
+
+        // DIR
+        createFormViewWithParent("file_rtl");
+        box = (Box)formView.createComponent();;
+        filePath = (JTextField)box.getComponent(0);
+        if (isHarmony()) {
+            assertEquals(box.getComponentOrientation(),
+                         ComponentOrientation.RIGHT_TO_LEFT);
+            assertEquals(filePath.getComponentOrientation(),
+                    ComponentOrientation.RIGHT_TO_LEFT);
+        }
+
+        // READONLY
+        createFormViewWithParent("file_readonly");
+        box = (Box)formView.createComponent();;
+        filePath = (JTextField)box.getComponent(0);
+        if (isHarmony()) {
+            assertFalse(filePath.isEditable());
+        } else {
+            assertTrue(filePath.isEditable());
+        }
+
+        // TITLE
+        createFormViewWithParent("file_title");
+        box = (Box)formView.createComponent();
+        filePath = (JTextField)box.getComponent(0);
+        browseButton = (JButton)box.getComponent(2);
+        if (isHarmony()) {
+            assertEquals("title_attribute",
+                         browseButton.getToolTipText());
+            assertEquals("title_attribute",
+                         filePath.getToolTipText());
+        } else {
+            assertNull(browseButton.getToolTipText());
+            assertNull(filePath.getToolTipText());
+        }
+
+        // ALIGN
+        createFormViewWithParent("file_default");
+        checkFileAlign();
+        createFormViewWithParent("file_align_top");
+        checkFileAlign();
+        createFormViewWithParent("file_align_right");
+        checkFileAlign();
+        createFormViewWithParent("file_align_justify");
+        checkFileAlign();
+
+        // DISABLED
+        createFormViewWithParent("file_disabled");
+        box = (Box)formView.createComponent();;
+        filePath = (JTextField)box.getComponent(0);
+        browseButton = (JButton)box.getComponent(2);
+        if (isHarmony()) {
+            assertFalse(browseButton.isEnabled());
+            assertFalse(filePath.isEnabled());
+        } else {
+            assertTrue(browseButton.isEnabled());
+            assertTrue(filePath.isEnabled());
+        }
+    }
+
+    private void checkFileAlign() {
+        Box box = (Box)formView.createComponent();
+        JTextField filePath = (JTextField)box.getComponent(0);
+        JButton browseButton = (JButton)box.getComponent(2);
+        checkAlign(box, JComponent.CENTER_ALIGNMENT,
+                   JComponent.BOTTOM_ALIGNMENT);
+        checkAlign(filePath, JComponent.CENTER_ALIGNMENT,
+                   JComponent.CENTER_ALIGNMENT);
+        checkAlign(browseButton, JComponent.LEFT_ALIGNMENT,
+                   JComponent.CENTER_ALIGNMENT);
+    }
+
+    private void checkAlign(final JComponent component,
+                           final float alignmentX, final float alignmentY) {
+        assertEquals(alignmentX, component.getAlignmentX(), 0.0001);
+        assertEquals(alignmentY, component.getAlignmentY(), 0.0001);
+    }
+
+    private void checkDisabled(final String id) {
+        createFormViewWithParent(id);
+        JComponent component = (JComponent) formView.createComponent();
+        if (isHarmony()) {
+            assertFalse(component.isEnabled());
+        } else {
+            assertTrue(component.isEnabled());
+        }
+    }
+
+    private void checkChecked(final String id) {
+        JToggleButton togleButton;
+        createFormViewWithParent(id);
+        togleButton = (JToggleButton) formView.createComponent();
+        assertTrue(togleButton.isSelected());
+    }
+
+    private void checkButtonAccessKey(final String id) {
+        AbstractButton button;
+        if (isHarmony()) {
+            createFormViewWithParent(id);
+            button = (AbstractButton) formView.createComponent();
+            assertEquals(Utilities.keyCodeToKeyChar(button.getMnemonic()),
+            'U');
+        }
+    }
+
+    private void checkButtonAlign(final String id) {
+        createFormViewWithParent(id);
+        checkAlign((JComponent) formView.createComponent(),
+                        JComponent.LEFT_ALIGNMENT,
+                        JComponent.BOTTOM_ALIGNMENT);
+    }
+
+    private void checkButtonAligns(final String type) {
+        checkButtonAlign(type + "_default");
+        checkButtonAlign(type + "_align_top");
+        checkButtonAlign(type + "_align_right");
+        checkButtonAlign(type + "_align_justify");
+    }
+
+    private void checkButtonSize(final String id) {
+        createFormViewWithParent(id);
+        JComponent component = (JComponent) formView.createComponent();
+        if (isHarmony()) {
+          assertEquals(component.getPreferredSize().width,
+                       100);
+        }
+        assertEquals(component.getPreferredSize(),
+                component.getMaximumSize());
+        assertEquals(component.getPreferredSize(),
+                component.getMinimumSize());
+    }
+
+    private void checkTextAlign(final String id) {
+        createFormViewWithParent(id);
+        checkAlign((JComponent) formView.createComponent(),
+                  JComponent.CENTER_ALIGNMENT,
+                  JComponent.BOTTOM_ALIGNMENT);
+    }
+
+    private void checkTextAligns(final String type) {
+        checkTextAlign(type + "_default");
+        checkTextAlign(type + "_align_top");
+        checkTextAlign(type + "_align_right");
+        checkTextAlign(type + "_align_justify");
+    }
+
+    private void checkTextDir(final String id) {
+        createFormViewWithParent(id);
+        JTextField passwordField = (JTextField) formView.createComponent();
+        if (isHarmony()) {
+            assertEquals(passwordField.getComponentOrientation(),
+                         ComponentOrientation.RIGHT_TO_LEFT);
+        }
+    }
+
+    private void checkTextReadonly(final String id) {
+        JTextComponent textComponent;
+        createFormViewWithParent(id);
+        textComponent = (JTextComponent) formView.createComponent();
+        if (isHarmony()) {
+            assertFalse(textComponent.isEditable());
+        } else {
+            assertTrue(textComponent.isEditable());
+        }
+    }
+
+    private void checkTextSize(final String type, final char ch) {
+        JTextComponent textComponent;
+
+        createFormViewWithParent(type + "_size");
+        textComponent = (JTextComponent) formView.createComponent();
+        checkTextSize(textComponent, ch, true);
+
+        createFormViewWithParent(type + "_default");
+        textComponent = (JTextComponent) formView.createComponent();
+        checkTextSize(textComponent, ch, false);
+
+    }
+    private void checkTextSize(final JTextComponent textComponent,
+                              final char ch, final boolean sizeWasSet) {
+        final FontMetrics fontMetrics
+            = textComponent.getFontMetrics(textComponent.getFont());
+        final int charWidth = fontMetrics.charWidth(ch);
+        Dimension size = textComponent.getPreferredSize();
+
+
+        size.width = (sizeWasSet ? 100 : DEFAULT_TEXTFIELD_SIZE) * charWidth;
+        if (isHarmony()) {
+            assertEquals(size, textComponent.getPreferredSize());
+            assertEquals(size, textComponent.getMaximumSize());
+            size = new Dimension(DEFAULT_TEXTFIELD_SIZE * charWidth,
+                                 size.height);
+            assertEquals(size, textComponent.getMinimumSize());
+        }
+    }
+
+    private void checkTitle(final String id) {
+        createFormViewWithParent(id);
+        JComponent checkBox = (JComponent) formView.createComponent();
+        if (isHarmony()) {
+            assertEquals("title_attribute", checkBox.getToolTipText());
+        } else {
+            assertNull(checkBox.getToolTipText());
+        }
+    }
+
+    private void createFormViewWithParent(final String id) {
+        elem = document.getElement(id);
+        formView = new FormView(elem);
+        formView.setParent(editorPane.getUI().getRootView(editorPane));
+    }
+
+    private void createHTMLSample(final String typeName) throws Exception {
+        StringBuffer htmlSrc = new StringBuffer();
+        htmlSrc.append("<HTML>");
+        htmlSrc.append("<HEAD></HEAD>");
+        htmlSrc.append("<BODY>");
+        htmlSrc.append("   Hello word!");
+        htmlSrc.append("<FORM ACTION = \"\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
+                + "ID=\"" + typeName + "\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\""
+                + "NAME =\"" + typeName + "_name\" "
+                + "VALUE = \"" + typeName + "_default\" "
+                + "ID=\"" + typeName + "_default\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\""
+                + "NAME =\"" + typeName + "_name\" "
+                + "VALUE = \"" + typeName + "_align_top\" "
+                + "ALIGN = \"top\""
+                + "ID=\"" + typeName + "_align_top\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\""
+                + "NAME =\"" + typeName + "_name\" "
+                + "VALUE = \"" + typeName + "_align_right\" "
+                + "ALIGN = \"right\""
+                + "ID=\"" + typeName + "_align_right\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\""
+                + "NAME =\"" + typeName + "_name\" "
+                + "VALUE = \"" + typeName + "_align_justify\" "
+                + "ALIGN = \"justify\""
+                + "ID=\"" + typeName + "_align_justify\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
+                + "NAME =\"\" "
+                + "VALUE = \"" + typeName + "_empty_name\" "
+                + "ID=\"" + typeName + "_empty_name\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
+                + "NAME =\"" + typeName + "_name\"  "
+                + "ID=\"" + typeName + "_name_only\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
+                + "SIZE = \"100\" "
+                + "NAME =\"" + typeName + "_name1\" "
+                + "VALUE = \"" + typeName + "_size\" "
+                + "ID=\"" + typeName + "_size\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName
+                + "\" MAXLENGTH = \"10\" "
+                + "NAME =\"" + typeName + "_name\" "
+                + "VALUE = \"" + typeName + "_maxlength\" "
+                + "ID=\"" + typeName + "_maxlength\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" CHECKED "
+                + "NAME =\"" + typeName + "_name\"" + ""
+                + "VALUE = \"" + typeName + "_checked\" "
+                + "ID=\"" + typeName + "_checked\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
+                + "SRC = \"\" "
+                + "NAME =\"" + typeName + "_name\" "
+                + "VALUE = \"" + typeName + "_src\""
+                + "ID=\"" + typeName + "_src\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
+                + "DIR = \"rtl\" "
+                + "NAME =\"" + typeName + "_name\" "
+                + "VALUE = \"" + typeName + "_rtl\" "
+                + "ID=\"" + typeName + "_rtl\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
+                + "ALT = \"alt_attribute\" NAME =\"" + typeName + "_name\" "
+                + "VALUE = \"" + typeName + "_alt\" "
+                + "ID=\"" + typeName + "_alt\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
+                + "ACCESSKEY=\"U\" "
+                + "NAME =\"" + typeName + "_name\" "
+                + "VALUE = \"" + typeName + "_accesskey\" "
+                + "ID=\"" + typeName + "_accesskey\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
+                + "TABINDEX = \"1\" "
+                + "NAME =\"" + typeName + "_name\" "
+                + "VALUE = \"" + typeName + "_tabindex\" "
+                + "ID=\"" + typeName + "_tabindex\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
+                + "TITLE = \"title_attribute\" NAME =\"" + typeName + "_name\" "
+                + "VALUE = \"" + typeName + "_title\" "
+                + "ID=\"" + typeName + "_title\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
+                + "ALIGN = \"right\" NAME =\"" + typeName + "_name\" "
+                + "VALUE = \"" + typeName + "\" "
+                + "ID=\"" + typeName + "_align_right\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
+                + "ALIGN = \"center\" NAME =\"" + typeName + "_name\" "
+                + "VALUE = \"" + typeName + "\" "
+                + "ID=\"" + typeName + "_align_center\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" READONLY "
+                + "NAME =\"" + typeName + "_name\" "
+                + "VALUE = \"" + typeName + "_readonly\" "
+                + "ID=\"" + typeName + "_readonly\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" DISABLED "
+                + "NAME =\"" + typeName + "_name\" "
+                + "VALUE = \"" + typeName + "_disabled\" "
+                + "ID=\"" + typeName + "_disabled\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
+                + "ALT = \"alt_attribute\" "
+                + "TITLE = \"title_attribute\" "
+                + "NAME =\"" + typeName + "_name\" "
+                + "VALUE = \"" + typeName + "_alt_title\" "
+                + "ID=\"" + typeName + "_alt_title\">");
+        htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
+                + "USEMAP=\"#map\">");
+        htmlSrc.append("    <INPUT TYPE = \"submit\" NAME =\"submit_name\" "
+                + "VALUE = \"submit:JTextField\" "
+                + "ID=\"submit\">");
+        htmlSrc.append("</FORM>");
+        htmlSrc.append("<MAP name=\"map\">");
+        htmlSrc.append("    <P> map_title");
+        htmlSrc.append("    <A href=\"\" shape=\"rect\" coords=\"0,0,100,50\"> "
+                        + "href</A>");
+        htmlSrc.append("</MAP>");
+        htmlSrc.append("</BODY>");
+        htmlSrc.append("</HTML>");
+
+        StringReader reader = new StringReader(htmlSrc.toString());
+        htmlEditorKit.read(reader, document, 0);
+    }
+}



Mime
View raw message