|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.faceless.pdf2.PDFObject
org.faceless.pdf2.PDFMap
org.faceless.pdf2.FormElement
org.faceless.pdf2.FormRadioBox
org.faceless.pdf2.FormCheckbox
A type of form element representing a Check Box, which can be
either "checked" or "cleared" (on or off), in the same way as
the HTML "checkbox" input type. In PDF, Checkboxes are almost
identical to Radio Buttons
- the only
difference is that radio buttons require at least one annotation
to be selected, whereas checkboxes don't.
Here's an example showing how to add a set of checkboxes to the form. Each one of these boxes may be turned on or off seperately.
FormCheckbox check1 = new FormCheckbox(page, 100,100,110,110); form.addElement("PowerSteering", check1); FormCheckbox check2 = new FormCheckbox(page, 100,120,110,130); form.addElement("ElectricWindows", check2); FormCheckbox check3 = new FormCheckbox(page, 100,140,110,150); form.addElement("AirConditioning", check3);
and here's how to determine which of those values is checked
Form form = pdf.getForm(); FormCheckbox check; check = (FormCheckbox)form.getElement("PowerSteering"); boolean powersteering = check.getValue()!=null; check = (FormCheckbox)form.getElement("ElectricWindows"); boolean electricwindows = check.getValue()!=null; etc.Multiple checkboxes with the same name can be created - these will function like radio buttons except for the fact that none of the boxes has to be set.
Constructor Summary | |
FormCheckbox()
Create a new FormCheckbox element. |
|
FormCheckbox(PDFPage page,
float x1,
float y1,
float x2,
float y2)
Create a new FormCheckbox with a single annotation at the specified position. |
Method Summary | |
WidgetAnnotation |
addAnnotation(String value,
PDFPage page,
float x1,
float y1,
float x2,
float y2)
Add an annotation to the Checkbox or RadioButton. |
String |
getDefaultValue()
Return the default value of this field, or null |
Map |
getOptions()
Return a read-only Map containing the values (annotations) that can be selected in this RadioButton or Checkbox. |
String |
getValue()
Get the value of this field. |
void |
setDefaultValue(String value)
Set the default value for this field. |
void |
setValue(String value)
Mark the specified annotation for the Checkbox/RadioButton as selected, and unselect any others. |
Methods inherited from class org.faceless.pdf2.FormElement |
equals, flatten, getAction, getAnnotation, getAnnotations, getDescription, getForm, isReadOnly, isRequired, isSubmitted, setAction, setDescription, setReadOnly, setRequired, setSubmitted, toString |
Methods inherited from class java.lang.Object |
getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public FormCheckbox()
FormRadioBox.addAnnotation(java.lang.String, org.faceless.pdf2.PDFPage, float, float, float, float)
method
public FormCheckbox(PDFPage page, float x1, float y1, float x2, float y2)
FormChecbox box = new FormCheckbox(); box.addAnnotation("Yes", page, x1, y1, x2, y2);
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 annotationMethod Detail |
public WidgetAnnotation addAnnotation(String value, PDFPage page, float x1, float y1, float x2, float y2)
value
- the value of the annotation - this will be the value returned
by FormRadioBox.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 annotationpublic void setValue(String value)
IllegalArgumentException
value
- the value of the annotation to select, or null
to turn them all off
IllegalArgumentException
- if no such annotation existspublic void setDefaultValue(String value)
PDFAction.formReset()
action is invoked.
value
- the value of the annotation to select, or null
to turn them all off
IllegalArgumentException
- if no such annotation existspublic String getValue()
null
if no annotation is selected.
getValue
in class FormElement
null
if none is selectedpublic String getDefaultValue()
null if no
default value exists.
- Returns:
- the default value of this field, or
null
if none is specified
public Map getOptions()
FormElement.getAnnotations()
,
this method is not strictly necessary, but it's a little more convenient
and intuitive so we've left it in.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |