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 [2/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
Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormControl.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormControl.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormControl.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormControl.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,255 @@
+package org.odftoolkit.simple.form;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.xerces.dom.NodeImpl;
+import org.odftoolkit.odfdom.dom.element.draw.DrawControlElement;
+import org.odftoolkit.odfdom.dom.element.form.FormFormElement;
+import org.odftoolkit.odfdom.dom.element.form.FormPropertiesElement;
+import org.odftoolkit.odfdom.dom.element.form.FormPropertyElement;
+import org.odftoolkit.odfdom.pkg.OdfElement;
+import org.odftoolkit.odfdom.pkg.OdfFileDom;
+import org.odftoolkit.simple.Component;
+import org.odftoolkit.simple.Document;
+import org.odftoolkit.simple.draw.Control;
+import org.odftoolkit.simple.draw.ControlContainer;
+import org.odftoolkit.simple.draw.FrameRectangle;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.AnchorType;
+import org.w3c.dom.NodeList;
+
+/**
+ *This class represents the form control, which provides the methods to get/set
+ * the control properties and style and layout properties of its binding drawing
+ * shape.
+ * 
+ * @since 0.8
+ */
+public abstract class FormControl extends Component {
+
+	protected Control drawingShape;
+	protected FormFormElement formElement;
+	protected FormPropertiesElement mFormProperties;
+	protected OdfElement mElement;
+
+	/**
+	 * Create an instance of a drawing shape(<code>DrawControlElement</code>) as
+	 * an visual representation of this form control.
+	 * 
+	 * @param parent
+	 *            - the container where this drawing shape is contained.
+	 * @return an instance of drawing shape
+	 */
+	Control createDrawControl(ControlContainer parent) {
+		drawingShape = parent.createDrawControl();
+		drawingShape.setControl(getId());
+		return drawingShape;
+	}
+
+	/**
+	 * Remove the form control from the container.
+	 * <p>
+	 * The resource is removed if it's only used by this object.
+	 * 
+	 * @see Control#remove()
+	 * 
+	 * @return true if the form control is successfully removed; false if
+	 *         otherwise.
+	 */
+	public boolean remove() {
+		try {
+			Document mOwnerDocument = (Document) ((OdfFileDom) mElement
+					.getOwnerDocument()).getDocument();
+			if (getDrawControl() == null)
+				loadDrawControl(mOwnerDocument.getContentRoot());
+			getDrawControl().remove();
+			formElement.removeChild(getOdfElement());
+			mOwnerDocument.removeElementLinkedResource(getOdfElement());
+			return true;
+		} catch (Exception e) {
+			Logger.getLogger(FormControl.class.getName()).log(Level.SEVERE,
+					"fail to remove this element.");
+			return false;
+		}
+	}
+
+	/**
+	 * Load an instance of drawing shape by searching the DrawControlElement
+	 * which contains a reference to this control.
+	 * 
+	 * @param root
+	 *            - root element where to search the DrawControlElement
+	 * @return true if an element is found; false no element is found.
+	 */
+	boolean loadDrawControl(OdfElement root) {
+		NodeList controls = root.getElementsByTagName("draw:control");
+		for (int i = 0; i < controls.getLength(); i++) {
+			DrawControlElement control = (DrawControlElement) controls.item(i);
+			if (control.getDrawControlAttribute().equals(getId())) {
+				drawingShape = (Control) Component
+						.getComponentByElement(control);
+				if (drawingShape == null) {
+					drawingShape = new Control(control);
+					Component.registerComponent(drawingShape, control);
+				}
+				return true;
+			}
+		}
+		return false;
+
+	}
+
+	/**
+	 * Get the OdfElement which represents this control
+	 * 
+	 * @return the OdfElement which represents this control
+	 */
+	public OdfElement getOdfElement() {
+		return mElement;
+	}
+
+	/**
+	 * Get the drawing shape binding to this control
+	 * 
+	 * @return the drawing shape binding to this control
+	 */
+	public Control getDrawControl() {
+		return drawingShape;
+	}
+
+	/**
+	 * Set the control id.
+	 * 
+	 * @param id
+	 *            -the control id.
+	 */
+	public abstract void setId(String id);
+
+	/**
+	 * Get the control id.
+	 * 
+	 * @return the control id.
+	 */
+	public abstract String getId();
+
+	/**
+	 * Set the control name.
+	 * 
+	 * @param name
+	 *            - the control name.
+	 */
+	public abstract void setName(String name);
+
+	/**
+	 * Get the control name.
+	 * 
+	 * @return the control name.
+	 */
+	public abstract String getName();
+
+	/**
+	 * Set the implementation of this control.
+	 * 
+	 * @param controlImpl
+	 *            - the implementation description of this control
+	 */
+	public abstract void setControlImplementation(String controlImpl);
+
+	/**
+	 * Set the anchor position how this form control is bound to a text
+	 * document.
+	 * 
+	 * @param anchorType
+	 *            - the anchor position
+	 */
+	public void setAnchorType(AnchorType anchorType) {
+		if (drawingShape == null)
+			throw new IllegalStateException(
+					"No drawing shape is binding to this control. Please call createDrawControl() or loadDrawControl() first.");
+		drawingShape.setAchorType(anchorType);
+	}
+
+	/**
+	 * Return the rectangle used as the bounding box of this form control
+	 * 
+	 * @return - the rectangle
+	 */
+	public FrameRectangle getRectangle() {
+		return getDrawControl().getRectangle();
+	}
+
+	/**
+	 * Set the rectangle used as the bounding box of this form control
+	 * 
+	 * @param rectangle
+	 *            - the rectangle
+	 */
+	public void setRectangle(FrameRectangle rectangle) {
+		getDrawControl().setRectangle(rectangle);
+
+	}
+
+	/**
+	 * Get the <code>FormPropertiesElement</code> of this control, which is used
+	 * to set the implementation-independent properties. If there's no such
+	 * element, create a new one for this control.
+	 * 
+	 * @return an instance of the <code>FormPropertiesElement</code>
+	 */
+	abstract FormPropertiesElement getFormPropertiesElementForWrite();
+
+	/**
+	 * Get the <code>FormPropertiesElement</code> of this control, which is used
+	 * to set the implementation-independent properties. If there's no such
+	 * element, null will be returned.
+	 * 
+	 * @return an instance of the <code>FormPropertiesElement</code>
+	 */
+	FormPropertiesElement getFormPropertiesElementForRead() {
+		return mFormProperties;
+	}
+
+	protected void setFormProperty(String formPropertyName,
+			String officeValueType, String officeStringValue,
+			Boolean officeBooleanValue, String officeDateValue,
+			String officeTimeValue, Double officeValue, String officeCurrency) {
+		FormPropertiesElement parentEle = getFormPropertiesElementForWrite();
+
+		// find the existing property with the appointed form property name
+		NodeList properties = parentEle.getChildNodes();
+		FormPropertyElement formProperty = null;
+		for (int i = 0; i < properties.getLength(); i++) {
+			FormPropertyElement property = (FormPropertyElement) properties
+					.item(i);
+			if (property.getFormPropertyNameAttribute()
+					.equals(formPropertyName)) {
+				formProperty = (FormPropertyElement) properties.item(i);
+				break;
+			}
+		}
+		// create a new property
+		if (formProperty == null) {
+			org.w3c.dom.Document ownerDocument = parentEle.getOwnerDocument();
+			formProperty = ((OdfFileDom) ownerDocument)
+					.newOdfElement(FormPropertyElement.class);
+			formProperty.setFormPropertyNameAttribute(formPropertyName);
+			formProperty.setOfficeValueTypeAttribute(officeValueType);
+		}
+		// set the value
+		if (officeStringValue != null)
+			formProperty.setOfficeStringValueAttribute(officeStringValue);
+		if (officeBooleanValue != null)
+			formProperty.setOfficeBooleanValueAttribute(officeBooleanValue);
+		if (officeDateValue != null)
+			formProperty.setOfficeDateValueAttribute(officeDateValue);
+		if (officeTimeValue != null)
+			formProperty.setOfficeTimeValueAttribute(officeTimeValue);
+		if (officeValue != null)
+			formProperty.setOfficeValueAttribute(officeValue);
+		if (officeCurrency != null)
+			formProperty.setOfficeCurrencyAttribute(officeCurrency);
+
+		((NodeImpl) parentEle).appendChild(formProperty);
+	}
+
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormProvider.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormProvider.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormProvider.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormProvider.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,33 @@
+package org.odftoolkit.simple.form;
+
+import org.odftoolkit.odfdom.dom.element.form.FormFormElement;
+import org.odftoolkit.odfdom.dom.element.office.OfficeFormsElement;
+
+/**
+ * FormProvider provides the methods to create and get form instance in a way
+ * that is implementation-independent.
+ * 
+ * @since 0.8
+ */
+public interface FormProvider {
+
+	/**
+	 * Create a form in a way that is implementation-independent.
+	 * 
+	 * @param name
+	 *            -the form name
+	 * @param parent
+	 *            -the container element of this form
+	 * @return a form instance
+	 */
+	public Form createForm(String name, OfficeFormsElement parent);
+
+	/**
+	 * Get a form instance by a <code>FormFormElement</code>
+	 * 
+	 * @param element
+	 *            - a <code>FormFormElement</code>
+	 * @return a form instance
+	 */
+	public Form getInstanceOf(FormFormElement element);
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormTypeDefinition.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormTypeDefinition.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormTypeDefinition.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/FormTypeDefinition.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,131 @@
+package org.odftoolkit.simple.form;
+
+/**
+ * This class defines the common used constants in form handling methods.
+ * 
+ * @since 0.8
+ */
+public class FormTypeDefinition {
+	/**
+	 * Common used image position of form from users perspective.
+	 * <p>
+	 * This attibute specifies the location of an image relative to the text of
+	 * a control.
+	 * 
+	 */
+	public static enum FormImageLocation {
+		BOTTOM("bottom"), CENTER("center"), END("end"), START("start"), TOP(
+				"top");
+
+		private String formImageLocation = "center";
+
+		FormImageLocation(String location) {
+			this.formImageLocation = location;
+		}
+
+		@Override
+		public String toString() {
+			return formImageLocation;
+		}
+	}
+
+	/**
+	 * Common used command type of form from users perspective. *
+	 * <p>
+	 * This attibute specifies the type of command to execute on a data source.
+	 */
+	public static enum FormCommandType {
+		COMMAND("command"), QUERY("query"), TABLE("table");
+
+		private String formCommandType = "command";
+
+		FormCommandType(String type) {
+			this.formCommandType = type;
+		}
+
+		public static FormCommandType enumValueOf(String aValue) {
+			if ((aValue == null) || (aValue.length() == 0))
+				return null;
+
+			for (FormCommandType aIter : values()) {
+				if (aValue.equals(aIter.toString())) {
+					return aIter;
+				}
+			}
+			throw new RuntimeException("Unsupported Form Command Type!");
+		}
+
+		@Override
+		public String toString() {
+			return formCommandType;
+		}
+	}
+
+	// table, query, sql, sql-pass-through, value-list or table-fields
+	/**
+	 * Common used source type of entry list from users perspective.
+	 * <p>
+	 * This attibutes pecifies how to populate the entry list in a combo box or
+	 * list box control.
+	 */
+	public static enum FormListSourceType {
+		TABLE("table"), QUERY("query"), SQL("sql"), SQL_PASS_THROUGH(
+				"sql-pass-through"), VALUE_LIST("value-list"), TABLE_FIELDS(
+				"table-fields");
+
+		private String formListSourceType = "sql";
+
+		FormListSourceType(String type) {
+			this.formListSourceType = type;
+		}
+
+		public static FormListSourceType enumValueOf(String aValue) {
+			if ((aValue == null) || (aValue.length() == 0))
+				return null;
+
+			for (FormListSourceType aIter : values()) {
+				if (aValue.equals(aIter.toString())) {
+					return aIter;
+				}
+			}
+			throw new RuntimeException("Unsupported Form Command Type!");
+		}
+
+		@Override
+		public String toString() {
+			return formListSourceType;
+		}
+	}
+
+	/**
+	 * Common used state for a check box from users perspective.
+	 * <p>
+	 *This attibutes pecifies the default state of a check box control.
+	 */
+	public static enum FormCheckboxState {
+		CHECKED("checked"), UNCHECKED("unchecked"), UNKNOWN("unknown");
+
+		private String formCheckboxState = "unchecked";
+
+		FormCheckboxState(String state) {
+			this.formCheckboxState = state;
+		}
+
+		public static FormCheckboxState enumValueOf(String aValue) {
+			if ((aValue == null) || (aValue.length() == 0))
+				return null;
+
+			for (FormCheckboxState aIter : values()) {
+				if (aValue.equals(aIter.toString())) {
+					return aIter;
+				}
+			}
+			throw new RuntimeException("Unsupported Check Box State!");
+		}
+
+		@Override
+		public String toString() {
+			return formCheckboxState;
+		}
+	}
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Label.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Label.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Label.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/Label.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,165 @@
+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.FormFixedTextElement;
+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 Label, provides methods to get/set
+ * the form properties and the style formatting of this control.
+ * 
+ * @since 0.8
+ */
+public class Label extends FormControl {
+
+	Label(FormFixedTextElement element) {
+		mElement = element;
+		formElement = (FormFormElement) element.getParentNode();
+	}
+
+	/**
+	 * Get an instance of label by an instance of FormFixedTextElement, while
+	 * searching the document content to make a bind with the DrawControl which
+	 * already reference to this label.
+	 * 
+	 * @param element
+	 *            - an instance of FormFixedTextElement
+	 * @return an instance of label
+	 */
+	public static Label getInstanceOf(FormFixedTextElement element) {
+		Label label = new Label(element);
+		try {
+			label.loadDrawControl(((Document) ((OdfFileDom) element
+					.getOwnerDocument()).getDocument()).getContentRoot());
+		} catch (Exception e) {
+			Logger.getLogger(Label.class.getName()).log(Level.WARNING,
+					"Cannot load the drawing shape of this label.");
+		}
+		return label;
+	}
+
+	@Override
+	public void setControlImplementation(String controlImpl) {
+		((FormFixedTextElement) mElement)
+				.setFormControlImplementationAttribute(controlImpl);
+	}
+
+	@Override
+	public String getId() {
+		return ((FormFixedTextElement) mElement).getFormIdAttribute();
+	}
+
+	@Override
+	public void setId(String id) {
+		((FormFixedTextElement) mElement).setFormIdAttribute(id);
+	}
+
+	@Override
+	FormPropertiesElement getFormPropertiesElementForWrite() {
+		if (mFormProperties == null)
+			mFormProperties = ((FormFixedTextElement) mElement)
+					.newFormPropertiesElement();
+		return mFormProperties;
+	}
+
+	@Override
+	public String getName() {
+		return ((FormFixedTextElement) mElement).getFormNameAttribute();
+	}
+
+	@Override
+	public void setName(String name) {
+		((FormFixedTextElement) mElement).setFormNameAttribute(name);
+	}
+
+	/**
+	 * Set the text content of this label
+	 * 
+	 * @param label
+	 *            - the text content of this label
+	 */
+	public void setLabel(String label) {
+		((FormFixedTextElement) mElement).setFormLabelAttribute(label);
+	}
+
+	/**
+	 * Get the text content of this label
+	 * 
+	 * @return the text content of this label
+	 */
+	public String getLabel() {
+		return ((FormFixedTextElement) mElement).getFormLabelAttribute();
+	}
+
+	/**
+	 * Get a simple iterator for labels.
+	 * 
+	 * @param container
+	 *            - an instance of form where to traverse the labels
+	 */
+	public static Iterator<FormControl> getSimpleIterator(Form container) {
+		return new SimpleLabelIterator(container);
+	}
+
+	private static class SimpleLabelIterator implements Iterator<FormControl> {
+
+		private FormFormElement containerElement;
+		private Label nextElement = null;
+		private Label tempElement = null;
+
+		private SimpleLabelIterator(Form container) {
+			containerElement = container.getOdfElement();
+		}
+
+		public boolean hasNext() {
+			tempElement = findNext(nextElement);
+			return (tempElement != null);
+		}
+
+		public Label 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 Label findNext(Label thisLabel) {
+			FormFixedTextElement nextLabel = null;
+			if (thisLabel == null) {
+				nextLabel = OdfElement.findFirstChildNode(
+						FormFixedTextElement.class, containerElement);
+			} else {
+				nextLabel = OdfElement.findNextChildNode(
+						FormFixedTextElement.class, thisLabel.getOdfElement());
+			}
+
+			if (nextLabel != null) {
+				return Label.getInstanceOf(nextLabel);
+			}
+			return null;
+		}
+	}
+
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/ListBox.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/ListBox.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/ListBox.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/ListBox.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,301 @@
+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.FormFormElement;
+import org.odftoolkit.odfdom.dom.element.form.FormListboxElement;
+import org.odftoolkit.odfdom.dom.element.form.FormOptionElement;
+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 List Box, provides methods to
+ * get/set the form properties and the style formatting of this control.
+ * 
+ * @since 0.8
+ */
+public class ListBox extends FormControl {
+
+	private ArrayList<String> entries;
+
+	ListBox(FormListboxElement element) {
+		this.mElement = element;
+		formElement = (FormFormElement) element.getParentNode();
+	}
+
+	/**
+	 * Get an instance of list box by an instance of FormListboxElement, while
+	 * searching the document content to make a bind with the DrawControl which
+	 * already reference to this list box.
+	 * 
+	 * @param element
+	 *            - an instance of FormComboboxElement
+	 * @return an instance of list box
+	 */
+	public static ListBox getInstanceOf(FormListboxElement element) {
+		ListBox listbox = new ListBox(element);
+		try {
+			listbox.loadDrawControl(((Document) ((OdfFileDom) element
+					.getOwnerDocument()).getDocument()).getContentRoot());
+		} catch (Exception e) {
+			Logger.getLogger(ListBox.class.getName()).log(Level.WARNING,
+					"Cannot load the drawing shape of this listbox.");
+		}
+		return listbox;
+	}
+
+	@Override
+	FormPropertiesElement getFormPropertiesElementForWrite() {
+		if (mFormProperties == null)
+			mFormProperties = ((FormListboxElement) mElement)
+					.newFormPropertiesElement();
+		return mFormProperties;
+	}
+
+	@Override
+	public void setControlImplementation(String controlImpl) {
+		((FormListboxElement) mElement)
+				.setFormControlImplementationAttribute(controlImpl);
+	}
+
+	@Override
+	public String getId() {
+		return ((FormListboxElement) mElement).getFormIdAttribute();
+	}
+
+	@Override
+	public void setId(String id) {
+		((FormListboxElement) mElement).setFormIdAttribute(id);
+	}
+
+	@Override
+	public String getName() {
+		return ((FormListboxElement) mElement).getFormNameAttribute();
+	}
+
+	@Override
+	public void setName(String name) {
+		((FormListboxElement) mElement).setFormNameAttribute(name);
+	}
+
+	/**
+	 * Set if the list box support multi-selection
+	 * 
+	 * @param isMultiSelection
+	 *            - specify if the list box supports multi-selection
+	 */
+	public void setFormMultiSelection(boolean isMultiSelection) {
+		((FormListboxElement) mElement)
+				.setFormMultipleAttribute(isMultiSelection);
+	}
+
+	/**
+	 * Get if the list box support multi-selection
+	 * 
+	 * @return true if the list box supports multi-selection; false if not.
+	 */
+	public boolean getFormMultiSelection() {
+		return ((FormListboxElement) mElement).getFormMultipleAttribute();
+	}
+
+	/**
+	 * Set the visibility of the drop-down list
+	 * 
+	 * @param isDropDown
+	 *            - specify if the drop-down list is visible
+	 */
+	public void setFormDropdown(boolean isDropDown) {
+		((FormListboxElement) mElement).setFormDropdownAttribute(isDropDown);
+	}
+
+	/**
+	 * Get the visibility of the drop-down list
+	 * 
+	 * @return true if the drop-down list is visible; false if not.
+	 */
+	public boolean getFormDropdown() {
+		return ((FormListboxElement) mElement).getFormDropdownAttribute();
+	}
+
+	/**
+	 * Add a list item to this list box.
+	 * 
+	 * @param item
+	 *            - a list item
+	 */
+	public void addItem(String item) {
+		if (item == null)
+			return;
+		if (entries == null)
+			entries = new ArrayList<String>();
+		((FormListboxElement) mElement).newFormOptionElement()
+				.setFormLabelAttribute(item);
+		entries.add(item);
+	}
+
+	/**
+	 * 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:option");
+			if (items != null && items.getLength() > 0) {
+				for (int i = 0; i < items.getLength(); i++) {
+					if (entries == null)
+						entries = new ArrayList<String>();
+					entries.add(((FormOptionElement) items.item(i))
+							.getFormLabelAttribute());
+				}
+				return entries;
+			}
+		}
+		return null;
+	}
+
+	/**
+	 * Add a group of list items to this list 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]);
+		}
+	}
+
+	/**
+	 * Set the source type of the data list.
+	 * 
+	 * @param type
+	 *            - the source type of this list
+	 */
+	public void setListSourceType(FormListSourceType type) {
+		((FormListboxElement) mElement).setFormListSourceTypeAttribute(type
+				.toString());
+	}
+
+	/**
+	 * Get the source type of the data list.
+	 * 
+	 * @return the source type of this list
+	 */
+	public FormListSourceType getListSourceType() {
+		String aValue = ((FormListboxElement) mElement)
+				.getFormListSourceTypeAttribute();
+		return FormListSourceType.enumValueOf(aValue);
+	}
+
+	/**
+	 * Set the source of this data list.
+	 * 
+	 * @param listSource
+	 *            - the source of this data list.
+	 */
+	public void setListSource(String listSource) {
+		((FormListboxElement) mElement).setFormListSourceAttribute(listSource);
+	}
+
+	/**
+	 * Get the source of this data list.
+	 * 
+	 * @return the source of this data list.
+	 */
+	public String getListSource() {
+		return ((FormListboxElement) 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) {
+		((FormListboxElement) mElement).setFormDataFieldAttribute(dataField);
+	}
+
+	/**
+	 * Get the data field referenced by this combo box
+	 * 
+	 * @return the data field
+	 */
+	public String getDataField() {
+		return ((FormListboxElement) mElement).getFormDataFieldAttribute();
+	}
+
+	/**
+	 * Get a simple iterator for list boxes.
+	 * 
+	 * @param container
+	 *            - an instance of form where to traverse the list boxes
+	 */
+	public static Iterator<FormControl> getSimpleIterator(Form container) {
+		return new SimpleListBoxIterator(container);
+	}
+
+	private static class SimpleListBoxIterator implements Iterator<FormControl> {
+
+		private FormFormElement containerElement;
+		private ListBox nextElement = null;
+		private ListBox tempElement = null;
+
+		private SimpleListBoxIterator(Form container) {
+			containerElement = container.getOdfElement();
+		}
+
+		public boolean hasNext() {
+			tempElement = findNext(nextElement);
+			return (tempElement != null);
+		}
+
+		public ListBox 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 ListBox findNext(ListBox thisListBox) {
+			FormListboxElement nextListBox = null;
+			if (thisListBox == null) {
+				nextListBox = OdfElement.findFirstChildNode(
+						FormListboxElement.class, containerElement);
+			} else {
+				nextListBox = OdfElement.findNextChildNode(
+						FormListboxElement.class, thisListBox.getOdfElement());
+			}
+
+			if (nextListBox != null) {
+				return ListBox.getInstanceOf(nextListBox);
+			}
+			return null;
+		}
+	}
+
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/NumericField.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/NumericField.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/NumericField.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/NumericField.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 NumericField extends Field {
+
+	NumericField(FormFormattedTextElement element) {
+		super(element);
+	}
+
+	/**
+	 * Get an instance of numeric field by an instance of
+	 * FormFormattedTextElement, while searching the document content to make a
+	 * bind with the DrawControl which already reference to this numeric field.
+	 * 
+	 * @param element
+	 *            - an instance of FormFormattedTextElement
+	 * @return an instance of numeric field
+	 */
+	public static TimeField getInstanceOf(FormFormattedTextElement element) {
+		TimeField field = new TimeField(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 decimal accuracy of the input value
+	 * 
+	 * @param value
+	 *            - specify how many digits will be kept after the decimal point
+	 */
+	public void setDecimalAccuracy(double value) {
+		this.setFormProperty(OOFormProvider.FORM_PROPERTY_NAME_DECIMALACCURACY,
+				"float", null, null, null, null, value, null);
+	}
+
+	/**
+	 * Set the step value for the spin button.
+	 * 
+	 * @param value
+	 *            - the step value for the spin button.
+	 */
+	public void setStepValue(double value) {
+		this.setFormProperty(OOFormProvider.FORM_PROPERTY_NAME_VALUESTEP,
+				"float", null, null, null, null, value, null);
+	}
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/OOForm.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/OOForm.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/OOForm.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/OOForm.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,527 @@
+package org.odftoolkit.simple.form;
+
+import org.odftoolkit.odfdom.dom.element.form.FormButtonElement;
+import org.odftoolkit.odfdom.dom.element.form.FormCheckboxElement;
+import org.odftoolkit.odfdom.dom.element.form.FormComboboxElement;
+import org.odftoolkit.odfdom.dom.element.form.FormFixedTextElement;
+import org.odftoolkit.odfdom.dom.element.form.FormFormElement;
+import org.odftoolkit.odfdom.dom.element.form.FormFormattedTextElement;
+import org.odftoolkit.odfdom.dom.element.form.FormFrameElement;
+import org.odftoolkit.odfdom.dom.element.form.FormListboxElement;
+import org.odftoolkit.odfdom.dom.element.form.FormRadioElement;
+import org.odftoolkit.odfdom.dom.element.office.OfficeFormsElement;
+import org.odftoolkit.odfdom.pkg.OdfElement;
+import org.odftoolkit.odfdom.pkg.OdfFileDom;
+import org.odftoolkit.simple.Component;
+import org.odftoolkit.simple.Document;
+import org.odftoolkit.simple.TextDocument;
+import org.odftoolkit.simple.draw.ControlContainer;
+import org.odftoolkit.simple.draw.FrameRectangle;
+import org.odftoolkit.simple.form.FormTypeDefinition.FormCommandType;
+import org.odftoolkit.simple.form.FormTypeDefinition.FormImageLocation;
+import org.odftoolkit.simple.form.OOFormProvider.FieldType;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.AnchorType;
+
+/**
+ * This class implements the interface of Form according to the implementation
+ * of OpenOffice.org.
+ * 
+ * @since 0.8
+ * 
+ */
+public class OOForm extends Component implements Form {
+
+	private FormFormElement mElement;
+	private Document mOwnerDocument;
+	protected OfficeFormsElement mFormContainerElement;
+	private int controlCount;
+
+	private OOForm(FormFormElement element) {
+		mElement = element;
+		mOwnerDocument = (Document) ((OdfFileDom) mElement.getOwnerDocument())
+				.getDocument();
+		mFormContainerElement = (OfficeFormsElement) mElement.getParentNode();
+	}
+
+	static OOForm createForm(String name, OfficeFormsElement parent) {
+		OOForm form = null;
+		if (parent != null) {
+			FormFormElement element = parent.newFormFormElement();
+			form = new OOForm(element);
+			form.setFormName(name);
+			form
+					.setControlImplementation(OOFormProvider.OO_CONTROL_IMPLEMENTATION_FORM);
+			Component.registerComponent(form, element);
+		}
+		return form;
+	}
+
+	public Document getOwnerDocument() {
+		return mOwnerDocument;
+	}
+
+	/**
+	 * Get a form instance by an instance of <code>FormFormElement</code>.
+	 * 
+	 * @param element
+	 * @return
+	 */
+	public static Form getInstance(FormFormElement element) {
+		OOForm form = null;
+		form = (OOForm) Component.getComponentByElement(element);
+		if (form == null) {
+			form = new OOForm(element);
+			Component.registerComponent(form, element);
+		}
+		return form;
+	}
+
+
+	public Button createButton(ControlContainer parent,
+			FrameRectangle rectangle, String name, String label) {
+		FormButtonElement btnElement = mElement.newFormButtonElement(
+				FormImageLocation.CENTER.toString(), generateFormId());
+		// set default control properties
+		Button btnForm = new Button(btnElement);
+		Component.registerComponent(btnForm, btnElement);
+		btnForm.setId(btnElement.getXmlIdAttribute());
+		btnForm.setName(name);
+		btnForm
+				.setControlImplementation(OOFormProvider.OO_CONTROL_IMPLEMENTATION_COMMANDBUTTON);
+		btnForm.setLabel(label);
+		btnForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_DEFAULTCONTROL, "string",
+				OOFormProvider.FORM_PROPERTY_VALUE_COMMANDBUTTON, null, null,
+				null, null, null);
+		// bond to drawing shape
+		btnForm.createDrawControl(parent);
+		// set default shape properties
+		if (parent instanceof TextDocument) {
+			btnForm.setAnchorType(AnchorType.TO_PAGE);
+		} else {
+			btnForm.setAnchorType(AnchorType.TO_PARAGRAPH);
+		}
+		btnForm.setRectangle(rectangle);
+		return btnForm;
+	}
+
+
+	public FormControl createLabel(ControlContainer parent,
+			FrameRectangle rectangle, String name, String text) {
+		FormFixedTextElement fixedTElement = mElement
+				.newFormFixedTextElement(generateFormId());
+		// set default control properties
+		Label labelForm = new Label(fixedTElement);
+		Component.registerComponent(labelForm, fixedTElement);
+		labelForm.setId(fixedTElement.getXmlIdAttribute());
+		labelForm
+				.setControlImplementation(OOFormProvider.OO_CONTROL_IMPLEMENTATION_FIXEDTEXT);
+		labelForm.setName(name);
+		labelForm.setLabel(text);
+		// bond to drawing shape
+		labelForm.createDrawControl(parent);
+		// set default shape properties
+		if (parent instanceof TextDocument) {
+			labelForm.setAnchorType(AnchorType.TO_PAGE);
+		} else {
+			labelForm.setAnchorType(AnchorType.TO_PARAGRAPH);
+		}
+		labelForm.setRectangle(rectangle);
+		return labelForm;
+	}
+
+
+	public FormControl createTextBox(ControlContainer parent,
+			FrameRectangle rectangle, String name, String defaultText,
+			boolean isMultipleLine) {
+		OdfElement textBoxElement;
+		String formId = generateFormId();
+		if (isMultipleLine) {
+			textBoxElement = mElement.newFormTextareaElement(formId);
+		} else {
+			textBoxElement = mElement.newFormTextElement(formId);
+		}
+		// set default control properties
+		TextBox textBoxForm = new TextBox(textBoxElement);
+		Component.registerComponent(textBoxForm, textBoxElement);
+		textBoxForm.setId(formId);
+		textBoxForm.setName(name);
+		textBoxForm
+				.setControlImplementation(OOFormProvider.OO_CONTROL_IMPLEMENTATION_TEXTFEILD);
+		textBoxForm.setValue(defaultText);
+		textBoxForm.setCurrentValue(defaultText);
+		textBoxForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_DEFAULTCONTROL, "string",
+				OOFormProvider.FORM_PROPERTY_VALUE_TEXTFEILD, null, null, null,
+				null, null);
+		if (isMultipleLine)
+			textBoxForm.setFormProperty(
+					OOFormProvider.FORM_PROPERTY_NAME_MULTILINE, "boolean",
+					null, true, null, null, null, null);
+		textBoxForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_OBJIDINMSO, "float", null,
+				null, null, null, 0.0, null);
+
+		// bond to drawing shape
+		textBoxForm.createDrawControl(parent);
+		// set default shape properties
+		if (parent instanceof TextDocument) {
+			textBoxForm.setAnchorType(AnchorType.TO_PAGE);
+		} else {
+			textBoxForm.setAnchorType(AnchorType.TO_PARAGRAPH);
+		}
+		textBoxForm.setRectangle(rectangle);
+		return textBoxForm;
+	}
+
+
+	public FormControl createListBox(ControlContainer parent,
+			FrameRectangle rectangle, String name, boolean isMultiSelection,
+			boolean isDropDown) {
+		String formId = generateFormId();
+		FormListboxElement listBoxElement = mElement
+				.newFormListboxElement(generateFormId());
+		// set default control properties
+		ListBox listBoxForm = new ListBox(listBoxElement);
+		Component.registerComponent(listBoxForm, listBoxElement);
+		listBoxForm.setId(formId);
+		listBoxForm.setName(name);
+		listBoxForm
+				.setControlImplementation(OOFormProvider.OO_CONTROL_IMPLEMENTATION_LISTBOX);
+		listBoxForm.setFormMultiSelection(isMultiSelection);
+		if (isDropDown) {
+			listBoxForm.setFormDropdown(true);
+		}
+		listBoxForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_COMPLEXSTRINGITEMLIST,
+				"float", null, null, null, null, null, null);
+		listBoxForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_DEFAULTCONTROL, "string",
+				OOFormProvider.FORM_PROPERTY_VALUE_LISTBOX, null, null, null,
+				null, null);
+		listBoxForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_CONTROLTYPEINMSO, "float",
+				null, null, null, null, 0.0, null);
+		listBoxForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_FOCUSEDITEM, "float", null,
+				null, null, null, 0.0, null);
+		listBoxForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_EXTMULTISELECTION, "float",
+				null, null, null, null, 0.0, null);
+		listBoxForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_OBJIDINMSO, "float", null,
+				null, null, null, 0.0, null);
+		// bond to drawing shape
+		listBoxForm.createDrawControl(parent);
+		// set default shape properties
+		if (parent instanceof TextDocument) {
+			listBoxForm.setAnchorType(AnchorType.TO_PAGE);
+		} else {
+			listBoxForm.setAnchorType(AnchorType.TO_PARAGRAPH);
+		}
+		listBoxForm.setRectangle(rectangle);
+		return listBoxForm;
+	}
+
+
+	public FormControl createComboBox(ControlContainer parent,
+			FrameRectangle rectangle, String name, String defaultText,
+			boolean isDropDown) {
+		String formId = generateFormId();
+		FormComboboxElement comboElement = mElement
+				.newFormComboboxElement(formId);
+		// set default control properties
+		ComboBox comboBoxForm = new ComboBox(comboElement);
+		Component.registerComponent(comboBoxForm, comboElement);
+		comboBoxForm.setId(formId);
+		comboBoxForm
+				.setControlImplementation(OOFormProvider.OO_CONTROL_IMPLEMENTATION_COMBOBOX);
+		comboBoxForm.setName(name);
+		if (defaultText != null) {
+			comboBoxForm.setCurrentValue(defaultText);
+			comboBoxForm.setValue(defaultText);
+		}
+		if (isDropDown) {
+			comboBoxForm.setFormDropdown(true);
+		}
+		comboBoxForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_COMPLEXSTRINGITEMLIST,
+				"float", null, null, null, null, null, null);
+		comboBoxForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_DEFAULTCONTROL, "string",
+				OOFormProvider.FORM_PROPERTY_VALUE_COMBOBOX, null, null, null,
+				null, null);
+		comboBoxForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_CONTROLTYPEINMSO, "float",
+				null, null, null, null, 0.0, null);
+		comboBoxForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_OBJIDINMSO, "float", null,
+				null, null, null, 0.0, null);
+		// bond to drawing shape
+		comboBoxForm.createDrawControl(parent);
+		// set default shape properties
+		if (parent instanceof TextDocument) {
+			comboBoxForm.setAnchorType(AnchorType.TO_PAGE);
+		} else {
+			comboBoxForm.setAnchorType(AnchorType.TO_PARAGRAPH);
+		}
+		comboBoxForm.setRectangle(rectangle);
+		return comboBoxForm;
+	}
+
+
+	public FormControl createRadioButton(ControlContainer parent,
+			FrameRectangle rectangle, String name, String label, String value) {
+		String formId = generateFormId();
+		FormRadioElement radioElement = mElement.newFormRadioElement("center",
+				formId);
+		// set default control properties
+		RadioButton radioBtnForm = new RadioButton(radioElement);
+		Component.registerComponent(radioBtnForm, radioElement);
+		radioBtnForm.setId(formId);
+		radioBtnForm
+				.setControlImplementation(OOFormProvider.OO_CONTROL_IMPLEMENTATION_RADIOBUTTON);
+		radioBtnForm.setLabel(label);
+		radioBtnForm.setName(name);
+		radioBtnForm.setValue(value);
+		radioBtnForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_CONTROLTYPEINMSO, "float",
+				null, null, null, null, 0.0, null);
+		radioBtnForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_DEFAULTCONTROL, "string",
+				OOFormProvider.FORM_PROPERTY_VALUE_RADIOBUTTON, null, null,
+				null, null, null);
+		// bond to drawing shape
+		radioBtnForm.createDrawControl(parent);
+		// set default shape properties
+		if (parent instanceof TextDocument) {
+			radioBtnForm.setAnchorType(AnchorType.TO_PAGE);
+		} else {
+			radioBtnForm.setAnchorType(AnchorType.TO_PARAGRAPH);
+		}
+		radioBtnForm.setRectangle(rectangle);
+		return radioBtnForm;
+	}
+
+
+	public FormControl createCheckBox(ControlContainer parent,
+			FrameRectangle rectangle, String name, String label, String value) {
+		String formId = generateFormId();
+		FormCheckboxElement checkboxElement = mElement.newFormCheckboxElement(
+				"center", formId);
+		// set default control properties
+		CheckBox checkboxForm = new CheckBox(checkboxElement);
+		Component.registerComponent(checkboxForm, checkboxElement);
+		checkboxForm.setId(formId);
+		checkboxForm.setName(name);
+		checkboxForm
+				.setControlImplementation(OOFormProvider.OO_CONTROL_IMPLEMENTATION_CHECKBOX);
+		checkboxForm.setLabel(label);
+		checkboxForm.setValue(value);
+		checkboxForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_CONTROLTYPEINMSO, "float",
+				null, null, null, null, 0.0, null);
+		checkboxForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_DEFAULTCONTROL, "string",
+				OOFormProvider.FORM_PROPERTY_VALUE_CHECKBOX, null, null, null,
+				null, null);
+		// bond to drawing shape
+		checkboxForm.createDrawControl(parent);
+		// set default shape properties
+		if (parent instanceof TextDocument) {
+			checkboxForm.setAnchorType(AnchorType.TO_PAGE);
+		} else {
+			checkboxForm.setAnchorType(AnchorType.TO_PARAGRAPH);
+		}
+		checkboxForm.setRectangle(rectangle);
+		return checkboxForm;
+	}
+
+	/**
+	 * 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. It's a 6 digits
+	 *            number, e.g. 20121015 represents 2012-10-15.
+	 * 
+	 * @return an instance of time field
+	 */
+	public FormControl createDateField(ControlContainer parent,
+			FrameRectangle rectangle, String name, String defaultValue) {
+		return createField(FieldType.DATE_FIELD, parent, rectangle, name,
+				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. It's a 6 digits
+	 *            number, e.g. 15304000 represents 15:30:40.
+	 * 
+	 * @return an instance of time field
+	 */
+	public FormControl createTimeField(ControlContainer parent,
+			FrameRectangle rectangle, String name, String defaultValue) {
+		return createField(FieldType.TIME_FIELD, parent, rectangle, name,
+				defaultValue);
+	}
+
+
+	public FormControl createNumericField(ControlContainer parent,
+			FrameRectangle rectangle, String name, String defaultValue) {
+		return createField(FieldType.NUMERIC_FIELD, parent, rectangle, name,
+				defaultValue);
+	}
+
+
+	public FormControl createPatternField(ControlContainer parent,
+			FrameRectangle rectangle, String name, String defaultValue) {
+		return createField(FieldType.PATTERN_FIELD, parent, rectangle, name,
+				defaultValue);
+	}
+
+
+	public FormControl createCurrencyField(ControlContainer parent,
+			FrameRectangle rectangle, String name, String defaultValue) {
+		return createField(FieldType.CURRENCY_FIELD, parent, rectangle, name,
+				defaultValue);
+	}
+
+	private FormControl createField(FieldType type, ControlContainer parent,
+			FrameRectangle rectangle, String name, String defaultValue) {
+		String formId = generateFormId();
+		FormFormattedTextElement formattedTextElement = mElement
+				.newFormFormattedTextElement(formId);
+		// create control according to the field type
+		Field fieldForm = null;
+		String defaultControl = null;
+		String controlImpl = null;
+		switch (type) {
+		case DATE_FIELD:
+			defaultControl = OOFormProvider.FORM_PROPERTY_VALUE_DATEFIELD;
+			controlImpl = OOFormProvider.OO_CONTROL_IMPLEMENTATION_DATEFIELD;
+			fieldForm = new DateField(formattedTextElement);
+			break;
+		case TIME_FIELD:
+			defaultControl = OOFormProvider.FORM_PROPERTY_VALUE_TIMEFIELD;
+			controlImpl = OOFormProvider.OO_CONTROL_IMPLEMENTATION_TIMEFIELD;
+			fieldForm = new TimeField(formattedTextElement);
+			break;
+		case NUMERIC_FIELD:
+			defaultControl = OOFormProvider.FORM_PROPERTY_VALUE_NUMERICFIELD;
+			controlImpl = OOFormProvider.OO_CONTROL_IMPLEMENTATION_NUMERICFIELD;
+			fieldForm = new NumericField(formattedTextElement);
+			break;
+		case PATTERN_FIELD:
+			defaultControl = OOFormProvider.FORM_PROPERTY_VALUE_PATTERNFIELD;
+			controlImpl = OOFormProvider.OO_CONTROL_IMPLEMENTATION_PATTERNFIELD;
+			fieldForm = new PatternField(formattedTextElement);
+			break;
+		case CURRENCY_FIELD:
+			defaultControl = OOFormProvider.FORM_PROPERTY_VALUE_CURRENCYFIELD;
+			controlImpl = OOFormProvider.OO_CONTROL_IMPLEMENTATION_CURRENCYFIELD;
+			fieldForm = new CurrencyField(formattedTextElement);
+			break;
+		}
+		if (fieldForm == null)
+			throw new RuntimeException("Fail to create a field.");
+		Component.registerComponent(fieldForm, formattedTextElement);
+		// set control properties
+		fieldForm.setName(name);
+		fieldForm.setId(formId);
+		fieldForm.setControlImplementation(controlImpl);
+		fieldForm.setValue(defaultValue);
+		fieldForm.setCurrentValue(defaultValue);
+		fieldForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_CONTROLTYPEINMSO, "float",
+				null, null, null, null, 0.0, null);
+		fieldForm.setFormProperty(
+				OOFormProvider.FORM_PROPERTY_NAME_DEFAULTCONTROL, "string",
+				defaultControl, null, null, null, null, null);
+		// bond to drawing shape
+		fieldForm.createDrawControl(parent);
+		// set default shape properties
+		if (parent instanceof TextDocument) {
+			fieldForm.setAnchorType(AnchorType.TO_PAGE);
+		} else {
+			fieldForm.setAnchorType(AnchorType.TO_PARAGRAPH);
+		}
+		fieldForm.setRectangle(rectangle);
+		return fieldForm;
+
+	}
+
+	private String generateFormId() {
+		return getFormName() + (++controlCount);
+	}
+
+
+	public void setControlImplementation(String controlImpl) {
+		mElement.setFormControlImplementationAttribute(controlImpl);
+	}
+
+
+	public void setFormName(String name) {
+		mElement.setFormNameAttribute(name);
+	}
+
+
+	public void setCommand(String command) {
+		mElement.setFormCommandAttribute(command);
+	}
+
+
+	public void setCommandType(FormCommandType commandType) {
+		mElement.setFormCommandTypeAttribute(commandType.toString());
+	}
+
+
+	public void setDataSource(String dataSource) {
+		mElement.setFormDatasourceAttribute(dataSource);
+	}
+
+
+	public FormFormElement getOdfElement() {
+		return mElement;
+	}
+
+
+	public String getFormName() {
+		return mElement.getFormNameAttribute();
+	}
+
+
+	public String getCommand() {
+		return mElement.getFormCommandAttribute();
+	}
+
+
+	public FormCommandType getCommandType() {
+		return FormCommandType.enumValueOf(mElement
+				.getFormCommandTypeAttribute());
+	}
+
+
+	public String getControlImplementation() {
+		return mElement.getFormControlImplementationAttribute();
+	}
+
+
+	public String getDataSource() {
+		return mElement.getFormDatasourceAttribute();
+	}
+
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/OOFormProvider.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/OOFormProvider.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/OOFormProvider.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/OOFormProvider.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,80 @@
+package org.odftoolkit.simple.form;
+
+import org.odftoolkit.odfdom.dom.element.form.FormFormElement;
+import org.odftoolkit.odfdom.dom.element.office.OfficeFormsElement;
+
+/**
+ * This class provide method to create/get the form instance implemented in
+ * Apache Open Office way.
+ * 
+ * @since 0.8
+ */
+public class OOFormProvider implements FormProvider {
+
+	static final String OO_CONTROL_IMPLEMENTATION_FORM = "ooo:com.sun.star.form.component.Form";
+	static final String OO_CONTROL_IMPLEMENTATION_COMMANDBUTTON = "ooo:com.sun.star.form.component.CommandButton";
+	static final String OO_CONTROL_IMPLEMENTATION_FIXEDTEXT = "ooo:com.sun.star.form.component.FixedText";
+	static final String OO_CONTROL_IMPLEMENTATION_TEXTFEILD = "ooo:com.sun.star.form.component.TextField";
+	static final String OO_CONTROL_IMPLEMENTATION_LISTBOX = "ooo:com.sun.star.form.component.ListBox";
+	static final String OO_CONTROL_IMPLEMENTATION_GROUPBOX = "ooo:com.sun.star.form.component.GroupBox";
+	static final String OO_CONTROL_IMPLEMENTATION_COMBOBOX = "ooo:com.sun.star.form.component.ComboBox";
+	static final String OO_CONTROL_IMPLEMENTATION_RADIOBUTTON = "ooo:com.sun.star.form.component.RadioButton";
+	static final String OO_CONTROL_IMPLEMENTATION_CHECKBOX = "ooo:com.sun.star.form.component.CheckBox";
+	static final String OO_CONTROL_IMPLEMENTATION_DATEFIELD = "ooo:com.sun.star.form.component.DateField";
+	static final String OO_CONTROL_IMPLEMENTATION_TIMEFIELD = "ooo:com.sun.star.form.component.TimeField";
+	static final String OO_CONTROL_IMPLEMENTATION_NUMERICFIELD = "ooo:com.sun.star.form.component.NumericField";
+	static final String OO_CONTROL_IMPLEMENTATION_PATTERNFIELD = "ooo:com.sun.star.form.component.PatternField";
+	static final String OO_CONTROL_IMPLEMENTATION_CURRENCYFIELD = "ooo:com.sun.star.form.component.CurrencyField";
+
+	static final String FORM_PROPERTY_VALUE_COMMANDBUTTON = "com.sun.star.form.control.CommandButton";
+	static final String FORM_PROPERTY_VALUE_TEXTFEILD = "com.sun.star.form.control.TextField";
+	static final String FORM_PROPERTY_VALUE_LISTBOX = "com.sun.star.form.control.ListBox";
+	static final String FORM_PROPERTY_VALUE_COMBOBOX = "com.sun.star.form.control.ComboBox";
+	static final String FORM_PROPERTY_VALUE_RADIOBUTTON = "com.sun.star.form.control.RadioButton";
+	static final String FORM_PROPERTY_VALUE_CHECKBOX = "com.sun.star.form.control.CheckBox";
+	static final String FORM_PROPERTY_VALUE_DATEFIELD = "com.sun.star.form.control.DateField";
+	static final String FORM_PROPERTY_VALUE_TIMEFIELD = "com.sun.star.form.control.TimeField";
+	static final String FORM_PROPERTY_VALUE_NUMERICFIELD = "com.sun.star.form.control.NumericField";
+	static final String FORM_PROPERTY_VALUE_PATTERNFIELD = "com.sun.star.form.control.PatternField";
+	static final String FORM_PROPERTY_VALUE_CURRENCYFIELD = "com.sun.star.form.control.CurrencyField";
+
+	static final String FORM_PROPERTY_NAME_DEFAULTCONTROL = "DefaultControl";
+	static final String FORM_PROPERTY_NAME_OBJIDINMSO = "ObjIDinMSO";
+	static final String FORM_PROPERTY_NAME_MULTILINE = "MultiLine";
+	static final String FORM_PROPERTY_NAME_COMPLEXSTRINGITEMLIST = "ComplexStringItemList";
+	static final String FORM_PROPERTY_NAME_CONTROLTYPEINMSO = "ControlTypeinMSO";
+	static final String FORM_PROPERTY_NAME_FOCUSEDITEM = "FocusedItem";
+	static final String FORM_PROPERTY_NAME_EXTMULTISELECTION = "ExtMultiSelection";
+	static final String FORM_PROPERTY_NAME_SPIN = "Spin";
+	static final String FORM_PROPERTY_NAME_DROPDOWN = "Dropdown";
+	public static final String FORM_PROPERTY_NAME_DECIMALACCURACY = "DecimalAccuracy";
+	public static final String FORM_PROPERTY_NAME_VALUESTEP = "ValueStep";
+	public static final String FORM_PROPERTY_NAME_EDITMASK = "EditMask";
+	public static final String FORM_PROPERTY_NAME_LITERALMASK = "LiteralMask";
+	public static final String FORM_PROPERTY_NAME_CURRENCYSYMBOL = "CurrencySymbol";
+	public static final String FORM_PROPERTY_NAME_PREPENDCURRENCYSYMBOL = "PrependCurrencySymbol";
+
+	static enum FieldType {
+		DATE_FIELD, TIME_FIELD, NUMERIC_FIELD, PATTERN_FIELD, CURRENCY_FIELD;
+	}
+
+	/**
+	 * Create a form in Apache Open Office way.
+	 * 
+	 * @see FormProvider#createForm(String, OfficeFormsElement)
+	 */
+	public Form createForm(String name, OfficeFormsElement parent) {
+
+		return OOForm.createForm(name, parent);
+	}
+
+	/**
+	 * Get a form instance implemented in Apache Open Office way.
+	 * 
+	 * @see FormProvider#getInstanceOf(FormFormElement)
+	 */
+	public Form getInstanceOf(FormFormElement element) {
+		return OOForm.getInstance(element);
+	}
+
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/PatternField.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/PatternField.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/PatternField.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/PatternField.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,47 @@
+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 PatternField extends Field {
+
+	PatternField(FormFormattedTextElement element) {
+		super(element);
+	}
+
+
+	/**
+	 * Get an instance of pattern field by an instance of FormFormattedTextElement,
+	 * while searching the document content to make a bind with the DrawControl
+	 * which already reference to this pattern field.
+	 * 
+	 * @param element
+	 *            - an instance of FormFormattedTextElement
+	 * @return an instance of pattern field
+	 */
+	public static PatternField getInstanceOf(FormFormattedTextElement element) {
+		PatternField field = new PatternField(element);
+		try {
+			field.loadDrawControl(((Document) ((OdfFileDom) element
+					.getOwnerDocument()).getDocument()).getContentRoot());
+		} catch (Exception e) {
+			Logger.getLogger(PatternField.class.getName()).log(Level.WARNING,
+					"Cannot load the drawing shape of this field.");
+		}
+		return field;
+	}
+
+	public void setEditMask(String mask) {
+		this.setFormProperty(OOFormProvider.FORM_PROPERTY_NAME_EDITMASK,
+				"string", mask, null, null, null, null, null);
+	}
+
+	public void setLiteralMask(String mask) {
+		this.setFormProperty(OOFormProvider.FORM_PROPERTY_NAME_LITERALMASK,
+				"string", mask, null, null, null, null, null);
+	}
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/RadioButton.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/RadioButton.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/RadioButton.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/RadioButton.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,227 @@
+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.form.FormPropertiesElement;
+import org.odftoolkit.odfdom.dom.element.form.FormRadioElement;
+import org.odftoolkit.odfdom.pkg.OdfElement;
+import org.odftoolkit.odfdom.pkg.OdfFileDom;
+import org.odftoolkit.simple.Document;
+import org.odftoolkit.simple.draw.Control;
+
+/**
+ * This class represents the form control of radio button, provides methods to
+ * get/set the form properties and the style formatting of this control.
+ * 
+ * @since 0.8
+ */
+public class RadioButton extends FormControl {
+
+	RadioButton(FormRadioElement element) {
+		mElement = element;
+		formElement = (FormFormElement) element.getParentNode();
+	}
+
+	/**
+	 * Get an instance of radio button by an instance of FormRadioElement, while
+	 * searching the document content to make a bind with the DrawControl which
+	 * already reference to this radio button.
+	 * 
+	 * @param element
+	 *            - an instance of FormRadioElement
+	 * @return an instance of radio button
+	 */
+	public static RadioButton getInstanceOf(FormRadioElement element) {
+		RadioButton radio = new RadioButton(element);
+		try {
+			radio.loadDrawControl(((Document) ((OdfFileDom) element
+					.getOwnerDocument()).getDocument()).getContentRoot());
+		} catch (Exception e) {
+			Logger.getLogger(RadioButton.class.getName()).log(Level.WARNING,
+					"Cannot load the drawing shape of this radio button.");
+		}
+		return radio;
+	}
+
+	@Override
+	public void setControlImplementation(String controlImpl) {
+		((FormRadioElement) mElement)
+				.setFormControlImplementationAttribute(controlImpl);
+	}
+
+	@Override
+	public String getId() {
+		return ((FormRadioElement) mElement).getFormIdAttribute();
+	}
+
+	@Override
+	public void setId(String id) {
+		((FormRadioElement) mElement).setFormIdAttribute(id);
+	}
+
+	@Override
+	FormPropertiesElement getFormPropertiesElementForWrite() {
+		if (mFormProperties == null)
+			mFormProperties = ((FormRadioElement) mElement)
+					.newFormPropertiesElement();
+		return mFormProperties;
+	}
+
+	/**
+	 * Set the label content of this radio button
+	 * 
+	 * @param label
+	 *            - the label content of this radio button
+	 */
+	public void setLabel(String label) {
+		((FormRadioElement) mElement).setFormLabelAttribute(label);
+	}
+
+	/**
+	 * Get the label content of this radio button
+	 * 
+	 * @return the label content of this radio button
+	 */
+	public String getLabel() {
+		return ((FormRadioElement) mElement).getFormLabelAttribute();
+	}
+
+	@Override
+	public String getName() {
+		return ((FormRadioElement) mElement).getFormNameAttribute();
+	}
+
+	@Override
+	public void setName(String name) {
+		((FormRadioElement) mElement).setFormNameAttribute(name);
+	}
+
+	/**
+	 * Get the default value of this control.
+	 * 
+	 * @param default value
+	 */
+	public String getValue() {
+		return ((FormRadioElement) mElement).getFormValueAttribute();
+	}
+
+	/**
+	 * Set the default value of this control, it will be override by current
+	 * value.
+	 * 
+	 * @param value
+	 *            - default value
+	 */
+	public void setValue(String value) {
+		((FormRadioElement) mElement).setFormValueAttribute(value);
+	}
+
+	/**
+	 * Set the default selection status of this radio button
+	 * 
+	 * @param isSelected
+	 *            - true means selected; false means unselected
+	 */
+	public void setDefaultSelected(boolean isSelected) {
+		((FormRadioElement) mElement).setFormSelectedAttribute(isSelected);
+	}
+
+	/**
+	 * Get the default selection status of this radio button
+	 * 
+	 * @return true means selected; false means unselected
+	 */
+	public boolean getDefaultSelected() {
+		return ((FormRadioElement) mElement).getFormSelectedAttribute();
+	}
+
+	/**
+	 * Set current selection status of this radio button, it override the
+	 * default status
+	 * 
+	 * @param isSelected
+	 *            - true means selected; false means unselected
+	 */
+	public void setCurrentSelected(boolean isSelected) {
+		((FormRadioElement) mElement)
+				.setFormCurrentSelectedAttribute(isSelected);
+	}
+
+	/**
+	 * Get current selection status of this radio button
+	 * 
+	 * @return true means selected; false means unselected
+	 */
+	public boolean getCurrentSelected() {
+		return ((FormRadioElement) mElement).getFormCurrentSelectedAttribute();
+	}
+
+	/**
+	 * Get a simple iterator for radio buttons.
+	 * 
+	 * @param container
+	 *            - an instance of form where to traverse the radio buttons
+	 */
+	public static Iterator<FormControl> getSimpleIterator(Form container) {
+		return new SimpleRadioButtonIterator(container);
+	}
+
+	private static class SimpleRadioButtonIterator implements
+			Iterator<FormControl> {
+
+		private FormFormElement containerElement;
+		private RadioButton nextElement = null;
+		private RadioButton tempElement = null;
+
+		private SimpleRadioButtonIterator(Form container) {
+			containerElement = container.getOdfElement();
+		}
+
+		public boolean hasNext() {
+			tempElement = findNext(nextElement);
+			return (tempElement != null);
+		}
+
+		public RadioButton 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 RadioButton findNext(RadioButton thisRadioButton) {
+			FormRadioElement nextRadioButton = null;
+			if (thisRadioButton == null) {
+				nextRadioButton = OdfElement.findFirstChildNode(
+						FormRadioElement.class, containerElement);
+			} else {
+				nextRadioButton = OdfElement
+						.findNextChildNode(FormRadioElement.class,
+								thisRadioButton.getOdfElement());
+			}
+
+			if (nextRadioButton != null) {
+				return RadioButton.getInstanceOf(nextRadioButton);
+			}
+			return null;
+		}
+	}
+
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/TextBox.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/TextBox.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/TextBox.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/TextBox.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,266 @@
+package org.odftoolkit.simple.form;
+
+import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.xerces.dom.ParentNode;
+import org.odftoolkit.odfdom.dom.element.form.FormFormElement;
+import org.odftoolkit.odfdom.dom.element.form.FormPropertiesElement;
+import org.odftoolkit.odfdom.dom.element.form.FormTextElement;
+import org.odftoolkit.odfdom.dom.element.form.FormTextareaElement;
+import org.odftoolkit.odfdom.pkg.OdfElement;
+import org.odftoolkit.odfdom.pkg.OdfFileDom;
+import org.odftoolkit.simple.Document;
+import org.odftoolkit.simple.draw.Control;
+import org.w3c.dom.Node;
+
+/**
+ * This class represents the form control of Text Box, provides methods to
+ * get/set the form properties and the style formatting of this control.
+ * 
+ * @since 0.8
+ */
+public class TextBox extends FormControl {
+	private boolean isMultipleLine = false;
+
+	TextBox(OdfElement element) {
+		if (element instanceof FormTextareaElement) {
+			isMultipleLine = true;
+			mElement = (FormTextareaElement) element;
+		} else {
+			mElement = (FormTextElement) element;
+		}
+		formElement = (FormFormElement) element.getParentNode();
+	}
+
+	/**
+	 * Get an instance of text box by an instance of OdfElement, while searching
+	 * the document content to make a bind with the DrawControl which already
+	 * reference to this text box.
+	 * 
+	 * @param element
+	 *            - an instance of OdfElement
+	 * @return an instance of text box
+	 */
+	public static TextBox getInstanceOf(OdfElement element) {
+		TextBox textbox = new TextBox(element);
+		try {
+			textbox.loadDrawControl(((Document) ((OdfFileDom) element
+					.getOwnerDocument()).getDocument()).getContentRoot());
+		} catch (Exception e) {
+			Logger.getLogger(TextBox.class.getName()).log(Level.WARNING,
+					"Cannot load the drawing shape of this textbox.");
+		}
+		return textbox;
+	}
+
+	@Override
+	FormPropertiesElement getFormPropertiesElementForWrite() {
+		if (mFormProperties == null) {
+			if (isMultipleLine) {
+				mFormProperties = ((FormTextareaElement) mElement)
+						.newFormPropertiesElement();
+			} else {
+				mFormProperties = ((FormTextElement) mElement)
+						.newFormPropertiesElement();
+			}
+		}
+		return mFormProperties;
+	}
+
+	@Override
+	public void setControlImplementation(String controlImpl) {
+		if (isMultipleLine) {
+			((FormTextareaElement) mElement)
+					.setFormControlImplementationAttribute(controlImpl);
+		} else {
+			((FormTextElement) mElement)
+					.setFormControlImplementationAttribute(controlImpl);
+		}
+
+	}
+
+	@Override
+	public String getId() {
+		String formId;
+		if (isMultipleLine) {
+			formId = ((FormTextareaElement) mElement).getFormIdAttribute();
+		} else {
+			formId = ((FormTextElement) mElement).getFormIdAttribute();
+		}
+		return formId;
+	}
+
+	@Override
+	public void setId(String id) {
+		if (isMultipleLine) {
+			((FormTextareaElement) mElement).setFormIdAttribute(id);
+		} else {
+			((FormTextElement) mElement).setFormIdAttribute(id);
+		}
+	}
+
+	@Override
+	public String getName() {
+		String name;
+		if (isMultipleLine) {
+			name = ((FormTextareaElement) mElement).getFormNameAttribute();
+		} else {
+			name = ((FormTextElement) mElement).getFormNameAttribute();
+		}
+		return name;
+	}
+
+	@Override
+	public void setName(String name) {
+		if (isMultipleLine) {
+			((FormTextareaElement) mElement).setFormNameAttribute(name);
+		} else {
+			((FormTextElement) 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 defaultValue) {
+		if (isMultipleLine) {
+			((FormTextareaElement) mElement)
+					.setFormValueAttribute(defaultValue);
+		} else {
+			((FormTextElement) mElement).setFormValueAttribute(defaultValue);
+		}
+	}
+
+	/**
+	 * Get the default value of this control
+	 * 
+	 * @return default value
+	 */
+	public String getValue() {
+		if (isMultipleLine) {
+			return ((FormTextareaElement) mElement).getFormValueAttribute();
+		} else {
+			return ((FormTextElement) mElement).getFormValueAttribute();
+		}
+	}
+
+	/**
+	 * Set the current value of this control, it override the default value.
+	 * 
+	 * @param currentValue
+	 *            - current value
+	 */
+	public void setCurrentValue(String currentValue) {
+		if (isMultipleLine) {
+			((FormTextareaElement) mElement)
+					.setFormCurrentValueAttribute(currentValue);
+		} else {
+			((FormTextElement) mElement)
+					.setFormCurrentValueAttribute(currentValue);
+		}
+	}
+
+	/**
+	 * Get the current value of this control
+	 * 
+	 * @return current value
+	 */
+	public String getCurrentValue() {
+		if (isMultipleLine) {
+			return ((FormTextareaElement) mElement)
+					.getFormCurrentValueAttribute();
+		} else {
+			return ((FormTextElement) mElement).getFormCurrentValueAttribute();
+		}
+	}
+
+	/**
+	 * Get a simple iterator for text boxes.
+	 * 
+	 * @param container
+	 *            - an instance of form where to traverse the text boxes
+	 */
+	public static Iterator<FormControl> getSimpleIterator(Form container) {
+		return new SimpleTextBoxIterator(container);
+	}
+
+	private static class SimpleTextBoxIterator implements Iterator<FormControl> {
+
+		private FormFormElement containerElement;
+		private TextBox nextElement = null;
+		private TextBox tempElement = null;
+
+		private SimpleTextBoxIterator(Form container) {
+			containerElement = container.getOdfElement();
+		}
+
+		public boolean hasNext() {
+			tempElement = findNext(nextElement);
+			return (tempElement != null);
+		}
+
+		public TextBox 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 TextBox findNext(TextBox thisTextBox) {
+			OdfElement nextTextBox = null;
+			if (thisTextBox == null) {
+				if (containerElement != null
+						&& containerElement instanceof ParentNode) {
+					Node node = ((ParentNode) containerElement).getFirstChild();
+					while ((node != null)
+							&& !FormTextareaElement.class.isInstance(node)
+							&& !FormTextElement.class.isInstance(node)) {
+						node = node.getNextSibling();
+					}
+					if (node != null) {
+						nextTextBox = (OdfElement) node;
+					}
+				}
+			} else {
+				Node refNode = thisTextBox.getOdfElement();
+				if (refNode != null) {
+					Node node = refNode.getNextSibling();
+					while (node != null
+							&& !FormTextareaElement.class.isInstance(node)
+							&& !FormTextElement.class.isInstance(node)) {
+						node = node.getNextSibling();
+					}
+
+					if (node != null) {
+						nextTextBox = (OdfElement) node;
+					}
+				}
+			}
+			if (nextTextBox != null) {
+				return TextBox.getInstanceOf(nextTextBox);
+			}
+			return null;
+		}
+	}
+
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/TimeField.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/TimeField.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/TimeField.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/form/TimeField.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,104 @@
+package org.odftoolkit.simple.form;
+
+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.element.OdfStyleBase;
+import org.odftoolkit.odfdom.dom.element.draw.DrawControlElement;
+import org.odftoolkit.odfdom.dom.element.form.FormFormattedTextElement;
+import org.odftoolkit.odfdom.dom.attribute.office.OfficeValueTypeAttribute.Value;
+import org.odftoolkit.odfdom.incubator.doc.number.OdfNumberTimeStyle;
+import org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeAutomaticStyles;
+import org.odftoolkit.odfdom.pkg.OdfFileDom;
+import org.odftoolkit.odfdom.pkg.OdfName;
+import org.odftoolkit.simple.Document;
+
+public class TimeField extends Field {
+
+	TimeField(FormFormattedTextElement element) {
+		super(element);
+	}
+
+	/**
+	 * Get an instance of time field by an instance of FormFormattedTextElement,
+	 * while searching the document content to make a bind with the DrawControl
+	 * which already reference to this time field.
+	 * 
+	 * @param element
+	 *            - an instance of FormFormattedTextElement
+	 * @return an instance of time field
+	 */
+	public static TimeField getInstanceOf(FormFormattedTextElement element) {
+		TimeField field = new TimeField(element);
+		try {
+			field.loadDrawControl(((Document) ((OdfFileDom) element
+					.getOwnerDocument()).getDocument()).getContentRoot());
+		} catch (Exception e) {
+			Logger.getLogger(TimeField.class.getName()).log(Level.WARNING,
+					"Cannot load the drawing shape of this field.");
+		}
+		return field;
+	}
+
+	/**
+	 * Format the time value according to the appointed format and locale.
+	 * 
+	 * @param formatStr
+	 *            - format code
+	 * @param locale
+	 *            - locale information
+	 */
+
+	public void setTimeFormat(String formatStr, Locale locale) {
+		this.setFormatString(formatStr, Value.TIME, locale);
+	}
+
+	/**
+	 * Set the format of this time field. Time format pattern is the same as
+	 * {@link java.text.SimpleDateFormat SimpleDateFormat}.
+	 * 
+	 * @param formatStr
+	 *            the format string of this date.
+	 * @see java.text.SimpleDateFormat
+	 */
+	public void formatTime(String formatStr, Locale locale) {
+		if (drawingShape == null)
+			throw new IllegalStateException(
+					"Please call loadDrawControl() first.");
+		DrawControlElement element = drawingShape.getOdfElement();
+		String name = getUniqueTimeStyleName();
+		OdfNumberTimeStyle timeStyle = new OdfNumberTimeStyle(
+				(OdfFileDom) element.getOwnerDocument(), formatStr, name);
+		timeStyle.setNumberLanguageAttribute(locale.getLanguage());
+		timeStyle.setNumberCountryAttribute(locale.getCountry());
+		element.getAutomaticStyles().appendChild(timeStyle);
+		OdfStyleBase styleElement = drawingShape.getStyleHandler()
+				.getStyleElementForWrite();
+		if (styleElement != null) {
+			styleElement.setOdfAttributeValue(OdfName.newName(
+					OdfDocumentNamespace.STYLE, "data-style-name"), name);
+		}
+	}
+
+	private String getUniqueTimeStyleName() {
+		String unique_name;
+		OdfOfficeAutomaticStyles styles = getDrawControl()
+				.getOdfElement().getAutomaticStyles();
+		do {
+			unique_name = String.format("t%06x",
+					(int) (Math.random() * 0xffffff));
+		} while (styles.getDateStyle(unique_name) != null);
+		return unique_name;
+	}
+
+	/**
+	 * Get the format code which is used to format the display value
+	 * 
+	 * @return the format code
+	 */
+	public String getTimeFormat() {
+		return this.getFormatString(Value.TIME);
+	}
+}

Modified: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/text/Paragraph.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/text/Paragraph.java?rev=1411080&r1=1411079&r2=1411080&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/text/Paragraph.java (original)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/text/Paragraph.java Mon Nov 19 06:51:44 2012
@@ -31,6 +31,7 @@ import org.odftoolkit.odfdom.dom.OdfStyl
 import org.odftoolkit.odfdom.dom.element.OdfStyleBase;
 import org.odftoolkit.odfdom.dom.element.dc.DcCreatorElement;
 import org.odftoolkit.odfdom.dom.element.dc.DcDateElement;
+import org.odftoolkit.odfdom.dom.element.draw.DrawControlElement;
 import org.odftoolkit.odfdom.dom.element.office.OfficeAnnotationElement;
 import org.odftoolkit.odfdom.dom.element.style.StyleTextPropertiesElement;
 import org.odftoolkit.odfdom.dom.element.text.TextAElement;
@@ -52,6 +53,8 @@ import org.odftoolkit.simple.Component;
 import org.odftoolkit.simple.Document;
 import org.odftoolkit.simple.PresentationDocument;
 import org.odftoolkit.simple.draw.AbstractTextboxContainer;
+import org.odftoolkit.simple.draw.Control;
+import org.odftoolkit.simple.draw.ControlContainer;
 import org.odftoolkit.simple.draw.FrameRectangle;
 import org.odftoolkit.simple.draw.Textbox;
 import org.odftoolkit.simple.draw.TextboxContainer;
@@ -69,7 +72,8 @@ import org.w3c.dom.Text;
  * 
  * @since 0.5
  */
-public class Paragraph extends Component implements TextboxContainer, TextHyperlinkContainer {
+public class Paragraph extends Component implements TextboxContainer,
+		TextHyperlinkContainer, ControlContainer {
 
 	private TextPElement mParagraphElement;
 	private TextHElement mHeadingElement;
@@ -758,4 +762,14 @@ public class Paragraph extends Component
 		return mHyperlinkContainerImpl;
 	}
 	/************ End of Hyperlink support ************/
+
+//	@Override
+	public Control createDrawControl() {
+		return Control.newDrawControl(this);
+	}
+
+//	@Override
+	public OdfElement getDrawControlContainerElement() {
+		return this.getOdfElement();
+	}
 }

Added: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/AbstractFormContainerTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/AbstractFormContainerTest.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/AbstractFormContainerTest.java (added)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/AbstractFormContainerTest.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,86 @@
+package org.odftoolkit.simple.form;
+
+import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.odftoolkit.simple.TextDocument;
+import org.odftoolkit.simple.draw.FrameRectangle;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.SupportedLinearMeasure;
+import org.odftoolkit.simple.table.Cell;
+import org.odftoolkit.simple.table.Table;
+import org.odftoolkit.simple.text.Paragraph;
+import org.odftoolkit.simple.utils.ResourceUtilities;
+
+public class AbstractFormContainerTest {
+	final static FrameRectangle btnRtg = new FrameRectangle(0.5, 2, 2.9433,
+			0.5567, SupportedLinearMeasure.IN);
+
+	@BeforeClass
+	public static void createForm() {
+		try {
+			TextDocument doc = TextDocument.newTextDocument();
+			Form form1 = doc.createForm("Form1");
+			form1.createButton(doc, btnRtg, "Button", "Push Button");
+
+			Paragraph para = doc.addParagraph("Insert a Label here.");
+			Form form2 = doc.createForm("Form2");
+			form2.createLabel(para, btnRtg, "Label", "Label");
+
+			Form form3 = doc.createForm("Form3");
+			Table table1 = Table.newTable(doc, 2, 2);
+			Cell cell = table1.getCellByPosition("A1");
+			para = cell.addParagraph("Insert a text box here.");
+			form3.createTextBox(para, btnRtg, "Text Box", "TextBox", true);
+
+			Assert.assertNotNull(doc.getFormByName("Form1"));
+
+			doc.save(ResourceUtilities.newTestOutputFile("TestCreateForm.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(AbstractFormContainerTest.class.getName()).log(
+					Level.SEVERE, null, e);
+		}
+	}
+
+	@Test
+	public void testCreateForm() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateForm.odt"));
+			Assert.assertNotNull(textDoc.getFormByName("Form1"));
+			Assert.assertNotNull(textDoc.getFormByName("Form2"));
+			Assert.assertNotNull(textDoc.getFormByName("Form3"));
+		} catch (Exception e) {
+			Logger.getLogger(AbstractFormContainerTest.class.getName()).log(
+					Level.SEVERE, null, e);
+		}
+	}
+
+	@Test
+	public void testRemoveForm() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateForm.odt"));
+			Form deleteForm = null;
+			Iterator<Form> iterator = textDoc.getFormIterator();
+			while (iterator.hasNext()) {
+				deleteForm = iterator.next();
+				if (deleteForm.getFormName().equals("Form3"))
+					break;
+			}
+			textDoc.removeForm(deleteForm);
+			Assert.assertNotNull(textDoc.getFormByName("Form1"));
+			Assert.assertNotNull(textDoc.getFormByName("Form2"));
+			Assert.assertNull(textDoc.getFormByName("Form3"));
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestRemoveForm.odt"));
+
+		} catch (Exception e) {
+			Logger.getLogger(AbstractFormContainerTest.class.getName()).log(
+					Level.SEVERE, null, e);
+		}
+	}
+}



Mime
View raw message