Example usage for com.lowagie.text.pdf TextField setDefaultText

List of usage examples for com.lowagie.text.pdf TextField setDefaultText

Introduction

In this page you can find the example usage for com.lowagie.text.pdf TextField setDefaultText.

Prototype

public void setDefaultText(String defaultText) 

Source Link

Document

Sets the default text.

Usage

From source file:net.sf.jasperreports.forms.textinput.TextInputElementPdfHandler.java

License:Open Source License

public void exportElement(JRPdfExporterContext exporterContext, JRGenericPrintElement element) {
    PdfWriter writer = exporterContext.getPdfWriter();
    JasperPrint jasperPrint = exporterContext.getExportedReport();

    JRPrintText printText = (JRPrintText) element
            .getParameterValue(TextInputElement.PARAMETER_PRINT_TEXT_ELEMENT);
    if (printText == null) //FIXMEINPUT deal with xml serialization
    {//from   www  .j  a  v a  2 s  .c  o m
        return;
    }

    Rectangle rectangle = new Rectangle(element.getX() + exporterContext.getOffsetX(),
            jasperPrint.getPageHeight() - element.getY() - exporterContext.getOffsetY(),
            element.getX() + exporterContext.getOffsetX() + element.getWidth(),
            jasperPrint.getPageHeight() - element.getY() - exporterContext.getOffsetY() - element.getHeight());
    TextField text = new TextField(writer, rectangle, getFieldName(element));
    text.setBackgroundColor(printText.getBackcolor());
    text.setTextColor(printText.getForecolor());
    text.setText(printText.getFullText());
    text.setDefaultText("default:" + printText.getFullText());
    //      text.setBackgroundColor(element.getBackcolor());
    //      text.setTextColor(element.getForecolor());
    //      text.setText(getText(element));
    //      text.setDefaultText(getDefaultText(element));

    //FIXME: dynamic settings below:

    //      text.setAlignment(Element.ALIGN_LEFT);
    //      text.setBorderColor(Color.BLACK);
    //      text.setBorderWidth(TextField.BORDER_WIDTH_THIN);
    //      text.setBorderStyle(PdfBorderDictionary.STYLE_INSET);

    //      text.setChoiceExports(null);
    //      text.setChoices(null);
    //      text.setChoiceSelection(0);
    //      text.setExtensionFont(null);
    //      text.setExtraMargin(0, 0);
    //      try{
    //         text.setFont(BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1250, true));
    //      }catch(Exception e){
    //         throw new JRRuntimeException(e);
    //      }
    text.setFontSize(printText.getFontsize());
    if (Boolean.TRUE.equals(element.getParameterValue(TextInputElement.PARAMETER_MULTI_LINE))) {
        text.setOptions(TextField.MULTILINE);
    }
    //      text.setRotation(90);
    //      text.setVisibility(TextField.VISIBLE);

    try {
        PdfFormField field = text.getTextField();
        writer.addAnnotation(field);
    } catch (Exception e) {
        throw new JRRuntimeException(e);
    }

}