incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liud...@apache.org
Subject svn commit: r1411080 [1/3] - in /incubator/odf/trunk/simple/src: main/java/org/odftoolkit/simple/ main/java/org/odftoolkit/simple/draw/ main/java/org/odftoolkit/simple/form/ main/java/org/odftoolkit/simple/text/ test/java/org/odftoolkit/simple/form/
Date Mon, 19 Nov 2012 06:51:46 GMT
Author: liudali
Date: Mon Nov 19 06:51:44 2012
New Revision: 1411080

URL: http://svn.apache.org/viewvc?rev=1411080&view=rev
Log:
fix for ODFTOOLKIT-340, patched by KeJiaYe.

Added:
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/draw/Control.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/draw/ControlContainer.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/draw/ControlStyleHandler.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/AbstractFormContainer.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Button.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/CheckBox.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/ComboBox.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/CurrencyField.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/DateField.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Field.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Form.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormContainer.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormControl.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormProvider.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormTypeDefinition.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Label.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/ListBox.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/NumericField.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/OOForm.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/OOFormProvider.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/PatternField.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/RadioButton.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/TextBox.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/TimeField.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/AbstractFormContainerTest.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/ButtonTest.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/CheckBoxTest.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/ComboBoxTest.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/FieldTest.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/LabelTest.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/ListBoxTest.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/RadioButtonTest.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/TextBoxTest.java
Modified:
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/TextDocument.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/text/Paragraph.java

Modified: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/TextDocument.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/TextDocument.java?rev=1411080&r1=1411079&r2=1411080&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/TextDocument.java (original)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/TextDocument.java Mon Nov 19 06:51:44 2012
@@ -36,8 +36,10 @@ import java.util.logging.Logger;
 import org.odftoolkit.odfdom.dom.OdfContentDom;
 import org.odftoolkit.odfdom.dom.OdfDocumentNamespace;
 import org.odftoolkit.odfdom.dom.attribute.text.TextAnchorTypeAttribute;
+import org.odftoolkit.odfdom.dom.element.draw.DrawControlElement;
 import org.odftoolkit.odfdom.dom.element.draw.DrawFrameElement;
 import org.odftoolkit.odfdom.dom.element.office.OfficeDocumentStylesElement;
+import org.odftoolkit.odfdom.dom.element.office.OfficeFormsElement;
 import org.odftoolkit.odfdom.dom.element.office.OfficeMasterStylesElement;
 import org.odftoolkit.odfdom.dom.element.office.OfficeTextElement;
 import org.odftoolkit.odfdom.dom.element.style.StyleColumnsElement;
@@ -55,6 +57,7 @@ import org.odftoolkit.odfdom.dom.element
 import org.odftoolkit.odfdom.dom.element.text.TextPElement;
 import org.odftoolkit.odfdom.dom.element.text.TextParagraphElementBase;
 import org.odftoolkit.odfdom.dom.element.text.TextSectionElement;
+import org.odftoolkit.odfdom.dom.element.text.TextSequenceDeclsElement;
 import org.odftoolkit.odfdom.dom.element.text.TextTableOfContentElement;
 import org.odftoolkit.odfdom.dom.element.text.TextTableOfContentEntryTemplateElement;
 import org.odftoolkit.odfdom.dom.element.text.TextTableOfContentSourceElement;
@@ -69,6 +72,7 @@ import org.odftoolkit.odfdom.incubator.d
 import org.odftoolkit.odfdom.incubator.doc.text.OdfTextParagraph;
 import org.odftoolkit.odfdom.pkg.MediaType;
 import org.odftoolkit.odfdom.pkg.OdfElement;
+import org.odftoolkit.odfdom.pkg.OdfFileDom;
 import org.odftoolkit.odfdom.pkg.OdfPackage;
 import org.odftoolkit.odfdom.type.CellRangeAddressList;
 import org.odftoolkit.odfdom.type.Length.Unit;
@@ -80,6 +84,11 @@ import org.odftoolkit.simple.common.fiel
 import org.odftoolkit.simple.common.field.VariableContainer;
 import org.odftoolkit.simple.common.field.VariableField;
 import org.odftoolkit.simple.common.field.VariableField.VariableType;
+import org.odftoolkit.simple.draw.Control;
+import org.odftoolkit.simple.draw.ControlContainer;
+import org.odftoolkit.simple.form.AbstractFormContainer;
+import org.odftoolkit.simple.form.Form;
+import org.odftoolkit.simple.form.FormContainer;
 import org.odftoolkit.simple.style.MasterPage;
 import org.odftoolkit.simple.style.TOCStyle;
 import org.odftoolkit.simple.table.Table;
@@ -101,7 +110,9 @@ import org.w3c.dom.Text;
  * This class represents an empty ODF text document.
  * 
  */
-public class TextDocument extends Document implements ListContainer, ParagraphContainer, VariableContainer, ChartContainer {
+public class TextDocument extends Document implements ListContainer,
+		ParagraphContainer, VariableContainer, ChartContainer, FormContainer,
+		ControlContainer {
 
 	private static final String EMPTY_TEXT_DOCUMENT_PATH = "/OdfTextDocument.odt";
 	static final Resource EMPTY_TEXT_DOCUMENT_RESOURCE = new Resource(EMPTY_TEXT_DOCUMENT_PATH);
@@ -110,6 +121,7 @@ public class TextDocument extends Docume
 	private ParagraphContainerImpl paragraphContainerImpl;
 	private VariableContainerImpl variableContainerImpl;
 	private ChartContainerImpl chartContainerImpl;
+	private FormContainerImpl formContainerImpl = null;
 	
 	private Header firstPageHeader;
 	private Header standardHeader;
@@ -1446,4 +1458,122 @@ public class TextDocument extends Docume
 			Logger.getLogger(TextDocument.class.getName()).log(Level.SEVERE, null, e);
 		}
 	}
+
+	private FormContainerImpl getFormContainerImpl() {
+		if (formContainerImpl == null) {
+			formContainerImpl = new FormContainerImpl();
+		}
+		return formContainerImpl;
+	}
+
+	private class FormContainerImpl extends AbstractFormContainer {
+
+		public OfficeFormsElement getFormContainerElement() {
+			OfficeFormsElement forms = null;
+			try {
+				OfficeTextElement root = getContentRoot();
+				forms = OdfElement.findFirstChildNode(OfficeFormsElement.class,
+						root);
+				if (forms == null) {
+					Node firstChild = root.getFirstChild();
+					OfficeFormsElement officeForms = ((OdfFileDom) getContentDom())
+							.newOdfElement(OfficeFormsElement.class);
+					forms = (OfficeFormsElement) root.insertBefore(officeForms,
+							firstChild);
+				}
+				return forms;
+			} catch (Exception e) {
+				Logger.getLogger(TextDocument.class.getName()).log(
+						Level.SEVERE, null, e);
+			}
+			return forms;
+		}
+
+	}
+
+	/**
+	 * Create a form with specified name in this text document.
+	 * 
+	 * @see FormContainer#createForm(String)
+	 */
+	public Form createForm(String name) {
+		return getFormContainerImpl().createForm(name);
+	}
+
+	/**
+	 * Get a form iterator to traverse all the forms in this document.
+	 * 
+	 * @see FormContainer#getFormIterator()
+	 */
+	public Iterator<Form> getFormIterator() {
+		return getFormContainerImpl().getFormIterator();
+	}
+
+	/**
+	 * Remove a form with the specified name in this document.
+	 * 
+	 * @see FormContainer#removeForm(Form)
+	 */
+	public boolean removeForm(Form form) {
+		return getFormContainerImpl().removeForm(form);
+	}
+
+//	@Override
+	public Form getFormByName(String name) {
+		return getFormContainerImpl().getFormByName(name);
+	}
+
+//	@Override
+	public OfficeFormsElement getFormContainerElement() {
+		return getFormContainerImpl().getFormContainerElement();
+	}
+
+//	@Override
+	public boolean getApplyDesignMode() {
+		return getFormContainerImpl().getApplyDesignMode();
+	}
+
+//	@Override
+	public boolean getAutomaticFocus() {
+		return getFormContainerImpl().getAutomaticFocus();
+	}
+
+//	@Override
+	public void setApplyDesignMode(boolean isDesignMode) {
+		getFormContainerImpl().setApplyDesignMode(isDesignMode);
+
+	}
+
+//	@Override
+	public void setAutomaticFocus(boolean isAutoFocus) {
+		getFormContainerImpl().setAutomaticFocus(isAutoFocus);
+
+	}
+
+//	@Override
+	public Control createDrawControl() {
+		OdfElement parent = this.getDrawControlContainerElement();
+		OdfFileDom ownerDom = (OdfFileDom) parent.getOwnerDocument();
+		DrawControlElement element = ownerDom
+				.newOdfElement(DrawControlElement.class);
+		Node refChild = OdfElement.findFirstChildNode(
+				TextSequenceDeclsElement.class, parent);
+		parent.insertBefore(element, refChild.getNextSibling());
+		Control control = new Control(element);
+		Component.registerComponent(control, element);
+		return control;
+	}
+
+//	@Override
+	public OdfElement getDrawControlContainerElement() {
+		OdfElement element = null;
+		try {
+			element = this.getContentRoot();
+		} catch (Exception e) {
+			Logger.getLogger(TextDocument.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+		return element;
+	}
+
 }

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/draw/Control.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/draw/Control.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/draw/Control.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/draw/Control.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,267 @@
+package org.odftoolkit.simple.draw;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.odftoolkit.odfdom.dom.OdfDocumentNamespace;
+import org.odftoolkit.odfdom.dom.attribute.office.OfficeValueTypeAttribute;
+import org.odftoolkit.odfdom.dom.element.OdfStyleBase;
+import org.odftoolkit.odfdom.dom.element.draw.DrawControlElement;
+import org.odftoolkit.odfdom.incubator.doc.number.OdfNumberDateStyle;
+import org.odftoolkit.odfdom.incubator.doc.number.OdfNumberPercentageStyle;
+import org.odftoolkit.odfdom.incubator.doc.number.OdfNumberTimeStyle;
+import org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeAutomaticStyles;
+import org.odftoolkit.odfdom.pkg.OdfElement;
+import org.odftoolkit.odfdom.pkg.OdfFileDom;
+import org.odftoolkit.odfdom.pkg.OdfName;
+import org.odftoolkit.simple.Component;
+import org.odftoolkit.simple.Document;
+import org.odftoolkit.simple.style.StyleTypeDefinitions;
+import org.w3c.dom.DOMException;
+
+/**
+ * This class represents control object, a shape that is linked to a control
+ * inside an form. It provides methods to get/set control properties, content,
+ * and styles.
+ * 
+ * @since 0.8
+ */
+public class Control extends Component {
+	private DrawControlElement mElement;
+	private OdfElement containerElement;
+	private ControlStyleHandler mStyleHandler;
+
+	public Control(DrawControlElement element) {
+		mElement = element;
+		containerElement = (OdfElement) element.getParentNode();
+	}
+
+	/**
+	 * Get the container element which contains this control.
+	 * 
+	 * @return the container element.
+	 */
+	public OdfElement getContainerElement() {
+		return containerElement;
+	}
+
+	/**
+	 * Get the instance of DrawControlElement which represents this control.
+	 * 
+	 * @return the instance of DrawControlElement
+	 */
+	public DrawControlElement getOdfElement() {
+		return mElement;
+	}
+
+	/**
+	 * Create an instance of control and and append it at the end of a container
+	 * element.
+	 * 
+	 * @param container
+	 *            - the container element
+	 * @return a control instance
+	 */
+	public static Control newDrawControl(ControlContainer container) {
+		OdfElement parent = container.getDrawControlContainerElement();
+		OdfFileDom ownerDom = (OdfFileDom) parent.getOwnerDocument();
+		DrawControlElement element = ownerDom
+				.newOdfElement(DrawControlElement.class);
+		parent.appendChild(element);
+		Control control = new Control(element);
+		Component.registerComponent(control, element);
+		return control;
+	}
+
+	/**
+	 * Get an instance of control according to a DrawControlElement.
+	 * 
+	 * @param element
+	 *            - an instance of DrawControlElement
+	 * @return an instance of DrawControlElement
+	 */
+	public static Control getInstanceof(DrawControlElement element) {
+		Control control = null;
+		control = (Control) Component.getComponentByElement(element);
+		if (control != null)
+			return control;
+
+		control = new Control(element);
+		Component.registerComponent(control, element);
+		return control;
+	}
+
+	/**
+	 * Remove the shape control from the container.
+	 * <p>
+	 * The resource is removed if it's only used by this object.
+	 * 
+	 * @return true if the shape control is successfully removed; false if
+	 *         otherwise.
+	 */
+	public boolean remove() {
+		try {
+			Document mOwnerDocument = (Document) ((OdfFileDom) mElement
+					.getOwnerDocument()).getDocument();
+			mOwnerDocument.removeElementLinkedResource(getOdfElement());
+			containerElement.removeChild(mElement);
+			return true;
+		} catch (DOMException exception) {
+			Logger.getLogger(Control.class.getName()).log(Level.WARNING,
+					exception.getMessage());
+			return false;
+		}
+	}
+
+	/**
+	 * Return the style handler for this control
+	 * 
+	 * @return the style handler
+	 */
+	public ControlStyleHandler getStyleHandler() {
+		if (mStyleHandler == null)
+			mStyleHandler = new ControlStyleHandler(this);
+		return mStyleHandler;
+	}
+
+	/**
+	 * Set a control within a form that is linked to this control shape by its
+	 * ID.
+	 * 
+	 * @param formControlId
+	 *            - id of a form control
+	 */
+	public void setControl(String formControlId) {
+		mElement.setDrawControlAttribute(formControlId);
+	}
+
+	/**
+	 * Set how a form control is bound to a text document. Default position
+	 * relative and alignment will be set.
+	 * 
+	 * <p>
+	 * If the document is not text document, nothing will happen.
+	 * 
+	 * @param achorType
+	 *            - the point at which a form control is bound to a text
+	 *            document
+	 */
+	public void setAchorType(StyleTypeDefinitions.AnchorType achorType) {
+		this.getStyleHandler().setAchorType(achorType);
+	}
+
+	/**
+	 * Set the rectangle used by this control
+	 * 
+	 * @param rectangle
+	 *            - the rectangle used by this control
+	 */
+	public void setRectangle(FrameRectangle rectangle) {
+		if (rectangle.getWidth() > 0)
+			mElement.setSvgWidthAttribute(rectangle.getWidthDesc());
+		if (rectangle.getHeight() > 0)
+			mElement.setSvgHeightAttribute(rectangle.getHeigthDesc());
+		if (rectangle.getX() > 0)
+			mElement.setSvgXAttribute(rectangle.getXDesc());
+		if (rectangle.getY() > 0)
+			mElement.setSvgYAttribute(rectangle.getYDesc());
+	}
+
+	/**
+	 * Return the rectangle used by this control
+	 * 
+	 * @return - the rectangle used by this control
+	 */
+	public FrameRectangle getRectangle() {
+		try {
+			FrameRectangle rectange = new FrameRectangle(mElement
+					.getSvgXAttribute(), mElement.getSvgYAttribute(), mElement
+					.getSvgWidthAttribute(), mElement.getSvgHeightAttribute());
+			return rectange;
+		} catch (Exception e) {
+			Logger.getLogger(Frame.class.getName()).log(Level.FINE,
+					e.getMessage(), e);
+			return null;
+		}
+	}
+
+	/**
+	 * Set the format string of the input control.
+	 * <p>
+	 * This function only works for date, time and percentage, otherwise an
+	 * {@link java.lang.IllegalArgumentException} will be thrown.
+	 * <p>
+	 * For value type percentage, the <code>formatStr</code> must follow the
+	 * encoding rule of {@link java.text.DecimalFormat
+	 * <code>java.text.DecimalFormat</code>}. For value type date and time, the
+	 * <code>formatStr</code> must follow the encoding rule of
+	 * {@link java.text.SimpleDateFormat
+	 * <code>java.text.SimpleDateFormat</code>}.
+	 * 
+	 * @param formatStr
+	 *            -the input need be formatted as this specified format string.
+	 * @param type
+	 *            - the type that need to be set
+	 * @throws IllegalArgumentException
+	 *             if <code>formatStr</code> is null or the value type is
+	 *             supported.
+	 * @see java.text.SimpleDateFormat
+	 * @see java.text.DecimalFormat
+	 */
+	public void setFormatString(String formatStr, String type) {
+		OfficeValueTypeAttribute.Value typeValue = null;
+		typeValue = OfficeValueTypeAttribute.Value.enumValueOf(type);
+		if (typeValue == OfficeValueTypeAttribute.Value.DATE) {
+			OdfNumberDateStyle dateStyle = new OdfNumberDateStyle(
+					(OdfFileDom) mElement.getOwnerDocument(), formatStr,
+					getUniqueDateStyleName(), null);
+			dateStyle.setNumberLanguageAttribute("en");
+			dateStyle.setNumberCountryAttribute("US");
+			mElement.getAutomaticStyles().appendChild(dateStyle);
+			setDataDisplayStyleName(dateStyle.getStyleNameAttribute());
+		} else if (typeValue == OfficeValueTypeAttribute.Value.TIME) {
+			OdfNumberTimeStyle timeStyle = new OdfNumberTimeStyle(
+					(OdfFileDom) mElement.getOwnerDocument(), formatStr,
+					getUniqueDateStyleName());
+			mElement.getAutomaticStyles().appendChild(timeStyle);
+			setDataDisplayStyleName(timeStyle.getStyleNameAttribute());
+		} else if (typeValue == OfficeValueTypeAttribute.Value.PERCENTAGE) {
+			OdfNumberPercentageStyle dateStyle = new OdfNumberPercentageStyle(
+					(OdfFileDom) mElement.getOwnerDocument(), formatStr,
+					getUniquePercentageStyleName());
+			mElement.getAutomaticStyles().appendChild(dateStyle);
+			setDataDisplayStyleName(dateStyle.getStyleNameAttribute());
+		} else {
+			throw new IllegalArgumentException("This function doesn't support "
+					+ type + "formatting.");
+		}
+	}
+
+	private String getUniqueDateStyleName() {
+		String unique_name;
+		OdfOfficeAutomaticStyles styles = mElement.getAutomaticStyles();
+		do {
+			unique_name = String.format("d%06x",
+					(int) (Math.random() * 0xffffff));
+		} while (styles.getDateStyle(unique_name) != null);
+		return unique_name;
+	}
+
+	private void setDataDisplayStyleName(String name) {
+		OdfStyleBase styleElement = getStyleHandler().getStyleElementForWrite();
+		if (styleElement != null) {
+			styleElement.setOdfAttributeValue(OdfName.newName(
+					OdfDocumentNamespace.STYLE, "data-style-name"), name);
+		}
+	}
+
+	private String getUniquePercentageStyleName() {
+		String unique_name;
+		OdfOfficeAutomaticStyles styles = mElement.getAutomaticStyles();
+		do {
+			unique_name = String.format("p%06x",
+					(int) (Math.random() * 0xffffff));
+		} while (styles.getDateStyle(unique_name) != null);
+		return unique_name;
+	}
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/draw/ControlContainer.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/draw/ControlContainer.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/draw/ControlContainer.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/draw/ControlContainer.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,26 @@
+package org.odftoolkit.simple.draw;
+
+import org.odftoolkit.odfdom.pkg.OdfElement;
+
+/**
+ * ControlContainer is a container which maintains Control(s) as element(s).
+ * 
+ * @since 0.8
+ */
+public interface ControlContainer {
+	/**
+	 * Create an instance of control and and append it at the end of this
+	 * container.
+	 * 
+	 * @return a control instance
+	 */
+	public Control createDrawControl();
+
+	/**
+	 * Get the ODF element which can have DrawControlElement as child element
+	 * directly.
+	 * 
+	 * @return - an ODF element which can have control as child
+	 */
+	public OdfElement getDrawControlContainerElement();
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/draw/ControlStyleHandler.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/draw/ControlStyleHandler.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/draw/ControlStyleHandler.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/draw/ControlStyleHandler.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,93 @@
+package org.odftoolkit.simple.draw;
+
+import org.odftoolkit.odfdom.dom.element.draw.DrawControlElement;
+import org.odftoolkit.simple.Document;
+import org.odftoolkit.simple.style.DefaultStyleHandler;
+import org.odftoolkit.simple.style.GraphicProperties;
+import org.odftoolkit.simple.style.StyleTypeDefinitions;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.FrameHorizontalPosition;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.FrameVerticalPosition;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.HorizontalRelative;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.VerticalRelative;
+
+/**
+ * This class provides functions to handle the style of a form control.
+ * 
+ * @since 0.8
+ */
+public class ControlStyleHandler extends DefaultStyleHandler {
+
+	private Control mControl;
+
+	public ControlStyleHandler(Control control) {
+		super(control.getOdfElement());
+		mControl = control;
+	}
+
+	/**
+	 * Set how a form control is bound to a text document. Default position
+	 * relative and alignment will be set.
+	 * 
+	 * <p>
+	 * If the document is not text document, nothing will happen.
+	 * 
+	 * @param achorType
+	 *            - the point at which a form control is bound to a text
+	 *            document
+	 */
+	public void setAchorType(StyleTypeDefinitions.AnchorType achorType) {
+		if (!mDocument.getMediaTypeString().equals(
+				Document.OdfMediaType.TEXT.getMediaTypeString())
+				&& !mDocument.getMediaTypeString().equals(
+						Document.OdfMediaType.TEXT_TEMPLATE
+								.getMediaTypeString()))
+			return;
+		GraphicProperties graphicPropertiesForWrite = getGraphicPropertiesForWrite();
+
+		DrawControlElement controlElement = (DrawControlElement) mOdfElement;
+		controlElement.setTextAnchorTypeAttribute(achorType.toString());
+
+		// set default relative
+		switch (achorType) {
+		case AS_CHARACTER:
+			graphicPropertiesForWrite
+					.setVerticalRelative(VerticalRelative.BASELINE);
+			graphicPropertiesForWrite
+					.setVerticalPosition(FrameVerticalPosition.TOP);
+			break;
+		case TO_CHARACTER:
+			graphicPropertiesForWrite
+					.setVerticalRelative(VerticalRelative.PARAGRAPH);
+			graphicPropertiesForWrite
+					.setVerticalPosition(FrameVerticalPosition.TOP);
+			graphicPropertiesForWrite
+					.setHorizontalRelative(HorizontalRelative.PARAGRAPH);
+			graphicPropertiesForWrite
+					.setHorizontalPosition(FrameHorizontalPosition.CENTER);
+			break;
+		case TO_PAGE:
+			controlElement.setTextAnchorPageNumberAttribute(Integer.valueOf(1));
+			graphicPropertiesForWrite
+					.setVerticalRelative(VerticalRelative.PAGE);
+			graphicPropertiesForWrite
+					.setVerticalPosition(FrameVerticalPosition.FROMTOP);
+			graphicPropertiesForWrite
+					.setHorizontalRelative(HorizontalRelative.PARAGRAPH);
+			graphicPropertiesForWrite
+					.setHorizontalPosition(FrameHorizontalPosition.FROMLEFT);
+			break;
+		case TO_PARAGRAPH:
+			graphicPropertiesForWrite
+					.setVerticalRelative(VerticalRelative.PARAGRAPH);
+			graphicPropertiesForWrite
+					.setVerticalPosition(FrameVerticalPosition.TOP);
+			graphicPropertiesForWrite
+					.setHorizontalRelative(HorizontalRelative.PARAGRAPH);
+			graphicPropertiesForWrite
+					.setHorizontalPosition(FrameHorizontalPosition.CENTER);
+			break;
+		case TO_FRAME:
+			break;
+		}
+	}
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/AbstractFormContainer.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/AbstractFormContainer.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/AbstractFormContainer.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/AbstractFormContainer.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,167 @@
+package org.odftoolkit.simple.form;
+
+import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.odftoolkit.odfdom.dom.element.form.FormFormElement;
+import org.odftoolkit.odfdom.dom.element.office.OfficeFormsElement;
+import org.odftoolkit.odfdom.pkg.OdfElement;
+import org.w3c.dom.DOMException;
+
+/**
+ * AbstractFormContainer is an abstract implementation of the FormContainer
+ * interface, with a default implementation for every method defined in
+ * FormContainer, except getFormContainerElement(). A subclass must implement
+ * the abstract method getFormContainerElement().
+ * 
+ * @since 0.8
+ */
+public abstract class AbstractFormContainer implements FormContainer {
+
+	private FormProvider provider = null;
+
+
+	public abstract OfficeFormsElement getFormContainerElement();
+
+
+	public Form createForm(String name) {
+		return getProvider().createForm(name, getFormContainerElement());
+	}
+
+
+	public boolean removeForm(Form form) {
+		if (form == null)
+			return true;
+		OdfElement containerElement = getFormContainerElement();
+		FormFormElement formElement = form.getOdfElement();
+		try {
+			containerElement.removeChild(formElement);
+		} catch (DOMException exception) {
+			Logger.getLogger(AbstractFormContainer.class.getName()).log(
+					Level.WARNING, exception.getMessage());
+			return false;
+		}
+		return true;
+	}
+
+
+	public Form getFormByName(String name) {
+		if (name == null)
+			return null;
+
+		OdfElement container = getFormContainerElement();
+		FormFormElement element = OdfElement.findFirstChildNode(
+				FormFormElement.class, container);
+		while (element != null) {
+			if (name.equals(element.getFormNameAttribute())) {
+				Form form = getProvider().getInstanceOf(element);
+				return form;
+			}
+			element = OdfElement.findNextChildNode(FormFormElement.class,
+					element);
+		}
+		return null;
+	}
+
+
+	public Iterator<Form> getFormIterator() {
+		return new SimpleFormIterator(this);
+	}
+
+	private class SimpleFormIterator implements Iterator<Form> {
+
+		private OdfElement containerElement;
+		private Form nextElement = null;
+		private Form tempElement = null;
+
+		private SimpleFormIterator(FormContainer container) {
+			containerElement = container.getFormContainerElement();
+		}
+
+		public boolean hasNext() {
+			tempElement = findNext(nextElement);
+			return (tempElement != null);
+		}
+
+		public Form next() {
+			if (tempElement != null) {
+				nextElement = tempElement;
+				tempElement = null;
+			} else {
+				nextElement = findNext(nextElement);
+			}
+			if (nextElement == null) {
+				return null;
+			} else {
+				return nextElement;
+			}
+		}
+
+		public void remove() {
+			if (nextElement == null) {
+				throw new IllegalStateException("please call next() first.");
+			}
+			containerElement.removeChild(nextElement.getOdfElement());
+		}
+
+		private Form findNext(Form thisForm) {
+			FormFormElement nextForm = null;
+			if (thisForm == null) {
+				nextForm = OdfElement.findFirstChildNode(FormFormElement.class,
+						containerElement);
+			} else {
+				nextForm = OdfElement.findNextChildNode(FormFormElement.class,
+						thisForm.getOdfElement());
+			}
+
+			if (nextForm != null) {
+				return getProvider().getInstanceOf(nextForm);
+			}
+			return null;
+		}
+	}
+
+
+	public boolean getApplyDesignMode() {
+		return getFormContainerElement().getFormApplyDesignModeAttribute();
+	}
+
+
+	public boolean getAutomaticFocus() {
+		return getFormContainerElement().getFormAutomaticFocusAttribute();
+	}
+
+
+	public void setApplyDesignMode(boolean isDesignMode) {
+		getFormContainerElement().setFormApplyDesignModeAttribute(isDesignMode);
+	}
+
+
+	public void setAutomaticFocus(boolean isAutoFocus) {
+		getFormContainerElement().setFormAutomaticFocusAttribute(isAutoFocus);
+	}
+
+	/**
+	 * Set the form provider of this container.
+	 * 
+	 * @param provider
+	 *            - which is used to instantiate a form
+	 */
+	public void setProvider(FormProvider provider) {
+		this.provider = provider;
+	}
+
+	/**
+	 * Get the form provider of this container.
+	 * 
+	 * @return provider - a default provider followed by OO definition will be
+	 *         created if users don't appointed one.
+	 */
+	public FormProvider getProvider() {
+		if (provider == null)
+			provider = new OOFormProvider();
+		return provider;
+	}
+
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Button.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Button.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Button.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Button.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,175 @@
+package org.odftoolkit.simple.form;
+
+import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.odftoolkit.odfdom.dom.element.form.FormButtonElement;
+import org.odftoolkit.odfdom.dom.element.form.FormFormElement;
+import org.odftoolkit.odfdom.dom.element.form.FormPropertiesElement;
+import org.odftoolkit.odfdom.pkg.OdfElement;
+import org.odftoolkit.odfdom.pkg.OdfFileDom;
+import org.odftoolkit.simple.Document;
+
+/**
+ * This class represents the form control of Button, provides methods to get/set
+ * the form properties and the style formatting of this control.
+ * 
+ * @since 0.8
+ */
+public class Button extends FormControl {
+
+	Button(FormButtonElement element) {
+		mElement = element;
+		formElement = (FormFormElement) element.getParentNode();
+	}
+
+	/**
+	 * Get an instance of button by an instance of FormButtonElement, while
+	 * searching the document content to make a bind with the DrawControl which
+	 * already reference to this button.
+	 * 
+	 * @param element
+	 *            - an instance of FormButtonElement
+	 * @return an instance of button
+	 */
+	public static Button getInstanceOf(FormButtonElement element) {
+		Button btn = new Button(element);
+		try {
+			btn.loadDrawControl(((Document) ((OdfFileDom) element
+					.getOwnerDocument()).getDocument()).getContentRoot());
+		} catch (Exception e) {
+			Logger.getLogger(Button.class.getName()).log(Level.WARNING,
+					"Cannot load the drawing shape of this button.");
+		}
+		return btn;
+	}
+
+	@Override
+	public void setControlImplementation(String controlImpl) {
+		((FormButtonElement) mElement)
+				.setFormControlImplementationAttribute(controlImpl);
+	}
+
+	FormPropertiesElement getFormPropertiesElementForWrite() {
+		if (mFormProperties == null)
+			mFormProperties = ((FormButtonElement) mElement)
+					.newFormPropertiesElement();
+		return mFormProperties;
+	}
+
+	@Override
+	public void setId(String id) {
+		((FormButtonElement) mElement).setFormIdAttribute(id);
+
+	}
+
+	@Override
+	public String getId() {
+		return ((FormButtonElement) mElement).getFormIdAttribute();
+	}
+
+	@Override
+	public String getName() {
+		return ((FormButtonElement) mElement).getFormNameAttribute();
+	}
+
+	@Override
+	public void setName(String name) {
+		((FormButtonElement) mElement).setFormNameAttribute(name);
+	}
+
+	/**
+	 * Set the label content of this button
+	 * 
+	 * @param label
+	 *            - the label
+	 */
+	public void setLabel(String label) {
+		((FormButtonElement) mElement).setFormLabelAttribute(label);
+	}
+
+	/**
+	 * Get the label content of this button
+	 * 
+	 * @return the label
+	 */
+	public String getLabel() {
+		return ((FormButtonElement) mElement).getFormLabelAttribute();
+	}
+
+	/**
+	 * Set the default value of this control, it will be override by current
+	 * value.
+	 * 
+	 * @param value
+	 *            - the default value
+	 */
+	public void setValue(String value) {
+		((FormButtonElement) mElement).setFormValueAttribute(value);
+
+	}
+
+	/**
+	 * Get a simple iterator for buttons.
+	 * 
+	 * @param container
+	 *            - an instance of form where to traverse the buttons
+	 */
+	public static Iterator<FormControl> getSimpleIterator(Form container) {
+		return new SimpleButtonIterator(container);
+	}
+
+	private static class SimpleButtonIterator implements Iterator<FormControl> {
+
+		private FormFormElement containerElement;
+		private Button nextElement = null;
+		private Button tempElement = null;
+
+		private SimpleButtonIterator(Form container) {
+			containerElement = container.getOdfElement();
+		}
+
+		public boolean hasNext() {
+			tempElement = findNext(nextElement);
+			return (tempElement != null);
+		}
+
+		public Button next() {
+			if (tempElement != null) {
+				nextElement = tempElement;
+				tempElement = null;
+			} else {
+				nextElement = findNext(nextElement);
+			}
+			if (nextElement == null) {
+				return null;
+			} else {
+				return nextElement;
+			}
+		}
+
+		public void remove() {
+			if (nextElement == null) {
+				throw new IllegalStateException("please call next() first.");
+			}
+			nextElement.remove();
+		}
+
+		private Button findNext(Button thisButton) {
+			FormButtonElement nextForm = null;
+			if (thisButton == null) {
+				nextForm = OdfElement.findFirstChildNode(
+						FormButtonElement.class, containerElement);
+			} else {
+				nextForm = OdfElement.findNextChildNode(
+						FormButtonElement.class, thisButton.getOdfElement());
+			}
+
+			if (nextForm != null) {
+				return Button.getInstanceOf(nextForm);
+			}
+			return null;
+		}
+	}
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/CheckBox.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/CheckBox.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/CheckBox.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/CheckBox.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,235 @@
+package org.odftoolkit.simple.form;
+
+import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.odftoolkit.odfdom.dom.element.form.FormCheckboxElement;
+import org.odftoolkit.odfdom.dom.element.form.FormFormElement;
+import org.odftoolkit.odfdom.dom.element.form.FormPropertiesElement;
+import org.odftoolkit.odfdom.pkg.OdfElement;
+import org.odftoolkit.odfdom.pkg.OdfFileDom;
+import org.odftoolkit.simple.Document;
+import org.odftoolkit.simple.form.FormTypeDefinition.FormCheckboxState;
+
+/**
+ * This class represents the form control of Check Box, provides methods to
+ * get/set the form properties and the style formatting of this control.
+ * 
+ * @since 0.8
+ */
+public class CheckBox extends FormControl {
+
+	CheckBox(FormCheckboxElement element) {
+		mElement = element;
+		formElement = (FormFormElement) element.getParentNode();
+	}
+
+	/**
+	 * Get an instance of check box by an instance of FormCheckboxElement, while
+	 * searching the document content to make a bind with the DrawControl which
+	 * already reference to this check box.
+	 * 
+	 * @param element
+	 *            - an instance of FormCheckboxElement
+	 * @return an instance of check box
+	 */
+	public static CheckBox getInstanceOf(FormCheckboxElement element) {
+		CheckBox checkbox = new CheckBox(element);
+		try {
+			checkbox.loadDrawControl(((Document) ((OdfFileDom) element
+					.getOwnerDocument()).getDocument()).getContentRoot());
+		} catch (Exception e) {
+			Logger.getLogger(CheckBox.class.getName()).log(Level.WARNING,
+					"Cannot load the drawing shape of this check box.");
+		}
+		return checkbox;
+	}
+
+	@Override
+	public void setControlImplementation(String controlImpl) {
+		((FormCheckboxElement) mElement)
+				.setFormControlImplementationAttribute(controlImpl);
+	}
+
+	@Override
+	public String getId() {
+		return ((FormCheckboxElement) mElement).getFormIdAttribute();
+	}
+
+	@Override
+	public void setId(String id) {
+		((FormCheckboxElement) mElement).setFormIdAttribute(id);
+	}
+
+	@Override
+	FormPropertiesElement getFormPropertiesElementForWrite() {
+		if (mFormProperties == null)
+			mFormProperties = ((FormCheckboxElement) mElement)
+					.newFormPropertiesElement();
+		return mFormProperties;
+	}
+
+	/**
+	 * Set the label content of this check box
+	 * 
+	 * @param label
+	 *            - the label of this check box
+	 */
+	public void setLabel(String label) {
+		((FormCheckboxElement) mElement).setFormLabelAttribute(label);
+	}
+
+	/**
+	 * Get the label content of this check box
+	 * 
+	 * @param label
+	 *            - the label of this check box
+	 */
+	public String getLabel() {
+		return ((FormCheckboxElement) mElement).getFormLabelAttribute();
+	}
+
+	@Override
+	public String getName() {
+		return ((FormCheckboxElement) mElement).getFormNameAttribute();
+	}
+
+	@Override
+	public void setName(String name) {
+		((FormCheckboxElement) mElement).setFormNameAttribute(name);
+	}
+
+	/**
+	 * Set the default value of this control, it will be override by current
+	 * value.
+	 * 
+	 * @param value
+	 *            - the default value
+	 */
+	public void setValue(String value) {
+		((FormCheckboxElement) mElement).setFormValueAttribute(value);
+
+	}
+
+	/**
+	 * Get the default value of this control, it will be override by current
+	 * value.
+	 * 
+	 * @return the default value
+	 */
+	public String getValue() {
+		return ((FormCheckboxElement) mElement).getFormValueAttribute();
+
+	}
+
+	/**
+	 * Set the default state of this check box
+	 * 
+	 * @param state
+	 *            - default state of this check box
+	 */
+	public void setDefaultState(FormCheckboxState state) {
+		((FormCheckboxElement) mElement)
+				.setFormStateAttribute(state.toString());
+	}
+
+	/**
+	 * Get the default state of this check box
+	 * 
+	 * @return default state of this check box
+	 */
+	public FormCheckboxState getDefaultState() {
+		String value = ((FormCheckboxElement) mElement).getFormStateAttribute();
+		return FormCheckboxState.enumValueOf(value);
+	}
+
+	/**
+	 * Set current state of this check box
+	 * 
+	 * @param state
+	 *            - current state of this check box
+	 */
+	public void setCurrentState(FormCheckboxState state) {
+		((FormCheckboxElement) mElement).setFormCurrentStateAttribute(state
+				.toString());
+	}
+
+	/**
+	 * Get current state of this check box
+	 * 
+	 * @return current state of this check box
+	 */
+	public FormCheckboxState getCurrentState() {
+		String value = ((FormCheckboxElement) mElement)
+				.getFormCurrentStateAttribute();
+		return FormCheckboxState.enumValueOf(value);
+	}
+
+	/**
+	 * Get a simple iterator for check boxes.
+	 * 
+	 * @param container
+	 *            - an instance of form where to traverse the check boxes
+	 */
+	public static Iterator<FormControl> getSimpleIterator(Form container) {
+		return new SimpleCheckBoxIterator(container);
+	}
+
+	private static class SimpleCheckBoxIterator implements
+			Iterator<FormControl> {
+
+		private FormFormElement containerElement;
+		private CheckBox nextElement = null;
+		private CheckBox tempElement = null;
+
+		private SimpleCheckBoxIterator(Form container) {
+			containerElement = container.getOdfElement();
+		}
+
+		public boolean hasNext() {
+			tempElement = findNext(nextElement);
+			return (tempElement != null);
+		}
+
+		public CheckBox next() {
+			if (tempElement != null) {
+				nextElement = tempElement;
+				tempElement = null;
+			} else {
+				nextElement = findNext(nextElement);
+			}
+			if (nextElement == null) {
+				return null;
+			} else {
+				return nextElement;
+			}
+		}
+
+		public void remove() {
+			if (nextElement == null) {
+				throw new IllegalStateException("please call next() first.");
+			}
+			nextElement.remove();
+
+		}
+
+		private CheckBox findNext(CheckBox thisCheckBox) {
+			FormCheckboxElement nextCheckBox = null;
+			if (thisCheckBox == null) {
+				nextCheckBox = OdfElement.findFirstChildNode(
+						FormCheckboxElement.class, containerElement);
+			} else {
+				nextCheckBox = OdfElement
+						.findNextChildNode(FormCheckboxElement.class,
+								thisCheckBox.getOdfElement());
+			}
+
+			if (nextCheckBox != null) {
+				return CheckBox.getInstanceOf(nextCheckBox);
+			}
+			return null;
+		}
+	}
+
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/ComboBox.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/ComboBox.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/ComboBox.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/ComboBox.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,324 @@
+package org.odftoolkit.simple.form;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.odftoolkit.odfdom.dom.element.form.FormComboboxElement;
+import org.odftoolkit.odfdom.dom.element.form.FormFormElement;
+import org.odftoolkit.odfdom.dom.element.form.FormItemElement;
+import org.odftoolkit.odfdom.dom.element.form.FormPropertiesElement;
+import org.odftoolkit.odfdom.pkg.OdfElement;
+import org.odftoolkit.odfdom.pkg.OdfFileDom;
+import org.odftoolkit.simple.Document;
+import org.odftoolkit.simple.form.FormTypeDefinition.FormListSourceType;
+import org.w3c.dom.NodeList;
+
+/**
+ * This class represents the form control of Combo Box, provides methods to
+ * get/set the form properties and the style formatting of this control.
+ * 
+ * @since 0.8
+ */
+public class ComboBox extends FormControl {
+
+	private ArrayList<String> entries;
+
+	ComboBox(FormComboboxElement element) {
+		this.mElement = element;
+		formElement = (FormFormElement) element.getParentNode();
+	}
+
+	/**
+	 * Get an instance of combo box by an instance of FormComboboxElement, while
+	 * searching the document content to make a bind with the DrawControl which
+	 * already reference to this check box.
+	 * 
+	 * @param element
+	 *            - an instance of FormComboboxElement
+	 * @return an instance of combo box
+	 */
+	public static ComboBox getInstanceOf(FormComboboxElement element) {
+		ComboBox combo = new ComboBox(element);
+		try {
+			combo.loadDrawControl(((Document) ((OdfFileDom) element
+					.getOwnerDocument()).getDocument()).getContentRoot());
+		} catch (Exception e) {
+			Logger.getLogger(ComboBox.class.getName()).log(Level.WARNING,
+					"Cannot load the drawing shape of this combo box.");
+		}
+		return combo;
+	}
+
+	@Override
+	FormPropertiesElement getFormPropertiesElementForWrite() {
+		if (mFormProperties == null)
+			mFormProperties = ((FormComboboxElement) mElement)
+					.newFormPropertiesElement();
+		return mFormProperties;
+	}
+
+	@Override
+	public void setControlImplementation(String controlImpl) {
+		((FormComboboxElement) mElement)
+				.setFormControlImplementationAttribute(controlImpl);
+	}
+
+	@Override
+	public String getId() {
+		return ((FormComboboxElement) mElement).getFormIdAttribute();
+	}
+
+	@Override
+	public void setId(String id) {
+		((FormComboboxElement) mElement).setFormIdAttribute(id);
+	}
+
+	@Override
+	public String getName() {
+		return ((FormComboboxElement) mElement).getFormNameAttribute();
+	}
+
+	@Override
+	public void setName(String name) {
+		((FormComboboxElement) mElement).setFormNameAttribute(name);
+	}
+
+	/**
+	 * Set the visibility of the drop-down list
+	 * 
+	 * @param isDropDown
+	 *            - specify if the drop-down list is visible
+	 */
+	public void setFormDropdown(boolean isDropDown) {
+		((FormComboboxElement) mElement).setFormDropdownAttribute(isDropDown);
+	}
+
+	/**
+	 * Get the visibility of the drop-down list
+	 * 
+	 * @return true means the drop-down list is visible; false means invisible
+	 */
+	public boolean getFormDropdown() {
+		return ((FormComboboxElement) mElement).getFormDropdownAttribute();
+	}
+
+	/**
+	 * Add a list item to this combo box.
+	 * 
+	 * @param item
+	 *            - a list item
+	 */
+	public void addItem(String item) {
+		if (item == null)
+			return;
+		if (entries == null)
+			entries = new ArrayList<String>();
+		((FormComboboxElement) mElement).newFormItemElement()
+				.setFormLabelAttribute(item);
+		entries.add(item);
+	}
+
+	/**
+	 * Add a group of list items to this combo box
+	 * 
+	 * @param items
+	 *            -a group of list items
+	 */
+	public void addItems(String[] items) {
+		if (items == null || items.length == 0)
+			return;
+		for (int i = 0; i < items.length; i++) {
+			addItem(items[i]);
+		}
+	}
+
+	/**
+	 * Get the list entries if they are initiated through a list of string.
+	 * 
+	 * @return the list entries
+	 */
+	public ArrayList<String> getEntries() {
+		if (entries == null || entries.size() == 0) {
+			NodeList items = mElement.getElementsByTagName("form:item");
+			if (items != null && items.getLength() > 0) {
+				for (int i = 0; i < items.getLength(); i++) {
+					if (entries == null)
+						entries = new ArrayList<String>();
+					entries.add(((FormItemElement) items.item(i))
+							.getFormLabelAttribute());
+				}
+				return entries;
+			}
+		}
+		return null;
+	}
+
+	/**
+	 * Set the source type of the data list.
+	 * 
+	 * @param type
+	 *            - the source type of this list
+	 */
+	public void setListSourceType(FormListSourceType type) {
+		((FormComboboxElement) mElement).setFormListSourceTypeAttribute(type
+				.toString());
+	}
+
+	/**
+	 * Get the source type of the data list.
+	 * 
+	 * @return the source type of this list
+	 */
+	public FormListSourceType getListSourceType() {
+		String value = ((FormComboboxElement) mElement)
+				.getFormListSourceTypeAttribute();
+		return FormListSourceType.enumValueOf(value);
+	}
+
+	/**
+	 * Set the source of this data list.
+	 * 
+	 * @param listSource
+	 *            - the source of this data list.
+	 */
+	public void setListSource(String listSource) {
+		((FormComboboxElement) mElement).setFormListSourceAttribute(listSource);
+	}
+
+	/**
+	 * Get the source of this data list.
+	 * 
+	 * @return the source of this data list.
+	 */
+	public String getListSource() {
+		return ((FormComboboxElement) mElement).getFormListSourceAttribute();
+	}
+
+	/**
+	 * Set the data field referenced by this combo box
+	 * 
+	 * @param dataField
+	 *            - the data field referenced by this combo box
+	 */
+	public void setDataField(String dataField) {
+		((FormComboboxElement) mElement).setFormDataFieldAttribute(dataField);
+	}
+
+	/**
+	 * Get the data field referenced by this combo box
+	 * 
+	 * @return the data field referenced by this combo box
+	 */
+	public String getDataField() {
+		return ((FormComboboxElement) mElement).getFormDataFieldAttribute();
+	}
+
+	/**
+	 * Set the default value of this control, it will be override by current
+	 * value.
+	 * 
+	 * @param value
+	 *            - default value
+	 */
+	public void setValue(String defaultValue) {
+		((FormComboboxElement) mElement).setFormValueAttribute(defaultValue);
+	}
+
+	/**
+	 * Get the default value of this control.
+	 * 
+	 * @return default value
+	 */
+	public String getValue() {
+		return ((FormComboboxElement) mElement).getFormValueAttribute();
+	}
+
+	/**
+	 * Set the current value of this control, it override the default value.
+	 * 
+	 * @param currentValue
+	 *            - current value
+	 */
+	public void setCurrentValue(String currentValue) {
+		((FormComboboxElement) mElement)
+				.setFormCurrentValueAttribute(currentValue);
+	}
+
+	/**
+	 * Get the current value of this control, it override the default value.
+	 * 
+	 * @return current value
+	 */
+	public String getCurrentValue() {
+		return ((FormComboboxElement) mElement).getFormCurrentValueAttribute();
+	}
+
+	/**
+	 * Get a simple iterator for combo boxes.
+	 * 
+	 * @param container
+	 *            - an instance of form where to traverse the combo boxes s
+	 */
+	public static Iterator<FormControl> getSimpleIterator(Form container) {
+		return new SimpleComboBoxIterator(container);
+	}
+
+	private static class SimpleComboBoxIterator implements
+			Iterator<FormControl> {
+
+		private FormFormElement containerElement;
+		private ComboBox nextElement = null;
+		private ComboBox tempElement = null;
+
+		private SimpleComboBoxIterator(Form container) {
+			containerElement = container.getOdfElement();
+		}
+
+		public boolean hasNext() {
+			tempElement = findNext(nextElement);
+			return (tempElement != null);
+		}
+
+		public ComboBox next() {
+			if (tempElement != null) {
+				nextElement = tempElement;
+				tempElement = null;
+			} else {
+				nextElement = findNext(nextElement);
+			}
+			if (nextElement == null) {
+				return null;
+			} else {
+				return nextElement;
+			}
+		}
+
+		public void remove() {
+			if (nextElement == null) {
+				throw new IllegalStateException("please call next() first.");
+			}
+			nextElement.remove();
+
+		}
+
+		private ComboBox findNext(ComboBox thisComboBox) {
+			FormComboboxElement nextComboBox = null;
+			if (thisComboBox == null) {
+				nextComboBox = OdfElement.findFirstChildNode(
+						FormComboboxElement.class, containerElement);
+			} else {
+				nextComboBox = OdfElement
+						.findNextChildNode(FormComboboxElement.class,
+								thisComboBox.getOdfElement());
+			}
+
+			if (nextComboBox != null) {
+				return ComboBox.getInstanceOf(nextComboBox);
+			}
+			return null;
+		}
+	}
+
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/CurrencyField.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/CurrencyField.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/CurrencyField.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/CurrencyField.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,58 @@
+package org.odftoolkit.simple.form;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.odftoolkit.odfdom.dom.element.form.FormFormattedTextElement;
+import org.odftoolkit.odfdom.pkg.OdfFileDom;
+import org.odftoolkit.simple.Document;
+
+public class CurrencyField extends Field {
+
+	CurrencyField(FormFormattedTextElement element) {
+		super(element);
+	}
+
+
+	/**
+	 * Get an instance of currency field by an instance of FormFormattedTextElement,
+	 * while searching the document content to make a bind with the DrawControl
+	 * which already reference to this currency field.
+	 * 
+	 * @param element
+	 *            - an instance of FormFormattedTextElement
+	 * @return an instance of currency field
+	 */
+	public static CurrencyField getInstanceOf(FormFormattedTextElement element) {
+		CurrencyField field = new CurrencyField(element);
+		try {
+			field.loadDrawControl(((Document) ((OdfFileDom) element
+					.getOwnerDocument()).getDocument()).getContentRoot());
+		} catch (Exception e) {
+			Logger.getLogger(CurrencyField.class.getName()).log(Level.WARNING,
+					"Cannot load the drawing shape of this field.");
+		}
+		return field;
+	}
+	
+	public void setCurrencySymbol(String symbol) {
+		this.setFormProperty(OOFormProvider.FORM_PROPERTY_NAME_CURRENCYSYMBOL,
+				"string", symbol, null, null, null, null, null);
+	}
+
+	public void setDecimalAccuracy(double value) {
+		this.setFormProperty(OOFormProvider.FORM_PROPERTY_NAME_DECIMALACCURACY,
+				"float", null, null, null, null, value, null);
+	}
+
+	public void setStepValue(double value) {
+		this.setFormProperty(OOFormProvider.FORM_PROPERTY_NAME_VALUESTEP,
+				"float", null, null, null, null, value, null);
+	}
+
+	public void setCurrencySymbolVisible(boolean visible) {
+		this.setFormProperty(OOFormProvider.FORM_PROPERTY_NAME_PREPENDCURRENCYSYMBOL,
+				"boolean", null, visible, null, null, null, null);
+
+	}
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/DateField.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/DateField.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/DateField.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/DateField.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,75 @@
+package org.odftoolkit.simple.form;
+
+import java.util.Locale;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.odftoolkit.odfdom.dom.attribute.office.OfficeValueTypeAttribute.Value;
+import org.odftoolkit.odfdom.dom.element.form.FormFormattedTextElement;
+import org.odftoolkit.odfdom.pkg.OdfFileDom;
+import org.odftoolkit.simple.Document;
+
+/**
+ * This class represents a date field of form.
+ * 
+ */
+public class DateField extends Field {
+
+	DateField(FormFormattedTextElement element) {
+		super(element);
+	}
+
+	/**
+	 * Get an instance of date field by an instance of FormFormattedTextElement,
+	 * while searching the document content to make a bind with the DrawControl
+	 * which already reference to this date field.
+	 * 
+	 * @param element
+	 *            - an instance of FormFormattedTextElement
+	 * @return an instance of date field
+	 */
+	public static DateField getInstanceOf(FormFormattedTextElement element) {
+		DateField field = new DateField(element);
+		try {
+			field.loadDrawControl(((Document) ((OdfFileDom) element
+					.getOwnerDocument()).getDocument()).getContentRoot());
+		} catch (Exception e) {
+			Logger.getLogger(DateField.class.getName()).log(Level.WARNING,
+					"Cannot load the drawing shape of this field.");
+		}
+		return field;
+	}
+
+	/**
+	 * Set the visibility of the drop-down button.
+	 * 
+	 * @param isVisible
+	 *            - the visibility of drop-down button.
+	 */
+	public void setDropDownVisible(boolean isVisible) {
+		this.setFormProperty(OOFormProvider.FORM_PROPERTY_NAME_DROPDOWN,
+				"boolean", null, isVisible, null, null, null, null);
+	}
+
+	/**
+	 * Format the date value according to the appointed format and locale.
+	 * 
+	 * @param formatStr
+	 *            - format code
+	 * @param locale
+	 *            - locale information
+	 */
+	public void formatDate(String formatStr, Locale locale) {
+		this.setFormatString(formatStr, Value.DATE, locale);
+	}
+
+	/**
+	 * Get the format code which is used to format the display value
+	 * 
+	 * @return the format code
+	 */
+	public String getDateFormat() {
+		return this.getFormatString(Value.DATE);
+	}
+
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Field.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Field.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Field.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Field.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,437 @@
+package org.odftoolkit.simple.form;
+
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.odftoolkit.odfdom.dom.OdfDocumentNamespace;
+import org.odftoolkit.odfdom.dom.OdfSchemaDocument;
+import org.odftoolkit.odfdom.dom.attribute.office.OfficeValueTypeAttribute;
+import org.odftoolkit.odfdom.dom.element.OdfStyleBase;
+import org.odftoolkit.odfdom.dom.element.form.FormFormElement;
+import org.odftoolkit.odfdom.dom.element.form.FormFormattedTextElement;
+import org.odftoolkit.odfdom.dom.element.form.FormPropertiesElement;
+import org.odftoolkit.odfdom.incubator.doc.number.OdfNumberDateStyle;
+import org.odftoolkit.odfdom.incubator.doc.number.OdfNumberPercentageStyle;
+import org.odftoolkit.odfdom.incubator.doc.number.OdfNumberStyle;
+import org.odftoolkit.odfdom.incubator.doc.number.OdfNumberTimeStyle;
+import org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeAutomaticStyles;
+import org.odftoolkit.odfdom.pkg.OdfElement;
+import org.odftoolkit.odfdom.pkg.OdfFileDom;
+import org.odftoolkit.odfdom.pkg.OdfName;
+import org.odftoolkit.simple.Document;
+
+/**
+ * This class represents the form control of Field, provides methods to get/set
+ * the form properties and the style formatting of this control.
+ * 
+ * @since 0.8
+ */
+public class Field extends FormControl {
+
+	Field(FormFormattedTextElement element) {
+		mElement = element;
+		formElement = (FormFormElement) element.getParentNode();
+	}
+
+	/**
+	 * Get an instance of field by an instance of FormFormattedTextElement,
+	 * while searching the document content to make a bind with the DrawControl
+	 * which already reference to this field.
+	 * 
+	 * @param element
+	 *            - an instance of FormFormattedTextElement
+	 * @return an instance of field
+	 */
+	public static Field getInstanceOf(FormFormattedTextElement element) {
+		Field field = null;
+		if (element.getFormControlImplementationAttribute().equals(
+				OOFormProvider.OO_CONTROL_IMPLEMENTATION_DATEFIELD)) {
+			return DateField.getInstanceOf(element);
+		} else if (element.getFormControlImplementationAttribute().equals(
+				OOFormProvider.OO_CONTROL_IMPLEMENTATION_TIMEFIELD)) {
+			return TimeField.getInstanceOf(element);
+		} else if (element.getFormControlImplementationAttribute().equals(
+				OOFormProvider.OO_CONTROL_IMPLEMENTATION_NUMERICFIELD)) {
+			return NumericField.getInstanceOf(element);
+		} else if (element.getFormControlImplementationAttribute().equals(
+				OOFormProvider.OO_CONTROL_IMPLEMENTATION_PATTERNFIELD)) {
+			return PatternField.getInstanceOf(element);
+		} else if (element.getFormControlImplementationAttribute().equals(
+				OOFormProvider.OO_CONTROL_IMPLEMENTATION_CURRENCYFIELD)) {
+			return CurrencyField.getInstanceOf(element);
+		} else {
+			field = new Field(element);
+		}
+		if (field == null)
+			throw new IllegalStateException(
+					"Failed to load and initiate a field.");
+
+		try {
+			field.loadDrawControl(((Document) ((OdfFileDom) element
+					.getOwnerDocument()).getDocument()).getContentRoot());
+		} catch (Exception e) {
+			Logger.getLogger(Field.class.getName()).log(Level.WARNING,
+					"Cannot load the drawing shape of this field.");
+		}
+		return field;
+	}
+
+	@Override
+	public String getId() {
+		return ((FormFormattedTextElement) mElement).getFormIdAttribute();
+	}
+
+	@Override
+	public void setControlImplementation(String controlImpl) {
+		((FormFormattedTextElement) mElement)
+				.setFormControlImplementationAttribute(controlImpl);
+	}
+
+	@Override
+	public void setId(String id) {
+		((FormFormattedTextElement) mElement).setFormIdAttribute(id);
+	}
+
+	FormPropertiesElement getFormPropertiesElementForWrite() {
+		if (mFormProperties == null)
+			mFormProperties = ((FormFormattedTextElement) mElement)
+					.newFormPropertiesElement();
+		return mFormProperties;
+	}
+
+	@Override
+	public String getName() {
+		return ((FormFormattedTextElement) mElement).getFormNameAttribute();
+	}
+
+	@Override
+	public void setName(String name) {
+		((FormFormattedTextElement) mElement).setFormNameAttribute(name);
+	}
+
+	/**
+	 * Set the default value of this control, it will be override by current
+	 * value.
+	 * 
+	 * @param value
+	 *            - default value
+	 */
+	public void setValue(String value) {
+		((FormFormattedTextElement) mElement).setFormValueAttribute(value);
+
+	}
+
+	/**
+	 * Get the default value of this control
+	 * 
+	 * @return default value
+	 */
+	public String getValue() {
+		return ((FormFormattedTextElement) mElement).getFormValueAttribute();
+
+	}
+
+	/**
+	 * Set the current value of this control, it override the default value.
+	 * 
+	 * @param currentValue
+	 *            - current value
+	 */
+	public void setCurrentValue(String value) {
+		((FormFormattedTextElement) mElement)
+				.setFormCurrentValueAttribute(value);
+	}
+
+	/**
+	 * Get the current value of this control
+	 * 
+	 * @return current value
+	 */
+	public String getCurrentValue() {
+		return ((FormFormattedTextElement) mElement)
+				.getFormCurrentValueAttribute();
+	}
+
+	/**
+	 * Set the visibility of the spin button
+	 * 
+	 * @param isVisible
+	 *            - true means the spin button is visible; false means the spin
+	 *            button is hidden
+	 */
+	public void setSpinButonVisible(boolean isVisible) {
+		this.setFormProperty(OOFormProvider.FORM_PROPERTY_NAME_SPIN, "boolean",
+				null, isVisible, null, null, null, null);
+	}
+
+/**
+	 * Set the format string of the field.
+	 * <p>
+	 * This function only works for float, date, time and percentage, otherwise an
+	 * {@link java.lang.IllegalArgumentException} will be thrown. 
+	 * <p>
+	 * For value type float and percentage, the <code>formatStr</code> must follow the encoding 
+	 * rule of {@link java.text.DecimalFormat <code>java.text.DecimalFormat</code>}.
+	 * For value type date and time, the <code>formatStr</code> must follow the encoding 
+	 * rule of {@link java.text.SimpleDateFormat <code>java.text.SimpleDateFormat</code>}.
+	 * <p>
+	 * <blockquote>
+	 * <table border=0 cellspacing=3 cellpadding=0 summary="Chart showing ValueType, Distinguish Symbol
+	 * and Distinguish Priority.">
+	 *     <tr bgcolor="#ccccff">
+	 *          <th align=left>ValueType
+	 *          <th align=left>Distinguish Symbol
+	 *          <th align=left>Distinguish Priority
+	 *     <tr valign=top>
+	 *          <td>percentage
+	 *          <td>%
+	 *          <td>1
+	 *     <tr valign=top>
+	 *          <td>time
+	 *          <td>H, k, m, s, S
+	 *          <td>2
+	 *     <tr valign=top>
+	 *          <td>date
+	 *          <td>y, M, w, W, D, d, F, E, K, h
+	 *          <td>3
+	 *     <tr valign=top>
+	 *          <td>float
+	 *          <td>#, 0
+	 *          <td>4
+	 * </table>
+	 * </blockquote>
+	 * If adaptive failed, an {@link java.lang.UnsupportedOperationException} will be thrown.
+	 * <p>
+	 * @param formatStr	the cell need be formatted as this specified format string.
+	 * @throws IllegalArgumentException if <code>formatStr</code> is null or the cell value type is supported.
+	 * @see java.text.SimpleDateFormat
+	 * @see java.text.DecimalFormat
+	 */
+	protected void setFormatString(String formatStr,
+			OfficeValueTypeAttribute.Value type, Locale locale) {
+		if (locale == null) {
+			locale = Locale.US;
+		}
+		if (formatStr == null)
+			throw new IllegalArgumentException("formatStr cannot be null.");
+
+		if (type == OfficeValueTypeAttribute.Value.FLOAT) {
+			OdfNumberStyle numberStyle = new OdfNumberStyle(
+					(OdfFileDom) mElement.getOwnerDocument(), formatStr,
+					getUniqueNumberStyleName());
+			numberStyle.setNumberLanguageAttribute(locale.getLanguage());
+			numberStyle.setNumberCountryAttribute(locale.getCountry());
+			drawingShape.getOdfElement().getAutomaticStyles().appendChild(
+					numberStyle);
+			setDataDisplayStyleName(numberStyle.getStyleNameAttribute());
+		} else if (type == OfficeValueTypeAttribute.Value.DATE) {
+			OdfNumberDateStyle dateStyle = new OdfNumberDateStyle(
+					(OdfFileDom) mElement.getOwnerDocument(), formatStr,
+					getUniqueDateStyleName(), null);
+			dateStyle.setNumberLanguageAttribute(locale.getLanguage());
+			dateStyle.setNumberCountryAttribute(locale.getCountry());
+			drawingShape.getOdfElement().getAutomaticStyles().appendChild(
+					dateStyle);
+			setDataDisplayStyleName(dateStyle.getStyleNameAttribute());
+		} else if (type == OfficeValueTypeAttribute.Value.TIME) {
+			OdfNumberTimeStyle timeStyle = new OdfNumberTimeStyle(
+					(OdfFileDom) mElement.getOwnerDocument(), formatStr,
+					getUniqueDateStyleName());
+			timeStyle.setNumberLanguageAttribute(locale.getLanguage());
+			timeStyle.setNumberCountryAttribute(locale.getCountry());
+			drawingShape.getOdfElement().getAutomaticStyles().appendChild(
+					timeStyle);
+			setDataDisplayStyleName(timeStyle.getStyleNameAttribute());
+		} else if (type == OfficeValueTypeAttribute.Value.PERCENTAGE) {
+			OdfNumberPercentageStyle dateStyle = new OdfNumberPercentageStyle(
+					(OdfFileDom) mElement.getOwnerDocument(), formatStr,
+					getUniquePercentageStyleName());
+			dateStyle.setNumberLanguageAttribute(locale.getLanguage());
+			dateStyle.setNumberCountryAttribute(locale.getCountry());
+			drawingShape.getOdfElement().getAutomaticStyles().appendChild(
+					dateStyle);
+			setDataDisplayStyleName(dateStyle.getStyleNameAttribute());
+		} else {
+			throw new IllegalArgumentException("This function doesn't support "
+					+ type + " fomat.");
+		}
+	}
+
+	/**
+	 * Get the format string of the field.
+	 * 
+	 * @return the format string of the field
+	 */
+	public String getFormatString(OfficeValueTypeAttribute.Value typeValue) {
+		Document mDocument = ((Document) ((OdfFileDom) mElement
+				.getOwnerDocument()).getDocument());
+
+		if (typeValue == OfficeValueTypeAttribute.Value.FLOAT) {
+			String name = getDataDisplayStyleName();
+			OdfNumberStyle style = drawingShape.getOdfElement()
+					.getAutomaticStyles().getNumberStyle(name);
+			if (style == null) {
+				style = ((OdfSchemaDocument) mDocument).getDocumentStyles()
+						.getNumberStyle(name);
+			}
+			if (style != null) {
+				return style.getFormat();
+			}
+		} else if (typeValue == OfficeValueTypeAttribute.Value.DATE) {
+			String name = getDataDisplayStyleName();
+			OdfNumberDateStyle style = drawingShape.getOdfElement()
+					.getAutomaticStyles().getDateStyle(name);
+			if (style == null) {
+				style = ((OdfSchemaDocument) mDocument).getDocumentStyles()
+						.getDateStyle(name);
+			}
+			if (style != null) {
+				return style.getFormat();
+			}
+		} else if (typeValue == OfficeValueTypeAttribute.Value.TIME) {
+			String name = getDataDisplayStyleName();
+			OdfNumberDateStyle style = drawingShape.getOdfElement()
+					.getAutomaticStyles().getDateStyle(name);
+			if (style == null) {
+				style = ((OdfSchemaDocument) mDocument).getDocumentStyles()
+						.getDateStyle(name);
+			}
+			if (style != null) {
+				return style.getFormat();
+			}
+		} else if (typeValue == OfficeValueTypeAttribute.Value.PERCENTAGE) {
+			String name = getDataDisplayStyleName();
+			OdfNumberPercentageStyle style = drawingShape.getOdfElement()
+					.getAutomaticStyles().getPercentageStyle(name);
+			if (style == null) {
+				style = ((OdfSchemaDocument) mDocument).getDocumentStyles()
+						.getPercentageStyle(name);
+			}
+			if (style != null) {
+				return style.getFormat();
+			}
+		}
+		return null;
+	}
+
+	private void setDataDisplayStyleName(String name) {
+		OdfStyleBase styleElement = drawingShape.getStyleHandler()
+				.getStyleElementForWrite();
+		if (styleElement != null) {
+			styleElement.setOdfAttributeValue(OdfName.newName(
+					OdfDocumentNamespace.STYLE, "data-style-name"), name);
+		}
+	}
+
+	private String getDataDisplayStyleName() {
+		String datadisplayStylename = null;
+		OdfStyleBase styleElement = drawingShape.getStyleHandler()
+				.getStyleElementForRead();
+		if (styleElement != null) {
+			datadisplayStylename = styleElement.getOdfAttributeValue(OdfName
+					.newName(OdfDocumentNamespace.STYLE, "data-style-name"));
+		}
+
+		return datadisplayStylename;
+	}
+
+	private String getUniqueNumberStyleName() {
+		String unique_name;
+		OdfOfficeAutomaticStyles styles = drawingShape.getOdfElement()
+				.getAutomaticStyles();
+		do {
+			unique_name = String.format("n%06x",
+					(int) (Math.random() * 0xffffff));
+		} while (styles.getNumberStyle(unique_name) != null);
+		return unique_name;
+	}
+
+	private String getUniqueDateStyleName() {
+		String unique_name;
+		OdfOfficeAutomaticStyles styles = drawingShape.getOdfElement()
+				.getAutomaticStyles();
+		do {
+			unique_name = String.format("d%06x",
+					(int) (Math.random() * 0xffffff));
+		} while (styles.getDateStyle(unique_name) != null);
+		return unique_name;
+	}
+
+	private String getUniquePercentageStyleName() {
+		String unique_name;
+		OdfOfficeAutomaticStyles styles = drawingShape.getOdfElement()
+				.getAutomaticStyles();
+		do {
+			unique_name = String.format("p%06x",
+					(int) (Math.random() * 0xffffff));
+		} while (styles.getPercentageStyle(unique_name) != null);
+		return unique_name;
+	}
+
+	/**
+	 * Get a simple iterator for Field.
+	 * 
+	 * @param container
+	 *            - an instance of form where to traverse the date fields
+	 */
+	public static Iterator<FormControl> getSimpleIterator(Form container) {
+		return new SimpleFieldIterator(container);
+	}
+
+	private static class SimpleFieldIterator implements Iterator<FormControl> {
+
+		private FormFormElement containerElement;
+		private Field nextElement = null;
+		private Field tempElement = null;
+
+		private SimpleFieldIterator(Form container) {
+			containerElement = container.getOdfElement();
+		}
+
+		public boolean hasNext() {
+			tempElement = findNext(nextElement);
+			return (tempElement != null);
+		}
+
+		public Field next() {
+			if (tempElement != null) {
+				nextElement = tempElement;
+				tempElement = null;
+			} else {
+				nextElement = findNext(nextElement);
+			}
+			if (nextElement == null) {
+				return null;
+			} else {
+				return nextElement;
+			}
+		}
+
+		public void remove() {
+			if (nextElement == null) {
+				throw new IllegalStateException("please call next() first.");
+			}
+			nextElement.remove();
+
+		}
+
+		private Field findNext(Field thisField) {
+			FormFormattedTextElement nextfield = null;
+			if (thisField == null) {
+				nextfield = OdfElement.findFirstChildNode(
+						FormFormattedTextElement.class, containerElement);
+			} else {
+				nextfield = OdfElement.findNextChildNode(
+						FormFormattedTextElement.class, thisField
+								.getOdfElement());
+			}
+			if (nextfield != null) {
+				return Field.getInstanceOf(nextfield);
+			}
+			return null;
+		}
+	}
+
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Form.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Form.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Form.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Form.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,317 @@
+package org.odftoolkit.simple.form;
+
+import org.odftoolkit.odfdom.dom.element.form.FormFormElement;
+import org.odftoolkit.simple.draw.ControlContainer;
+import org.odftoolkit.simple.draw.FrameRectangle;
+import org.odftoolkit.simple.form.FormTypeDefinition.FormCommandType;
+
+/**
+ * This class represents form object. It provides method to get/set form
+ * properties, content, layout and styles. A form is a container to hold
+ * controls like buttons, combo boxes, labels, fields, check boxes, radio
+ * buttons, text boxes, list boxes and etc.
+ * 
+ * @since 0.8
+ */
+public interface Form {
+
+	/**
+	 * Create a button control in this form.
+	 * 
+	 * @param parent
+	 *            - the element that contains this form control
+	 * @param rectangle
+	 *            - the bounding rectangle used by this button
+	 * @param name
+	 *            - the name of the control
+	 * @param label
+	 *            - the text label of the button
+	 * 
+	 * @return an instance of button
+	 */
+	public FormControl createButton(ControlContainer parent,
+			FrameRectangle rectangle, String name, String label);
+
+	/**
+	 * Create a label control in this form.
+	 * 
+	 * @param parent
+	 *            - the element that contains this form control
+	 * @param rectangle
+	 *            - the bounding rectangle used by this button
+	 * @param name
+	 *            - the name of the control
+	 * @param text
+	 *            -default text of the label
+	 * 
+	 * @return an instance of label
+	 */
+	public FormControl createLabel(ControlContainer parent,
+			FrameRectangle rectangle, String name, String text);
+
+	/**
+	 * Create a textbox in this form.
+	 * 
+	 * @param parent
+	 *            - the element that contains this form control
+	 * @param rectangle
+	 *            - the bounding rectangle used by this button
+	 * @param name
+	 *            - the name of the control
+	 * @param defaultText
+	 *            -default text of the textbox
+	 * @param isMultipleLine
+	 *            - if this textbox supports multiple lines input
+	 * 
+	 * @return an instance of text box
+	 */
+	public FormControl createTextBox(ControlContainer parent,
+			FrameRectangle rectangle, String name, String defaultText,
+			boolean isMultipleLine);
+
+	/**
+	 * Create a list box in this form.
+	 * 
+	 * @param parent
+	 *            - the element that contains this form control
+	 * @param rectangle
+	 *            - the bounding rectangle used by this button
+	 * @param name
+	 *            - the name of the control
+	 * @param isMultiSelection
+	 *            - support multi-selection or not
+	 * @param isDropDown
+	 *            - the drop-down list is visible or not
+	 * 
+	 * @return an instance of list box
+	 */
+	public FormControl createListBox(ControlContainer parent,
+			FrameRectangle rectangle, String name, boolean isMultiSelection,
+			boolean isDropDown);
+
+	/**
+	 * Create a combo box in this form.
+	 * 
+	 * @param parent
+	 *            - the element that contains this form control
+	 * @param rectangle
+	 *            - the bounding rectangle used by this button
+	 * @param name
+	 *            - the name of the control
+	 * @param defaultText
+	 *            - the default text of combobox
+	 * @param isDropDown
+	 *            - the drop-down list is visible or not
+	 * 
+	 * @return an instance of combo box
+	 */
+	public FormControl createComboBox(ControlContainer parent,
+			FrameRectangle rectangle, String name, String defaultText,
+			boolean isDropDown);
+
+	/**
+	 * Create a radio button in this form.
+	 * 
+	 * @param parent
+	 *            - the element that contains this form control
+	 * @param rectangle
+	 *            - the bounding rectangle used by this button
+	 * @param name
+	 *            - the name of the control
+	 * @param label
+	 *            - the label of this radio button
+	 * @param value
+	 *            - the value assign to this option
+	 * 
+	 * @return an instance of radio button
+	 */
+	public FormControl createRadioButton(ControlContainer parent,
+			FrameRectangle rectangle, String name, String label, String value);
+
+	/**
+	 * Create a check box in this form.
+	 * 
+	 * @param parent
+	 *            - the element that contains this form control
+	 * @param rectangle
+	 *            - the bounding rectangle used by this button
+	 * @param name
+	 *            - the name of the control
+	 * @param label
+	 *            - the label of this check box
+	 * @param value
+	 *            - the value assign to this option
+	 * 
+	 * @return an instance of check box
+	 */
+	public FormControl createCheckBox(ControlContainer parent,
+			FrameRectangle rectangle, String name, String label, String value);
+
+	/**
+	 * Create a date field in this form.
+	 * 
+	 * @param parent
+	 *            - the element that contains this form control
+	 * @param rectangle
+	 *            - the bounding rectangle used by this button
+	 * @param name
+	 *            - the name of the control
+	 * @param defaultValue
+	 *            - the default value of this input field
+	 * 
+	 * @return an instance of date field
+	 */
+	public FormControl createDateField(ControlContainer parent,
+			FrameRectangle rectangle, String name, String defaultValue);
+
+	/**
+	 * Create a time field in this form.
+	 * 
+	 * @param parent
+	 *            - the element that contains this form control
+	 * @param rectangle
+	 *            - the bounding rectangle used by this button
+	 * @param name
+	 *            - the name of the control
+	 * @param defaultValue
+	 *            - the default value of this input field
+	 * 
+	 * @return an instance of time field
+	 */
+	public FormControl createTimeField(ControlContainer parent,
+			FrameRectangle rectangle, String name, String defaultValue);
+
+	/**
+	 * Create a numeric field in this form.
+	 * 
+	 * @param parent
+	 *            - the element that contains this form control
+	 * @param rectangle
+	 *            - the bounding rectangle used by this button
+	 * @param name
+	 *            - the name of the control
+	 * @param defaultValue
+	 *            - the default value of this input field
+	 * 
+	 * @return an instance of numeric field
+	 */
+	public FormControl createNumericField(ControlContainer parent,
+			FrameRectangle rectangle, String name, String defaultValue);
+
+	/**
+	 * Create a pattern field in this form.
+	 * 
+	 * @param parent
+	 *            - the element that contains this form control
+	 * @param rectangle
+	 *            - the bounding rectangle used by this button
+	 * @param name
+	 *            - the name of the control
+	 * @param defaultValue
+	 *            - the default value of this input field
+	 * 
+	 * @return an instance of pattern field
+	 */
+	public FormControl createPatternField(ControlContainer parent,
+			FrameRectangle rectangle, String name, String defaultValue);
+
+	/**
+	 * Create a currency field in this form.
+	 * 
+	 * @param parent
+	 *            - the element that contains this form control
+	 * @param rectangle
+	 *            - the bounding rectangle used by this button
+	 * @param name
+	 *            - the name of the control
+	 * @param defaultValue
+	 *            - the default value of this input field
+	 * 
+	 * @return an instance of currency field
+	 */
+	public FormControl createCurrencyField(ControlContainer parent,
+			FrameRectangle rectangle, String name, String defaultValue);
+
+	/**
+	 * Set the name of this form
+	 * 
+	 * @param name
+	 *            - the form name
+	 */
+	public void setFormName(String name);
+
+	/**
+	 * Get the form name
+	 * 
+	 * @return the form name
+	 */
+	public String getFormName();
+
+	/**
+	 * Set the implementation of the created control
+	 * 
+	 * @param controlImpl
+	 *            - implementation of control
+	 */
+	public void setControlImplementation(String controlImpl);
+
+	/**
+	 * Get the implementation of the created control
+	 * 
+	 * @return a control implementation
+	 */
+	public String getControlImplementation();
+
+	/**
+	 * Set the data source to be used by the form
+	 * 
+	 * @param dataSource
+	 *            - name of data source
+	 */
+	public void setDataSource(String dataSource);
+
+	/**
+	 * Get the name of data source
+	 * 
+	 * @return the name of data source used by the form
+	 */
+	public String getDataSource();
+
+	/**
+	 * Set the type of command to execute on a data source.
+	 * 
+	 * @param commandType
+	 *            the command type
+	 */
+	public void setCommandType(FormCommandType commandType);
+
+	/**
+	 * Get the type of command to execute on a data source
+	 * 
+	 * @return the command type
+	 */
+	public FormCommandType getCommandType();
+
+	/**
+	 * Set a command to execute on a data source
+	 * 
+	 * @param command
+	 * 
+	 */
+	public void setCommand(String command);
+
+	/**
+	 * Get the command to execute on a data source
+	 * 
+	 * @return the command
+	 */
+	public String getCommand();
+
+	/**
+	 * Get the instance of <code>FormFormElemnt</code> element.
+	 * 
+	 * @return the instance of <code>FormFormElemnt</code>
+	 */
+	public FormFormElement getOdfElement();
+
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormContainer.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormContainer.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormContainer.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormContainer.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,98 @@
+package org.odftoolkit.simple.form;
+
+import java.util.Iterator;
+
+import org.odftoolkit.odfdom.dom.element.office.OfficeFormsElement;
+
+/**
+ * FormContainer is a container which maintains Form(s) as element(s).
+ * 
+ * @since 0.8
+ */
+public interface FormContainer {
+
+	/**
+	 * Get the ODF element <code>OfficeFormsElement</code> which can have
+	 * <code>FormFormElement</code> as child element directly according to ODF
+	 * specification. This element will help to find the position to insert a
+	 * new <code>FormFormElement</code> element.
+	 * 
+	 * @return the element of office:forms
+	 */
+	public OfficeFormsElement getFormContainerElement();
+
+	/**
+	 * create and add a form into this container.
+	 * 
+	 * @param name
+	 *            - form name, represents attribute <code>form:name</code>
+	 * @return an instance of Form
+	 */
+	public Form createForm(String name);
+
+	/**
+	 * Remove the form and its binding shape.
+	 * 
+	 * @param form
+	 *            - the form to be removed
+	 * @return true if the form is removed successfully, false if errors happen.
+	 */
+	public boolean removeForm(Form form);
+
+	/**
+	 * Return a form whose name is a given value.
+	 * 
+	 * @param name
+	 *            - the name of the form
+	 * @return a form whose name is a given value
+	 */
+	public Form getFormByName(String name);
+
+	/**
+	 * Get an iterator to traverse each form in this container.
+	 * 
+	 * @return form iterator
+	 */
+	public Iterator<Form> getFormIterator();
+
+	/**
+	 * Get the attribute <code>form:apply-design-mode</code> which specifies
+	 * whether forms are presented in editable or non-editable state.
+	 * 
+	 * @return true if forms in document are presented in editable state;false
+	 *         if forms in document are presented in completed state
+	 */
+	public boolean getApplyDesignMode();
+
+	/**
+	 * Get the attribute <code>form:automatic-focus</code> which specifies
+	 * whether the consumer loading the document should set the focus to a form
+	 * control.
+	 * 
+	 * @return true if sets the focus to a form control after loading the
+	 *         document; false if else.
+	 */
+	public boolean getAutomaticFocus();
+
+	/**
+	 * Set the attribute <code>form:apply-design-mode</code> which specifies
+	 * whether forms are presented in editable or non-editable state.
+	 * 
+	 * @param isDesignMode
+	 *            - true if forms in document are presented in editable state;
+	 *            false if forms in document are presented in completed state
+	 */
+	public void setApplyDesignMode(boolean isDesignMode);
+
+	/**
+	 * Set the attribute <code>form:automatic-focus</code> which specifies
+	 * whether the consumer loading the document should set the focus to a form
+	 * control.
+	 * 
+	 * @param isAutoFocus
+	 *            -true if sets the focus to a form control after loading the
+	 *            document; false if else.
+	 */
+	public void setAutomaticFocus(boolean isAutoFocus);
+
+}



Mime
View raw message