Example usage for com.lowagie.text Paragraph Paragraph

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

Introduction

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

Prototype

public Paragraph(float leading, String string) 

Source Link

Document

Constructs a Paragraph with a certain String and a certain leading.

Usage

From source file:com.bytecode.customexporter.PDFCustomExporter.java

protected void exportCells(DataTable table, PdfPTable pdfTable) {
    for (UIColumn col : table.getColumns()) {

        if (col instanceof DynamicColumn) {
            ((DynamicColumn) col).applyStatelessModel();
        }/*from  ww w .  j a  v a 2 s  . c  o  m*/

        if (col.isRendered() && col.isExportable()) {
            if (col.getSelectionMode() != null) {
                pdfTable.addCell(new Paragraph(col.getSelectionMode(), this.cellFont));
                continue;
            }
            addColumnValue(pdfTable, col.getChildren(), this.cellFont, "data");
        }

    }
    pdfTable.completeRow();
    FacesContext context = null;
    if (table.getRowIndex() == 0) {
        for (UIComponent component : table.getChildren()) {
            if (component instanceof RowExpansion) {
                RowExpansion rowExpansion = (RowExpansion) component;
                if (rowExpansion.getChildren() != null) {
                    if (rowExpansion.getChildren().get(0) instanceof DataTable) {
                        DataTable childTable = (DataTable) rowExpansion.getChildren().get(0);
                        childTable.setRowIndex(-1);
                    }
                    if (rowExpansion.getChildren().get(0) instanceof DataList) {
                        DataList childList = (DataList) rowExpansion.getChildren().get(0);
                        childList.setRowIndex(-1);
                    }
                }

            }
        }
    }
    for (UIComponent component : table.getChildren()) {
        if (component instanceof RowExpansion) {
            RowExpansion rowExpansion = (RowExpansion) component;
            if (rowExpansion.getChildren() != null) {
                if (rowExpansion.getChildren().get(0) instanceof DataTable) {
                    DataTable childTable = (DataTable) rowExpansion.getChildren().get(0);
                    PdfPTable pdfTableChild = exportPDFTable(context, childTable, false, false, "-", false);
                    PdfPCell cell = new PdfPCell();
                    cell.addElement(pdfTableChild);
                    cell.setColspan(pdfTable.getNumberOfColumns());
                    pdfTable.addCell(cell);
                }
                if (rowExpansion.getChildren().get(0) instanceof DataList) {
                    DataList list = (DataList) rowExpansion.getChildren().get(0);
                    PdfPTable pdfTableChild = exportPDFTable(context, list, false, "-");
                    pdfTableChild.getDefaultCell().setBorder(Rectangle.NO_BORDER);
                    PdfPCell cell = new PdfPCell();
                    cell.addElement(pdfTableChild);
                    cell.setColspan(pdfTable.getNumberOfColumns());
                }
            }

        }
        pdfTable.completeRow();
    }

}

From source file:com.bytecode.customexporter.PDFCustomExporter.java

protected void addColumnFacets(DataTable table, PdfPTable pdfTable, ColumnType columnType) {
    for (UIColumn col : table.getColumns()) {

        if (col instanceof DynamicColumn) {
            ((DynamicColumn) col).applyStatelessModel();
        }//  w  w  w.  ja  v  a 2s.  com
        PdfPCell cell = null;
        if (col.isRendered() && col.isExportable()) {
            if (col.getHeaderText() != null && columnType.name().equalsIgnoreCase("header")) {
                cell = new PdfPCell(new Paragraph(col.getHeaderText(), this.facetFont));
                if (facetBackground != null) {
                    cell.setBackgroundColor(facetBackground);
                }
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                pdfTable.addCell(cell);
            } else if (col.getFooterText() != null && columnType.name().equalsIgnoreCase("footer")) {
                cell = new PdfPCell(new Paragraph(col.getFooterText(), this.facetFont));
                if (facetBackground != null) {
                    cell.setBackgroundColor(facetBackground);
                }
                pdfTable.addCell(cell);
            } else {
                addColumnValue(pdfTable, col.getFacet(columnType.facet()), this.facetFont, columnType.name());
            }
        }
    }
}

From source file:com.bytecode.customexporter.PDFCustomExporter.java

protected void addColumnFacets(SubTable table, PdfPTable pdfTable, ColumnType columnType) {
    for (UIColumn col : table.getColumns()) {

        if (col instanceof DynamicColumn) {
            ((DynamicColumn) col).applyStatelessModel();
        }/*from  w w  w .  ja  va2  s . c  om*/
        PdfPCell cell = null;
        if (col.isRendered() && col.isExportable()) {
            if (col.getHeaderText() != null && columnType.name().equalsIgnoreCase("header")) {
                cell = new PdfPCell(new Paragraph(col.getHeaderText(), this.facetFont));
                if (facetBackground != null) {
                    cell.setBackgroundColor(facetBackground);
                }
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                pdfTable.addCell(cell);
            } else if (col.getFooterText() != null && columnType.name().equalsIgnoreCase("footer")) {
                cell = new PdfPCell(new Paragraph(col.getFooterText(), this.facetFont));
                if (facetBackground != null) {
                    cell.setBackgroundColor(facetBackground);
                }
                pdfTable.addCell(cell);
            } else {

                addColumnValue(pdfTable, col.getFacet(columnType.facet()), this.facetFont, columnType.name());
            }
        }
    }
}

From source file:com.bytecode.customexporter.PDFCustomExporter.java

protected void addColumnValue(PdfPTable pdfTable, UIComponent component, Font font, String columnType) {
    String value = component == null ? "" : exportValue(FacesContext.getCurrentInstance(), component);
    PdfPCell cell = new PdfPCell(new Paragraph(value, font));

    if (facetBackground != null) {
        cell.setBackgroundColor(facetBackground);
    }/*from w  ww. j  ava 2 s.  co m*/
    if (columnType.equalsIgnoreCase("header")) {
        cell = addFacetAlignments(component, cell);
    } else {
        cell = addColumnAlignments(component, cell);
    }
    pdfTable.addCell(cell);
}

From source file:com.bytecode.customexporter.PDFCustomExporter.java

protected void addColumnValue(PdfPTable pdfTable, List<UIComponent> components, Font font, String columnType) {
    StringBuilder builder = new StringBuilder();

    for (UIComponent component : components) {
        if (component.isRendered()) {
            String value = exportValue(FacesContext.getCurrentInstance(), component);

            if (value != null) {
                builder.append(value);/*  w  ww.  java  2  s.co m*/
            }
        }
    }
    PdfPCell cell = new PdfPCell(new Paragraph(builder.toString(), font));
    for (UIComponent component : components) {
        cell = addColumnAlignments(component, cell);
    }
    if (columnType.equalsIgnoreCase("header")) {
        for (UIComponent component : components) {
            cell = addFacetAlignments(component, cell);
        }
    }
    pdfTable.addCell(cell);
}

From source file:com.centurylink.mdw.designer.pages.ExportHelper.java

License:Apache License

private Chapter printOneProcessPdf(DocWriter writer, DesignerCanvas canvas, String type, int chapter_number,
        Graph process, String filename, Rectangle page_size) throws Exception {
    Paragraph cTitle = new Paragraph("Workflow Process: \"" + process.getName() + "\"", chapterFont);
    Chapter chapter = new Chapter(cTitle, chapter_number);
    // print image
    printGraphPdf(writer, canvas, process, page_size, type, filename, chapter, chapter_number);
    // print documentation text
    printGraphPdf(process, chapter);/* w  ww .j  a  va2  s  . c  om*/
    for (Node node : process.getNodes(nodeIdType)) {
        printNodePdf(node, chapter);
    }
    for (SubGraph subgraph : process.getSubgraphs(nodeIdType)) {
        printGraphPdf(subgraph, chapter);
        for (Node node : subgraph.getNodes(nodeIdType)) {
            printNodePdf(node, chapter);
        }
    }
    if (options.contains(VARIABLES)) {
        printVariablesPdf(chapter, process.getProcessVO().getVariables(),
                options.contains(SECTION_NUMBER) ? 1 : 0);
    }

    return chapter;
}

From source file:com.centurylink.mdw.designer.pages.ExportHelper.java

License:Apache License

private void printGraphPdf(GraphCommon graph, Chapter chapter) throws Exception {
    Section section;/*from  ww w  .  jav a 2  s  .  co m*/
    String tmp = null;
    if (graph instanceof SubGraph) {
        SubGraph subgraph = (SubGraph) graph;
        String id = subgraph.getDisplayId(nodeIdType);
        if (id == null || id.length() == 0)
            id = subgraph.getId().toString();
        tmp = "Subprocess " + id + ": \"" + subgraph.getName().replace('\n', ' ') + "\"";
    } else {
        tmp = "Process Description";
    }
    Paragraph sTitle = new Paragraph(tmp, sectionFont);
    sTitle.setSpacingBefore(10);
    section = chapter.addSection(sTitle, options.contains(SECTION_NUMBER) ? 2 : 0);
    String summary = (graph instanceof SubGraph) ? ((SubGraph) graph).getProcessVO().getProcessDescription()
            : ((Graph) graph).getProcessVO().getProcessDescription();
    if (summary != null && summary.length() > 0)
        printBoldParagraphsPdf(section, summary);
    if (options.contains(DOCUMENTATION)) {
        String detail = graph.getProcessVO().getAttribute(WorkAttributeConstant.DOCUMENTATION);
        if (detail != null && detail.length() > 0) {
            printHtmlParagraphsPdf(section, detail, options.contains(SECTION_NUMBER) ? 2 : 0);
        }
    }
    if (options.contains(ATTRIBUTES) && !graph.getProcessVO().getAttributes().isEmpty()
            && graph instanceof SubGraph) {
        printAttributesPdf(section, graph.getProcessVO().getAttributes(),
                options.contains(SECTION_NUMBER) ? 2 : 0);
    }
}

From source file:com.centurylink.mdw.designer.pages.ExportHelper.java

License:Apache License

private void printNodePdf(Node node, Chapter chapter) throws Exception {
    Section section;// w ww .jav a  2s  . c o m
    String id = node.getDisplayId(nodeIdType);
    if (id == null || id.length() == 0)
        id = node.getId().toString();
    String tmp = "Activity " + id + ": \"" + node.getName().replace('\n', ' ') + "\n";
    Paragraph sTitle = new Paragraph(tmp, sectionFont);
    section = chapter.addSection(sTitle, options.contains(SECTION_NUMBER) ? 2 : 0);
    String summary = node.getAttribute(WorkAttributeConstant.DESCRIPTION);
    if (summary != null && summary.length() > 0) {
        printBoldParagraphsPdf(section, summary);
    }

    if (options.contains(DOCUMENTATION)) {
        String detail = node.getAttribute(WorkAttributeConstant.DOCUMENTATION);
        if (detail != null && detail.length() > 0) {
            printHtmlParagraphsPdf(section, detail, options.contains(SECTION_NUMBER) ? 2 : 0);
            section.add(new Paragraph("\n",
                    FontFactory.getFont(FontFactory.TIMES, 4, Font.NORMAL, new Color(0, 0, 0))));
        }
    }
    if (options.contains(ATTRIBUTES) && !node.getAttributes().isEmpty()) {
        printAttributesPdf(section, node.getAttributes(), options.contains(SECTION_NUMBER) ? 2 : 0);
    }
    section.add(new Paragraph("\n", normalFont));
}

From source file:com.centurylink.mdw.designer.pages.ExportHelper.java

License:Apache License

private void printBoldParagraphsPdf(Section section, String content) {
    if (content == null || content.length() == 0)
        return;/* w ww . j  a v a  2  s . c o  m*/
    String[] details = content.split("\n");
    String tmp = null;
    for (int j = 0; j < details.length; j++) {
        if (details[j].length() == 0) {
            if (tmp != null)
                section.add(new Paragraph(tmp + "\n", boldFont));
            tmp = null;
        } else if (tmp == null) {
            tmp = details[j];
        } else {
            tmp += " " + details[j];
        }
    }
    if (tmp != null) {
        section.add(new Paragraph(tmp + "\n", boldFont));
    }
}

From source file:com.centurylink.mdw.designer.pages.ExportHelper.java

License:Apache License

private void printAttributesPdf(Section section, List<AttributeVO> attrs, int parentLevel) {
    Paragraph sTitle = new Paragraph("Activity Attributes", subSectionFont);
    Section subsection = section.addSection(sTitle, parentLevel == 0 ? 0 : (parentLevel + 1));
    com.lowagie.text.List list = new com.lowagie.text.List(false, false, 20.0f);
    for (AttributeVO attr : attrs) {
        if (excludeAttribute(attr.getAttributeName(), attr.getAttributeValue()))
            continue;
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(attr.getAttributeName(), fixedWidthFont));
        String v = attr.getAttributeValue();
        if (v == null)
            v = "";
        phrase.add(new Chunk(": " + v, normalFont));
        list.add(new ListItem(phrase));
    }/*  w  ww.  j  av  a2s . c  om*/
    subsection.add(list);
}