Example usage for com.lowagie.text.pdf PdfAnnotation APPEARANCE_DOWN

List of usage examples for com.lowagie.text.pdf PdfAnnotation APPEARANCE_DOWN

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfAnnotation APPEARANCE_DOWN.

Prototype

PdfName APPEARANCE_DOWN

To view the source code for com.lowagie.text.pdf PdfAnnotation APPEARANCE_DOWN.

Click Source Link

Document

appearance attributename

Usage

From source file:org.xhtmlrenderer.pdf.RadioButtonFormField.java

License:Open Source License

private void createAppearances(PdfContentByte cb, PdfFormField field, String onValue, float width, float height,
        boolean normal, FSColor color, FSColor darker) {
    // XXX Should cache this by width and height, but they're small so
    // don't bother for now...      
    PdfAppearance tpOff = cb.createAppearance(width, height);
    PdfAppearance tpOn = cb.createAppearance(width, height);

    float diameter = Math.min(width, height);

    setStrokeColor(tpOff, color);//from  w w  w .j av a  2s .c  o  m
    setStrokeColor(tpOn, color);

    if (!normal) {
        setStrokeColor(tpOff, darker);
        setStrokeColor(tpOn, darker);
    }

    float strokeWidth = Math.max(1.0f, reduce(diameter));

    tpOff.setLineWidth(strokeWidth);
    tpOn.setLineWidth(strokeWidth);

    tpOff.circle(width / 2, height / 2, diameter / 2 - strokeWidth / 2);
    tpOn.circle(width / 2, height / 2, diameter / 2 - strokeWidth / 2);

    if (!normal) {
        tpOff.fillStroke();
        tpOn.fillStroke();
    } else {
        tpOff.stroke();
        tpOn.stroke();
    }

    setFillColor(tpOn, color);
    if (!normal) {
        tpOn.circle(width / 2, height / 2, diameter * 0.23f);
    } else {
        tpOn.circle(width / 2, height / 2, diameter * 0.20f);
    }
    tpOn.fill();

    if (normal) {
        field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, OFF_STATE, tpOff);
        field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, onValue, tpOn);
    } else {
        field.setAppearance(PdfAnnotation.APPEARANCE_DOWN, OFF_STATE, tpOff);
        field.setAppearance(PdfAnnotation.APPEARANCE_DOWN, onValue, tpOn);
    }
}