public class AcroChoiceField
extends java.lang.Object
Represents a multiple-choice form field in an interactive AcroForm.
getValue()
will return the 'export value' set on the field being
represented; this is the name of the option that was selected by the user.
The display value of that option (a user-friendly representation of the export value)
can be retrieved using the getDisplayValue(String)
function.
If allowsMultipleChoices()
returns true, getValue()
may
return a String[]
instance containing export values, one for each
of the options selected by the user. These values may also be used as parameters
into the getDisplayValue(String)
function.
Note that if isEditable()
returns true, the String returned by
getValue()
may be user-entered text, and therefore would likely not have
a corresponding display value provided by getDisplayValue(String)
.
In addition to the standard AcroFormField.setValue(String)
function, AcroChoiceField
instances provide a setValue(String[])
function, enabling the value of a multiple-selection
choice field possible.
Modifier and Type | Field and Description |
---|---|
protected com.snowtide.pdf.PDFTextStreamCallback |
callback |
static int |
CHOICE_TYPE_COMBO
Value returned by
getWidgetType() , indicating that an AcroChoiceField
is representing a drop-down combo box. |
static int |
CHOICE_TYPE_LIST
Value returned by
getWidgetType() indicating that an AcroChoiceField
is representing a list that can potentially allow multiple values to be selected. |
FIELD_TYPE_BUTTON, FIELD_TYPE_CHOICE, FIELD_TYPE_OTHER, FIELD_TYPE_SIGNATURE, FIELD_TYPE_TEXT
Modifier and Type | Method and Description |
---|---|
boolean |
allowsMultipleChoices()
Returns true if this choice field's widget allows multiple selections.
|
boolean |
canChangeValue()
Always returns true.
|
java.lang.Object |
getDefaultValue()
Returns the default value to which the field reverts when a reset-form action is executed,
as specified in the /DV entry in this field's PDF dictionary.
|
java.lang.String |
getDisplayValue(java.lang.String exportValue)
Returns the display value associated with the supplied export value.
|
java.lang.String |
getExportValue(java.lang.String displayValue) |
java.lang.String |
getFullName()
Returns the fully-qualified name of this field, which should be unique within a PDF document form.
|
java.lang.String |
getLocalName()
Returns the local name of the field, as specified in the /T entry in this field's PDF dictionary.
|
java.lang.String |
getMappingName()
Returns the 'mapping name' of this field, as specified in the /TM entry in this field's PDF dictionary.
|
java.lang.String |
getName()
Returns the canonical name of this field.
|
java.util.Map |
getOptions()
Returns a Map containing all of the options offered by this choice field, using
export values (strings that can be returned by
getValue() ) as keys mapped to
display values (strings that are returned by getDisplayValue(String) , given
a valid export value). |
java.lang.Object |
getType()
Returns the type of field, as specified in the /FT entry in this field's PDF dictionary.
|
java.lang.String |
getUIName()
Returns the user-friendly name of this field, as specified in the /TU entry in this field's PDF
dictionary.
|
java.lang.Object |
getValue()
Returns the value of this field, as specified in the /V entry in this field's PDF dictionary.
|
int |
getWidgetType()
Returns either
CHOICE_TYPE_COMBO (indicating that this choice widget is a dropdown,
single-selection field), or CHOICE_TYPE_LIST , indicating that this choice widget is a
multiple-row, possibly multiple-selection field). |
boolean |
hasValueChanged()
Returns true only if this field's value has been changed since being loaded from the PDF document.
|
boolean |
isEditable()
Returns true if this field is user-editable, indicating that a user may
set this field's value to a arbitrary character string.
|
boolean |
isReadOnly()
Returns true only if this field is designated as read-only.
|
boolean |
setValue(java.lang.String value)
Updates this choice field's value so that the option corresponding with the single specified String
is selected.
|
boolean |
setValue(java.lang.String[] values)
Updates this choice field's value so that each of the options corresponding with the Strings in the
specified array are selected.
|
public static final int CHOICE_TYPE_COMBO
getWidgetType()
, indicating that an AcroChoiceField
is representing a drop-down combo box.public static final int CHOICE_TYPE_LIST
getWidgetType()
indicating that an AcroChoiceField
is representing a list that can potentially allow multiple values to be selected.allowsMultipleChoices()
,
Constant Field Valuesprotected final com.snowtide.pdf.PDFTextStreamCallback callback
public boolean setValue(java.lang.String value) throws java.lang.IllegalArgumentException
setValue
in interface AcroFormField
java.lang.IllegalArgumentException
- - if the specified value is not an allowable value. To be
allowable, the specified value must appear as a key in the Map returned by getExportValue(String)
,
or, if this field is editable
, then any non-null String value is allowable.public boolean setValue(java.lang.String[] values) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- - if this field does not allow multiple choices
or if any String in the provided array is not an allowable value. To be
allowable, each String in the given array must be non-null, and must appear as a key in the Map returned by
getExportValue(String)
.public boolean canChangeValue()
canChangeValue
in interface AcroFormField
public java.lang.String getDisplayValue(java.lang.String exportValue)
public java.lang.String getExportValue(java.lang.String displayValue)
public java.util.Map getOptions()
getValue()
) as keys mapped to
display values (strings that are returned by getDisplayValue(String)
, given
a valid export value).public boolean isEditable()
getDisplayValue(String)
.public int getWidgetType()
CHOICE_TYPE_COMBO
(indicating that this choice widget is a dropdown,
single-selection field), or CHOICE_TYPE_LIST
, indicating that this choice widget is a
multiple-row, possibly multiple-selection field).public boolean allowsMultipleChoices()
Returns true if this choice field's widget allows multiple selections. This will only be true if
getWidgetType()
returns CHOICE_TYPE_LIST
.
This is important in that if this choice field's widget allows multiple selections, and multiple options
have been selected, then the getValue()
function will return an array of the selected
options' values, instead of a simple String.
public boolean isReadOnly()
AcroFormField
isReadOnly
in interface AcroFormField
public java.lang.Object getDefaultValue()
AcroFormField
AcroFormField.getValue()
function, and depends upon the
type of this field.getDefaultValue
in interface AcroFormField
public java.lang.String getFullName()
AcroFormField
Returns the fully-qualified name of this field, which should be unique within a PDF document form. Details of how full names are constructed are specified in Section 8.6.2 (Field Names) of the PDF Document Specification.
It suffices to say here that form fields in an interactive AcroForm are defined in a hierarchical manner,
and that their local names
are used to derive a period-delimited
full name that guarantees each name's uniqueness within the parent AcroForm.
getFullName
in interface AcroFormField
public java.lang.String getLocalName()
AcroFormField
FormField.getName()
implementation.getLocalName
in interface AcroFormField
public java.lang.String getMappingName()
AcroFormField
getMappingName
in interface AcroFormField
public java.lang.String getName()
FormField
FormField
instance with a particular name should be available from a Form
instance.public java.lang.Object getType()
AcroFormField
FIELD_TYPE_BUTTON
, then this AcroFormField
is an instance of AcroButtonField
FIELD_TYPE_TEXT
, then this AcroFormField
is an instance of AcroTextField
FIELD_TYPE_CHOICE
, then this AcroFormField
is an instance of AcroChoiceField
FIELD_TYPE_SIGNATURE
, then this AcroFormField
is an instance of AcroSignatureField
FIELD_TYPE_OTHER
, then this AcroFormField
has no specific concrete implementation. This case is reserved for form fields
with new type indicators that may be introduced by Adobe in the future.getType
in interface AcroFormField
public boolean hasValueChanged()
AcroFormField
hasValueChanged
in interface AcroFormField
public java.lang.String getUIName()
AcroFormField
Returns the user-friendly name of this field, as specified in the /TU entry in this field's PDF dictionary. This function can return null if no user-friendly field name is defined.
getUIName
in interface AcroFormField
getUIName
in interface FormField
public java.lang.Object getValue()
AcroFormField
getValue
in interface AcroFormField
getValue
in interface FormField