public class FormField extends SpecialChar
To learn more, visit the Working with Form Fields documentation article.
Remarks:
Microsoft Word provides the following form fields: checkbox, text input and dropdown (combobox).
FormField is an inline-node and can only be a child of Paragraph.
FormField is represented in a document by a special character and positioned as a character within a line of text.
A complete form field in a Word document is a complex structure represented by several nodes: field start, field code such as FORMTEXT, form field data, field separator, field result, field end and a bookmark. To programmatically create form fields in a Word document use DocumentBuilder.insertCheckBox(java.lang.String, boolean, int), M:Aspose.Words.DocumentBuilder.InsertTextInput(System.String,Aspose.Words.Fields.TextFormFieldType,System.String,System.String,System.Int32) and DocumentBuilder.insertComboBox(java.lang.String, java.lang.String[], int) which make sure all of the form field nodes are created in a correct order and in a suitable state.
Examples:
Shows how to insert a combo box.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Please select a fruit: ");
// Insert a combo box which will allow a user to choose an option from a collection of strings.
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"Apple", "Banana", "Cherry"}, 0);
Assert.assertEquals("MyComboBox", comboBox.getName());
Assert.assertEquals(FieldType.FIELD_FORM_DROP_DOWN, comboBox.getType());
Assert.assertEquals("Apple", comboBox.getResult());
// The form field will appear in the form of a "select" html tag.
doc.save(getArtifactsDir() + "FormFields.Create.html");
Shows how to formatting the entire FormField, including the field value.
Document doc = new Document(getMyDir() + "Form fields.docx");
FormField formField = doc.getRange().getFormFields().get(0);
formField.getFont().setBold(true);
formField.getFont().setSize(24.0);
formField.getFont().setColor(Color.RED);
formField.setResult("Aspose.FormField");
doc = DocumentHelper.saveOpen(doc);
Run formFieldRun = doc.getFirstSection().getBody().getFirstParagraph().getRuns().get(1);
Assert.assertEquals("Aspose.FormField", formFieldRun.getText());
Assert.assertEquals(true, formFieldRun.getFont().getBold());
Assert.assertEquals(24.0, formFieldRun.getFont().getSize());
Assert.assertEquals(Color.RED.getRGB(), formFieldRun.getFont().getColor().getRGB());
| Modifier and Type | Method and Description |
|---|---|
boolean |
accept(DocumentVisitor visitor)
Accepts a visitor.
|
boolean |
getCalculateOnExit()
True if references to the specified form field are automatically updated whenever the field is exited.
|
double |
getCheckBoxSize()
Gets the size of the checkbox in points.
|
boolean |
getChecked()
Gets the checked status of the check box form field.
|
boolean |
getDefault()
Gets the default value of the check box form field.
|
DropDownItemCollection |
getDropDownItems()
Provides access to the items of a dropdown form field.
|
int |
getDropDownSelectedIndex()
Gets the index specifying the currently selected item in a dropdown form field.
|
boolean |
getEnabled()
True if a form field is enabled.
|
java.lang.String |
getEntryMacro()
Gets an entry macro name for the form field.
|
java.lang.String |
getExitMacro()
Gets an exit macro name for the form field.
|
java.lang.String |
getHelpText()
Gets the text that's displayed in a message box when the form field has the focus and the user presses F1.
|
int |
getMaxLength()
Maximum length for the text field.
|
java.lang.String |
getName()
Gets the form field name.
|
int |
getNodeType()
Returns
NodeType.FORM_FIELD. |
boolean |
getOwnHelp()
Specifies the source of the text that's displayed in a message box when a form field has the focus and the user presses F1.
|
boolean |
getOwnStatus()
Specifies the source of the text that's displayed in the status bar when a form field has the focus.
|
java.lang.String |
getResult()
Gets a string that represents the result of this form field.
|
java.lang.String |
getStatusText()
Gets the text that's displayed in the status bar when a form field has the focus.
|
java.lang.String |
getTextInputDefault()
Gets the default string or a calculation expression of a text form field.
|
java.lang.String |
getTextInputFormat()
Gets the text formatting for a text form field.
|
int |
getTextInputType()
Gets the type of a text form field.
|
int |
getType()
Returns the form field type.
|
boolean |
isCheckBoxExactSize()
Gets the boolean value that indicates whether the size of the textbox is automatic or specified explicitly.
|
void |
isCheckBoxExactSize(boolean value)
Sets the boolean value that indicates whether the size of the textbox is automatic or specified explicitly.
|
void |
removeField()
Removes the complete form field, not just the form field special character.
|
void |
setCalculateOnExit(boolean value)
True if references to the specified form field are automatically updated whenever the field is exited.
|
void |
setCheckBoxSize(double value)
Sets the size of the checkbox in points.
|
void |
setChecked(boolean value)
Sets the checked status of the check box form field.
|
void |
setDefault(boolean value)
Sets the default value of the check box form field.
|
void |
setDropDownSelectedIndex(int value)
Sets the index specifying the currently selected item in a dropdown form field.
|
void |
setEnabled(boolean value)
True if a form field is enabled.
|
void |
setEntryMacro(java.lang.String value)
Sets an entry macro name for the form field.
|
void |
setExitMacro(java.lang.String value)
Sets an exit macro name for the form field.
|
void |
setHelpText(java.lang.String value)
Sets the text that's displayed in a message box when the form field has the focus and the user presses F1.
|
void |
setMaxLength(int value)
Maximum length for the text field.
|
void |
setName(java.lang.String value)
Sets the form field name.
|
void |
setOwnHelp(boolean value)
Specifies the source of the text that's displayed in a message box when a form field has the focus and the user presses F1.
|
void |
setOwnStatus(boolean value)
Specifies the source of the text that's displayed in the status bar when a form field has the focus.
|
void |
setResult(java.lang.String value)
Sets a string that represents the result of this form field.
|
void |
setRunAttr(int key,
java.lang.Object value) |
void |
setStatusText(java.lang.String value)
Sets the text that's displayed in the status bar when a form field has the focus.
|
void |
setTextInputDefault(java.lang.String value)
Sets the default string or a calculation expression of a text form field.
|
void |
setTextInputFormat(java.lang.String value)
Sets the text formatting for a text form field.
|
void |
setTextInputType(int value)
Sets the type of a text form field.
|
void |
setTextInputValue(java.lang.Object newValue)
Applies the text format specified in
getTextInputFormat() / setTextInputFormat(java.lang.String) and stores the value in getResult() / setResult(java.lang.String). |
getTextclearRunAttrs, fetchInheritedRunAttr, getDirectRunAttr, getDirectRunAttr, getDocument_IInline, getFont, getParentParagraph_IInline, getParentParagraph, isDeleteRevision, isFormatRevision, isInsertRevision, isMoveFromRevision, isMoveToRevision, removeMoveRevisions, removeRunAttrdeepClone, getAncestor, getAncestor, getCustomNodeId, getDocument, getNextSibling, getParentNode, getPreviousSibling, getRange, isComposite, memberwiseClone, nextPreOrder, nodeTypeToString, previousPreOrder, remove, setCustomNodeId, toString, toString, toString, visitorActionToBoolpublic void setRunAttr(int key,
java.lang.Object value)
setRunAttr in class Inlinepublic boolean accept(DocumentVisitor visitor) throws java.lang.Exception
Remarks:
Calls DocumentVisitor.visitFormField(com.aspose.words.FormField).
For more info see the Visitor design pattern.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
accept in class SpecialCharvisitor - The visitor that will visit the node.false if the visitor requested the enumeration to stop.java.lang.Exceptionpublic void removeField()
throws java.lang.Exception
Remarks:
If there is a bookmark associated with the form field, the bookmark is not removed.
Examples:
Shows how to delete a form field.
Document doc = new Document(getMyDir() + "Form fields.docx");
FormField formField = doc.getRange().getFormFields().get(3);
formField.removeField();
java.lang.Exceptionpublic void setTextInputValue(java.lang.Object newValue)
throws java.lang.Exception
getTextInputFormat() / setTextInputFormat(java.lang.String) and stores the value in getResult() / setResult(java.lang.String).
Remarks:
The getTextInputDefault() / setTextInputDefault(java.lang.String) value is applied if newValue is null.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
newValue - Can be a string, number or a DateTime object.java.lang.Exceptionpublic int getNodeType()
NodeType.FORM_FIELD.
Examples:
Shows how to traverse a composite node's tree of child nodes.
public void recurseChildren() throws Exception {
Document doc = new Document(getMyDir() + "Paragraphs.docx");
// Any node that can contain child nodes, such as the document itself, is composite.
Assert.assertTrue(doc.isComposite());
// Invoke the recursive function that will go through and print all the child nodes of a composite node.
traverseAllNodes(doc, 0);
}
/// <summary>
/// Recursively traverses a node tree while printing the type of each node
/// with an indent depending on depth as well as the contents of all inline nodes.
/// </summary>
public void traverseAllNodes(CompositeNode parentNode, int depth) {
for (Node childNode = parentNode.getFirstChild(); childNode != null; childNode = childNode.getNextSibling()) {
System.out.println(MessageFormat.format("{0}{1}", String.format(" ", depth), Node.nodeTypeToString(childNode.getNodeType())));
// Recurse into the node if it is a composite node. Otherwise, print its contents if it is an inline node.
if (childNode.isComposite()) {
System.out.println();
traverseAllNodes((CompositeNode) childNode, depth + 1);
} else if (childNode instanceof Inline) {
System.out.println(MessageFormat.format(" - \"{0}\"", childNode.getText().trim()));
} else {
System.out.println();
}
}
}
getNodeType in class SpecialCharNodeType.FORM_FIELD. The returned value is one of NodeType constants.public java.lang.String getName()
Remarks:
Microsoft Word allows strings with at most 20 characters.
Examples:
Shows how to insert a combo box.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Please select a fruit: ");
// Insert a combo box which will allow a user to choose an option from a collection of strings.
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"Apple", "Banana", "Cherry"}, 0);
Assert.assertEquals("MyComboBox", comboBox.getName());
Assert.assertEquals(FieldType.FIELD_FORM_DROP_DOWN, comboBox.getType());
Assert.assertEquals("Apple", comboBox.getResult());
// The form field will appear in the form of a "select" html tag.
doc.save(getArtifactsDir() + "FormFields.Create.html");
public void setName(java.lang.String value)
throws java.lang.Exception
Remarks:
Microsoft Word allows strings with at most 20 characters.
Examples:
Shows how to insert a combo box.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Please select a fruit: ");
// Insert a combo box which will allow a user to choose an option from a collection of strings.
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"Apple", "Banana", "Cherry"}, 0);
Assert.assertEquals("MyComboBox", comboBox.getName());
Assert.assertEquals(FieldType.FIELD_FORM_DROP_DOWN, comboBox.getType());
Assert.assertEquals("Apple", comboBox.getResult());
// The form field will appear in the form of a "select" html tag.
doc.save(getArtifactsDir() + "FormFields.Create.html");
value - The form field name.java.lang.Exceptionpublic int getType()
Examples:
Shows how to insert a combo box.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Please select a fruit: ");
// Insert a combo box which will allow a user to choose an option from a collection of strings.
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"Apple", "Banana", "Cherry"}, 0);
Assert.assertEquals("MyComboBox", comboBox.getName());
Assert.assertEquals(FieldType.FIELD_FORM_DROP_DOWN, comboBox.getType());
Assert.assertEquals("Apple", comboBox.getResult());
// The form field will appear in the form of a "select" html tag.
doc.save(getArtifactsDir() + "FormFields.Create.html");
FieldType constants.public java.lang.String getResult()
Remarks:
For a text form field the result is the text that is in the field.
For a checkbox form field the result can be "1" or "0" to indicate checked or unchecked.
For a dropdown form field the result is the string selected in the dropdown.
Setting getResult() / setResult(java.lang.String) for a text form field does not apply the text format specified in getTextInputFormat() / setTextInputFormat(java.lang.String). If you want to set a value and apply the format, use the setTextInputValue(java.lang.Object) method.
For a text form field the getTextInputDefault() / setTextInputDefault(java.lang.String) value is applied if value is null.
Examples:
Shows how to insert a combo box.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Please select a fruit: ");
// Insert a combo box which will allow a user to choose an option from a collection of strings.
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"Apple", "Banana", "Cherry"}, 0);
Assert.assertEquals("MyComboBox", comboBox.getName());
Assert.assertEquals(FieldType.FIELD_FORM_DROP_DOWN, comboBox.getType());
Assert.assertEquals("Apple", comboBox.getResult());
// The form field will appear in the form of a "select" html tag.
doc.save(getArtifactsDir() + "FormFields.Create.html");
public void setResult(java.lang.String value)
throws java.lang.Exception
Remarks:
For a text form field the result is the text that is in the field.
For a checkbox form field the result can be "1" or "0" to indicate checked or unchecked.
For a dropdown form field the result is the string selected in the dropdown.
Setting getResult() / setResult(java.lang.String) for a text form field does not apply the text format specified in getTextInputFormat() / setTextInputFormat(java.lang.String). If you want to set a value and apply the format, use the setTextInputValue(java.lang.Object) method.
For a text form field the getTextInputDefault() / setTextInputDefault(java.lang.String) value is applied if value is null.
Examples:
Shows how to insert a combo box.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Please select a fruit: ");
// Insert a combo box which will allow a user to choose an option from a collection of strings.
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"Apple", "Banana", "Cherry"}, 0);
Assert.assertEquals("MyComboBox", comboBox.getName());
Assert.assertEquals(FieldType.FIELD_FORM_DROP_DOWN, comboBox.getType());
Assert.assertEquals("Apple", comboBox.getResult());
// The form field will appear in the form of a "select" html tag.
doc.save(getArtifactsDir() + "FormFields.Create.html");
value - A string that represents the result of this form field.java.lang.Exceptionpublic java.lang.String getStatusText()
Remarks:
If the getOwnStatus() / setOwnStatus(boolean) property is set to true, the getStatusText() / setStatusText(java.lang.String) property specifies the status bar text. If the getOwnStatus() / setOwnStatus(boolean) property is set to false, the getStatusText() / setStatusText(java.lang.String) property specifies the name of an AutoText entry that contains status bar text for the form field.
Microsoft Word allows strings with at most 138 characters.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
public void setStatusText(java.lang.String value)
Remarks:
If the getOwnStatus() / setOwnStatus(boolean) property is set to true, the getStatusText() / setStatusText(java.lang.String) property specifies the status bar text. If the getOwnStatus() / setOwnStatus(boolean) property is set to false, the getStatusText() / setStatusText(java.lang.String) property specifies the name of an AutoText entry that contains status bar text for the form field.
Microsoft Word allows strings with at most 138 characters.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
value - The text that's displayed in the status bar when a form field has the focus.public boolean getOwnStatus()
Remarks:
If true, the text specified by the getStatusText() / setStatusText(java.lang.String) property is displayed. If false, the text of the AutoText entry specified by the getStatusText() / setStatusText(java.lang.String) property is displayed.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
boolean value.public void setOwnStatus(boolean value)
Remarks:
If true, the text specified by the getStatusText() / setStatusText(java.lang.String) property is displayed. If false, the text of the AutoText entry specified by the getStatusText() / setStatusText(java.lang.String) property is displayed.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
value - The corresponding boolean value.public java.lang.String getHelpText()
Remarks:
If the getOwnHelp() / setOwnHelp(boolean) property is set to true, getHelpText() / setHelpText(java.lang.String) specifies the text string value. If getOwnHelp() / setOwnHelp(boolean) is set to false, getHelpText() / setHelpText(java.lang.String) specifies the name of an AutoText entry that contains help text for the form field.
Microsoft Word allows strings with at most 255 characters.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
public void setHelpText(java.lang.String value)
Remarks:
If the getOwnHelp() / setOwnHelp(boolean) property is set to true, getHelpText() / setHelpText(java.lang.String) specifies the text string value. If getOwnHelp() / setOwnHelp(boolean) is set to false, getHelpText() / setHelpText(java.lang.String) specifies the name of an AutoText entry that contains help text for the form field.
Microsoft Word allows strings with at most 255 characters.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
value - The text that's displayed in a message box when the form field has the focus and the user presses F1.public boolean getOwnHelp()
Remarks:
If true, the text specified by the getHelpText() / setHelpText(java.lang.String) property is displayed. If false, the text in the AutoText entry specified by the getHelpText() / setHelpText(java.lang.String) property is displayed.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
boolean value.public void setOwnHelp(boolean value)
Remarks:
If true, the text specified by the getHelpText() / setHelpText(java.lang.String) property is displayed. If false, the text in the AutoText entry specified by the getHelpText() / setHelpText(java.lang.String) property is displayed.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
value - The corresponding boolean value.public boolean getCalculateOnExit()
Remarks:
Setting getCalculateOnExit() / setCalculateOnExit(boolean) only affects the behavior of the form field when the document is opened in Microsoft Word. Aspose.Words never updates references to the form field.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
boolean value.public void setCalculateOnExit(boolean value)
Remarks:
Setting getCalculateOnExit() / setCalculateOnExit(boolean) only affects the behavior of the form field when the document is opened in Microsoft Word. Aspose.Words never updates references to the form field.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
value - The corresponding boolean value.public java.lang.String getEntryMacro()
Remarks:
The entry macro runs when the form field gets the focus in Microsoft Word.
Microsoft Word allows strings with at most 32 characters.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
public void setEntryMacro(java.lang.String value)
Remarks:
The entry macro runs when the form field gets the focus in Microsoft Word.
Microsoft Word allows strings with at most 32 characters.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
value - An entry macro name for the form field.public java.lang.String getExitMacro()
Remarks:
The exit macro runs when the form field loses the focus in Microsoft Word.
Microsoft Word allows strings with at most 32 characters.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
public void setExitMacro(java.lang.String value)
Remarks:
The exit macro runs when the form field loses the focus in Microsoft Word.
Microsoft Word allows strings with at most 32 characters.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
value - An exit macro name for the form field.public boolean getEnabled()
Remarks:
If a form field is enabled, its contents can be changed as the form is filled in.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
boolean value.public void setEnabled(boolean value)
Remarks:
If a form field is enabled, its contents can be changed as the form is filled in.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
value - The corresponding boolean value.public java.lang.String getTextInputFormat()
Remarks:
If the text form field contains regular text, then valid format strings are "", "UPPERCASE", "LOWERCASE", "FIRST CAPITAL" and "TITLE CASE". The strings are case-insensitive.
If the text form field contains a number or a date/time value, then valid format strings are number or date and time format strings.
Microsoft Word allows strings with at most 64 characters.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
public void setTextInputFormat(java.lang.String value)
Remarks:
If the text form field contains regular text, then valid format strings are "", "UPPERCASE", "LOWERCASE", "FIRST CAPITAL" and "TITLE CASE". The strings are case-insensitive.
If the text form field contains a number or a date/time value, then valid format strings are number or date and time format strings.
Microsoft Word allows strings with at most 64 characters.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
value - The text formatting for a text form field.public int getTextInputType()
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
TextFormFieldType constants.public void setTextInputType(int value)
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
value - The type of a text form field. The value must be one of TextFormFieldType constants.public java.lang.String getTextInputDefault()
Remarks:
The meaning of this property depends on the value of the getTextInputType() / setTextInputType(int) property.
When getTextInputType() / setTextInputType(int) is TextFormFieldType.REGULAR or TextFormFieldType.NUMBER, this string specifies the default string for the text form field. This string is the content that Microsoft Word will display in the document when the form field is empty.
When getTextInputType() / setTextInputType(int) is TextFormFieldType.CALCULATED, then this string holds the expression to be calculated. The expression needs to be a formula valid according to Microsoft Word formula field requirements. When you set a new expression using this property, Aspose.Words calculates the formula result automatically and inserts it into the form field.
Microsoft Word allows strings with at most 255 characters.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
public void setTextInputDefault(java.lang.String value)
throws java.lang.Exception
Remarks:
The meaning of this property depends on the value of the getTextInputType() / setTextInputType(int) property.
When getTextInputType() / setTextInputType(int) is TextFormFieldType.REGULAR or TextFormFieldType.NUMBER, this string specifies the default string for the text form field. This string is the content that Microsoft Word will display in the document when the form field is empty.
When getTextInputType() / setTextInputType(int) is TextFormFieldType.CALCULATED, then this string holds the expression to be calculated. The expression needs to be a formula valid according to Microsoft Word formula field requirements. When you set a new expression using this property, Aspose.Words calculates the formula result automatically and inserts it into the form field.
Microsoft Word allows strings with at most 255 characters.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
value - The default string or a calculation expression of a text form field.java.lang.Exceptionpublic int getMaxLength()
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
int value.public void setMaxLength(int value)
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
value - The corresponding int value.public DropDownItemCollection getDropDownItems()
Remarks:
Microsoft Word allows maximum 25 items in a dropdown form field.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
DropDownItemCollection value.public int getDropDownSelectedIndex()
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
public void setDropDownSelectedIndex(int value)
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
value - The index specifying the currently selected item in a dropdown form field.public boolean getChecked()
false.
Remarks:
Applicable for a check box form field only.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
public void setChecked(boolean value)
false.
Remarks:
Applicable for a check box form field only.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
value - The checked status of the check box form field.public boolean getDefault()
false.
Remarks:
Applicable for a check box form field only.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
public void setDefault(boolean value)
false.
Remarks:
Applicable for a check box form field only.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
value - The default value of the check box form field.public boolean isCheckBoxExactSize()
Remarks:
Applicable for a check box form field only.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
getCheckBoxSize(),
setCheckBoxSize(double)public void isCheckBoxExactSize(boolean value)
Remarks:
Applicable for a check box form field only.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
value - The boolean value that indicates whether the size of the textbox is automatic or specified explicitly.getCheckBoxSize(),
setCheckBoxSize(double)public double getCheckBoxSize()
isCheckBoxExactSize() / isCheckBoxExactSize(boolean) is true.
Remarks:
Applicable for a check box form field only.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
isCheckBoxExactSize(),
isCheckBoxExactSize(boolean)public void setCheckBoxSize(double value)
isCheckBoxExactSize() / isCheckBoxExactSize(boolean) is true.
Remarks:
Applicable for a check box form field only.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator<FormField> fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
/// <summary>
/// Visitor implementation that prints details of form fields that it visits.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
/// <summary>
/// Adds newline char-terminated text to the current output.
/// </summary>
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
value - The size of the checkbox in points.isCheckBoxExactSize(),
isCheckBoxExactSize(boolean)