new Rectangle(150, 50, 136, 36)
);
WidgetActions fieldWidgetActions = new WidgetActions(fieldWidget);
fieldWidget.setActions(fieldWidgetActions);
fieldWidgetActions.setOnActivate(
new JavaScript(
document,
"app.alert(\"Radio button currently selected: '\" + this.getField(\"myRadio\").value + \"'.\",3,0,\"Activation event\");"
)
);
PushButton field = new PushButton(
"okButton",
fieldWidget,
"Push" // Current value.
); // 4.1. Field instantiation.
fields.add(field); // 4.2. Field insertion into the fields collection.
fieldStyle.apply(field); // 4.3. Appearance style applied.
{
BlockComposer blockComposer = new BlockComposer(composer);
blockComposer.begin(new Rectangle2D.Double(296,50,page.getSize().getWidth()-336,36),AlignmentXEnum.Left,AlignmentYEnum.Middle);
composer.setFont(composer.getState().getFont(),7);
blockComposer.showText("If you click this push button, a javascript action should prompt you an alert box responding to the activation event triggered by your PDF viewer.");
blockComposer.end();
}
}
// 4.b. Check box.
{
composer.showText(
"CheckBox:",
new Point2D.Double(140, 118),
AlignmentXEnum.Right,
AlignmentYEnum.Middle,
0
);
CheckBox field = new CheckBox(
"myCheck",
new Widget(
page,
new Rectangle(150, 100, 36, 36)
),
true // Current value.
); // 4.1. Field instantiation.
fieldStyle.apply(field);
fields.add(field);
field = new CheckBox(
"myCheck2",
new Widget(
page,
new Rectangle(200, 100, 36, 36)
),
true // Current value.
); // 4.1. Field instantiation.
fieldStyle.apply(field);
fields.add(field);
field = new CheckBox(
"myCheck3",
new Widget(
page,
new Rectangle(250, 100, 36, 36)
),
false // Current value.
); // 4.1. Field instantiation.
fields.add(field); // 4.2. Field insertion into the fields collection.
fieldStyle.apply(field); // 4.3. Appearance style applied.
}
// 4.c. Radio button.
{
composer.showText(
"RadioButton:",
new Point2D.Double(140, 168),
AlignmentXEnum.Right,
AlignmentYEnum.Middle,
0
);
RadioButton field = new RadioButton(
"myRadio",
/*
NOTE: A radio button field typically combines multiple alternative widgets.
*/
new DualWidget[]
{
new DualWidget(
page,
new Rectangle(150, 150, 36, 36),
"first"
),
new DualWidget(
page,
new Rectangle(200, 150, 36, 36),
"second"
),
new DualWidget(
page,
new Rectangle(250, 150, 36, 36),
"third"
)
},
"second" // Selected item (it MUST correspond to one of the available widgets' names).
); // 4.1. Field instantiation.
fields.add(field); // 4.2. Field insertion into the fields collection.
fieldStyle.apply(field); // 4.3. Appearance style applied.
}
// 4.d. Text field.
{
composer.showText(
"TextField:",
new Point2D.Double(140, 218),
AlignmentXEnum.Right,
AlignmentYEnum.Middle,
0
);
TextField field = new TextField(
"myText",
new Widget(
page,
new Rectangle(150, 200, 200, 36)
),
"Carmen Consoli" // Current value.
); // 4.1. Field instantiation.
field.setSpellChecked(false); // Avoids text spell check.
FieldActions fieldActions = new FieldActions(document);
field.setActions(fieldActions);
fieldActions.setOnValidate(
new JavaScript(
document,
"app.alert(\"Text '\" + this.getField(\"myText\").value + \"' has changed!\",3,0,\"Validation event\");"
)
);
fields.add(field); // 4.2. Field insertion into the fields collection.