Example usage for com.lowagie.text.pdf PdfPCell PdfPCell

List of usage examples for com.lowagie.text.pdf PdfPCell PdfPCell

Introduction

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

Prototype

public PdfPCell(PdfPCell cell) 

Source Link

Document

Constructs a deep copy of a PdfPCell.

Usage

From source file:optika.sql.java

public PdfPCell getCellPadding(String text, int alignment) {
    PdfPCell cell = new PdfPCell(new Phrase(text));
    cell.setPadding(0);/*from w  w w.ja  va 2s.  c om*/
    cell.setHorizontalAlignment(alignment);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingBottom(36);
    return cell;
}

From source file:optika.sql.java

public PdfPCell getCell(String text, int alignment, int bottom) {
    PdfPCell cell = new PdfPCell(new Phrase(text));
    cell.setPadding(0);/*from  ww w .j  a va 2s  .  c  o  m*/
    cell.setHorizontalAlignment(alignment);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingBottom(bottom);
    return cell;
}

From source file:org.areasy.common.doclet.document.Members.java

License:Open Source License

/**
 * Prints member information.//from   www  .j  a v  a  2 s .c  om
 *
 * @param declaration      The modifiers ("public static final..").
 * @param returnType       Phrase with the return type text (might be
 *                         a hyperlink)
 * @param parms            Parameters of a method or constructor, null for a field.
 * @param thrownExceptions Exceptions of a method, null for a field or constructor.
 * @param isFirst          True if it is the first field/method/constructor in the list.
 * @param isField          True if it is a field.
 * @param isConstructor    True if it is a constructor.
 * @throws Exception
 */
public static void printMember(String declaration, Phrase returnType, ProgramElementDoc commentDoc,
        Parameter[] parms, ClassDoc[] thrownExceptions, boolean isFirst, boolean isField, boolean isConstructor,
        boolean isDeprecated, Phrase deprecatedPhrase, Object constantValue) throws Exception {
    String name = commentDoc.name();

    State.setCurrentMember(State.getCurrentClass() + "." + name);
    State.setCurrentDoc(commentDoc);

    // Returns the text, resolving any "inheritDoc" inline tags
    String commentText = DocletUtility.getComment(commentDoc);

    // TODO: The following line may set the wrong page number
    //      in the index, when the member gets printed on a
    //      new page completely (because it is in one table).
    // Solution unknown yet. Probably split up table.
    Doclet.getIndex().addToMemberList(State.getCurrentMember());

    // Prepare list of exceptions (if it throws any)
    String throwsText = "throws";
    int parmsColumn = declaration.length() + (name.length() - throwsText.length());

    // First output text line (declaration of method and first parameter or "()" ).
    // This first line is a special case because the class name is bold,
    // while the rest is regular plain text, so it must be built using three Chunks.
    Paragraph declarationParagraph = new Paragraph((float) 10.0);

    // left part / declaration ("public static..")
    Chunk leftPart = new Chunk(declaration, Fonts.getFont(CODE_FONT, 10));

    declarationParagraph.add(leftPart);

    if (returnType != null) {
        // left middle part / declaration ("public static..")
        declarationParagraph.add(returnType);
        declarationParagraph.add(new Chunk(" ", Fonts.getFont(CODE_FONT, 10)));
        parmsColumn = 2;
    }

    // right middle part / bold class name
    declarationParagraph.add(new Chunk(name, Fonts.getFont(CODE_FONT, BOLD, 10)));

    if (!isField) {
        // 1st parameter or empty brackets

        if ((parms != null) && (parms.length > 0)) {
            Phrase wholePhrase = new Phrase("(", Fonts.getFont(CODE_FONT, 10));
            // create link for parameter type
            wholePhrase.add(PDFUtility.getParameterTypePhrase(parms[0], 10));
            // then normal text for parameter name
            wholePhrase.add(" " + parms[0].name());
            if (parms.length > 1) {
                wholePhrase.add(",");
            } else {
                wholePhrase.add(")");
            }

            // In order to have the parameter types in the bookmark,
            // make the current state text more detailled
            String txt = State.getCurrentMethod() + "(";
            for (int i = 0; i < parms.length; i++) {
                if (i > 0)
                    txt = txt + ",";
                txt = txt + DocletUtility.getParameterType(parms[i]);
            }

            txt = txt + ")";
            State.setCurrentMethod(txt);

            // right part / parameter and brackets
            declarationParagraph.add(wholePhrase);

        } else {
            String lastPart = "()";
            State.setCurrentMethod(State.getCurrentMethod() + lastPart);

            // right part / parameter and brackets
            declarationParagraph.add(new Chunk(lastPart, Fonts.getFont(CODE_FONT, 10)));
        }

    }

    float[] widths = { (float) 6.0, (float) 94.0 };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage((float) 100);

    // Before the first constructor or method, create a coloured title bar
    if (isFirst) {
        PdfPCell colorTitleCell = null;

        // Some empty space...
        Document.add(new Paragraph((float) 6.0, " "));

        if (isConstructor)
            colorTitleCell = new CustomPdfPCell("Constructors");
        else if (isField)
            colorTitleCell = new CustomPdfPCell("Fields");
        else
            colorTitleCell = new CustomPdfPCell("Methods");

        colorTitleCell.setColspan(2);
        table.addCell(colorTitleCell);
    }

    // Method name (large, first line of a method description block)
    Phrase linkPhrase = Destinations.createDestination(commentDoc.name(), commentDoc,
            Fonts.getFont(TEXT_FONT, BOLD, 14));
    Paragraph nameTitle = new Paragraph(linkPhrase);
    PdfPCell nameCell = new CellNoBorderNoPadding(nameTitle);

    if (isFirst)
        nameCell.setPaddingTop(10);
    else
        nameCell.setPaddingTop(0);

    nameCell.setPaddingBottom(8);
    nameCell.setColspan(1);

    // Create nested table in order to try to prevent the stuff inside
    // this table from being ripped appart over a page break. The method
    // name and the declaration/parm/exception line(s) should always be
    // together, because everything else just looks bad
    PdfPTable linesTable = new PdfPTable(1);
    linesTable.addCell(nameCell);
    linesTable.addCell(new CellNoBorderNoPadding(declarationParagraph));

    if (!isField) {
        // Set up following declaration lines
        Paragraph[] params = PDFUtility.createParameters(parmsColumn, parms);
        Paragraph[] exceps = PDFUtility.createExceptions(parmsColumn, thrownExceptions);

        for (int i = 0; i < params.length; i++) {
            linesTable.addCell(new CellNoBorderNoPadding(params[i]));
        }

        for (int i = 0; i < exceps.length; i++) {
            linesTable.addCell(new CellNoBorderNoPadding(exceps[i]));
        }
    }

    // Create cell for inserting the nested table into the outer table
    PdfPCell cell = new PdfPCell(linesTable);
    cell.setPadding(5);
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(2);
    table.addCell(cell);

    // The empty, left cell (the invisible indentation column)
    State.setContinued(true);

    PdfPCell leftCell = PDFUtility.createElementCell(5, new Phrase("", Fonts.getFont(TEXT_FONT, BOLD, 6)));
    PdfPCell spacingCell = new PdfPCell();
    spacingCell.setFixedHeight((float) 8.0);
    spacingCell.setBorder(Rectangle.NO_BORDER);
    table.addCell(spacingCell);
    table.addCell(spacingCell);

    // The descriptive method explanation text

    if (isDeprecated) {
        Phrase commentPhrase = new Phrase();
        commentPhrase
                .add(new Phrase(AbstractConfiguration.LB_DEPRECATED_TAG, Fonts.getFont(TEXT_FONT, BOLD, 10)));
        commentPhrase.add(deprecatedPhrase);
        table.addCell(leftCell);
        table.addCell(PDFUtility.createElementCell(0, commentPhrase));

        commentPhrase = new Phrase();
        commentPhrase.add(Chunk.NEWLINE);
        table.addCell(leftCell);
        table.addCell(PDFUtility.createElementCell(0, commentPhrase));
    }

    Element[] objs = HtmlParserWrapper.createPdfObjects(commentText);

    if (objs.length == 1) {
        table.addCell(leftCell);
        table.addCell(PDFUtility.createElementCell(0, objs[0]));
    } else {
        table.addCell(leftCell);
        table.addCell(PDFUtility.createElementCell(0, Element.ALIGN_LEFT, objs));
    }

    // TODO: FORMAT THIS CONSTANT VALUE OUTPUT CORRECTLY

    if (isField) {
        if (constantValue != null) {
            // Add 2nd comment line (left cell empty, right cell text)
            Chunk valueTextChunk = new Chunk("Constant value: ", Fonts.getFont(TEXT_FONT, PLAIN, 10));
            Chunk valueContentChunk = new Chunk(constantValue.toString(), Fonts.getFont(CODE_FONT, BOLD, 10));
            Phrase constantValuePhrase = new Phrase("");
            constantValuePhrase.add(valueTextChunk);
            constantValuePhrase.add(valueContentChunk);
            table.addCell(leftCell);
            table.addCell(PDFUtility.createElementCell(0, constantValuePhrase));
        }
    }

    // Add whole method block to document
    Document.add(table);
}

From source file:org.areasy.common.doclet.document.tags.TagPRE.java

License:Open Source License

/**
 * Creates a PRE tag object.//  w  w w  .ja  v  a2  s  . c o m
 *
 * @param parent The parent HTML object.
 * @param type   The type for this tag.
 */
public TagPRE(HtmlTag parent, int type) {
    super(parent, type);
    setPre(true);

    cellPara = new Paragraph("", getFont());

    colorTitleCell = new PdfPCell(cellPara);
    colorTitleCell.setBorder(Rectangle.TOP + Rectangle.LEFT + Rectangle.RIGHT + Rectangle.BOTTOM);
    colorTitleCell.setPadding(6);
    colorTitleCell.setPaddingBottom(12);
    colorTitleCell.setPaddingLeft(10);
    colorTitleCell.setPaddingRight(10);
    colorTitleCell.setBorderWidth(1);
    colorTitleCell.setBorderColor(Color.gray);
    colorTitleCell.setBackgroundColor(COLOR_LIGHTER_GRAY);
    colorTitleCell.addElement(cellPara);

    mainTable.addCell(colorTitleCell);
}

From source file:org.areasy.common.doclet.document.tags.TagTABLE.java

License:Open Source License

public void addNestedTagContent(Element[] elements) {
    PdfPCell[] row = getRow(elements);/*from  w ww.j a v  a2s . co m*/

    // If elements is a row of Cells, add it to the table

    if (row != null) {
        if (table == null) {
            createTable(getNumColumns(row));
            hasHeaders = isHeader(row[0]);
        } else if (!isHeader(row[0]) && hasHeaders) {
            table.setHeaderRows(table.size());
            hasHeaders = false;
        }

        for (int i = 0; i < row.length; i++) {
            row[i].setBorderWidth(table.getDefaultCell().borderWidth());
            row[i].setBorderColor(table.getDefaultCell().borderColor());
            row[i].setBorder(table.getDefaultCell().border());
            row[i].setPadding(table.getDefaultCell().getPaddingLeft());

            table.addCell(row[i]);
        }

        /* If we haven't finished a row, fill it out.  Not sure this is a good idea. */
        int col = getCurrCol(table);
        int expectedCols = table.getAbsoluteWidths().length;
        if (col > 0) {
            for (int i = col; i < expectedCols; i++) {
                table.addCell(new PdfPCell(new Phrase()));
            }
        }
    }
}

From source file:org.caisi.tickler.web.TicklerPrinter.java

License:Open Source License

private void addStandardTableEntry(PdfPTable table, String name, String value) {
    PdfPCell cell1 = new PdfPCell(getParagraph(name + ":"));

    cell1.setBorder(PdfPCell.BOTTOM);/*from   w w  w.  j a v  a2  s  .c  o m*/
    cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
    PdfPCell cell2 = new PdfPCell(getParagraph(value));
    cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell2.setBorder(PdfPCell.BOTTOM);

    table.addCell(cell1);
    table.addCell(cell2);
}

From source file:org.caisi.tickler.web.TicklerPrinter.java

License:Open Source License

public void printTicklerInfo() throws DocumentException {

    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(50f);/*from w w w .ja  v a  2s . co m*/
    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);

    addStandardTableEntry(table, "Created By", tickler.getProvider().getFormattedName());
    addStandardTableEntry(table, "Last Updated", formatter.format(tickler.getUpdateDate()));
    addStandardTableEntry(table, "Service Date", formatter.format(tickler.getServiceDate()));
    addStandardTableEntry(table, "Assigned To", tickler.getAssignee().getFormattedName());
    addStandardTableEntry(table, "Priority", tickler.getPriority().toString());
    addStandardTableEntry(table, "Status", tickler.getStatusWeb());
    addStandardTableEntry(table, "Program",
            (tickler.getProgram() != null) ? tickler.getProgram().getName() : "N/A");

    getDocument().add(table);

    table = new PdfPTable(1);
    table.setWidthPercentage(70f);

    PdfPCell cell1 = new PdfPCell(getParagraph("Message"));

    cell1.setBorder(PdfPCell.NO_BORDER);
    cell1.setHorizontalAlignment(Element.ALIGN_LEFT);

    table.addCell(cell1);

    cell1 = new PdfPCell(getParagraph(tickler.getMessage()));
    cell1.setHorizontalAlignment(Element.ALIGN_LEFT);

    table.addCell(cell1);

    getDocument().add(table);

}

From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java

License:Open Source License

/**
 * This method add Activities for the summary project
 *///  ww  w.  j a  v  a  2s .  co m
private void addActivities() {

    try {
        document.newPage();
        Paragraph activityBlock = new Paragraph("6. " + this.getText("summaries.project.activity"),
                HEADING2_FONT);
        activityBlock.setAlignment(Element.ALIGN_JUSTIFIED);
        activityBlock.add(Chunk.NEWLINE);

        PdfPTable table;
        List<Activity> listActivities = project.getActivities();

        if (listActivities.isEmpty()) {
            activityBlock.setFont(BODY_TEXT_FONT);
            activityBlock.add(this.getText("summaries.project.empty"));
            document.add(activityBlock);
        } else {
            activityBlock.add(Chunk.NEWLINE);
            document.add(activityBlock);
            int counter = 1;
            for (Activity activity : listActivities) {
                boolean printActity = true;
                if (activity != null) {
                    if (!project.isReporting()) {
                        Calendar c = Calendar.getInstance();
                        c.setTime(activity.getEndDate());
                        Calendar cStartDate = Calendar.getInstance();
                        cStartDate.setTime(activity.getStartDate());
                        if (c.get(Calendar.YEAR) != config.getPlanningCurrentYear()) {
                            if (cStartDate.get(Calendar.YEAR) != config.getPlanningCurrentYear()) {
                                printActity = false;
                            }

                        }

                        if (activity.getActivityStatus() == Integer
                                .parseInt(ProjectStatusEnum.Cancelled.getStatusId())) {
                            printActity = false;
                        }
                    }
                    if (printActity) {
                        table = new PdfPTable(2);
                        table.setTotalWidth(480);
                        table.setLockedWidth(true);

                        // Header table
                        activityBlock = new Paragraph();
                        activityBlock.setAlignment(Element.ALIGN_CENTER);
                        activityBlock.setFont(TABLE_HEADER_FONT);
                        activityBlock.add("Activity #" + counter);

                        PdfPCell cell_new = new PdfPCell(activityBlock);
                        cell_new.setHorizontalAlignment(Element.ALIGN_CENTER);
                        cell_new.setVerticalAlignment(Element.ALIGN_MIDDLE);
                        cell_new.setBackgroundColor(TABLE_HEADER_BACKGROUND);
                        cell_new.setUseBorderPadding(true);
                        cell_new.setPadding(3);
                        cell_new.setBorderColor(TABLE_CELL_BORDER_COLOR);
                        cell_new.setColspan(2);

                        this.addTableHeaderCell(table, cell_new);

                        // Activity title
                        activityBlock = new Paragraph();
                        activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                        activityBlock.add(this.getText("summaries.project.activities.title"));

                        activityBlock.setFont(TABLE_BODY_FONT);
                        activityBlock.add(this.messageReturn(activity.getTitle()));
                        activityBlock.add(Chunk.NEWLINE);
                        this.addTableColSpanCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1, 2);

                        // Activity description
                        activityBlock = new Paragraph();
                        activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                        activityBlock.add(this.getText("summaries.project.activities.description"));

                        activityBlock.setFont(TABLE_BODY_FONT);
                        activityBlock.add(this.messageReturn(activity.getDescription()));
                        activityBlock.add(Chunk.NEWLINE);
                        this.addTableColSpanCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1, 2);

                        String startDate = null;
                        String endDate = null;
                        try {
                            startDate = new SimpleDateFormat("dd-MM-yyyy").format(activity.getStartDate());
                        } catch (Exception e) {

                        }
                        try {

                            endDate = new SimpleDateFormat("dd-MM-yyyy").format(activity.getEndDate());
                        } catch (Exception e) {

                        }

                        // Activity Start Date
                        activityBlock = new Paragraph();
                        activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                        activityBlock.add(this.getText("summaries.project.startDate") + " (dd-MM-yyyy)" + ": ");

                        activityBlock.setFont(TABLE_BODY_FONT);
                        activityBlock.add(startDate);
                        activityBlock.add(Chunk.NEWLINE);
                        this.addTableBodyCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1);

                        // Activity End Date
                        activityBlock = new Paragraph();
                        activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                        activityBlock.add(this.getText("summaries.project.endDate") + " (dd-MM-yyyy)" + ": ");

                        activityBlock.setFont(TABLE_BODY_FONT);
                        activityBlock.add(endDate);
                        activityBlock.add(Chunk.NEWLINE);
                        this.addTableBodyCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1);

                        // Activity Leader
                        activityBlock = new Paragraph();
                        activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                        activityBlock.add(this.getText("summaries.project.activities.activityLeader") + ": ");
                        activityBlock.setFont(TABLE_BODY_FONT);

                        PartnerPerson activityPartnerPerson = activity.getLeader();

                        if (activityPartnerPerson != null) {
                            activityBlock.add(activityPartnerPerson.getComposedName());
                            String partnerInstitution = this.mapPartnerPersons
                                    .get(String.valueOf(activityPartnerPerson.getId()));
                            if (partnerInstitution != null) {
                                activityBlock.add(", " + partnerInstitution);
                            }
                        } else {
                            activityBlock.add(this.getText("summaries.project.empty"));
                        }
                        activityBlock.add(Chunk.NEWLINE);
                        this.addTableColSpanCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1, 2);

                        // if (project.isReporting()) {
                        // status
                        activityBlock = new Paragraph();
                        activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                        activityBlock.add(this.getText("summaries.project.activities.status"));

                        activityBlock.setFont(TABLE_BODY_FONT);
                        if (activity.getActivityStatus() > 0) {
                            activityBlock.add(statuses.get(String.valueOf(activity.getActivityStatus())));
                        } else {
                            activityBlock.add(" " + this.getText("summaries.project.empty"));
                            // }
                            activityBlock.add(Chunk.NEWLINE);

                            if (activity.isStatusCancelled() || activity.isStatusExtended()
                                    || activity.isStatusOnGoing()) {
                                this.addTableBodyCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1);

                                activityBlock = new Paragraph();
                                activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                                activityBlock.add(this.getText("summaries.project.activities.justification"));

                                activityBlock.setFont(TABLE_BODY_FONT);
                                activityBlock.add(this.messageReturn(activity.getActivityProgress()));
                                activityBlock.add(Chunk.NEWLINE);

                                this.addTableBodyCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1);
                            } else {
                                this.addTableColSpanCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1, 2);
                            }
                        }

                        // document.add(Chunk.NEWLINE);
                        document.add(table);
                        activityBlock = new Paragraph();
                        activityBlock.add(Chunk.NEWLINE);
                        document.add(activityBlock);
                        counter++;

                    }
                }

            }

            // Leason regardins
            activityBlock = new Paragraph();
            activityBlock.setAlignment(Element.ALIGN_JUSTIFIED);
            activityBlock.setFont(BODY_TEXT_BOLD_FONT);
            if (!project.isReporting()) {
                activityBlock.add(this.getText("summaries.project.activities.lessonsRegarding"));
            } else {
                activityBlock.add(this.getText("summaries.project.activities.reporting.lessonsRegarding"));
            }
            activityBlock.setFont(BODY_TEXT_FONT);

            if (project.getComponentLesson("activities") != null) {
                activityBlock.add(this.messageReturn(project.getComponentLesson("activities").getLessons()));
            } else {
                activityBlock.add(this.messageReturn(null));
            }
            document.add(activityBlock);

        }

    } catch (DocumentException e) {
        LOG.error(
                "There was an error trying to add the project activities to the project summary pdf of project {} ",
                e, project.getId());
    }

}

From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java

License:Open Source License

private void addBudgetByMogOne(Paragraph paragraph, PdfPTable table, StringBuffer budgetLabel, IPElement mog,
        int startYear, int endYear, BudgetType budgetType) {
    paragraph = new Paragraph();
    budgetLabel = new StringBuffer();
    paragraph.setFont(TABLE_BODY_FONT);/*from w  ww. j  a va2  s  .  c  om*/
    budgetLabel.append(mog.getProgram().getAcronym());
    budgetLabel.append(" - MOG # ");
    budgetLabel.append(this.getMOGIndex(mog));
    budgetLabel.append(": ");
    budgetLabel.append(mog.getDescription());
    budgetLabel.append(" - " + budgetType.name().replace("_", "/"));
    paragraph.add(budgetLabel.toString());
    this.addCustomTableCell(table, paragraph, Element.ALIGN_JUSTIFIED, BODY_TEXT_FONT, Color.WHITE,
            table.getNumberOfColumns(), 0, false);

    PdfPCell cell;
    // year
    paragraph = new Paragraph(this.getText("summaries.project.budget.overall.type"), TABLE_HEADER_FONT);
    cell = new PdfPCell(paragraph);
    cell.setRowspan(2);
    this.addTableHeaderCell(table, cell);

    // % de amount
    paragraph = new Paragraph(this.getText("summaries.project.budget.mog.anual.percentaje",
            new String[] { budgetType.name().replace("_", "/") }), TABLE_HEADER_FONT);
    cell = new PdfPCell(paragraph);
    cell.setColspan(2);
    this.addTableHeaderCell(table, cell);

    // gender
    paragraph = new Paragraph(this.getText("summaries.project.budget.mog.anual.gender",
            new String[] { budgetType.name().replace("_", "/") }), TABLE_HEADER_FONT);
    cell = new PdfPCell(paragraph);
    cell.setColspan(2);
    this.addTableHeaderCell(table, cell);

    // amount (%)
    paragraph = new Paragraph("(%)", TABLE_HEADER_FONT);
    this.addTableHeaderCell(table, paragraph);

    // amount (USD)
    paragraph = new Paragraph("(USD)", TABLE_HEADER_FONT);
    this.addTableHeaderCell(table, paragraph);

    // gender (%)
    paragraph = new Paragraph("(%)", TABLE_HEADER_FONT);
    this.addTableHeaderCell(table, paragraph);

    // gender (USD)
    paragraph = new Paragraph("(USD)", TABLE_HEADER_FONT);
    this.addTableHeaderCell(table, paragraph);

    double[] totalsByYear = { 0, 0 };

    for (int year = startYear; year <= endYear; year++) {
        paragraph = new Paragraph(String.valueOf(year), TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, paragraph, Element.ALIGN_CENTER, 0);
        this.addBudgetMogByYear(year, paragraph, table, mog, budgetType, totalsByYear);
    }

    // Totals
    paragraph = new Paragraph(this.getText("summaries.project.budget.overall.total"), TABLE_BODY_BOLD_FONT);
    this.addTableBodyCell(table, paragraph, Element.ALIGN_CENTER, 0);

    // total amount $
    paragraph = new Paragraph(this.budgetFormatter.format(totalsByYear[0]), TABLE_BODY_BOLD_FONT);
    this.addTableColSpanCell(table, paragraph, Element.ALIGN_RIGHT, 1, 2);

    // total gender $
    paragraph = new Paragraph(this.budgetFormatter.format(totalsByYear[1]), TABLE_BODY_BOLD_FONT);
    this.addTableColSpanCell(table, paragraph, Element.ALIGN_RIGHT, 1, 2);

}

From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java

License:Open Source License

private void addBudgetPartner(ProjectPartner projectPartner, Paragraph paragraph, PdfPTable table,
        BudgetType budgetType, int startYear, int endYear) {

    PdfPCell cell;//from  w w  w .j  a  v a  2s. c  o  m

    paragraph = new Paragraph(
            projectPartner.getInstitution().getComposedName() + " " + budgetType.name().replace("_", "/"),
            BODY_TEXT_BOLD_FONT);
    this.addCustomTableCell(table, paragraph, Element.ALIGN_CENTER, BODY_TEXT_BOLD_FONT, Color.WHITE,
            table.getNumberOfColumns(), 0, false);

    // year
    paragraph = new Paragraph(this.getText("summaries.project.budget.overall.type"), TABLE_HEADER_FONT);
    cell = new PdfPCell(paragraph);
    cell.setRowspan(2);
    this.addTableHeaderCell(table, cell);

    // amount
    paragraph = new Paragraph(this.getText("summaries.project.budget.overall.amount", new String[] { "" })
            + budgetType.name().toString().replace("_", "/") + " (USD)", TABLE_HEADER_FONT);
    cell = new PdfPCell(paragraph);
    cell.setRowspan(2);
    this.addTableHeaderCell(table, cell);

    // gender
    paragraph = new Paragraph(this.getText("summaries.project.budget.overall.gender", new String[] { "" })
            + budgetType.name().toString().replace("_", "/"), TABLE_HEADER_FONT);
    cell = new PdfPCell(paragraph);
    cell.setColspan(2);
    this.addTableHeaderCell(table, cell);

    // gender (%)
    paragraph = new Paragraph("(%)", TABLE_HEADER_FONT);
    this.addTableHeaderCell(table, paragraph);

    // gender (USD)
    paragraph = new Paragraph("(USD)", TABLE_HEADER_FONT);
    this.addTableHeaderCell(table, paragraph);

    for (int year = startYear; year <= endYear; year++) {
        paragraph = new Paragraph(String.valueOf(year), TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, paragraph, Element.ALIGN_CENTER, 0);
        this.addRowBudgetByPartners(paragraph, projectPartner.getInstitution(), year, table, budgetType);
    }

    // ************** Totals
    paragraph = new Paragraph(this.getText("summaries.project.budget.overall.total"), TABLE_BODY_BOLD_FONT);
    this.addTableBodyCell(table, paragraph, Element.ALIGN_CENTER, 0);

    // amount
    double value = this.budgetManager.calculateTotalCCAFSBudgetByInstitutionAndType(project.getId(),
            projectPartner.getInstitution().getId(), budgetType.getValue());
    paragraph = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT);
    this.addTableBodyCell(table, paragraph, Element.ALIGN_RIGHT, 1);

    // gender
    value = this.budgetManager.calculateTotalGenderBudgetByInstitutionAndType(project.getId(),
            projectPartner.getInstitution().getId(), budgetType.getValue());
    paragraph = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT);
    this.addTableColSpanCell(table, paragraph, Element.ALIGN_RIGHT, 1, 2);
}