public class FormFieldCollection
Example:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.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 \u0001", doc.getRange().getFields().get(0).getFieldCode()); Assert.assertEquals(" FORMCHECKBOX \u0001", doc.getRange().getFields().get(1).getFieldCode()); Assert.assertEquals(" FORMTEXT \u0001", 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 /*override*/ /*VisitorAction*/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; }
Property Getters/Setters Summary | ||
---|---|---|
int | getCount() | |
Returns the number of form fields in the collection.
|
||
FormField | get(int index) | |
Returns a form field at the specified index.
|
||
FormField | get(java.lang.String bookmarkName) | |
Returns a form field by bookmark name.
|
Method Summary | ||
---|---|---|
void | clear() | |
Removes all form fields from this collection and from the document.
|
||
java.util.Iterator<FormField> | iterator() | |
Returns an enumerator object.
|
||
void | remove(java.lang.String formField) | |
Removes a form field with the specified name.
|
||
void | removeAt(int index) | |
Removes a form field at the specified index.
|
public int getCount()
Example:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.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 \u0001", doc.getRange().getFields().get(0).getFieldCode()); Assert.assertEquals(" FORMCHECKBOX \u0001", doc.getRange().getFields().get(1).getFieldCode()); Assert.assertEquals(" FORMTEXT \u0001", 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 /*override*/ /*VisitorAction*/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 FormField get(int index)
The index is zero-based.
Negative indexes are allowed and indicate access from the back of the collection. For example -1 means the last item, -2 means the second before last and so on.
If index is greater than or equal to the number of items in the list, this returns a null reference.
If index is negative and its absolute value is greater than the number of items in the list, this returns a null reference.
index
- An index into the collection.Example:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.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 \u0001", doc.getRange().getFields().get(0).getFieldCode()); Assert.assertEquals(" FORMCHECKBOX \u0001", doc.getRange().getFields().get(1).getFieldCode()); Assert.assertEquals(" FORMTEXT \u0001", 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 /*override*/ /*VisitorAction*/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 FormField get(java.lang.String bookmarkName)
bookmarkName
- Case-insensitive bookmark name.Example:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.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 \u0001", doc.getRange().getFields().get(0).getFieldCode()); Assert.assertEquals(" FORMCHECKBOX \u0001", doc.getRange().getFields().get(1).getFieldCode()); Assert.assertEquals(" FORMTEXT \u0001", 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 /*override*/ /*VisitorAction*/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 clear() throws java.lang.Exception
Example:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.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 \u0001", doc.getRange().getFields().get(0).getFieldCode()); Assert.assertEquals(" FORMCHECKBOX \u0001", doc.getRange().getFields().get(1).getFieldCode()); Assert.assertEquals(" FORMTEXT \u0001", 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 /*override*/ /*VisitorAction*/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 java.util.Iterator<FormField> iterator()
Example:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.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 \u0001", doc.getRange().getFields().get(0).getFieldCode()); Assert.assertEquals(" FORMCHECKBOX \u0001", doc.getRange().getFields().get(1).getFieldCode()); Assert.assertEquals(" FORMTEXT \u0001", 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 /*override*/ /*VisitorAction*/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 remove(java.lang.String formField) throws java.lang.Exception
formField
- The case-insensitive name of the form field to remove.Example:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.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 \u0001", doc.getRange().getFields().get(0).getFieldCode()); Assert.assertEquals(" FORMCHECKBOX \u0001", doc.getRange().getFields().get(1).getFieldCode()); Assert.assertEquals(" FORMTEXT \u0001", 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 /*override*/ /*VisitorAction*/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 removeAt(int index) throws java.lang.Exception
index
- The zero-based index of the form field to remove.Example:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.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 \u0001", doc.getRange().getFields().get(0).getFieldCode()); Assert.assertEquals(" FORMCHECKBOX \u0001", doc.getRange().getFields().get(1).getFieldCode()); Assert.assertEquals(" FORMTEXT \u0001", 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 /*override*/ /*VisitorAction*/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; }