harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r427121 [4/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/h...
Date Mon, 31 Jul 2006 14:08:55 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/CascadedStyle.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/CascadedStyle.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/CascadedStyle.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/CascadedStyle.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,349 @@
+/*
+ *  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 Alexey A. Ivanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+import javax.swing.event.ChangeListener;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.Element;
+import javax.swing.text.Style;
+import javax.swing.text.StyleConstants;
+
+/**
+ * Storage for all the attributes applicable for the
+ * {@link javax.swing.text.Element} for which CascadedStyle
+ * is built. Applicability is defined by CSS1 specification (http://www.w3.org/TR/CSS1).
+ */
+final class CascadedStyle implements Style {
+    private final StyleSheet styleSheet;
+    private final List styleList;
+    private final List sheetList;
+    private final String name;
+    private final Selector selector;
+
+    CascadedStyle(final StyleSheet styleSheet, final Element element,
+                  final List styleList, final Iterator sheetIt) {
+        this(styleSheet, getElementTreeSelector(element), styleList, sheetIt);
+    }
+
+    CascadedStyle(final StyleSheet styleSheet, final String name,
+                  final List styleList, final Iterator sheetIt) {
+        this.styleSheet = styleSheet;
+        this.styleList = styleList;
+        this.name = name;
+        this.selector = new Selector(name);
+
+        sheetList = new LinkedList();
+        while (sheetIt.hasNext()) {
+            sheetList.add(((StyleSheet)sheetIt.next()).getRule(name));
+        }
+    }
+
+    public static String getElementTreeSelector(final Element element) {
+        final StringBuffer result = new StringBuffer();
+        result.append(getFullName(element));
+        Element parent = element.getParentElement();
+        while (parent != null) {
+            result.insert(0, ' ');
+            result.insert(0, getFullName(parent));
+            parent = parent.getParentElement();
+        }
+        return result.toString();
+    }
+
+    public static String getFullName(final Element element) {
+        HTML.Tag tag = SelectorMatcher.getTag(element);
+        if (tag == null) {
+            return getFullName(element.getParentElement());
+        }
+
+        return getFullElementName(element, tag);
+    }
+
+    public static String getFullElementName(final Element element) {
+        HTML.Tag tag = SelectorMatcher.getTag(element);
+        if (tag == null) {
+            return null;
+        }
+
+        return getFullElementName(element, tag);
+    }
+
+    public static String getFullElementName(final Element element,
+                                            final HTML.Tag tag) {
+        final String tagName = tag.toString();
+        final String id      = SelectorMatcher.getID(tag, element);
+        final String clazz   = SelectorMatcher.getClass(tag, element);
+
+        final StringBuffer result = new StringBuffer();
+        if (tagName != null) {
+            result.append(tagName);
+        }
+        if (id != null) {
+            result.append('#').append(id);
+        }
+        if (clazz != null) {
+            result.append('.').append(clazz);
+        }
+
+        return result.toString();
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void addChangeListener(final ChangeListener arg0) {
+    }
+
+    public void removeChangeListener(final ChangeListener arg0) {
+    }
+
+    public void removeAttribute(final Object arg0) {
+//        throw new UnsupportedOperationException("Not implemented yet");
+    }
+
+    public void removeAttributes(final Enumeration arg0) {
+//        throw new UnsupportedOperationException("Not implemented yet");
+    }
+
+    public void addAttributes(final AttributeSet arg0) {
+//        throw new UnsupportedOperationException("Not implemented yet");
+    }
+
+    public void removeAttributes(final AttributeSet arg0) {
+//        throw new UnsupportedOperationException("Not implemented yet");
+    }
+
+    public void setResolveParent(final AttributeSet arg0) {
+//        throw new UnsupportedOperationException("Not implemented yet");
+    }
+
+    public void addAttribute(final Object arg0, final Object arg1) {
+//        throw new UnsupportedOperationException("Not implemented yet");
+    }
+
+    public int getAttributeCount() {
+        Iterator it = styleList.iterator();
+        int result = 0;
+        while (it.hasNext()) {
+            result += styleSheet.getStyle(it.next().toString())
+                      .getAttributeCount();
+        }
+
+        it = sheetList.iterator();
+        while (it.hasNext()) {
+            result += ((AttributeSet)it.next()).getAttributeCount();
+        }
+        return result;
+    }
+
+    public boolean isDefined(final Object arg0) {
+        Iterator it = styleList.iterator();
+        boolean result = false;
+        while (!result && it.hasNext()) {
+            Style style = styleSheet.getStyle(it.next().toString());
+            result = style.isDefined(arg0);
+        }
+        if (result) {
+            return result;
+        }
+
+        it = sheetList.iterator();
+        while (!result && it.hasNext()) {
+            result = ((AttributeSet)it.next()).isDefined(arg0);
+        }
+        return result;
+    }
+
+    public Enumeration getAttributeNames() {
+        return new Enumeration() {
+            private final Iterator styleIt = styleList.iterator();
+            private final Iterator sheetIt = sheetList.iterator();
+            private Enumeration current;
+
+            public boolean hasMoreElements() {
+                return styleIt.hasNext()
+                       || current != null && current.hasMoreElements()
+                       || hasAttributesInSheets();
+            }
+
+            public Object nextElement() {
+                if (current != null && current.hasMoreElements()) {
+                    return current.nextElement();
+                }
+                if (styleIt.hasNext()) {
+                    current = getAttributeNamesOfNextStyle();
+                    return nextElement();
+                }
+                if (hasAttributesInSheets()) {
+                    return current.nextElement();
+                }
+
+                throw new NoSuchElementException();
+            }
+
+            private boolean hasAttributesInSheets() {
+                if (sheetIt.hasNext()) {
+                    current =
+                        ((AttributeSet)sheetIt.next()).getAttributeNames();
+                }
+                return current != null && current.hasMoreElements();
+            }
+
+            private Enumeration getAttributeNamesOfNextStyle() {
+                return styleSheet.getStyle(styleIt.next().toString())
+                                  .getAttributeNames();
+            }
+        };
+    }
+
+    public AttributeSet copyAttributes() {
+        throw new UnsupportedOperationException("Not implemented yet");
+    }
+
+    public AttributeSet getResolveParent() {
+        return (AttributeSet)getAttribute(StyleConstants.ResolveAttribute);
+    }
+
+    public boolean containsAttributes(final AttributeSet arg0) {
+        boolean result = true;
+        final Enumeration keys = arg0.getAttributeNames();
+        while (result && keys.hasMoreElements()) {
+            Object key = keys.nextElement();
+            Object value = arg0.getAttribute(key);
+            result = containsAttribute(key, value);
+        }
+        return result;
+    }
+
+    public boolean isEqual(final AttributeSet arg0) {
+        if (getAttributeCount() != arg0.getAttributeCount()) {
+            return false;
+        }
+        return containsAttributes(arg0);
+    }
+
+    public Object getAttribute(final Object key) {
+        Iterator it = styleList.iterator();
+        Object result = null;
+        while (result == null && it.hasNext()) {
+            Style style = styleSheet.getStyle(it.next().toString());
+            result = style.getAttribute(key);
+        }
+        if (result != null) {
+            return result;
+        }
+        it = sheetList.iterator();
+        while (result == null && it.hasNext()) {
+            result = ((AttributeSet)it.next()).getAttribute(key);
+        }
+        return result;
+    }
+
+    public Object getAttribute(final Object key, final Element element) {
+        if (!(key instanceof CSS.Attribute)
+            || ((CSS.Attribute)key).isInherited()) {
+
+            return getAttribute(key);
+        }
+        final String elementName = getFullElementName(element);
+        if (elementName == null) {
+            return null;
+        }
+        final SimpleSelector elementSelector = new SimpleSelector(elementName);
+
+        Iterator it = styleList.iterator();
+        Object result = null;
+        while (result == null && it.hasNext()) {
+            Selector styleSelector = (Selector)it.next();
+            if (!elementSelector.applies(styleSelector.getLastSelector())) {
+                continue;
+            }
+            Style style = styleSheet.getStyle(styleSelector.toString());
+            result = style.getAttribute(key);
+        }
+        if (result != null) {
+            return result;
+        }
+        it = sheetList.iterator();
+        while (result == null && it.hasNext()) {
+            result = ((AttributeSet)it.next()).getAttribute(key);
+        }
+        return result;
+    }
+
+    public boolean containsAttribute(final Object arg0, final Object arg1) {
+        Iterator it = styleList.iterator();
+        boolean result = false;
+        while (!result && it.hasNext()) {
+            Style style = styleSheet.getStyle(it.next().toString());
+            result = style.containsAttribute(arg0, arg1);
+        }
+        if (result) {
+            return result;
+        }
+        it = sheetList.iterator();
+        while (!result && it.hasNext()) {
+            result = ((AttributeSet)it.next()).containsAttribute(arg0, arg1);
+        }
+        return result;
+    }
+
+    void addStyle(final String styleName) {
+        Selector styleSelector = new Selector(styleName);
+        if (selector.applies(styleSelector)) {
+            styleList.add(styleSelector);
+            Collections.sort(styleList, SpecificityComparator.compator);
+        }
+    }
+
+    void removeStyle(final String styleName) {
+        Iterator it = styleList.iterator();
+        while (it.hasNext()) {
+            Selector s = (Selector)it.next();
+            if (styleName.equals(s.toString())) {
+                it.remove();
+                break;
+            }
+        }
+    }
+
+    void addStyleSheet(final StyleSheet ss) {
+        sheetList.add(0, ss.getRule(name));
+    }
+
+    void removeStyleSheet(final StyleSheet ss) {
+        final Iterator it = sheetList.iterator();
+        while (it.hasNext()) {
+            CascadedStyle rs = (CascadedStyle)it.next();
+            if (rs.styleSheet == ss) {
+                it.remove();
+                break;
+            }
+        }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/CompositeAttributeSet.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/CompositeAttributeSet.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/CompositeAttributeSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/CompositeAttributeSet.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,108 @@
+/*
+ *  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 Vadim L. Bogdanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import java.util.Enumeration;
+
+import javax.swing.text.AttributeSet;
+
+class CompositeAttributeSet implements AttributeSet {
+
+    private final AttributeSet primarySet;
+    private final AttributeSet secondarySet;
+
+    CompositeAttributeSet(final AttributeSet primarySet,
+                          final AttributeSet secondarySet) {
+        this.primarySet = primarySet;
+        this.secondarySet = secondarySet;
+    }
+
+    public boolean containsAttribute(final Object key, final Object value) {
+        return primarySet.containsAttribute(key, value)
+            || secondarySet.containsAttribute(key, value);
+    }
+
+    public boolean containsAttributes(final AttributeSet attrSet) {
+        boolean result = true;
+        final Enumeration keys = attrSet.getAttributeNames();
+        while (keys.hasMoreElements() && result) {
+            Object key = keys.nextElement();
+            result = containsAttribute(key, attrSet.getAttribute(key));
+        }
+
+        return result;
+    }
+
+    public AttributeSet copyAttributes() {
+        return this;
+    }
+
+    public Object getAttribute(final Object key) {
+        Object v = primarySet.getAttribute(key);
+        return v != null ? v : secondarySet.getAttribute(key);
+    }
+
+    public int getAttributeCount() {
+        return primarySet.getAttributeCount() + secondarySet.getAttributeCount();
+    }
+
+    public Enumeration getAttributeNames() {
+        return new Enumeration() {
+            private final Enumeration primaryNames =
+                primarySet.getAttributeNames();
+            private final Enumeration secondaryNames =
+                secondarySet.getAttributeNames();
+
+            public boolean hasMoreElements() {
+                return primaryNames.hasMoreElements()
+                       || secondaryNames.hasMoreElements();
+            }
+
+            public Object nextElement() {
+                return primaryNames.hasMoreElements()
+                    ? primaryNames.nextElement()
+                    : secondaryNames.nextElement();
+            }
+        };
+    }
+
+    public AttributeSet getResolveParent() {
+        return (AttributeSet)getAttribute(AttributeSet.ResolveAttribute);
+    }
+
+    public boolean isDefined(final Object key) {
+        return primarySet.isDefined(key) || secondarySet.isDefined(key);
+    }
+
+    public boolean isEqual(final AttributeSet attrSet) {
+        if (getAttributeCount() != attrSet.getAttributeCount()) {
+            return false;
+        }
+        return containsAttributes(attrSet);
+    }
+
+    protected final AttributeSet getPrimarySet() {
+        return primarySet;
+    }
+
+    protected final AttributeSet getSecondarySet() {
+        return secondarySet;
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormSubmitEvent.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormSubmitEvent.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormSubmitEvent.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormSubmitEvent.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,80 @@
+/*
+ *  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 Vadim L. Bogdanov
+ * @version $Revision$
+ */
+
+package javax.swing.text.html;
+
+import java.net.URL;
+
+import javax.swing.text.Element;
+
+public class FormSubmitEvent extends HTMLFrameHyperlinkEvent {
+
+    public static class MethodType {
+        // TODO: Uncomment along with transition to 1.5
+        // public static enum MethodType extends Enum<MethodType> {
+
+        public static final MethodType GET = new MethodType();
+        public static final MethodType POST = new MethodType();
+
+        private MethodType() {
+        }
+
+        public static MethodType valueOf(final String name) {
+            if ("GET".equals(name)) {
+                return GET;
+            } else if ("POST".equals(name)) {
+                return POST;
+            }
+            throw new IllegalArgumentException("parameter has to be GET or POST");
+        }
+
+        public static final MethodType[] values() {
+            MethodType[] result = new MethodType[2];
+            result[0] = GET;
+            result[1] = POST;
+            return result;
+        }
+    }
+
+    private String data;
+    private MethodType method;
+
+    FormSubmitEvent(final Object source, final EventType type,
+                    final URL targetURL, final String desc,
+                    final Element sourceElement,
+                    final String targetFrame,
+                    final MethodType method,
+                    final String data) {
+
+        super(source, type, targetURL, targetFrame);
+
+        this.data = data;
+        this.method = method;
+    }
+
+    public String getData() {
+        return data;
+    }
+
+    public MethodType getMethod() {
+        return method;
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormView.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormView.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormView.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormView.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,353 @@
+/*
+ *  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.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import javax.swing.AbstractButton;
+import javax.swing.Icon;
+import javax.swing.JToggleButton;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.ComponentView;
+import javax.swing.text.Element;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.View;
+import javax.swing.text.html.FormViewComponentFactory.InputImageIcon;
+
+import org.apache.harmony.x.swing.Utilities;
+import org.apache.harmony.x.swing.text.html.form.Form;
+import org.apache.harmony.x.swing.text.html.form.FormAttributes;
+import org.apache.harmony.x.swing.text.html.form.FormButtonModel;
+import org.apache.harmony.x.swing.text.html.form.FormElement;
+import org.apache.harmony.x.swing.text.html.form.FormSelectComboBoxModel;
+import org.apache.harmony.x.swing.text.html.form.FormSelectListModel;
+import org.apache.harmony.x.swing.text.html.form.FormTextModel;
+import org.apache.harmony.x.swing.text.html.form.FormToggleButtonModel;
+
+public class FormView extends ComponentView implements ActionListener {
+    private static final int EMPTY_SPAN = 0;
+
+    protected class MouseEventListener extends MouseAdapter {
+        public void mouseReleased(final MouseEvent evt) {
+            throw new UnsupportedOperationException("Not implemented");
+        }
+    }
+
+    /**
+     * @deprecated
+     */
+    public static final String RESET = "Reset";
+
+    /**
+     * @deprecated
+     */
+    public static final String SUBMIT = "Submit Query";
+
+    private int inputTypeIndex = FormAttributes.INPUT_TYPE_INDEX_UNDEFINED;
+
+    public FormView(final Element elem) {
+        super(elem);
+    }
+
+    public float getMaximumSpan(final int axis) {
+        if (getComponent() == null || getParent() == null) {
+            return EMPTY_SPAN;
+        }
+
+        Object tag = getElement().getAttributes()
+                             .getAttribute(StyleConstants.NameAttribute);
+        if (HTML.Tag.INPUT.equals(tag)
+            || HTML.Tag.TEXTAREA.equals(tag)
+            || HTML.Tag.BUTTON.equals(tag)) {
+
+            return getPreferredSpan(axis);
+        } else if (HTML.Tag.SELECT.equals(tag)) {
+            if (getAttributes().getAttribute(HTML.Attribute.MULTIPLE) == null) {
+                return getPreferredSpan(axis);
+            }
+        }
+        if (axis == View.X_AXIS) {
+            return getComponent().getMaximumSize().width + 2;
+        } else {
+            return getComponent().getMaximumSize().height;
+        }
+    }
+
+    public void actionPerformed(final ActionEvent event) {
+        final Object source = event.getSource();
+        try {
+            switch (inputTypeIndex) {
+            case FormAttributes.INPUT_TYPE_PASSWORD_INDEX:
+//                Document doc = ((JTextComponent) source).getDocument();
+                /*
+                 * If password is last element in form, form
+                 * should be submitted.
+                 *
+                 * determineValidControls();
+                 */
+                break;
+            case FormAttributes.INPUT_TYPE_TEXT_INDEX:
+                /*
+                 * If text is last element in form, form
+                 * should be submitted.
+                 *
+                 * determineValidControls();
+                 */
+                break;
+           case FormAttributes.INPUT_TYPE_SUBMIT_INDEX:
+                final Form form = ((FormButtonModel)((AbstractButton)source)
+                                                    .getModel()).getForm();
+                determineValidControls(form);
+                /*
+                 * TODO Submit form.
+                 */
+                break;
+            case FormAttributes.INPUT_TYPE_RESET_INDEX:
+                resetForm(((FormButtonModel)((AbstractButton)source).getModel())
+                          .getForm());
+                break;
+            default:
+                // Do nothing
+                break;
+            }
+        } catch (ClassCastException e) {
+            // Do nothing
+        }
+    }
+
+    public void preferenceChanged(final View child, final boolean width,
+            final boolean height) {
+
+        if (getParent() != null) {
+            if (inputTypeIndex == FormAttributes.INPUT_TYPE_IMAGE_INDEX) {
+                final AbstractButton image = (AbstractButton) getComponent();
+                if (image == null) {
+                    return;
+                }
+                final Dimension size;
+                final Icon icon = image.getIcon();
+                if (!(icon instanceof InputImageIcon)
+                    || ((InputImageIcon)icon).imageWasLoaded()) {
+                    image.setBorderPainted(false);
+                    size = new Dimension(icon.getIconWidth(),
+                                         icon.getIconHeight());
+                } else {
+                    size = image.getPreferredSize();
+                }
+                image.setMinimumSize(size);
+                image.setPreferredSize(size);
+                image.setMaximumSize(size);
+                image.setContentAreaFilled(false);
+                image.setFocusPainted(false);
+            }
+        }
+        super.preferenceChanged(this, width, height);
+    }
+
+    protected Component createComponent() {
+        try {
+            final AttributeSet attrs = getElement().getAttributes();
+            final FormElement model = (FormElement)attrs
+                .getAttribute(StyleConstants.ModelAttribute);
+
+//            if (model == null) {
+//                return null;
+//            }
+//            inputTypeIndex = model.getElementType();
+            inputTypeIndex = FormAttributes.getElementTypeIndex(attrs);
+
+            switch (inputTypeIndex) {
+
+            case FormAttributes.INPUT_TYPE_BUTTON_INDEX:
+                return FormViewComponentFactory
+                           .createInputButtonComponent(model, attrs);
+
+            case FormAttributes.INPUT_TYPE_IMAGE_INDEX:
+                return FormViewComponentFactory
+                           .createInputImageComponent(model, attrs, this);
+
+            case FormAttributes.INPUT_TYPE_RESET_INDEX:
+                return FormViewComponentFactory
+                           .createInputResetComponent(model, attrs, this);
+
+            case FormAttributes.INPUT_TYPE_SUBMIT_INDEX:
+                return FormViewComponentFactory
+                           .createInputSubmitComponent(model, attrs, this);
+
+            case FormAttributes.INPUT_TYPE_CHECKBOX_INDEX:
+                return FormViewComponentFactory
+                           .createInputCheckBoxComponent(model, attrs);
+
+            case FormAttributes.INPUT_TYPE_RADIO_INDEX:
+                return FormViewComponentFactory
+                           .createInputRadioComponent(model, attrs);
+
+            case FormAttributes.INPUT_TYPE_FILE_INDEX:
+                return FormViewComponentFactory
+                           .createInputFileComponent(model, attrs);
+
+            case FormAttributes.INPUT_TYPE_PASSWORD_INDEX:
+                return FormViewComponentFactory
+                           .createInputPasswordComponent(model, attrs, this);
+
+            case FormAttributes.INPUT_TYPE_TEXT_INDEX:
+                return FormViewComponentFactory
+                           .createInputTextComponent(model, attrs, this);
+
+            case FormAttributes.TEXTAREA_TYPE_INDEX:
+                return FormViewComponentFactory
+                           .createTextAreaComponent(model, attrs, this);
+
+            case FormAttributes.SELECT_LIST_TYPE_INDEX:
+                return FormViewComponentFactory
+                           .createSelectMultipleComponent(model, attrs);
+
+            case FormAttributes.SELECT_COMBOBOX_TYPE_INDEX:
+                return FormViewComponentFactory
+                           .createSelectSimpleComponent(model, attrs);
+            /*
+             * TODO Uncomment this, when BUTTON model would be implemented.
+             *
+             *  case FormAttributes.BUTTON_TYPE_INDEX:
+             *      return FormViewComponentFactory
+             *                 .createButtonComponent(model, attrs, this);
+             */
+            default:
+                // Do nothing
+                break;
+            }
+        } catch (ClassCastException e) {
+            // Do nothing
+        }
+        return null;
+
+    }
+
+    protected void imageSubmit(final String imageData) {
+        // TODO implement imageSubmit
+        throw new UnsupportedOperationException("Not implemented");
+    }
+
+    protected void submitData(final String data) {
+        // TODO implement submitData
+        throw new UnsupportedOperationException("Not implemented");
+    }
+
+    private void determineValidControls(final Form form) {
+        FormElement formElement;
+
+        for (int i = 0; i < form.getElementsCount(); i++) {
+            formElement = form.getElement(i);
+
+            switch (formElement.getElementType()) {
+            case FormAttributes.INPUT_TYPE_BUTTON_INDEX :
+            case FormAttributes.INPUT_TYPE_IMAGE_INDEX :
+            case FormAttributes.INPUT_TYPE_RESET_INDEX :
+            case FormAttributes.INPUT_TYPE_SUBMIT_INDEX :
+            case FormAttributes.INPUT_TYPE_CHECKBOX_INDEX :
+            case FormAttributes.INPUT_TYPE_RADIO_INDEX :
+            case FormAttributes.INPUT_TYPE_FILE_INDEX :
+            case FormAttributes.INPUT_TYPE_PASSWORD_INDEX :
+            case FormAttributes.INPUT_TYPE_TEXT_INDEX :
+            case FormAttributes.TEXTAREA_TYPE_INDEX :
+            case FormAttributes.SELECT_LIST_TYPE_INDEX :
+            case FormAttributes.SELECT_COMBOBOX_TYPE_INDEX :
+                throw new UnsupportedOperationException("Not implemented");
+            default :
+                // Do nothing
+                break;
+            }
+        }
+    }
+
+    private void resetForm(final Form form) {
+        FormElement formElement;
+        AttributeSet attrs;
+
+        for (int i = 0; i < form.getElementsCount(); i++) {
+            formElement = form.getElement(i);
+
+            attrs = formElement.getAttributes();
+            switch (formElement.getElementType()) {
+            case FormAttributes.INPUT_TYPE_BUTTON_INDEX :
+            case FormAttributes.INPUT_TYPE_IMAGE_INDEX :
+            case FormAttributes.INPUT_TYPE_RESET_INDEX :
+            case FormAttributes.INPUT_TYPE_SUBMIT_INDEX :
+                //Do nothing
+                break;
+            case FormAttributes.INPUT_TYPE_CHECKBOX_INDEX :
+            case FormAttributes.INPUT_TYPE_RADIO_INDEX :
+                resetToogleButton((FormToggleButtonModel)formElement, attrs);
+                break;
+            case FormAttributes.INPUT_TYPE_FILE_INDEX :
+                resetText((FormTextModel)formElement,
+                          attrs, false);
+                break;
+            case FormAttributes.INPUT_TYPE_PASSWORD_INDEX :
+            case FormAttributes.INPUT_TYPE_TEXT_INDEX :
+            case FormAttributes.TEXTAREA_TYPE_INDEX :
+                resetText((FormTextModel)formElement,
+                          attrs, true);
+                break;
+            case FormAttributes.SELECT_LIST_TYPE_INDEX :
+                FormViewUtils.resetMultipleSelection((FormSelectListModel)
+                                                         formElement);
+                break;
+            case FormAttributes.SELECT_COMBOBOX_TYPE_INDEX :
+                FormViewUtils.resetSimpleSelection((FormSelectComboBoxModel)
+                                                       formElement);
+                break;
+            default :
+                // Do nothing
+                break;
+            }
+        }
+    }
+
+    private void resetText(final FormTextModel document,
+                           final AttributeSet attrs,
+                           final boolean loadDefaultText) {
+        try {
+            document.remove(0, document.getLength());
+
+            String initialContent = document.getInitialContent();
+            if (initialContent == null) {
+                initialContent = (String)attrs.getAttribute(HTML.Attribute.VALUE);
+            }
+
+            if (loadDefaultText && !Utilities.isEmptyString(initialContent)) {
+                document.insertString(0, initialContent, null);
+            }
+        } catch (BadLocationException e) {
+        }
+    }
+
+    private void resetToogleButton(final JToggleButton.ToggleButtonModel model,
+                                   final AttributeSet attrs) {
+        //CHECKED
+        model.setSelected(attrs.getAttribute(HTML.Attribute.CHECKED) != null);
+    }
+}
\ No newline at end of file

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormViewComponentFactory.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormViewComponentFactory.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormViewComponentFactory.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormViewComponentFactory.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,1030 @@
+/*
+ *  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.Color;
+import java.awt.Component;
+import java.awt.ComponentOrientation;
+import java.awt.Cursor;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.InputEvent;
+import java.net.URL;
+
+import javax.swing.AbstractButton;
+import javax.swing.Box;
+import javax.swing.ButtonGroup;
+import javax.swing.ButtonModel;
+import javax.swing.Icon;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JFileChooser;
+import javax.swing.JList;
+import javax.swing.JPasswordField;
+import javax.swing.JRadioButton;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.JToggleButton;
+import javax.swing.KeyStroke;
+import javax.swing.ListSelectionModel;
+import javax.swing.JToggleButton.ToggleButtonModel;
+import javax.swing.border.BevelBorder;
+import javax.swing.border.Border;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.EmptyBorder;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.JTextComponent;
+import javax.swing.text.PlainDocument;
+import javax.swing.text.SimpleAttributeSet;
+
+import org.apache.harmony.x.swing.Utilities;
+import org.apache.harmony.x.swing.text.html.HTMLIconFactory;
+import org.apache.harmony.x.swing.text.html.form.Form;
+import org.apache.harmony.x.swing.text.html.form.FormButtonModel;
+import org.apache.harmony.x.swing.text.html.form.FormSelectComboBoxModel;
+import org.apache.harmony.x.swing.text.html.form.FormSelectListModel;
+import org.apache.harmony.x.swing.text.html.form.FormTextModel;
+import org.apache.harmony.x.swing.text.html.form.FormToggleButtonModel;
+
+final class FormViewComponentFactory {
+    public static class InputImageIcon implements Icon {
+        private BackgroundImageLoader loader;
+        private Icon icon;
+
+        public InputImageIcon(final String src, final URL baseURL,
+                                   final FormView view) {
+            if (src == null) {
+                icon = HTMLIconFactory.getNoImageIcon();
+            } else {
+                URL url = HTML.resolveURL(src, baseURL);
+                if (url == null) {
+                    icon = HTMLIconFactory.getLoadingFailedIcon();
+                } else {
+                    loader = new BackgroundImageLoader(url, -1, -1) {
+                        protected void onReady() {
+                            super.onReady();
+                            view.preferenceChanged(view, true, true);
+                        }
+
+                        protected void onError() {
+                            super.onError();
+                            icon = HTMLIconFactory.getNoImageIcon();
+                            view.preferenceChanged(view, true, true);
+                        }
+                   };
+                }
+            }
+        }
+
+        public boolean imageWasLoaded() {
+            return loader != null && loader.isReady();
+        }
+
+        public void paintIcon(final Component c, final Graphics g,
+                              final int x, final int y) {
+            if (icon != null) {
+                icon.paintIcon(c, g, x, y);
+                return;
+            }
+
+            if (!loader.isReady()) {
+                HTMLIconFactory.getLoadingImageIcon().paintIcon(c, g, x, y);
+                return;
+            }
+
+            g.drawImage(loader.image,
+                        x, y,
+                        getIconWidth(), getIconHeight(),
+                        loader);
+        }
+
+        public int getIconWidth() {
+            if (icon != null) {
+                return icon.getIconWidth();
+            }
+
+            if (!loader.isReady()) {
+                return HTMLIconFactory.getLoadingImageIcon().getIconWidth();
+            }
+
+            return loader.getWidth();
+        }
+
+        public int getIconHeight() {
+            if (icon != null) {
+                return icon.getIconHeight();
+            }
+
+            if (!loader.isReady()) {
+                return HTMLIconFactory.getLoadingImageIcon().getIconHeight();
+            }
+
+            return loader.getHeight();
+        }
+    };
+
+        private static final int DEFAULT_TEXTFIELD_SIZE = 20;
+        private static final int DEFAULT_STRUT = 5;
+        private static final int DEFAULT_COLS_COUNT = 20;
+        private static final int DEFAULT_ROWS_COUNT = 3;
+
+        private static final char MEAN_CHAR = 'z';
+
+        private static final Color IMG_BORDER_HIGHLIGHT = new Color(136, 136,
+                                                                    136);
+        private static final Color IMG_BORDER_SHADOW = new Color(204, 204, 204);
+
+        private static final String DIR_RTL = "rtl";
+        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 FormViewComponentFactory() {
+        }
+
+        public static Component createButtonComponent(final Object model,
+                                                       final AttributeSet attrs,
+                                                       final FormView view) {
+
+            // TODO Implement support of BUTTON content
+            return createImageComponent(model, attrs, view);
+        }
+
+        public static Component createInputButtonComponent(final Object model,
+                final AttributeSet attrs) {
+
+            ButtonModel buttonModel = (ButtonModel) model;
+            final JButton button = new JButton("");
+
+            // Model
+            if (buttonModel == null) {
+                buttonModel = new FormButtonModel(new Form(SimpleAttributeSet.EMPTY),
+                                                  SimpleAttributeSet.EMPTY);
+            }
+            button.setModel(buttonModel);
+
+            // VALUE
+            String attribute = (String)attrs.getAttribute(HTML.Attribute.VALUE);
+            if (!Utilities.isEmptyString(attribute)) {
+                button.setText(attribute);
+            } else {
+                final int width, height;
+                final FontMetrics fontMetrics
+                    = button.getFontMetrics(button.getFont());
+                final Insets insets = button.getInsets();
+                width =  DEFAULT_STRUT + insets.top
+                         + insets.bottom;
+                height =  fontMetrics.getHeight() + insets.top + insets.bottom;
+
+                Dimension size = button.getPreferredSize();
+                size.width = width;
+                size.height = height;
+                button.setPreferredSize(size);
+                button.setMaximumSize(size);
+                button.setMinimumSize(size);
+            }
+
+            // SIZE
+            setButtonSize(button, attrs);
+
+            // TITLE
+            setTitle(button, attrs);
+
+            // ACCESSKEY
+            setButtonAccessKey(button, attrs);
+
+            // ALIGN
+            setButtonAlign(button);
+
+            // DISABLED
+            setDisabled(button, attrs);
+
+            return button;
+        }
+
+        public static Component createInputCheckBoxComponent(final Object model,
+                                                     final AttributeSet attrs) {
+            ToggleButtonModel checkBoxModel = (ToggleButtonModel) model;
+            final JCheckBox checkBox = new JCheckBox();
+
+            // Model
+            if (checkBoxModel == null) {
+                checkBoxModel = new FormToggleButtonModel(new Form(SimpleAttributeSet.EMPTY),
+                                                          SimpleAttributeSet.EMPTY);
+            }
+            checkBox.setModel(checkBoxModel);
+
+            // SIZE
+            setButtonSize(checkBox, attrs);
+
+            // TITLE
+            setTitle(checkBox, attrs);
+
+            // CHECKED
+            setChecked(checkBox, attrs);
+
+            // ACCESSKEY
+            setButtonAccessKey(checkBox, attrs);
+
+            // ALIGN
+            setButtonAlign(checkBox);
+
+            // DISABLED
+            setDisabled(checkBox, attrs);
+
+            return checkBox;
+        }
+
+        public static Component createInputImageComponent(final Object model,
+                                                          final AttributeSet attrs,
+                                                          final FormView view) {
+            final Component image = createImageComponent(model, attrs, view);
+
+            // ActionPerformed
+            image.addMouseListener(view.new MouseEventListener());
+
+            return image;
+        }
+
+        public static Component createInputPasswordComponent(final Object model,
+                                                 final AttributeSet attrs,
+                                                 final FormView view) {
+            PlainDocument document = (PlainDocument) model;
+            final JPasswordField passwordField = new JPasswordField();
+
+            // Model
+            if (document == null) {
+                document = new FormTextModel(new Form(SimpleAttributeSet.EMPTY),
+                                             SimpleAttributeSet.EMPTY);
+            }
+            passwordField.setDocument(document);
+
+            // ActionPerformed
+            passwordField.addActionListener(new ActionListener() {
+
+                public void actionPerformed(final ActionEvent event) {
+                    view.actionPerformed(event);
+                }
+
+            });
+
+            // VALUE
+            String attribute = (String)attrs.getAttribute(HTML.Attribute.VALUE);
+
+            if (!Utilities.isEmptyString(attribute)) {
+                passwordField.setText(attribute);
+            }
+
+            // SIZE
+            setTextSize(passwordField, attrs, passwordField.getEchoChar());
+
+            // TITLE
+            setTitle(passwordField, attrs);
+
+            // ACCESSKEY
+            setTextAccessKey(passwordField, attrs);
+
+            // DIR
+            setTextDir(passwordField, attrs);
+
+            // READONLY
+            setTextReadonly(passwordField, attrs);
+
+            // ALIGN
+            setTextAlign(passwordField);
+
+            // DISABLED
+            setDisabled(passwordField, attrs);
+
+            return passwordField;
+        }
+
+        public static Component createInputRadioComponent(final Object model,
+                                                    final AttributeSet attrs) {
+            ToggleButtonModel radioButtonModel;
+            final JRadioButton radioButton = new JRadioButton();
+
+            // NAME
+            String attribute = (String) attrs.getAttribute(HTML.Attribute.NAME);
+            if (!Utilities.isEmptyString(attribute)) {
+                radioButtonModel = (ToggleButtonModel) model;
+            } else {
+                radioButtonModel = new ToggleButtonModel() {
+                    public void setGroup(final ButtonGroup group) {
+                        //Do nothing
+                    };
+                };
+            }
+
+            // Model
+            if (radioButtonModel == null) {
+                radioButtonModel = new FormToggleButtonModel(new Form(SimpleAttributeSet.EMPTY),
+                                                             SimpleAttributeSet.EMPTY);
+            }
+            radioButton.setModel(radioButtonModel);
+
+            // SIZE
+            setButtonSize(radioButton, attrs);
+
+            // TITLE
+            setTitle(radioButton, attrs);
+
+            // CHECKED
+            setChecked(radioButton, attrs);
+
+            // ACCESSKEY
+            setButtonAccessKey(radioButton, attrs);
+
+            // ALIGN
+            setButtonAlign(radioButton);
+
+            // DISABLED
+            setDisabled(radioButton, attrs);
+
+            return radioButton;
+        }
+
+        public static Component createInputResetComponent(final Object model,
+                                                     final AttributeSet attrs,
+                                                     final FormView view) {
+            ButtonModel resetButtonModel = (ButtonModel) model;
+            final JButton resetButton = new JButton();
+
+            // Model
+            if (resetButtonModel == null) {
+                resetButtonModel = new FormButtonModel(new Form(SimpleAttributeSet.EMPTY),
+                                                       SimpleAttributeSet.EMPTY);
+            }
+            resetButton.setModel(resetButtonModel);
+
+            // ActionPerformed
+            resetButton.addActionListener(new ActionListener() {
+
+                public void actionPerformed(final ActionEvent event) {
+                    view.actionPerformed(event);
+                }
+
+            });
+
+            // VALUE
+            String attribute = (String)attrs.getAttribute(HTML.Attribute.VALUE);
+
+            if (!Utilities.isEmptyString(attribute)) {
+                resetButton.setText(attribute);
+            } else {
+                resetButton.setText(RESET_DEFAULT_TEXT);
+            }
+
+            // SIZE
+            setButtonSize(resetButton, attrs);
+
+            // TITLE
+            setTitle(resetButton, attrs);
+
+            // ACCESSKEY
+            setButtonAccessKey(resetButton, attrs);
+
+            // ALIGN
+            setButtonAlign(resetButton);
+
+            // DISABLED
+            setDisabled(resetButton, attrs);
+
+            return resetButton;
+        }
+
+        public static Component createInputSubmitComponent(final Object model,
+                                                       final AttributeSet attrs,
+                                                       final FormView view) {
+            ButtonModel submitButtonModel = (ButtonModel) model;
+            final JButton submitButton = new JButton();
+
+            // Model
+            if (submitButtonModel == null) {
+                submitButtonModel = new FormButtonModel(new Form(SimpleAttributeSet.EMPTY),
+                                                        SimpleAttributeSet.EMPTY);
+            }
+            submitButton.setModel(submitButtonModel);
+
+            // ActionPerformed
+            submitButton.addActionListener(new ActionListener() {
+
+                public void actionPerformed(final ActionEvent event) {
+                    view.actionPerformed(event);
+                }
+
+            });
+
+            // VALUE
+            String attribute = (String)attrs.getAttribute(HTML.Attribute.VALUE);
+
+            if (!Utilities.isEmptyString(attribute)) {
+                submitButton.setText(attribute);
+            } else {
+                submitButton.setText(SUBMIT_DEFAULT_TEXT);
+            }
+
+            // SIZE
+            setButtonSize(submitButton, attrs);
+
+            // TITLE
+            setTitle(submitButton, attrs);
+
+            // ACCESSKEY
+            setButtonAccessKey(submitButton, attrs);
+
+            // ALIGN
+            setButtonAlign(submitButton);
+
+            // DISABLED
+            setDisabled(submitButton, attrs);
+
+            return submitButton;
+        }
+
+        public static Component createInputTextComponent(final Object model,
+                                                     final AttributeSet attrs,
+                                                     final FormView view) {
+            PlainDocument document = (PlainDocument) model;
+            final JTextField textField = new JTextField();
+
+            // Model
+            if (document == null) {
+                document = new FormTextModel(new Form(SimpleAttributeSet.EMPTY),
+                                             SimpleAttributeSet.EMPTY);
+            }
+            textField.setDocument(document);
+
+            // ActionPerformed
+            textField.addActionListener(new ActionListener() {
+
+                public void actionPerformed(final ActionEvent event) {
+                    view.actionPerformed(event);
+                }
+
+            });
+
+            // VALUE
+            final String attribute = (String)attrs.getAttribute(HTML.Attribute
+                                                                .VALUE);
+            if (!Utilities.isEmptyString(attribute)) {
+                textField.setText(attribute);
+            }
+
+            // SIZE
+            setTextSize(textField, attrs, MEAN_CHAR);
+
+            // TITLE
+            setTitle(textField, attrs);
+
+            // ACCESSKEY
+            setTextAccessKey(textField, attrs);
+
+            // DIR
+            setTextDir(textField, attrs);
+
+            // READONLY
+            setTextReadonly(textField, attrs);
+
+            // ALIGN
+            setTextAlign(textField);
+
+            // DISABLED
+            setDisabled(textField, attrs);
+
+            return textField;
+        }
+
+        public static Component createInputFileComponent(final Object model,
+                                                     final AttributeSet attrs) {
+            /*
+             * FilePath attributes
+             */
+            PlainDocument document = (PlainDocument) model;
+            final JTextField filePath = new JTextField();
+
+            // Model
+            if (document == null) {
+                document = new FormTextModel(new Form(SimpleAttributeSet.EMPTY),
+                                             SimpleAttributeSet.EMPTY);
+            }
+            filePath.setDocument(document);
+
+            // SIZE
+            setTextSize(filePath, attrs, MEAN_CHAR);
+
+            // ACCESSKEY
+            setTextAccessKey(filePath, attrs);
+
+            // DIR
+            boolean isRTL = setTextDir(filePath, attrs);
+
+            /*
+             * Browse button attributes
+             */
+            final JButton browseButton
+                = new JButton(BROWSE_BUTTON_DEFAULT_TEXT);
+
+            // READONLY
+            String attribute = (String) attrs.getAttribute(HTML.Attribute
+                                                           .READONLY);
+            if (attribute != null) {
+               filePath.setEditable(false);
+            } else {
+                browseButton.addActionListener(new ActionListener() {
+                    private JFileChooser chooser;
+                    public void actionPerformed(final ActionEvent e) {
+                        if (chooser == null) {
+                            chooser = new JFileChooser();
+                        }
+                        if (chooser.showOpenDialog(browseButton)
+                            == JFileChooser.APPROVE_OPTION) {
+
+                            filePath.setText(chooser.getSelectedFile().getPath());
+                        }
+                    }
+                });
+            }
+
+            /*
+             * Box attributes
+             */
+            final Box box = Box.createHorizontalBox();
+
+            // TITLE
+            attribute = (String) attrs.getAttribute(HTML.Attribute.TITLE);
+            if (!Utilities.isEmptyString(attribute)) {
+                filePath.setToolTipText(attribute);
+                browseButton.setToolTipText(attribute);
+            }
+
+            // ALIGN
+            box.setAlignmentX(JComponent.CENTER_ALIGNMENT);
+            box.setAlignmentY(JComponent.BOTTOM_ALIGNMENT);
+            browseButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
+            browseButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
+
+            // DISABLED
+            if (attrs.getAttribute(HTML.Attribute.DISABLED) != null) {
+                filePath.setEnabled(false);
+                browseButton.setEnabled(false);
+            }
+
+            box.add(filePath);
+            box.add(Box.createHorizontalStrut(5));
+            box.add(browseButton);
+
+            if (isRTL) {
+                box.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
+            }
+
+            return box;
+        }
+
+        public static JComponent createSelectMultipleComponent(
+                                                       final Object model,
+                                                       final AttributeSet attrs) {
+            // MULTIPLE
+            final boolean isMultiple
+                = (attrs.getAttribute(HTML.Attribute.MULTIPLE) != null);
+
+            // SIZE
+            int linesCount = 0;
+            String attribute = (String)attrs.getAttribute(HTML.Attribute.SIZE);
+            if (!Utilities.isEmptyString(attribute)) {
+                try {
+                    linesCount = Integer.parseInt(attribute);
+                } catch (NumberFormatException e) {
+                    //DO nothing
+                }
+            }
+
+            /*
+             * JList attributes
+             */
+            JList selectionList = new JList();
+            FormSelectListModel optionModel;
+
+            // Model
+            if (model != null) {
+                optionModel = (FormSelectListModel)model;
+            } else {
+                optionModel = new FormSelectListModel(new Form(SimpleAttributeSet.EMPTY),
+                                                      SimpleAttributeSet.EMPTY,
+                                                      selectionList.getSelectionModel());
+            }
+
+            selectionList.setModel(optionModel);
+            selectionList.setSelectionModel(optionModel.getSelectionModel());
+
+            if (isMultiple) {
+                selectionList.setSelectionMode(ListSelectionModel
+                                               .MULTIPLE_INTERVAL_SELECTION);
+
+            }
+
+            // TITLE
+            if (!Utilities.isEmptyString(optionModel.getTitle())) {
+                selectionList.setToolTipText(optionModel.getTitle());
+            }
+
+            // DIR
+            setTextDir(selectionList, attrs);
+
+            // OPTION attributes
+            if (linesCount <= 1) {
+                linesCount = Math.max(1, selectionList.getModel().getSize());
+            }
+
+            // Selection
+            FormViewUtils.resetMultipleSelection(optionModel);
+
+            /*
+             * JScrollPane attributes
+             */
+            final FontMetrics fontMetrics
+                = selectionList.getFontMetrics(selectionList.getFont());
+            Dimension size;
+            if (optionModel.getSize() == 0) {
+                size = selectionList.getPreferredSize();
+                Insets insets = selectionList.getInsets();
+                size.width = fontMetrics.charWidth(MEAN_CHAR)
+                             + insets.left + insets.right;
+                selectionList.setPreferredSize(size);
+            }
+
+            JScrollPane pane = new JScrollPane(selectionList,
+                                               JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+                                               JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+
+
+            size = pane.getPreferredSize();
+            size.height = linesCount * fontMetrics.getHeight();
+            pane.setMinimumSize(size);
+            pane.setMaximumSize(size);
+            pane.setPreferredSize(size);
+            pane.setAlignmentY(JComponent.BOTTOM_ALIGNMENT);
+
+            // DISABLED
+            if (optionModel.isEnabled()) {
+                pane.setEnabled(false);
+            }
+
+            return pane;
+        }
+
+        public static JComponent createSelectSimpleComponent(
+                                                     final Object model,
+                                                     final AttributeSet attrs) {
+            JComboBox selectElement = new JComboBox();
+            FormSelectComboBoxModel comboBoxModel = (FormSelectComboBoxModel)model;
+            // Model
+            if (comboBoxModel == null) {
+                comboBoxModel = new FormSelectComboBoxModel(new Form(SimpleAttributeSet.EMPTY),
+                                                            SimpleAttributeSet.EMPTY);
+
+            }
+            selectElement.setModel(comboBoxModel);
+
+            selectElement.setAlignmentY(JComponent.BOTTOM_ALIGNMENT);
+
+            // TITLE
+            if (!Utilities.isEmptyString(comboBoxModel.getTitle())) {
+                selectElement.setToolTipText(comboBoxModel.getTitle());
+            }
+
+            // DIR
+            setTextDir(selectElement, attrs);
+
+            // Selection
+            FormViewUtils.resetSimpleSelection(selectElement.getModel());
+
+            // Size
+            final Dimension size = selectElement.getPreferredSize();
+            selectElement.setMinimumSize(size);
+            selectElement.setMaximumSize(size);
+
+            // DISABLED
+            if (!comboBoxModel.isEnabled()) {
+               selectElement.setEnabled(false);
+            }
+
+            return selectElement;
+        }
+
+
+        public static Component createTextAreaComponent(final Object model,
+                                                        final AttributeSet attrs,
+                                                        final FormView view) {
+            /*
+             * JTextArea attributes
+             */
+            Dimension size;
+            PlainDocument document = (PlainDocument)model;
+
+            //ROWS
+            int rowsCount = DEFAULT_ROWS_COUNT;
+            String attribute = (String)attrs.getAttribute(HTML.Attribute.ROWS);
+            if (!Utilities.isEmptyString(attribute)) {
+                try {
+                    rowsCount = Integer.parseInt(attribute);
+                } catch (NumberFormatException  e) {
+                    //Do nothing
+                }
+            }
+
+            //COLS
+            int columnsCount = DEFAULT_COLS_COUNT;
+            attribute = (String)attrs.getAttribute(HTML.Attribute.COLS);
+            if (!Utilities.isEmptyString(attribute)) {
+                try {
+                    columnsCount = Integer.parseInt(attribute);
+                } catch (NumberFormatException  e) {
+                    //Do nothing
+                }
+            }
+
+            //Model
+            if (document == null) {
+                document = new FormTextModel(new Form(SimpleAttributeSet.EMPTY),
+                                             SimpleAttributeSet.EMPTY);
+            }
+
+            final JTextArea textArea = new JTextArea(document,
+                                                     null,
+                                                     rowsCount,
+                                                     columnsCount);
+            //DIR
+            setTextDir(textArea, attrs);
+
+            //ACCESSKEY
+            setTextAccessKey(textArea, attrs);
+
+            //READONLY
+            setTextReadonly(textArea, attrs);
+
+            /*
+             * JScrollPane attributes
+             */
+            final JScrollPane pane = new JScrollPane(textArea);
+            size = pane.getPreferredSize();
+            pane.setMinimumSize(size);
+            pane.setPreferredSize(size);
+            pane.setMaximumSize(size);
+
+            pane.setAlignmentY(JComponent.BOTTOM_ALIGNMENT);
+
+            //TITLE
+            attribute = (String) attrs.getAttribute(HTML.Attribute.TITLE);
+            if (!Utilities.isEmptyString(attribute)) {
+                textArea.setToolTipText(attribute);
+                pane.setToolTipText(attribute);
+                pane.getVerticalScrollBar().setToolTipText(attribute);
+                pane.getHorizontalScrollBar().setToolTipText(attribute);
+            }
+
+
+            //DISABLED
+            if (attrs.getAttribute(HTML.Attribute.DISABLED) != null) {
+                textArea.setEnabled(false);
+                pane.setEnabled(false);
+            }
+
+            return pane;
+        }
+
+        private static Component createImageComponent(final Object model,
+                                                      final AttributeSet attrs,
+                                                      final FormView view) {
+
+            ButtonModel imageModel = (ButtonModel) model;
+            final JButton image = new JButton("");
+
+            // Model
+            if (imageModel == null) {
+                imageModel = new FormButtonModel(new Form(SimpleAttributeSet.EMPTY),
+                                                 SimpleAttributeSet.EMPTY);
+            }
+            image.setModel(imageModel);
+
+            image.setCursor(new Cursor(Cursor.HAND_CURSOR));
+
+            // SRC, ALT
+            String attribute = (String)attrs.getAttribute(HTML.Attribute.SRC);
+
+            InputImageIcon icon
+                = new InputImageIcon(attribute,
+                                          ((HTMLDocument)view.getDocument())
+                                          .getBase(),
+                                          view);
+            image.setIcon(icon);
+            image.setBackground(Color.WHITE);
+            Dimension size;
+            if (icon.imageWasLoaded()) {
+                image.setBorderPainted(false);
+                size = new Dimension(icon.getIconWidth(),
+                                     icon.getIconHeight());
+            } else {
+                Border outside = new BevelBorder(BevelBorder.LOWERED,
+                                                 IMG_BORDER_SHADOW,
+                                                 IMG_BORDER_HIGHLIGHT);
+                image.setBorder(new CompoundBorder(outside,
+                                                  new EmptyBorder(5, 5, 5, 5)));
+                image.setContentAreaFilled(false);
+                image.setFocusPainted(false);
+                attribute = (String)attrs.getAttribute(HTML.Attribute.ALT);
+                if (!Utilities.isEmptyString(attribute)) {
+                    image.setFont(new Font("Button.font", 0 , 12));
+                    image.setText(attribute);
+                    image.setToolTipText(attribute);
+                }
+                size = image.getPreferredSize();
+            }
+            image.setMinimumSize(size);
+            image.setPreferredSize(size);
+            image.setMaximumSize(size);
+
+            //SIZE
+            setButtonSize(image, attrs);
+
+            //TITLE
+            setTitle(image, attrs);
+
+            //ACCESSKEY
+            setButtonAccessKey(image, attrs);
+
+            //ALIGN
+            setButtonAlign(image);
+
+            //DISABLED
+            setDisabled(image, attrs);
+
+            return image;
+        }
+
+        private static void setTextSize(final JTextComponent textComponent,
+                final AttributeSet attrs, final char widestChar) {
+            final String attribute
+                = (String) attrs.getAttribute(HTML.Attribute.SIZE);
+            int width = DEFAULT_TEXTFIELD_SIZE;
+            if (attribute != null) {
+                try {
+                    final int newWidth = Integer.parseInt(attribute);
+                    if (newWidth > width) {
+                        width = newWidth;
+                    }
+                } catch (NumberFormatException e) {
+                    // do nothing
+                }
+            }
+            final FontMetrics fontMetrics
+                = textComponent.getFontMetrics(textComponent.getFont());
+            final int charWidth = fontMetrics.charWidth(widestChar);
+            Dimension size = textComponent.getPreferredSize();
+
+            size.width = width * charWidth;
+            textComponent.setPreferredSize(size);
+            textComponent.setMaximumSize(size);
+
+            size = new Dimension(DEFAULT_TEXTFIELD_SIZE * charWidth,
+                                 size.height);
+            textComponent.setMinimumSize(size);
+        }
+
+        private static String setTitle(final JComponent component,
+                                       final AttributeSet attrs) {
+            final String attribute = (String) attrs.getAttribute(HTML.Attribute
+                                                                 .TITLE);
+            if (!Utilities.isEmptyString(attribute)) {
+                component.setToolTipText(attribute);
+            }
+            return attribute;
+        }
+
+        private static void setTextReadonly(final JTextComponent textComponent,
+                                            final AttributeSet attrs) {
+            if (attrs.getAttribute(HTML.Attribute.READONLY) != null) {
+                textComponent.setEditable(false);
+            }
+        }
+
+        private static void setButtonAccessKey(final AbstractButton button,
+                                               final AttributeSet attrs) {
+            final String attribute = (String) attrs.getAttribute(HTML.Attribute
+                                                                 .ACCESSKEY);
+            if (!Utilities.isEmptyString(attribute)) {
+                button.setMnemonic(attribute.charAt(0));
+            }
+        }
+
+        private static void setButtonAlign(final AbstractButton button) {
+            button.setAlignmentX(JComponent.LEFT_ALIGNMENT);
+            button.setAlignmentY(JComponent.BOTTOM_ALIGNMENT);
+        }
+
+        private static void setButtonSize(final AbstractButton button,
+                                          final AttributeSet attrs) {
+            final String attribute;
+            attribute = (String)attrs.getAttribute(HTML.Attribute.SIZE);
+            if (attribute != null) {
+                Dimension size = button.getPreferredSize();
+                try {
+                    size.width = Integer.parseInt(attribute);
+                } catch (NumberFormatException  e) {
+                    //Do nothing
+                }
+                button.setPreferredSize(size);
+                button.setMaximumSize(size);
+                button.setMinimumSize(size);
+            }
+        }
+
+        private static void setChecked(final JToggleButton button,
+                                       final AttributeSet attrs) {
+            if (attrs.getAttribute(HTML.Attribute.CHECKED) != null) {
+                button.setSelected(true);
+            }
+        }
+
+        private static void setDisabled(final Component component,
+                                        final AttributeSet attrs) {
+            if (attrs.getAttribute(HTML.Attribute.DISABLED) != null) {
+                component.setEnabled(false);
+            }
+        }
+
+        private static void setTextAccessKey(final JTextComponent textComponent,
+                                             final AttributeSet attrs) {
+            final String attribute = (String) attrs.getAttribute(HTML.Attribute
+                                                                 .ACCESSKEY);
+            if (!Utilities.isEmptyString(attribute)) {
+                ActionListener listener = new ActionListener() {
+
+                    public void actionPerformed(final ActionEvent e) {
+                        textComponent.requestFocusInWindow();
+                    }
+
+                };
+                final char key = attribute.charAt(0);
+                final KeyStroke keystroke1
+                    = KeyStroke.getKeyStroke(Character.toLowerCase(key),
+                                             InputEvent.ALT_MASK);
+                final KeyStroke keystroke2
+                    = KeyStroke.getKeyStroke(Character.toUpperCase(key),
+                                             InputEvent.ALT_MASK);
+                textComponent.registerKeyboardAction(listener,
+                                                     keystroke1,
+                                                     JComponent
+                                                     .WHEN_IN_FOCUSED_WINDOW);
+                textComponent.registerKeyboardAction(listener,
+                                                     keystroke2,
+                                                     JComponent
+                                                     .WHEN_IN_FOCUSED_WINDOW);
+            }
+        }
+
+        private static void setTextAlign(final JTextComponent component) {
+            component.setAlignmentX(JComponent.CENTER_ALIGNMENT);
+            component.setAlignmentY(JComponent.BOTTOM_ALIGNMENT);
+        }
+
+        private static boolean setTextDir(final Component component,
+                                          final AttributeSet attrs) {
+            final String attribute = (String)attrs.getAttribute(HTML.Attribute
+                                                                .DIR);
+            if (!Utilities.isEmptyString(attribute)) {
+                if (DIR_RTL.equals(attribute.toLowerCase())) {
+                    component.setComponentOrientation(ComponentOrientation
+                                                          .RIGHT_TO_LEFT);
+                    return true;
+                }
+            }
+            return false;
+        }
+
+}
\ No newline at end of file

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormViewUtils.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormViewUtils.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormViewUtils.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormViewUtils.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,112 @@
+/*
+ *  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.util.Stack;
+
+import javax.swing.ComboBoxModel;
+import javax.swing.ListSelectionModel;
+import javax.swing.text.AttributeSet;
+
+import org.apache.harmony.x.swing.text.html.form.FormOption;
+import org.apache.harmony.x.swing.text.html.form.FormSelectListModel;
+
+final class FormViewUtils {
+
+    private FormViewUtils() {
+    }
+
+    public static boolean selectOption(final FormOption option,
+                                         final boolean isMultiple,
+                                         final boolean notSelected) {
+
+        if (isMultiple || notSelected) {
+            AttributeSet attrs = option.getAttributes();
+
+            // SELECTED
+            Object attribute = attrs.getAttribute(HTML.Attribute.SELECTED);
+            if (attribute != null) {
+                option.setSelection(true);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public static void resetSimpleSelection(final ComboBoxModel model) {
+        Object element;
+        FormOption option;
+        Stack options = new Stack();
+
+        boolean notSelected = true;
+        for (int i = model.getSize() - 1; i >= 0; i--) {
+            element = model.getElementAt(i);
+            if (element instanceof FormOption) {
+                option = (FormOption) element;
+                notSelected &= !selectElement(option, false, notSelected);
+                if (option.isSelected()) {
+                    model.setSelectedItem(element);
+                }
+                options.push(option);
+            }
+        }
+        if (notSelected) {
+            while (!options.isEmpty()) {
+                option = (FormOption)options.pop();
+                if (option.isEnabled()) {
+                    model.setSelectedItem(option);
+                    break;
+                }
+            }
+        }
+    }
+
+    public static void resetMultipleSelection(final FormSelectListModel model) {
+        Object item;
+        FormOption option;
+
+        ListSelectionModel selectionModel = model.getSelectionModel();
+        selectionModel.clearSelection();
+
+        for (int i = 0; i < model.getSize(); i++) {
+            item = model.getElementAt(i);
+
+            if (item instanceof FormOption) {
+                option = (FormOption) item;
+                selectElement(option, true, true);
+                if (option.isSelected()) {
+                    selectionModel.addSelectionInterval(i, i);
+                }
+            }
+        }
+    }
+
+    private static boolean selectElement(final FormOption option,
+                                      final boolean multiple,
+                                      final boolean notSelected) {
+
+        option.setSelection(false);
+        if (option.getDepth() == 0) {
+            return selectOption(option, multiple, notSelected);
+        }
+        return false;
+    }
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FrameSetTagView.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FrameSetTagView.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FrameSetTagView.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FrameSetTagView.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,181 @@
+/*
+ *  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 Vadim L. Bogdanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import javax.swing.text.BoxView;
+import javax.swing.text.Element;
+import javax.swing.text.View;
+
+class FrameSetTagView extends BoxView {
+
+    public FrameSetTagView(final Element elem) {
+        super(elem, calculateMajorAxis(elem));
+    }
+
+    protected void layoutMajorAxis(final int targetSpan, final int axis,
+                                   final int[] offsets, final int[] spans) {
+        if (!hasNoFramesView()) {
+            layoutAxisImpl(targetSpan, axis, offsets, spans);
+            return;
+        }
+
+        View noFramesView = getView(getViewCount() - 1);
+        int noFramesSpan = (int)noFramesView.getMinimumSpan(axis);
+        int newTargetSpan = targetSpan - noFramesSpan;
+
+        layoutAxisImpl(newTargetSpan, axis, offsets, spans);
+
+        offsets[getViewCount() - 1] = newTargetSpan;
+        spans[getViewCount() - 1] = noFramesSpan;
+    }
+
+    protected void layoutMinorAxis(final int targetSpan, final int axis,
+                                   final int[] offsets, final int[] spans) {
+        layoutAxisImpl(targetSpan, axis, offsets, spans);
+
+        if (hasNoFramesView()) {
+            offsets[getViewCount() - 1] = 0;
+            spans[getViewCount() - 1] = targetSpan;
+        }
+    }
+
+    private void layoutAxisImpl(final int targetSpan, final int axis,
+                                   final int[] offsets, final int[] spans) {
+        Object attr;
+        if (axis == X_AXIS) {
+            attr = HTML.Attribute.COLS;
+        } else {
+            attr = HTML.Attribute.ROWS;
+        }
+
+        String[] strLengths = parseLengths(
+            (String)getAttributes().getAttribute(attr));
+        int lineLength = strLengths.length;
+
+        int[] lengths = calculateLengths(strLengths, targetSpan);
+
+        int x = 0;
+        int y = 0;
+        int curOffset = 0;
+        int viewsToLayout = hasNoFramesView() ? getViewCount() - 1 : getViewCount();
+        for (int i = 0; i < viewsToLayout; i++) {
+            offsets[i] = curOffset;
+            spans[i] = lengths[x];
+
+            if (axis == X_AXIS) {
+                curOffset += spans[i];
+                x++;
+                if (x >= lineLength) {
+                    x = 0;
+                    y++;
+                    curOffset = 0;
+                }
+            } else {
+                y++;
+                if (y >= offsets.length / lineLength) {
+                    x++;
+                    y = 0;
+                    curOffset += spans[i];
+                }
+            }
+        }
+    }
+
+    private int[] calculateLengths(final String[] strLengths,
+                                   final int targetLength) {
+        int[] lengths = new int[strLengths.length];
+
+        int remainingLength = targetLength;
+        int starsCount = 0;
+        for (int i = 0; i < lengths.length; i++) {
+            String strLen = strLengths[i];
+            if (strLen.endsWith("%")) {
+                lengths[i] = targetLength * cutTailAndParseInt(strLen) / 100;
+            } else if (strLen.endsWith("*")) {
+                // we'll just count '*' during this pass
+                lengths[i] = 0;
+                starsCount += cutTailAndParseInt(strLen);
+            } else {
+                lengths[i] = Integer.parseInt(strLen);
+            }
+            remainingLength -= lengths[i];
+        }
+
+        // allocate space for '*' frames
+        int starsLength = Math.max(remainingLength, 0);
+        if (starsCount > 0) {
+            for (int i = 0; i < lengths.length; i++) {
+                String strLen = strLengths[i];
+                if (strLen.endsWith("*")) {
+                    lengths[i] = starsLength
+                        * cutTailAndParseInt(strLen) / starsCount;
+                    remainingLength -= lengths[i];
+                }
+            }
+        }
+
+        normalizeLengths(lengths, targetLength, targetLength - remainingLength);
+        return lengths;
+    }
+
+    private int cutTailAndParseInt(final String str) {
+        if ("*".equals(str)) {
+            return 1;
+        }
+        return Integer.parseInt(str.substring(0, str.length() - 1));
+    }
+
+    private void normalizeLengths(final int[] lengths, final int targetLength,
+                                  final int allocatedLength) {
+        if (targetLength == allocatedLength || allocatedLength == 0) {
+            return;
+        } else if (Math.abs(targetLength - allocatedLength) < lengths.length) {
+            lengths[lengths.length - 1] += targetLength - allocatedLength;
+            return;
+        }
+
+        int usedLength = 0;
+        for (int i = 0; i < lengths.length; i++) {
+            lengths[i] = lengths[i] * targetLength / allocatedLength;
+            usedLength += lengths[i];
+        }
+
+        lengths[lengths.length - 1] += targetLength - usedLength;
+    }
+
+    private static String[] parseLengths(final String lengths) {
+        if (lengths == null) {
+            return new String[] {"100%"};
+        }
+
+        return lengths.split(", *");
+    }
+
+    private static int calculateMajorAxis(final Element elem) {
+        return elem.getAttributes().isDefined(HTML.Attribute.ROWS) ? Y_AXIS : X_AXIS;
+    }
+
+    private boolean hasNoFramesView() {
+        if (getViewCount() == 0) {
+            return false;
+        }
+        return getView(getViewCount() - 1) instanceof NoFramesTagView;
+    }
+}



Mime
View raw message