Example usage for com.lowagie.text Cell Cell

List of usage examples for com.lowagie.text Cell Cell

Introduction

In this page you can find the example usage for com.lowagie.text Cell Cell.

Prototype

public Cell(Element element) throws BadElementException 

Source Link

Document

Constructs a Cell with a certain Element.

if the element is a ListItem, Row or Cell, an exception will be thrown.

Usage

From source file:org.inbio.modeling.core.manager.impl.ExportManagerImpl.java

License:Open Source License

private void addTableHeader(Table t, String text) throws BadElementException {
    Chunk chunk = new Chunk(text, new Font(Font.TIMES_ROMAN, 15, Font.BOLD));
    Cell cell = new Cell(chunk);
    cell.setHorizontalAlignment(Cell.ALIGN_CENTER);
    cell.setHeader(true);/*from www  .  ja va 2s . c om*/
    cell.setColspan(2);
    t.addCell(cell);

}

From source file:org.kuali.kfs.module.cam.report.DepreciationReport.java

License:Open Source License

/**
 * This method adds the log lines into the report
 * //ww w .  ja  v  a  2  s  . com
 * @param reportLog
 */
private void generateReportLogBody(List<String[]> reportLog) {
    try {
        Font font = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.NORMAL);
        int columnwidths[];
        columnwidths = new int[] { 40, 15 };

        Table aTable = new Table(2, linesPerPage);
        int rowsWritten = 0;
        for (String[] columns : reportLog) {
            if (pageNumber == 0 || line >= linesPerPage) {
                if (pageNumber > 0) {
                    this.document.add(aTable);
                }
                int elementsLeft = reportLog.size() - rowsWritten;
                int rowsNeeded = (elementsLeft >= linesPerPage ? linesPerPage : elementsLeft);
                this.document.newPage();

                this.generateColumnHeaders();

                aTable = new Table(2, rowsNeeded); // 12 columns, 11 rows.

                aTable.setAutoFillEmptyCells(true);
                aTable.setPadding(3);
                aTable.setWidths(columnwidths);
                aTable.setWidth(100);
                aTable.setBorder(Rectangle.NO_BORDER);

                line = 0;
                pageNumber++;
            }
            rowsWritten++;

            Cell cell;
            cell = new Cell(new Phrase(columns[0], font));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            aTable.addCell(cell);

            cell = new Cell(new Phrase(columns[1], font));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            aTable.addCell(cell);
            line++;
        }
        this.document.add(aTable);
    } catch (DocumentException de) {
        throw new RuntimeException(
                "DepreciationReport.generateReportLogBody(List<String[]> reportLog) - error: "
                        + de.getMessage());
    }
}

From source file:org.kuali.kfs.module.cam.report.DepreciationReport.java

License:Open Source License

/**
 * This method creates a report group for the error message on the report
 * /* ww w .jav a  2 s  .  c  o  m*/
 * @throws DocumentException
 */
private void generateErrorColumnHeaders() throws DocumentException {
    try {
        int headerwidths[] = { 60 };

        Table aTable = new Table(1, 1); // 2 columns, 1 rows.

        aTable.setAutoFillEmptyCells(true);
        aTable.setPadding(3);
        aTable.setWidths(headerwidths);
        aTable.setWidth(100);

        Cell cell;

        Font font = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.NORMAL);

        cell = new Cell(new Phrase("Error(s)", font));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setGrayFill(0.9f);
        aTable.addCell(cell);

        this.document.add(aTable);

    } catch (Exception e) {
        throw new RuntimeException(
                "DepreciationReport.generateErrorColumnHeaders() - Error: " + e.getMessage());
    }
}

From source file:org.kuali.kfs.module.cam.report.DepreciationReport.java

License:Open Source License

/**
 * This method creates the headers for the report statistics
 *///from  w w w  .  j  a  v  a  2  s. co m
private void generateColumnHeaders() {
    try {
        int headerwidths[] = { 40, 15 };

        Table aTable = new Table(2, 1); // 2 columns, 1 rows.

        aTable.setAutoFillEmptyCells(true);
        aTable.setPadding(3);
        aTable.setWidths(headerwidths);
        aTable.setWidth(100);

        Cell cell;

        Font font = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.NORMAL);

        cell = new Cell(new Phrase(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(
                CamsKeyConstants.Depreciation.MSG_REPORT_DEPRECIATION_HEADING1), font));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setGrayFill(0.9f);
        aTable.addCell(cell);

        cell = new Cell(new Phrase(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(
                CamsKeyConstants.Depreciation.MSG_REPORT_DEPRECIATION_HEADING2), font));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setGrayFill(0.9f);
        aTable.addCell(cell);
        this.document.add(aTable);

    } catch (Exception e) {
        throw new RuntimeException("DepreciationReport.generateColumnHeaders() - Error: " + e.getMessage());
    }
}

From source file:org.kuali.kfs.module.tem.pdf.Coversheet.java

License:Open Source License

/**
 * Helper method to create a Header Cell from text
 *
 * @returns {@link Cell} with the header flag set
 *//* w  w  w .  j a  v  a2s  .c o  m*/
protected Cell getBorderlessCell(final String text) throws BadElementException {
    final Font normalFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
    final Cell retval = new Cell(new Chunk(text, normalFont));
    retval.setBorder(NO_BORDER);
    return retval;
}

From source file:org.kuali.kfs.module.tem.pdf.Coversheet.java

License:Open Source License

/**
 * Helper method to create a Header Cell from text
 *
 * @returns {@link Cell} with the header flag set
 *//*from   w w  w  . j  a  v  a 2 s.co m*/
protected Cell getHeaderCell(final String text) throws BadElementException {
    final Font headerFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    final Cell retval = new Cell(new Chunk(text, headerFont));
    retval.setBorder(NO_BORDER);
    retval.setHeader(true);
    return retval;
}

From source file:org.netxilia.server.rest.pdf.SheetPdfProvider.java

License:Open Source License

/**
 * Returns a formatted cell for the given value.
 * /*from  w  w w. jav a2s.c o  m*/
 * @param value
 *            cell value
 * @return Cell
 * @throws BadElementException
 *             errors while generating content
 */
private Cell getCell(String value, Font font, int horizAlign, int width) throws BadElementException {
    Cell cell = new Cell(new Chunk(StringUtils.trimToEmpty(value), font));
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setHorizontalAlignment(horizAlign);
    cell.setLeading(8);
    if (width > 0) {
        cell.setWidth(width);
    }
    return cell;
}

From source file:org.openswing.swing.export.java.ExportToRTF14.java

License:Open Source License

private void processComponent(Table table, int parentTableCols, Document document, ExportOptions opt,
        Object obj) throws Throwable {
    if (obj != null) {
        GridExportCallbacks callbacks = null;
        if (obj instanceof GridExportOptions) {
            callbacks = (GridExportCallbacks) ((GridExportOptions) obj).getCallbacks();
            if (callbacks != null)
                processComponent(table, parentTableCols, document, opt, callbacks.getHeaderComponent());
            prepareGrid(table, parentTableCols, document, opt, (GridExportOptions) obj);
            if (callbacks != null)
                processComponent(table, parentTableCols, document, opt, callbacks.getFooterComponent());
        } else if (obj instanceof ComponentExportOptions)
            prepareGenericComponent(table, parentTableCols, document, opt, (ComponentExportOptions) obj);
        else//from  ww w  .j  a v  a2s . c o m
            return;

        if (table != null) {
            Cell cell = new Cell(new Paragraph("\n"));
            //        cell.setColspan(parentTableCols);
            table.addCell(cell);
        } else
            document.add(new Paragraph("\n"));
    }
}

From source file:org.openswing.swing.export.java.ExportToRTF14.java

License:Open Source License

private void prepareGenericComponent(Table parentTable, int parentTableCols, Document document,
        ExportOptions exportOptions, ComponentExportOptions opt) throws Throwable {
    if (opt.getCellsContent() == null || opt.getCellsContent().length == 0)
        return;/*from w  ww. j a  v a  2 s. c  o  m*/

    int cols = opt.getCellsContent()[0].length;
    Object[] row = null;
    Object obj = null;
    SimpleDateFormat sdatf = new SimpleDateFormat(exportOptions.getDateTimeFormat());
    int[] headerwidths = new int[cols];
    for (int i = 0; i < headerwidths.length; i++)
        headerwidths[i] = (int) PageSize.A4.width() / cols;

    Table table = new Table(cols);
    table.setWidths(headerwidths);
    table.setBorderWidth(2);
    table.setBorderColor(Color.black);
    table.setGrayFill(exportOptions.getExportToRTFAdapter().getHeaderGrayFill());
    table.setPadding(3);

    for (int i = 0; i < opt.getCellsContent().length; i++) {
        row = opt.getCellsContent()[i];
        for (int j = 0; j < row.length; j++) {
            obj = row[j];

            if (obj != null) {
                if (obj instanceof Date || obj instanceof java.util.Date || obj instanceof java.sql.Timestamp) {
                    table.addCell(new Phrase(sdatf.format((java.util.Date) obj),
                            (Font) exportOptions.getExportToRTFAdapter().getGenericComponentFont(i, j, obj)));
                } else {
                    table.addCell(new Phrase(obj.toString(),
                            (Font) exportOptions.getExportToRTFAdapter().getGenericComponentFont(i, j, obj)));
                }
            } else {
                table.addCell(new Phrase("",
                        (Font) exportOptions.getExportToRTFAdapter().getGenericComponentFont(i, j, null)));
            }

        }
    }

    if (parentTable != null) {
        Cell c = new Cell(table);
        //      c.setColspan(parentTableCols);
        parentTable.addCell(c);
    } else
        document.add(table);

}

From source file:org.openswing.swing.export.java.ExportToRTF14.java

License:Open Source License

private void prepareGrid(Table parentTable, int parentTableCols, Document document, ExportOptions exportOptions,
        GridExportOptions opt) throws Throwable {
    // prepare vo getters methods...
    String methodName = null;/*from   w  ww.  ja v  a 2s. co m*/
    String attributeName = null;
    Hashtable gettersMethods = new Hashtable();
    Method[] voMethods = opt.getValueObjectType().getMethods();
    for (int i = 0; i < voMethods.length; i++) {
        methodName = voMethods[i].getName();
        if (methodName.startsWith("get")) {
            attributeName = methodName.substring(3, 4).toLowerCase() + methodName.substring(4);
            if (opt.getExportAttrColumns().contains(attributeName))
                gettersMethods.put(attributeName, voMethods[i]);
        }
    }

    Response response = null;
    int start = 0;
    int rownum = 0;
    Object value = null;
    Object vo = null;
    int type;

    SimpleDateFormat sdf = new SimpleDateFormat(exportOptions.getDateFormat());
    SimpleDateFormat sdatf = new SimpleDateFormat(exportOptions.getDateTimeFormat());
    SimpleDateFormat stf = new SimpleDateFormat(exportOptions.getTimeFormat());

    int headerwidths[] = new int[opt.getExportColumns().size()];
    int total = 0;
    for (int i = 0; i < opt.getExportColumns().size(); i++) {
        headerwidths[i] = Math.max(opt.getExportColumns().get(i).toString().length() * 10,
                ((Integer) opt.getColumnsWidth().get(opt.getExportAttrColumns().get(i))).intValue());
        total += headerwidths[i];
    }

    //    Document document = new Document();
    //    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    //    RtfWriter2 w = RtfWriter2.getInstance(document,baos);
    //    document.open();

    Paragraph line = null;
    if (opt.getTitle() != null && !opt.getTitle().equals("")) {
        line = new Paragraph(opt.getTitle(), (Font) exportOptions.getExportToRTFAdapter().getFontTitle());
        line.setAlignment(Element.ALIGN_CENTER);
        document.add(line);
        document.add(new Paragraph(""));
    }
    String[] filters = opt.getFilteringConditions();
    if (filters != null) {
        for (int i = 0; i < filters.length; i++) {
            line = new Paragraph(filters[i]);
            document.add(line);
        }
        document.add(new Paragraph(""));
    }

    Table table = new Table(opt.getExportColumns().size());
    table.setWidths(headerwidths);
    table.setBorderWidth(2);
    table.setBorderColor(Color.black);
    table.setGrayFill(exportOptions.getExportToRTFAdapter().getHeaderGrayFill());
    table.setPadding(3);

    Phrase cell = null;
    for (int i = 0; i < opt.getExportColumns().size(); i++) {
        cell = new Phrase(opt.getExportColumns().get(i).toString(), (Font) exportOptions.getExportToRTFAdapter()
                .getHeaderFont(opt.getExportAttrColumns().get(i).toString()));
        table.addCell(cell);
    }
    //    table.setHeaderRows(1);
    //    table.getDefaultCell().setBorderWidth(1);
    //    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    //    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);

    for (int j = 0; j < opt.getTopRows().size(); j++) {
        // create a row for each top rows...
        vo = opt.getTopRows().get(j);
        appendRow(document, exportOptions, table, vo, opt, gettersMethods, sdf, sdatf, stf, j, 0);
    }

    do {
        response = opt.getGridDataLocator().loadData(GridParams.NEXT_BLOCK_ACTION, start,
                opt.getFilteredColumns(), opt.getCurrentSortedColumns(), opt.getCurrentSortedVersusColumns(),
                opt.getValueObjectType(), opt.getOtherGridParams());
        if (response.isError())
            throw new Exception(response.getErrorMessage());

        boolean even = false;

        for (int j = 0; j < ((VOListResponse) response).getRows().size(); j++) {
            if (even) {
                even = false;
            } else {
                even = true;
            }

            vo = ((VOListResponse) response).getRows().get(j);

            appendRow(document, exportOptions, table, vo, opt, gettersMethods, sdf, sdatf, stf, rownum, 1);

            rownum++;
        }

        start = start + ((VOListResponse) response).getRows().size();

        if (!((VOListResponse) response).isMoreRows())
            break;
    } while (rownum < opt.getMaxRows());

    for (int j = 0; j < opt.getBottomRows().size(); j++) {
        // create a row for each bottom rows...
        table.setGrayFill(exportOptions.getExportToRTFAdapter().getBottomRowsGrayFill(j));
        vo = opt.getBottomRows().get(j);
        appendRow(document, exportOptions, table, vo, opt, gettersMethods, sdf, sdatf, stf, j, 2);
    }

    //    rtfTable.importTable(table,total);
    if (parentTable != null) {
        Cell c = new Cell(table);
        //      c.setColspan(parentTableCols);
        parentTable.addCell(c);
        //      table.setCellsFitPage(true);
        //      parentTable.insertTable(table,new Point(parentTable.getNextRow()+1,0));

    } else
        document.add(table);

    //    document.add(table);
}