com.lowagie.text.pdf

Class 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();
 

Author: Paulo Soares (psoares@consiste.pt)

Field Summary
booleanchecked
Holds value of property checked.
intcheckType
Holds value of property checkType.
StringonValue
Holds value of property onValue.
static String[]typeChars
static intTYPE_CHECK
A field with the symbol check
static intTYPE_CIRCLE
A field with the symbol circle
static intTYPE_CROSS
A field with the symbol cross
static intTYPE_DIAMOND
A field with the symbol diamond
static intTYPE_SQUARE
A field with the symbol square
static intTYPE_STAR
A field with the symbol star
Constructor Summary
RadioCheckField(PdfWriter writer, Rectangle box, String fieldName, String onValue)
Creates a new instance of RadioCheckField
Method Summary
PdfAppearancegetAppearance(boolean isRadio, boolean on)
Gets the field appearance.
PdfAppearancegetAppearanceRadioCircle(boolean on)
Gets the special field appearance for the radio circle.
PdfFormFieldgetCheckField()
Gets the check field.
intgetCheckType()
Getter for property checkType.
protected PdfFormFieldgetField(boolean isRadio)
Gets a radio or check field.
StringgetOnValue()
Getter for property onValue.
PdfFormFieldgetRadioField()
Gets the radio field.
PdfFormFieldgetRadioGroup(boolean noToggleToOff, boolean radiosInUnison)
Gets a radio group.
booleanisChecked()
Getter for property checked.
voidsetChecked(boolean checked)
Sets the state of the field to checked or unchecked.
voidsetCheckType(int checkType)
Sets the checked symbol.
voidsetOnValue(String onValue)
Sets the value when the field is checked.

Field Detail

checked

private boolean checked
Holds value of property checked.

checkType

private int checkType
Holds value of property checkType.

onValue

private String onValue
Holds value of property onValue.

typeChars

private static String[] typeChars

TYPE_CHECK

public static final int TYPE_CHECK
A field with the symbol check

TYPE_CIRCLE

public static final int TYPE_CIRCLE
A field with the symbol circle

TYPE_CROSS

public static final int TYPE_CROSS
A field with the symbol cross

TYPE_DIAMOND

public static final int TYPE_DIAMOND
A field with the symbol diamond

TYPE_SQUARE

public static final int TYPE_SQUARE
A field with the symbol square

TYPE_STAR

public static final int TYPE_STAR
A field with the symbol star

Constructor Detail

RadioCheckField

public RadioCheckField(PdfWriter writer, Rectangle box, String fieldName, String onValue)
Creates a new instance of RadioCheckField

Parameters: writer the document PdfWriter box the field location and dimensions fieldName the field name. It must not be null onValue the value when the field is checked

Method Detail

getAppearance

public PdfAppearance getAppearance(boolean isRadio, boolean on)
Gets the field appearance.

Parameters: isRadio true for a radio field and false for a check field on true for the checked state, false otherwise

Returns: the appearance

Throws: IOException on error DocumentException on error

getAppearanceRadioCircle

public PdfAppearance getAppearanceRadioCircle(boolean on)
Gets the special field appearance for the radio circle.

Parameters: on true for the checked state, false otherwise

Returns: the appearance

getCheckField

public PdfFormField getCheckField()
Gets the check field.

Returns: the check field

Throws: IOException on error DocumentException on error

getCheckType

public int getCheckType()
Getter for property checkType.

Returns: Value of property checkType.

getField

protected PdfFormField getField(boolean isRadio)
Gets a radio or check field.

Parameters: isRadio true to get a radio field, false to get a check field

Returns: the field

Throws: IOException on error DocumentException on error

getOnValue

public String getOnValue()
Getter for property onValue.

Returns: Value of property onValue.

getRadioField

public PdfFormField getRadioField()
Gets the radio field. It's only composed of the widget keys and must be used with RadioCheckField.

Returns: the radio field

Throws: IOException on error DocumentException on error

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 with addKid().

Parameters: noToggleToOff if true, exactly one radio button must be selected at all times; clicking the currently selected button has no effect. If false, clicking the selected button deselects it, leaving no button selected. radiosInUnison if true, 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. If false, the buttons are mutually exclusive (the same behavior as HTML radio buttons)

Returns: the radio group

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 and false for unchecked

setCheckType

public void setCheckType(int checkType)
Sets the checked symbol. It can be TYPE_CHECK, TYPE_CIRCLE, TYPE_CROSS, TYPE_DIAMOND, TYPE_SQUARE and TYPE_STAR.

Parameters: checkType the checked symbol

setOnValue

public void setOnValue(String onValue)
Sets the value when the field is checked.

Parameters: onValue the value when the field is checked