Example usage for com.lowagie.text.pdf PdfPTable getDefaultCell

List of usage examples for com.lowagie.text.pdf PdfPTable getDefaultCell

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPTable getDefaultCell.

Prototype

public PdfPCell getDefaultCell() 

Source Link

Document

Gets the default PdfPCell that will be used as reference for all the addCell methods except addCell(PdfPCell).

Usage

From source file:com.qcadoo.mes.workPlans.pdf.document.WorkPlanPdfForDivision.java

License:Open Source License

private void addOperationSummary(PdfPCell cell, Entity operationComponent) throws DocumentException {
    Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION);

    PdfPTable operationTable = pdfHelper.createPanelTable(1);

    PdfPCell numberCell = new PdfPCell();
    numberCell.setBorder(Rectangle.NO_BORDER);
    Paragraph operationName = new Paragraph(operation.getStringField(OperationFields.NUMBER) + " - "
            + operation.getStringField(OperationFields.NAME), FontUtils.getDejavuBold7Dark());
    numberCell.addElement(operationName);

    PdfPCell descriptionCell = new PdfPCell();
    descriptionCell.setBorder(Rectangle.NO_BORDER);
    String comment = operation.getStringField(OperationFields.COMMENT);
    Paragraph description = null;//from   w w  w.j a v a 2 s . c om
    if (!StringUtils.isEmpty(comment)) {
        description = new Paragraph(comment, FontUtils.getDejavuBold7Dark());
    }

    operationTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    operationTable.setTableEvent(null);
    operationTable.addCell(numberCell);
    if (description != null) {
        descriptionCell.addElement(description);
        operationTable.addCell(descriptionCell);
    } else {
        operationTable.addCell("");
    }
    cell.addElement(operationTable);
}

From source file:com.qcadoo.mes.workPlans.pdf.document.WorkPlanPdfForDivision.java

License:Open Source License

private void addOrderSummary(PdfPCell cell, Entity order, Entity product, Entity operationComponent)
        throws DocumentException {
    Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION);
    PdfPTable orderTable = pdfHelper.createPanelTable(3);
    PdfPCell operationCell = new PdfPCell();
    operationCell.setBorder(Rectangle.NO_BORDER);
    Paragraph operationName = new Paragraph(operation.getStringField(OperationFields.NUMBER) + " - "
            + operation.getStringField(OperationFields.NAME), FontUtils.getDejavuBold7Dark());
    operationCell.addElement(operationName);

    PdfPCell numberCell = new PdfPCell();
    numberCell.setBorder(Rectangle.NO_BORDER);
    Paragraph number = new Paragraph(order.getStringField(OrderFields.NUMBER), FontUtils.getDejavuBold7Dark());
    number.setAlignment(Element.ALIGN_RIGHT);
    numberCell.addElement(number);/*from www  . j  av a 2s  . c  o m*/

    PdfPCell quantityCell = new PdfPCell();
    quantityCell.setBorder(Rectangle.NO_BORDER);
    Paragraph quantity = new Paragraph(
            numberService.formatWithMinimumFractionDigits(order.getDecimalField(OrderFields.PLANNED_QUANTITY),
                    0) + " " + product.getStringField(ProductFields.UNIT),
            FontUtils.getDejavuBold7Dark());
    quantity.setAlignment(Element.ALIGN_CENTER);
    quantityCell.addElement(quantity);

    PdfPCell descriptionCell = new PdfPCell();
    descriptionCell.setBorder(Rectangle.NO_BORDER);
    descriptionCell.setColspan(3);
    String comment = operationComponent.getStringField(TechnologyOperationComponentFields.COMMENT);
    Paragraph description = null;
    if (!StringUtils.isEmpty(comment)) {
        description = new Paragraph(comment, FontUtils.getDejavuBold7Dark());
    }

    float[] tableColumnWidths = new float[] { 160f, 30f, 10f };
    orderTable.setWidths(tableColumnWidths);
    orderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    orderTable.setTableEvent(null);
    orderTable.addCell(operationCell);
    orderTable.addCell(numberCell);
    orderTable.addCell(quantityCell);
    if (description != null) {
        descriptionCell.addElement(description);
        orderTable.addCell(descriptionCell);
    }
    cell.addElement(orderTable);
}

From source file:com.qcadoo.mes.workPlans.pdf.document.WorkPlanPdfForDivision.java

License:Open Source License

private void addOperationProductsTable(PdfPCell cell, List<Entity> operationProductComponents,
        Map<OperationProductColumn, ColumnAlignment> operationProductColumnAlignmentMap,
        ProductDirection direction, Locale locale) throws DocumentException {

    if (operationProductComponents.isEmpty()) {
        return;/*from ww w  .  j  a  v  a  2s . com*/
    }

    int columnCount = operationProductColumnAlignmentMap.size();

    Map<String, HeaderAlignment> headerAlignments = new HashMap<String, HeaderAlignment>(columnCount);
    List<String> headers = new ArrayList<String>(columnCount);
    float[] widths = fill(locale, operationProductColumnAlignmentMap, headers, headerAlignments, direction);

    PdfPTable table = pdfHelper.createTableWithHeader(columnCount, headers, false, headerAlignments);
    table.setWidths(widths);
    PdfPCell defaultCell = table.getDefaultCell();
    for (Entity operationProduct : operationProductComponents) {
        for (Map.Entry<OperationProductColumn, ColumnAlignment> e : operationProductColumnAlignmentMap
                .entrySet()) {
            alignColumn(defaultCell, e.getValue());
            table.addCell(operationProductPhrase(operationProduct, e.getKey()));
        }

    }
    cell.addElement(table);
}

From source file:com.qcadoo.report.internal.PdfHelperImpl.java

License:Open Source License

@Override
public void addDocumentHeader(final Document document, final String name, final String documenTitle,
        final String documentAuthor, final Date date, final String username) throws DocumentException {
    SimpleDateFormat df = new SimpleDateFormat(DateUtils.L_DATE_TIME_FORMAT, getLocale());
    LineSeparator line = new LineSeparator(3, 100f, ColorUtils.getLineDarkColor(), Element.ALIGN_LEFT, 0);
    document.add(Chunk.NEWLINE);/*  w w w . j  av a2s . com*/
    Paragraph title = new Paragraph(new Phrase(documenTitle, FontUtils.getDejavuBold17Light()));
    title.add(new Phrase(" " + name, FontUtils.getDejavuBold17Dark()));
    title.setSpacingAfter(7f);
    document.add(title);
    document.add(line);
    PdfPTable userAndDate = new PdfPTable(2);
    userAndDate.setWidthPercentage(100f);
    userAndDate.setHorizontalAlignment(Element.ALIGN_LEFT);
    userAndDate.getDefaultCell().setBorderWidth(0);
    Paragraph userParagraph = new Paragraph(new Phrase(documentAuthor, FontUtils.getDejavuRegular9Light()));
    userParagraph.add(new Phrase(" " + username, FontUtils.getDejavuRegular9Dark()));
    Paragraph dateParagraph = new Paragraph(df.format(date), FontUtils.getDejavuRegular9Light());
    userAndDate.addCell(userParagraph);
    userAndDate.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
    userAndDate.addCell(dateParagraph);
    userAndDate.setSpacingAfter(14f);
    document.add(userAndDate);
}

From source file:com.qcadoo.report.internal.PdfHelperImpl.java

License:Open Source License

@Override
public void addDocumentHeader(final Document document, final String name, final String documenTitle,
        final String documentAuthor, final Date date) throws DocumentException {
    SimpleDateFormat df = new SimpleDateFormat(DateUtils.L_DATE_TIME_FORMAT, getLocale());
    LineSeparator line = new LineSeparator(2, 100f, ColorUtils.getLineDarkColor(), Element.ALIGN_LEFT, 0);
    document.add(Chunk.NEWLINE);//from  w  w  w . ja  v  a2s . c o  m
    Paragraph title = new Paragraph(new Phrase(documenTitle, FontUtils.getDejavuBold17Light()));
    title.add(new Phrase(" " + name, FontUtils.getDejavuBold17Dark()));
    title.setSpacingAfter(7f);
    document.add(title);
    document.add(line);
    PdfPTable userAndDate = new PdfPTable(2);
    userAndDate.setWidthPercentage(100f);
    userAndDate.setHorizontalAlignment(Element.ALIGN_LEFT);
    userAndDate.getDefaultCell().setBorderWidth(0);
    Paragraph userParagraph = new Paragraph(new Phrase(documentAuthor, FontUtils.getDejavuRegular9Light()));
    userParagraph.add(new Phrase(" " + getDocumentAuthor(), FontUtils.getDejavuRegular9Dark()));
    Paragraph dateParagraph = new Paragraph(df.format(date), FontUtils.getDejavuRegular9Light());
    userAndDate.addCell(userParagraph);
    userAndDate.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
    userAndDate.addCell(dateParagraph);
    userAndDate.setSpacingAfter(14f);
    document.add(userAndDate);
}

From source file:com.qcadoo.report.internal.PdfHelperImpl.java

License:Open Source License

@Override
public void addDocumentHeaderThin(final Document document, final String name, final String documentTitle,
        final String documentAuthor, final Date date) throws DocumentException {
    SimpleDateFormat df = new SimpleDateFormat(DateUtils.L_DATE_TIME_FORMAT, getLocale());
    LineSeparator line = new LineSeparator(2, 100f, ColorUtils.getLineDarkColor(), Element.ALIGN_LEFT, 0);
    Paragraph title = new Paragraph(new Phrase(documentTitle, FontUtils.getDejavuBold14Light()));
    title.add(new Phrase(" " + name, FontUtils.getDejavuBold14Dark()));
    title.setSpacingAfter(7f);//from   w  w  w  .j a  va  2 s .  c  om
    document.add(title);
    document.add(line);
    PdfPTable userAndDate = new PdfPTable(2);
    userAndDate.setWidthPercentage(100f);
    userAndDate.setHorizontalAlignment(Element.ALIGN_LEFT);
    userAndDate.getDefaultCell().setBorderWidth(0);
    Paragraph userParagraph = new Paragraph(new Phrase(documentAuthor, FontUtils.getDejavuRegular9Light()));
    userParagraph.add(new Phrase(" " + getDocumentAuthor(), FontUtils.getDejavuRegular9Dark()));
    Paragraph dateParagraph = new Paragraph(df.format(date), FontUtils.getDejavuRegular9Light());
    userAndDate.addCell(userParagraph);
    userAndDate.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
    userAndDate.addCell(dateParagraph);
    userAndDate.setSpacingAfter(10f);
    document.add(userAndDate);
}

From source file:com.qcadoo.report.internal.PdfHelperImpl.java

License:Open Source License

@Override
public PdfPTable createPanelTable(final int column) {
    PdfPTable mainData = new PdfPTable(column);
    mainData.setWidthPercentage(100f);//w  w  w.j  a v  a 2 s  .  c o m
    mainData.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    mainData.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);
    mainData.getDefaultCell().setPadding(4.0f);
    mainData.setTableEvent(new TableBorderEvent());
    return mainData;
}

From source file:com.qcadoo.report.internal.PdfHelperImpl.java

License:Open Source License

@Override
public PdfPTable createPanelTableWithSimpleFormat(final int column) {
    PdfPTable pdfPTable = new PdfPTable(column);
    pdfPTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    pdfPTable.getDefaultCell().setPadding(6.0f);
    pdfPTable.getDefaultCell().setVerticalAlignment(PdfPCell.ALIGN_TOP);
    return pdfPTable;
}

From source file:com.qcadoo.report.internal.PdfHelperImpl.java

License:Open Source License

private void addTableCellAsTable(final PdfPTable table, final String label, final Object fieldValue,
        final String nullValue, final Font headerFont, final Font valueFont, final int columns,
        final int[] columnWidths) {
    PdfPTable cellTable = new PdfPTable(columns);

    if (columnWidths.length > 0) {
        try {//from w  w  w.j  a v  a  2s . c o m
            cellTable.setWidths(columnWidths);
        } catch (DocumentException e) {
            LOG.error(e.getMessage(), e);
        }
    }

    cellTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    cellTable.addCell(new Phrase(label, headerFont));

    if (fieldValue == null) {
        cellTable.addCell(new Phrase(nullValue, valueFont));
    } else {
        cellTable.addCell(new Phrase(fieldValue.toString(), valueFont));
    }

    table.addCell(cellTable);
}

From source file:com.qcadoo.report.internal.PdfHelperImpl.java

License:Open Source License

private PdfPTable setTableProperties(final List<String> header, final boolean lastColumnAligmentToLeft,
        final PdfPTable table, final Map<String, HeaderAlignment> alignments) {
    table.setWidthPercentage(100f);// www  . j  a v  a  2  s.  c o m
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    table.setSpacingBefore(7.0f);
    // table.getDefaultCell().setBackgroundColor(ColorUtils.getBackgroundColor());
    table.getDefaultCell().setBorderColor(ColorUtils.getLineDarkColor());
    table.getDefaultCell().setBorderWidth(1.0f);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.getDefaultCell().setPadding(5.0f);
    table.getDefaultCell().disableBorderSide(Rectangle.RIGHT);

    if (alignments == null || alignments.isEmpty()) {
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        int i = 0;
        for (String element : header) {
            i++;
            if (i == header.size()) {
                table.getDefaultCell().enableBorderSide(Rectangle.RIGHT);
            }
            table.addCell(new Phrase(element, FontUtils.getDejavuBold7Dark()));
            if (i == 1) {
                table.getDefaultCell().disableBorderSide(Rectangle.LEFT);
            }
        }
    } else {
        int i = 0;

        for (String element : header) {
            i++;
            HeaderAlignment alignment = alignments.get(element);
            if (HeaderAlignment.LEFT.equals(alignment)) {
                table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            } else if (HeaderAlignment.RIGHT.equals(alignment)) {
                table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
            }
            if (i == header.size()) {
                table.getDefaultCell().enableBorderSide(Rectangle.RIGHT);
            }
            table.addCell(new Phrase(element, FontUtils.getDejavuBold7Dark()));
            if (i == 1) {
                table.getDefaultCell().disableBorderSide(Rectangle.LEFT);
            }
        }
    }
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    table.getDefaultCell().setBackgroundColor(null);
    table.getDefaultCell().disableBorderSide(Rectangle.RIGHT);
    table.getDefaultCell().setBorderColor(ColorUtils.getLineLightColor());
    return table;
}