Package org.faceless.pdf2
Class FormRadioButton
- java.lang.Object
-
- org.faceless.pdf2.FormElement
-
- org.faceless.pdf2.FormRadioButton
-
- All Implemented Interfaces:
Cloneable
public final class FormRadioButton extends FormElement
A type of form element representing a Radio Button, which can be either "checked" or "cleared" (on or off), in the same way as the HTML "radiobutton" input type. Unlike Checkboxes, at least one annotation for each Radio Button must be set.
Here's an example showing how to add a set of RadioButtons to a form
FormRadioButton ccard = new FormRadioButton(); ccard.addAnnotation("Mastercard", page, 100, 100, 110, 110); ccard.addAnnotation("Visa", page, 120, 100, 130, 110); ccard.addAnnotation("Amex", page, 140, 100, 150, 110); form.addElement("CreditCard", ccard);and here's how to determine which of those values is checked
Form form = pdf.getForm(); FormRadioButton ccard = (FormRadioButton)form.getElement("CreditCard"); String value = ccard.getValue(); // May be null if none are checked- Since:
- 1.1.23
-
-
Constructor Summary
Constructors Constructor Description FormRadioButton()Create a new FormRadioButton element.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WidgetAnnotationaddAnnotation(String value, PDFPage page, float x1, float y1, float x2, float y2)Add an annotation to the Checkbox or RadioButton.protected Objectclone()StringgetDefaultValue()Return the default value of this field, ornullif no default value exists.Map<String,WidgetAnnotation>getOptions()Return a read-only Map containing the values (annotations) that can be selected in this RadioButton or Checkbox.StringgetValue()Get the value of this field.booleanisNoToggleToOff()Return true if the "NoToggleToOff" flag is set, which means it should not be possible to set the value of this field to null by clicking on an already selected Radio Button.booleanisRadiosInUnison()Return true if the "RadiosInUnison" flag is set, which means fields with the same value are all turned on or off in unison (if one is chcked, they are all checked).voidrebuild()Cause the annotation list to be rebuilt.voidsetDefaultValue(String value)Set the default value for this field.voidsetRadiosInUnison(boolean flag)Set the value of the "RadiosInUnison" flag, as returned byisRadiosInUnison()voidsetValue(String value)Mark the specified annotation for the Checkbox/RadioButton as selected, and unselect any others.StringtoString()-
Methods inherited from class org.faceless.pdf2.FormElement
addPropertyChangeListener, duplicate, flatten, getAction, getAnnotation, getAnnotations, getDescription, getForm, isReadOnly, isRequired, isSubmitted, removePropertyChangeListener, setAction, setDescription, setReadOnly, setRequired, setSubmitted
-
-
-
-
Constructor Detail
-
FormRadioButton
public FormRadioButton()
Create a new FormRadioButton element. Any annotations must be positioned explicitly by calling theaddAnnotation(java.lang.String, org.faceless.pdf2.PDFPage, float, float, float, float)method.- Since:
- 1.1.26
-
-
Method Detail
-
isRadiosInUnison
public boolean isRadiosInUnison()
Return true if the "RadiosInUnison" flag is set, which means fields with the same value are all turned on or off in unison (if one is chcked, they are all checked).- Since:
- 2.10.6
-
setRadiosInUnison
public void setRadiosInUnison(boolean flag)
Set the value of the "RadiosInUnison" flag, as returned byisRadiosInUnison()- Since:
- 2.10.6
-
setValue
public void setValue(String value)
Mark the specified annotation for the Checkbox/RadioButton as selected, and unselect any others. The specified value must be the thevalueof one of this field'sWidgetAnnotationobjects, otherwise an anIllegalArgumentExceptionis thrown.- Parameters:
value- the value of the annotation to select, ornullto turn them all off
-
setDefaultValue
public void setDefaultValue(String value)
Set the default value for this field. Fields revert to their default value when thePDFAction.formReset()action is invoked. SeesetValue(java.lang.String, java.lang.String)for a discussion of which values are valid.- Parameters:
value- the value of the annotation to select, ornullto turn them all off
-
getValue
public String getValue()
Get the value of this field. This will be the value of the selected RadioButton/Checkbox annotation, ornullif no annotation is selected.- Returns:
- the value of the selected annotation, or
nullif none is selected
-
getDefaultValue
public String getDefaultValue()
Return the default value of this field, ornullif no default value exists.- Returns:
- the default value of this field, or
nullif none is specified
-
getOptions
public Map<String,WidgetAnnotation> getOptions()
Return a read-only Map containing the values (annotations) that can be selected in this RadioButton or Checkbox. As each annotation's value can be checked by iterating through the list returned fromFormElement.getAnnotations(), this method is not strictly necessary, but it's a little more convenient and intuitive so we've left it in.
-
rebuild
public void rebuild()
Description copied from class:FormElementCause the annotation list to be rebuilt. Unless you're rendering the annotation using the viewer, it's not necessary to call this method.
-
isNoToggleToOff
public boolean isNoToggleToOff()
Return true if the "NoToggleToOff" flag is set, which means it should not be possible to set the value of this field to null by clicking on an already selected Radio Button. Note this flag is a legacy (you should use a FormCheckbox if you want this functionality) and so cannot be set.- Since:
- 2.11.14
-
addAnnotation
public WidgetAnnotation addAnnotation(String value, PDFPage page, float x1, float y1, float x2, float y2)
Add an annotation to the Checkbox or RadioButton.- Parameters:
value- the value of the annotation - this will be the value returned byFormElement.getValue()if this annotation is selected. Note that "Off" is not allowed as an annotation name.page- the page to place the annotation onx1- the left-most X co-ordinate of the annotationy1- the top-most Y co-ordinate of the annotationx2- the right-most X co-ordinate of the annotationy2- the bottom-most Y co-ordinate of the annotation
-
toString
public String toString()
-
-