Example usage for com.lowagie.text Element ALIGN_RIGHT

List of usage examples for com.lowagie.text Element ALIGN_RIGHT

Introduction

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

Prototype

int ALIGN_RIGHT

To view the source code for com.lowagie.text Element ALIGN_RIGHT.

Click Source Link

Document

A possible value for paragraph alignment.

Usage

From source file:open.dolphin.hiro.PrescriptionPDFMaker.java

/**
 * ??
 * ???
 * @param pcell
 */
private void setAlignRight(PdfPCell pcell) {
    pcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
}

From source file:org.apache.poi.xwpf.converter.internal.itext.stylable.StylableParagraph.java

License:Open Source License

public void applyStyles(XWPFParagraph p, Style style) {

    if (style != null) {
        // first process values from "style"
        // will be overridden by in-line values if available...
        StyleParagraphProperties paragraphProperties = style.getParagraphProperties();

        if (paragraphProperties != null) {
            FontInfos fontInfos = paragraphProperties.getFontInfos();
            if (fontInfos != null) {
                Font font = XWPFFontRegistry.getRegistry().getFont(fontInfos.getFontFamily(),
                        fontInfos.getFontEncoding(), fontInfos.getFontSize(), fontInfos.getFontStyle(),
                        fontInfos.getFontColor());
                setFont(font);/*from  ww  w . j  a v  a  2s.c om*/
            }
            // Alignment
            int alignment = paragraphProperties.getAlignment();
            if (alignment != Element.ALIGN_UNDEFINED) {
                setAlignment(alignment);
            }

            Float lineHeight = paragraphProperties.getLineHeight();
            if (lineHeight != null) {
                // super.getPdfPCell().setMinimumHeight(lineHeight);
                // FIXME : Is it correct???
                setLeading(lineHeight * super.getTotalLeading());
            }
            // System.err.println("IndentationRight "+paragraphProperties.getIndentationRight());
            setIndentationRight(paragraphProperties.getIndentationRight());
            setIndentationLeft(paragraphProperties.getIndentationLeft());
            setFirstLineIndent(paragraphProperties.getIndentationFirstLine());
            // StyleBorder borderBottom= paragraphProperties.getBorderBottom();

        }

    }

    ParagraphAlignment paragraphAlignment = p.getAlignment();

    // text-align

    if (paragraphAlignment != null) {
        int alignment = Element.ALIGN_UNDEFINED;
        switch (paragraphAlignment) {
        case LEFT:
            alignment = Element.ALIGN_LEFT;
            break;
        case RIGHT:
            alignment = Element.ALIGN_RIGHT;
            break;
        case CENTER:
            alignment = Element.ALIGN_CENTER;
            break;
        case BOTH:
            alignment = Element.ALIGN_JUSTIFIED;
            break;
        default:
            break;
        }

        setAlignment(alignment);
    }

    int indentationLeft = p.getIndentationLeft();
    if (indentationLeft > 0) {
        setIndentationLeft(indentationLeft);
    }

    // text-indent
    int indentationFirstLine = p.getIndentationFirstLine();
    if (indentationFirstLine > 0) {
        setFirstLineIndent(indentationFirstLine);
    }

    int indentationRight = p.getIndentationRight();

    if (indentationRight > 0) {
        setIndentationRight(indentationRight);
    }
    // verticalAlignment DOES not exists in StyleParagraphProperties iText
    // TextAlignment textAlignment = p.getVerticalAlignment();

    int left = p.getIndentationLeft();
    int right = p.getIndentationRight();

    if (right > 0) {
        setIndentationRight(dxa2points(right));
    }

    if (left > 0) {
        setIndentationLeft(dxa2points(left));
    }

    int firstLineIndent = p.getIndentationFirstLine();
    if (firstLineIndent > 0) {
        setFirstLineIndent(dxa2points(firstLineIndent));
    }

    int spacingBefore = p.getSpacingBefore();
    if (spacingBefore > 0) {
        setSpacingBefore(dxa2points(spacingBefore));
    }
    if (p.getSpacingAfter() >= 0) {
        setSpacingAfter(dxa2points(p.getSpacingAfter()));

    } else {
        // XXX Seems to be a default :
        setSpacingAfter(10f);
    }

    if (p.getCTP().getPPr() != null) {
        if (p.getCTP().getPPr().getSpacing() != null) {

            if (p.getCTP().getPPr().getSpacing().getLine() != null) {

                // XXX PLQ : why 240 ???
                float leading = (p.getCTP().getPPr().getSpacing().getLine().floatValue() / 240);
                setMultipliedLeading(leading);
            }

        }
    }

    ParagraphAlignment alignment = p.getAlignment();
    switch (alignment) {
    case LEFT:
        setAlignment(Element.ALIGN_LEFT);
        break;
    case RIGHT:
        setAlignment(Element.ALIGN_RIGHT);
        break;

    case CENTER:
        setAlignment(Element.ALIGN_CENTER);
        break;

    case BOTH:
        setAlignment(Element.ALIGN_JUSTIFIED);
        break;

    default:
        break;
    }

}

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

License:Open Source License

/**
 * Creates a PDF Paragraph with the appropriate
 * alignment and the default leading and correct font.
 *
 * @param content The Chunk that goes into the Paragraph.
 * @return The resulting PDF Paragraph object.
 *///  w w w  .  ja  v  a2 s. co  m
public Paragraph createParagraph(Chunk content) {
    Paragraph result = new Paragraph(getLeading(), content);

    if (isCentered())
        result.setAlignment(Element.ALIGN_CENTER);
    if (isRight())
        result.setAlignment(Element.ALIGN_RIGHT);

    return result;
}

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

License:Open Source License

/**
 * Returns the Element constant associated with the specified horizontal
 * alignment (left, right, center, justified).
 *///from  w  ww  . j  a v a 2 s  . co m
public static int getAlignment(String htmlAlignString, int defaultAlign) {
    if (htmlAlignString == null)
        return defaultAlign;

    if ("center".equalsIgnoreCase(htmlAlignString))
        return Element.ALIGN_CENTER;
    if ("right".equalsIgnoreCase(htmlAlignString))
        return Element.ALIGN_RIGHT;
    if ("left".equalsIgnoreCase(htmlAlignString))
        return Element.ALIGN_LEFT;
    if ("justify".equalsIgnoreCase(htmlAlignString))
        return Element.ALIGN_JUSTIFIED;

    return defaultAlign;
}

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

License:Open Source License

/**
 * This method is used for add the main information table of project summary
 *//*ww w.j  a  va  2  s  . c  o m*/
private void addMainInformationTable() {

    String startDate, endDate;
    if (project.getStartDate() != null) {
        startDate = new SimpleDateFormat("dd-MM-yyyy").format(project.getStartDate());
    } else {
        startDate = this.messageReturn(null);
    }

    if (project.getEndDate() != null) {
        endDate = new SimpleDateFormat("dd-MM-yyyy").format(project.getEndDate());
    } else {
        endDate = this.messageReturn(null);
    }

    Paragraph cellContent;

    // Add content
    try {
        PdfPTable table = new PdfPTable(4);

        // Set table widths
        table.setLockedWidth(true);
        table.setTotalWidth(480);
        table.setWidths(new int[] { 3, 5, 3, 5 });

        // First row
        cellContent = new Paragraph(this.getText("summaries.project.startDate") + "\n" + " (dd-MM-yyyy)",
                TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0);

        cellContent = new Paragraph(this.messageReturn(startDate), TABLE_BODY_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0);

        cellContent = new Paragraph(this.getText("summaries.project.endDate") + "\n" + " (dd-MM-yyyy)",
                TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0);

        cellContent = new Paragraph(this.messageReturn(endDate), TABLE_BODY_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0);

        // Second row
        cellContent = new Paragraph(this.getText("summaries.project.managementLiaison"), TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1);

        cellContent = new Paragraph(this.messageReturn(project.getLiaisonInstitution().getAcronym() + " - "
                + project.getLiaisonInstitution().getName()), TABLE_BODY_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1);

        cellContent = new Paragraph(this.getText("summaries.project.contactPerson"), TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1);

        cellContent = new Paragraph(this.messageReturn(project.getOwner().getComposedName()), TABLE_BODY_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1);

        // Third row
        cellContent = new Paragraph(this.getText("summaries.project.leadOrganization"), TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0);
        if (project.getLeader() == null || project.getLeader().getInstitution() == null) {
            cellContent = new Paragraph(this.getText("summaries.project.empty"), TABLE_BODY_FONT);
        } else {
            cellContent = new Paragraph(
                    this.messageReturn(
                            this.messageReturn(project.getLeader().getInstitution().getComposedName())),
                    TABLE_BODY_FONT);

        }
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0);

        cellContent = new Paragraph(this.getText("summaries.project.projectLeader"), TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0);
        if (project.getLeaderPerson() == null || project.getLeaderPerson().getUser() == null) {
            cellContent = new Paragraph(this.getText("summaries.project.empty"), TABLE_BODY_FONT);
        } else {
            cellContent = new Paragraph(
                    this.messageReturn(project.getLeaderPerson().getUser().getComposedName()), TABLE_BODY_FONT);
        }

        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0);

        // Fourth row
        cellContent = (new Paragraph(this.getText("summaries.project.projectType"), TABLE_BODY_BOLD_FONT));
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1);

        cellContent = new Paragraph(this.messageReturn(project.getType().replaceAll("_", " ")),
                TABLE_BODY_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1);

        // Fiveth row
        Chunk imdb = null;
        Font hyperLink = new Font(FontFactory.getFont("openSans", 10, Color.BLUE));
        hyperLink.setStyle(Font.UNDERLINE);

        // -- Not Bilateral
        if (!project.isBilateralProject()) {
            cellContent = (new Paragraph(this.getText("summaries.project.detailed"), TABLE_BODY_BOLD_FONT));
            this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1);

            if (project.getWorkplanName() != null && !project.getWorkplanName().equals("")) {
                imdb = new Chunk(project.getWorkplanName(), hyperLink);
                try {
                    imdb.setAction(new PdfAction(new URL(this.messageReturn(project.getWorkplanURL()))));
                } catch (MalformedURLException exp) {
                    imdb = new Chunk(project.getWorkplanName(), TABLE_BODY_FONT);
                    LOG.error("There is an Malformed exception in " + project.getWorkplanName());
                }
            } else {
                imdb = new Chunk(this.getText("summaries.project.empty"), TABLE_BODY_FONT);
            }
        }

        // -- Bilateral
        else {
            cellContent = (new Paragraph(this.getText("summaries.project.ipContributions.proposal.space"),
                    TABLE_BODY_BOLD_FONT));
            this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1);

            if (project.getBilateralContractProposalName() != null
                    && !project.getBilateralContractProposalName().equals("")) {
                imdb = new Chunk(project.getBilateralContractProposalName(), hyperLink);
                try {
                    imdb.setAction(new PdfAction(new URL(this.messageReturn(project.getWorkplanURL()))));
                } catch (MalformedURLException exp) {
                    imdb = new Chunk(project.getBilateralContractProposalName(), TABLE_BODY_FONT);
                    LOG.error("There is an Malformed exception in bilateral contract: "
                            + project.getBilateralContractProposalName());
                }
            } else {
                imdb = new Chunk(this.getText("summaries.project.empty"), TABLE_BODY_FONT);
            }
        }

        cellContent = new Paragraph();
        cellContent.add(imdb);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1);

        document.add(table);
        document.add(Chunk.NEWLINE);
    } catch (DocumentException e) {
        LOG.error(
                "-- generatePdf() > There was an error adding the table with content for case study summary. ",
                e);
    }
}

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  ww w. ja v a  2s  .  c  o m*/
    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

/**
 * @param year year of Budget//from w  w  w . j a v a 2s  .co m
 * @param cell cell of tge table
 * @param table table for to represent the budget MOG
 * @param mog MOG to calculate the budget
 * @param budgetType type budget
 */
private void addBudgetMogByYear(int year, Paragraph cell, PdfPTable table, IPElement mog, BudgetType budgetType,
        double[] totalsByYear) {

    List<OutputBudget> listOutputBudgets = new ArrayList<>();

    listOutputBudgets = budgetByMogManager.getProjectOutputsBudgetByTypeAndYear(project.getId(),
            budgetType.getValue(), year);
    OutputBudget budget_temp = this.getOutputBudgetByMog(listOutputBudgets, mog);

    cell = new Paragraph();
    cell.setFont(TABLE_BODY_FONT);

    if (budget_temp == null) {

        // amount
        cell.add(this.genderFormatter.format(0));
        this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

        cell = new Paragraph();
        cell.setFont(TABLE_BODY_FONT);
        cell.add(budgetFormatter.format(0));
        this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

        // gender
        cell = new Paragraph();
        cell.setFont(TABLE_BODY_FONT);
        cell.add(genderFormatter.format(0));
        this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

        cell = new Paragraph();
        cell.setFont(TABLE_BODY_FONT);
        cell.add(budgetFormatter.format(0));
        this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

    } else {
        double value = budget_temp.getTotalContribution() * 0.01;
        // amount %
        cell = new Paragraph();
        cell.setFont(TABLE_BODY_FONT);
        cell.add(genderFormatter.format(value));
        this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

        // amoun $
        cell = new Paragraph();
        cell.setFont(TABLE_BODY_FONT);
        value = budget_temp.getTotalContribution() * 0.01 * budgetManager
                .calculateProjectBudgetByTypeAndYear(project.getId(), budgetType.getValue(), year);
        cell.add(budgetFormatter.format(value));
        this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
        totalsByYear[0] += value;

        // Gender %
        cell = new Paragraph();
        cell.setFont(TABLE_BODY_FONT);
        cell.add(this.genderFormatter.format(budget_temp.getGenderContribution() * 0.01));
        this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

        cell = new Paragraph();
        cell.setFont(TABLE_BODY_FONT);

        cell = new Paragraph();
        // Gender $
        cell.setFont(TABLE_BODY_FONT);
        value = budget_temp.getGenderContribution() * 0.01 * budgetManager
                .calculateGenderBudgetByTypeAndYear(project.getId(), budgetType.getValue(), year);
        cell.add(budgetFormatter.format(value));
        this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
        totalsByYear[1] += value;
    }

}

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;// w ww .  j  a  va2  s.  co 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);
}

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

License:Open Source License

/**
 * This Method is for to calculate the overall or gender summary
 * /*from   w w  w.ja v  a  2s  . co m*/
 * @param startYear start year to calculate the summary
 * @param endYear end year to calculate the summary
 * @param type this is used for to determinate the type the report to create
 */
private void addBudgetsSummaryByPartners(int startYear, int endYear, int typeSummary) {

    try {
        Paragraph cell;
        if (typeSummary == 0) {
            cell = new Paragraph(this.getText("summaries.project.budget.summary", new String[] { "Overall" }),
                    BODY_TEXT_BOLD_FONT);
        } else {
            cell = new Paragraph(this.getText("summaries.project.budget.summary", new String[] { "Gender" }),
                    BODY_TEXT_BOLD_FONT);
        }
        PdfPTable table;
        if (project.isCoFundedProject()) {
            table = new PdfPTable(4);
            table.setWidths(new int[] { 2, 3, 3, 3 });
        } else {
            table = new PdfPTable(2);
            table.setWidths(new int[] { 3, 3 });
        }

        table.setLockedWidth(true);
        table.setTotalWidth(400);

        table.setHeaderRows(1);

        // Add cell with the name summary
        this.addCustomTableCell(table, cell, Element.ALIGN_CENTER, BODY_TEXT_BOLD_FONT, Color.WHITE,
                table.getNumberOfColumns(), 0, false);

        cell = new Paragraph(this.getText("summaries.project.budget.overall.type"), TABLE_HEADER_FONT);
        this.addTableHeaderCell(table, cell);

        if (project.isCoFundedProject()) {

            if (typeSummary == 0) {
                cell = new Paragraph(
                        this.getText("summaries.project.budget.overall.text",
                                new String[] { BudgetType.W1_W2.name().replace("_", "/") }) + "(USD)",
                        TABLE_HEADER_FONT);
                this.addTableHeaderCell(table, cell);

                cell = new Paragraph(
                        this.getText("summaries.project.budget.overall.text",
                                new String[] { BudgetType.W3_BILATERAL.name().replace("_", "/") }) + "(USD)",
                        TABLE_HEADER_FONT);
            } else {
                cell = new Paragraph(
                        this.getText("summaries.project.budget.overall.gender",
                                new String[] { BudgetType.W1_W2.name().replace("_", "/") }) + "(USD)",
                        TABLE_HEADER_FONT);
                this.addTableHeaderCell(table, cell);

                cell = new Paragraph(
                        this.getText("summaries.project.budget.overall.gender",
                                new String[] { BudgetType.W3_BILATERAL.name().replace("_", "/") }) + "(USD)",
                        TABLE_HEADER_FONT);
            }
            this.addTableHeaderCell(table, cell);

            // Total column
            cell = new Paragraph(this.getText("summaries.project.budget.overall.total") + " (USD)",
                    TABLE_HEADER_FONT);
            this.addTableHeaderCell(table, cell);
        }

        else {

            if (typeSummary == 0) {
                cell = new Paragraph(
                        this.getText("summaries.project.budget.overall.text",
                                new String[] { this.getBudgetType().name().replace("_", "/") }) + "(USD)",
                        TABLE_HEADER_FONT);
            } else {
                cell = new Paragraph(
                        this.getText("summaries.project.budget.overall.gender",
                                new String[] { this.getBudgetType().name().replace("_", "/") }) + "(USD)",
                        TABLE_HEADER_FONT);
            }
            this.addTableHeaderCell(table, cell);
        }

        double value, valueSum;
        value = 0.0;

        for (int year = startYear; year <= endYear; year++) {
            cell = new Paragraph(String.valueOf(year), TABLE_BODY_BOLD_FONT);
            this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 0);

            valueSum = 0.0;

            if (project.isCoFundedProject()) {
                if (typeSummary == 0) {
                    // amount w1/w2
                    value = this.budgetManager.calculateProjectBudgetByTypeAndYear(project.getId(),
                            BudgetType.W1_W2.getValue(), year);
                    cell = new Paragraph(this.budgetFormatter.format(value), TABLE_BODY_FONT);
                    ;
                    this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
                    valueSum = value;

                    // amount w3/Bilateral
                    value = this.budgetManager.calculateProjectBudgetByTypeAndYear(project.getId(),
                            BudgetType.W3_BILATERAL.getValue(), year);

                } else {

                    // gender w1/w2
                    value = this.budgetManager.calculateGenderBudgetByTypeAndYear(project.getId(),
                            BudgetType.W1_W2.getValue(), year);
                    cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_FONT);
                    ;
                    this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
                    valueSum = value;

                    // gender w3/Bilateral
                    value = this.budgetManager.calculateGenderBudgetByTypeAndYear(project.getId(),
                            BudgetType.W3_BILATERAL.getValue(), year);
                }

                cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_FONT);
                ;
                this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

                // Total
                valueSum += value;
                cell = new Paragraph(budgetFormatter.format(valueSum), TABLE_BODY_FONT);
                this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

            } else {
                if (typeSummary == 0) {
                    // amount w1/w2
                    value = this.budgetManager.calculateProjectBudgetByTypeAndYear(project.getId(),
                            this.getBudgetType().getValue(), year);
                    cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_FONT);
                    ;
                    this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

                } else {

                    // gender w1/w2
                    value = this.budgetManager.calculateGenderBudgetByTypeAndYear(project.getId(),
                            this.getBudgetType().getValue(), year);
                    cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_FONT);
                    ;
                    this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

                }
            }
        }

        // ********************** Totals *************

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

        if (project.isCoFundedProject()) {

            if (typeSummary == 0) {
                value = budgetManager.calculateTotalCCAFSBudgetByType(project.getId(),
                        BudgetType.W1_W2.getValue());
                cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT);
                this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
                valueSum = value;

                value = budgetManager.calculateTotalCCAFSBudgetByType(project.getId(),
                        BudgetType.W3_BILATERAL.getValue());
                cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT);
                this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
                valueSum += value;
            } else {

                value = budgetManager.calculateTotalGenderPercentageByType(project.getId(),
                        BudgetType.W1_W2.getValue());
                cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT);
                this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
                valueSum = value;

                value = budgetManager.calculateTotalGenderPercentageByType(project.getId(),
                        BudgetType.W3_BILATERAL.getValue());
                cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT);
                this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
                valueSum += value;
            }

            // Total
            cell = new Paragraph(budgetFormatter.format(valueSum), TABLE_BODY_BOLD_FONT);
            this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
        }

        else {
            if (typeSummary == 0) {
                value = budgetManager.calculateTotalCCAFSBudgetByType(project.getId(),
                        this.getBudgetType().getValue());
            } else {
                value = budgetManager.calculateTotalGenderPercentageByType(project.getId(),
                        this.getBudgetType().getValue());
            }

            cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT);
            this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
            valueSum = value;
        }
        document.add(table);
        cell = new Paragraph(Chunk.NEWLINE);
        document.add(cell);

    } catch (DocumentException e) {
        LOG.error(
                "-- generatePdf() > There was an error adding the table with content for case study summary. ",
                e);
    }
}

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

License:Open Source License

/**
 * @param paragraph paragraph for write/*from  www .  j  a v  a2  s. c  o  m*/
 * @param institution PPA to calculate your budget
 * @param startYear start year
 * @param endYear end year to calculate
 * @param table table to represent the budget
 * @param budgetType budget type
 * @return
 */
private void addRowBudgetByPartners(Paragraph paragraph, Institution institution, int year, PdfPTable table,
        BudgetType budgetType) {

    Budget budget;

    budget = project.getBudget(institution.getId(), budgetType.getValue(), year);
    if (budget == null) {
        // Annual budget
        paragraph = new Paragraph(this.budgetFormatter.format(0.0), TABLE_BODY_FONT);
        this.addTableBodyCell(table, paragraph, Element.ALIGN_RIGHT, 1);

        // gender percentage (%)
        paragraph = new Paragraph(this.genderFormatter.format(0), TABLE_BODY_FONT);
        this.addTableBodyCell(table, paragraph, Element.ALIGN_RIGHT, 1);

        // gender percentage (USD)
        paragraph = new Paragraph(budgetFormatter.format(0.0), TABLE_BODY_FONT);
        budget = null;
    } else {

        // Annual budget
        paragraph = new Paragraph(budgetFormatter.format(budget.getAmount()), TABLE_BODY_FONT);
        this.addTableBodyCell(table, paragraph, Element.ALIGN_RIGHT, 1);

        // gender percentage
        paragraph = new Paragraph(genderFormatter.format(budget.getGenderPercentage() * 0.01), TABLE_BODY_FONT);
        this.addTableBodyCell(table, paragraph, Element.ALIGN_RIGHT, 1);

        paragraph = new Paragraph(
                budgetFormatter.format(budget.getAmount() * budget.getGenderPercentage() * 0.01),
                TABLE_BODY_FONT);
        budget = null;
    }
    this.addTableBodyCell(table, paragraph, Element.ALIGN_RIGHT, 1);
}