Package com.lowagie.text.pdf
Class RadioCheckField
- java.lang.Object
-
- com.lowagie.text.pdf.BaseField
-
- com.lowagie.text.pdf.RadioCheckField
-
public class RadioCheckField extends BaseField
Creates a radio or a check field. Example usage:Document document = new Document(PageSize.A4, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("output.pdf")); document.open(); PdfContentByte cb = writer.getDirectContent(); RadioCheckField bt = new RadioCheckField(writer, new Rectangle(100, 100, 200, 200), "radio", "v1"); bt.setCheckType(RadioCheckField.TYPE_CIRCLE); bt.setBackgroundColor(Color.cyan); bt.setBorderStyle(PdfBorderDictionary.STYLE_SOLID); bt.setBorderColor(Color.red); bt.setTextColor(Color.yellow); bt.setBorderWidth(BaseField.BORDER_WIDTH_THICK); bt.setChecked(false); PdfFormField f1 = bt.getRadioField(); bt.setOnValue("v2"); bt.setChecked(true); bt.setBox(new Rectangle(100, 300, 200, 400)); PdfFormField f2 = bt.getRadioField(); bt.setChecked(false); PdfFormField top = bt.getRadioGroup(true, false); bt.setOnValue("v3"); bt.setBox(new Rectangle(100, 500, 200, 600)); PdfFormField f3 = bt.getRadioField(); top.addKid(f1); top.addKid(f2); top.addKid(f3); writer.addAnnotation(top); bt = new RadioCheckField(writer, new Rectangle(300, 300, 400, 400), "check1", "Yes"); bt.setCheckType(RadioCheckField.TYPE_CHECK); bt.setBorderWidth(BaseField.BORDER_WIDTH_THIN); bt.setBorderColor(Color.black); bt.setBackgroundColor(Color.white); PdfFormField ck = bt.getCheckField(); writer.addAnnotation(ck); document.close();
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
checked
Holds value of property checked.private int
checkType
Holds value of property checkType.private java.lang.String
onValue
Holds value of property onValue.static int
TYPE_CHECK
A field with the symbol checkstatic int
TYPE_CIRCLE
A field with the symbol circlestatic int
TYPE_CROSS
A field with the symbol crossstatic int
TYPE_DIAMOND
A field with the symbol diamondstatic int
TYPE_SQUARE
A field with the symbol squarestatic int
TYPE_STAR
A field with the symbol starprivate static java.lang.String[]
typeChars
-
Fields inherited from class com.lowagie.text.pdf.BaseField
alignment, alternateFieldName, backgroundColor, BORDER_WIDTH_MEDIUM, BORDER_WIDTH_THICK, BORDER_WIDTH_THIN, borderColor, borderStyle, borderWidth, box, COMB, DO_NOT_SCROLL, DO_NOT_SPELL_CHECK, EDIT, fieldName, FILE_SELECTION, font, fontSize, HIDDEN, HIDDEN_BUT_PRINTABLE, INVISIBLE, LOCKED, mappingName, maxCharacterLength, MULTILINE, MULTISELECT, NOVIEW, options, PASSWORD, PRINT, READ_ONLY, REQUIRED, rotation, text, textColor, visibility, VISIBLE, VISIBLE_BUT_DOES_NOT_PRINT, writer
-
-
Constructor Summary
Constructors Constructor Description RadioCheckField(PdfWriter writer, Rectangle box, java.lang.String fieldName, java.lang.String onValue)
Creates a new instance of RadioCheckFieldRadioCheckField(PdfWriter writer, java.lang.String fieldName, java.lang.String onValue)
Creates a new instance of parent RadioCheckField with the default appearance of type 'cross'
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PdfAppearance
getAppearance(boolean on, PdfWriter writer, int checkType, int rotation, int borderStyle, Rectangle box, float borderWidth, float fontSize, java.lang.String text, java.awt.Color textColor, java.awt.Color backgroundColor, java.awt.Color borderColor, BaseFont ufont)
Gets the field appearance.static PdfAppearance
getAppearanceRadioCircle(boolean on, PdfWriter writer, Rectangle box, int rotation, java.awt.Color backgroundColor, float borderWidth, java.awt.Color borderColor, java.awt.Color textColor)
Gets the special field appearance for the radio circle.static PdfAppearance
getAppearanceRadioCross(boolean on, PdfWriter writer, Rectangle box, int rotation, java.awt.Color backgroundColor, float borderWidth, java.awt.Color borderColor, java.awt.Color textColor)
Gets the special field appearance for the radio circle.PdfFormField
getCheckboxParent()
Gets a parent of a checkbox autofill parent.int
getCheckType()
Getter for property checkType.protected PdfFormField
getField(boolean isKid)
Gets a radio or check field.PdfFormField
getFullField()
Gets the full parent field (There are no kids) This is the case for non-autofill fields and non-radiobutton fieldsPdfFormField
getKidField()
Gets the child field.java.lang.String
getOnValue()
Getter for property onValue.PdfFormField
getRadioGroup(boolean noToggleToOff, boolean radiosInUnison)
Gets a radio group.boolean
isChecked()
Getter for property checked.void
setChecked(boolean checked)
Sets the state of the field to checked or unchecked.void
setCheckType(int checkType)
Sets the checked symbol.void
setOnValue(java.lang.String onValue)
Sets the value when the field is checked.-
Methods inherited from class com.lowagie.text.pdf.BaseField
breakLines, getAlignment, getAllHardBreaks, getAlternateFieldName, getBackgroundColor, getBorderAppearance, getBorderColor, getBorderStyle, getBorderWidth, getBox, getFieldName, getFont, getFontSize, getMappingName, getMaxCharacterLength, getOptions, getRealFont, getRotation, getText, getTextColor, getVisibility, getWriter, moveFields, setAlignment, setAlternateFieldName, setBackgroundColor, setBorderColor, setBorderStyle, setBorderWidth, setBox, setFieldName, setFont, setFontSize, setMappingName, setMaxCharacterLength, setOptions, setRotation, setRotationFromPage, setText, setTextColor, setVisibility, setWriter, trimRight
-
-
-
-
Field Detail
-
TYPE_CHECK
public static final int TYPE_CHECK
A field with the symbol check- See Also:
- Constant Field Values
-
TYPE_CIRCLE
public static final int TYPE_CIRCLE
A field with the symbol circle- See Also:
- Constant Field Values
-
TYPE_CROSS
public static final int TYPE_CROSS
A field with the symbol cross- See Also:
- Constant Field Values
-
TYPE_DIAMOND
public static final int TYPE_DIAMOND
A field with the symbol diamond- See Also:
- Constant Field Values
-
TYPE_SQUARE
public static final int TYPE_SQUARE
A field with the symbol square- See Also:
- Constant Field Values
-
TYPE_STAR
public static final int TYPE_STAR
A field with the symbol star- See Also:
- Constant Field Values
-
typeChars
private static java.lang.String[] typeChars
-
checkType
private int checkType
Holds value of property checkType.
-
onValue
private java.lang.String onValue
Holds value of property onValue.
-
checked
private boolean checked
Holds value of property checked.
-
-
Constructor Detail
-
RadioCheckField
public RadioCheckField(PdfWriter writer, Rectangle box, java.lang.String fieldName, java.lang.String onValue)
Creates a new instance of RadioCheckField- Parameters:
writer
- the documentPdfWriter
box
- the field location and dimensionsfieldName
- the field name. It must not benull
onValue
- the value when the field is checked
-
RadioCheckField
public RadioCheckField(PdfWriter writer, java.lang.String fieldName, java.lang.String onValue)
Creates a new instance of parent RadioCheckField with the default appearance of type 'cross'- Parameters:
writer
- the documentPdfWriter
fieldName
- the field name. It must not benull
onValue
- the value when the field is checked
-
-
Method Detail
-
getAppearance
public static PdfAppearance getAppearance(boolean on, PdfWriter writer, int checkType, int rotation, int borderStyle, Rectangle box, float borderWidth, float fontSize, java.lang.String text, java.awt.Color textColor, java.awt.Color backgroundColor, java.awt.Color borderColor, BaseFont ufont)
Gets the field appearance.For Circle and Cross own appearances are drawn. For all other styles the ZapfDingbats font it used.
- Returns:
- the appearance
-
getAppearanceRadioCircle
public static PdfAppearance getAppearanceRadioCircle(boolean on, PdfWriter writer, Rectangle box, int rotation, java.awt.Color backgroundColor, float borderWidth, java.awt.Color borderColor, java.awt.Color textColor)
Gets the special field appearance for the radio circle.- Parameters:
on
-true
for the checked state otherwise,false
- Returns:
- the appearance
-
getAppearanceRadioCross
public static PdfAppearance getAppearanceRadioCross(boolean on, PdfWriter writer, Rectangle box, int rotation, java.awt.Color backgroundColor, float borderWidth, java.awt.Color borderColor, java.awt.Color textColor)
Gets the special field appearance for the radio circle.- Parameters:
on
-true
for the checked state,false
otherwise- Returns:
- the appearance
-
getCheckType
public int getCheckType()
Getter for property checkType.- Returns:
- Value of property checkType.
-
setCheckType
public void setCheckType(int checkType)
Sets the checked symbol. It can beTYPE_CHECK
,TYPE_CIRCLE
,TYPE_CROSS
,TYPE_DIAMOND
,TYPE_SQUARE
andTYPE_STAR
.- Parameters:
checkType
- the checked symbol
-
getOnValue
public java.lang.String getOnValue()
Getter for property onValue.- Returns:
- Value of property onValue.
-
setOnValue
public void setOnValue(java.lang.String onValue)
Sets the value when the field is checked.- Parameters:
onValue
- the value when the field is checked
-
isChecked
public boolean isChecked()
Getter for property checked.- Returns:
- Value of property checked.
-
setChecked
public void setChecked(boolean checked)
Sets the state of the field to checked or unchecked.- Parameters:
checked
- the state of the field,true
for checked andfalse
for unchecked
-
getRadioGroup
public PdfFormField getRadioGroup(boolean noToggleToOff, boolean radiosInUnison)
Gets a radio group. It's composed of the field specific keys, without the widget ones. This field is to be used as a field aggregator withaddKid()
.- Parameters:
noToggleToOff
- iftrue
, exactly one radio button must be selected at all times; clicking the currently selected button has no effect. Iffalse
, clicking the selected button deselects it, leaving no button selected.radiosInUnison
- iftrue
, a group of radio buttons within a radio button field that use the same value for the on state will turn on and off in unison; that is if one is checked, they are all checked. Iffalse
, the buttons are mutually exclusive (the same behavior as HTML radio buttons)- Returns:
- the radio group
-
getCheckboxParent
public PdfFormField getCheckboxParent()
Gets a parent of a checkbox autofill parent. It is composed of the field specific keys, without the widget ones. This field is to be used as a field aggregator withaddKid()
.- Returns:
- the radio group
-
getKidField
public PdfFormField getKidField() throws java.io.IOException, DocumentException
Gets the child field. It's only composed of the widget keys and is valid for all autofill fields and radiobuttons. Has to be used withgetRadioGroup(boolean, boolean)
orgetCheckboxParent()
.- Returns:
- the radio field
- Throws:
java.io.IOException
- on errorDocumentException
- on error
-
getFullField
public PdfFormField getFullField() throws java.io.IOException, DocumentException
Gets the full parent field (There are no kids) This is the case for non-autofill fields and non-radiobutton fields- Returns:
- the check field
- Throws:
java.io.IOException
- on errorDocumentException
- on error
-
getField
protected PdfFormField getField(boolean isKid) throws java.io.IOException, DocumentException
Gets a radio or check field.- Parameters:
isKid
-true
to get a child field,false
to get full parent field- Returns:
- the field
- Throws:
java.io.IOException
- on errorDocumentException
- on error
-
-