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:org.revager.export.ProtocolPDFExporter.java

License:Open Source License

/**
 * Writes the given meeting to the protocol.
 * //from   w w w .j ava 2  s . c o m
 * @param meeting
 *            the meeting
 * @param attachExtRefs
 *            true if the external references should be part of the protocol
 * @param showSignatureFields
 *            true, if the signature fields should be part of the protocol
 * 
 * @throws ExportException
 *             If an error occurs while writing the meeting
 */
protected void writeMeeting(Meeting meeting, boolean attachExtRefs, boolean showSignatureFields)
        throws ExportException {
    Protocol protocol = meeting.getProtocol();

    if (protocol != null) {
        try {
            Font plainFont = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

            Font boldFont = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

            Font italicFont = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

            Font boldItalicFont = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED),
                    10);

            Font boldFontTitle = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 17);

            Font italicFontTitle = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 13);

            /*
             * Base table for the meeting properties
             */
            PdfPTable tableMeeting = new PdfPTable(2);
            tableMeeting.setWidthPercentage(100);
            tableMeeting.setSplitRows(false);
            tableMeeting.getDefaultCell().setBorderWidth(0);
            tableMeeting.getDefaultCell().setPadding(0);

            /*
             * Write date, time and location of the meeting
             */
            String meetingDate = sdfDate.format(protocol.getDate().getTime());

            String meetingTime = sdfTime.format(protocol.getStart().getTime()) + " - "
                    + sdfTime.format(protocol.getEnd().getTime()) + " ["
                    + protocol.getEnd().getTimeZone().getDisplayName() + "]";

            Anchor anchorTitle = new Anchor(translate("Review Meeting on") + " " + meetingDate, boldFontTitle);
            anchorTitle.setName(Long
                    .toString(protocol.getDate().getTimeInMillis() + protocol.getStart().getTimeInMillis()));

            PdfPCell cellTitle = new PdfPCell(anchorTitle);
            cellTitle.setColspan(2);
            cellTitle.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellTitle.setPadding(0);
            cellTitle.setBorderWidth(0);
            cellTitle.setPaddingTop(PDFTools.cmToPt(0.6f));
            cellTitle.setPaddingBottom(padding * 2);

            tableMeeting.addCell(cellTitle);

            PdfPCell cellTime = new PdfPCell(new Phrase(meetingTime, italicFontTitle));
            cellTime.setColspan(2);
            cellTime.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellTime.setPadding(0);
            cellTime.setBorderWidth(0);
            cellTime.setPaddingBottom(padding * 2);

            tableMeeting.addCell(cellTime);

            String location = protocol.getLocation();

            if (location.trim().equals("")) {
                location = "--";
            }

            PdfPCell cellLocation = new PdfPCell(
                    new Phrase(translate("Location") + ": " + location, italicFontTitle));
            cellLocation.setColspan(2);
            cellLocation.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellLocation.setPadding(0);
            cellLocation.setBorderWidth(0);
            cellLocation.setPaddingBottom(PDFTools.cmToPt(1.5f));

            tableMeeting.addCell(cellLocation);

            /*
             * Compare with planned meeting
             */
            PdfPCell cellPlanned;

            boolean plannedDateEqualsProtocolDate = meeting.getPlannedDate()
                    .get(Calendar.DAY_OF_MONTH) == protocol.getDate().get(Calendar.DAY_OF_MONTH)
                    && meeting.getPlannedDate().get(Calendar.MONTH) == protocol.getDate().get(Calendar.MONTH)
                    && meeting.getPlannedDate().get(Calendar.YEAR) == protocol.getDate().get(Calendar.YEAR);
            boolean plannedStartEqualsProtocolStart = meeting.getPlannedStart().get(Calendar.HOUR) == protocol
                    .getStart().get(Calendar.HOUR)
                    && meeting.getPlannedStart().get(Calendar.MINUTE) == protocol.getStart()
                            .get(Calendar.MINUTE)
                    && meeting.getPlannedStart().get(Calendar.AM_PM) == protocol.getStart().get(Calendar.AM_PM);
            boolean plannedEndEqualsProtocolEnd = meeting.getPlannedEnd().get(Calendar.HOUR) == protocol
                    .getEnd().get(Calendar.HOUR)
                    && meeting.getPlannedEnd().get(Calendar.MINUTE) == protocol.getEnd().get(Calendar.MINUTE)
                    && meeting.getPlannedEnd().get(Calendar.AM_PM) == protocol.getEnd().get(Calendar.AM_PM);
            boolean plannedLocationEqualsProtocolLocation = meeting.getPlannedLocation()
                    .equals(protocol.getLocation());

            if (plannedDateEqualsProtocolDate && plannedStartEqualsProtocolStart && plannedEndEqualsProtocolEnd
                    && plannedLocationEqualsProtocolLocation) {
                cellPlanned = new PdfPCell(
                        new Phrase(translate("The meeting took place as it has been planned."), plainFont));
            } else {
                cellPlanned = new PdfPCell();

                cellPlanned.addElement(new Phrase(translate(
                        "The meeting didn't take place as it has been planned. The meeting was planned:"),
                        plainFont));

                /*
                 * Planned date, time and location
                 */
                String plannedDate = sdfDate.format(meeting.getPlannedDate().getTime());

                String plannedTime = sdfTime.format(meeting.getPlannedStart().getTime()) + " - "
                        + sdfTime.format(meeting.getPlannedEnd().getTime()) + " ["
                        + meeting.getPlannedEnd().getTimeZone().getDisplayName() + "]";

                Phrase phrasePlanned = new Phrase(plannedDate + " (" + plannedTime + "); "
                        + translate("Location") + ": " + meeting.getPlannedLocation(), italicFont);

                cellPlanned.addElement(phrasePlanned);
            }

            cellPlanned.setColspan(2);
            cellPlanned.setBorderWidth(0);
            cellPlanned.setPadding(padding);
            cellPlanned.setPaddingBottom(PDFTools.cmToPt(1.5f));

            tableMeeting.addCell(cellPlanned);

            /*
             * Comments of the meeting and protocol
             */
            Phrase phraseComments = new Phrase(translate("Comments on the Meeting:"), boldFont);
            PdfPCell cellComments = new PdfPCell(phraseComments);
            cellComments.setBorderWidth(0);
            cellComments.setPadding(padding);
            cellComments.setBorderColor(verticalBorderColor);
            cellComments.setBorderWidthLeft(verticalBorderWidth);

            tableMeeting.addCell(cellComments);

            phraseComments = new Phrase(translate("Comments on the Findings List:"), boldFont);
            cellComments = new PdfPCell(phraseComments);
            cellComments.setBorderWidth(0);
            cellComments.setPadding(padding);
            cellComments.setBorderColor(verticalBorderColor);
            cellComments.setBorderWidthLeft(verticalBorderWidth);

            tableMeeting.addCell(cellComments);

            String meetingComments = meeting.getComments();
            if (meetingComments.trim().equals("")) {
                meetingComments = "--";
            }

            phraseComments = new Phrase(meetingComments, italicFont);
            phraseComments.setLeading(leading);
            cellComments = new PdfPCell();
            cellComments.addElement(phraseComments);
            cellComments.setBorderWidth(0);
            cellComments.setPadding(padding);
            cellComments.setPaddingBottom(padding * 1.8f);
            cellComments.setBorderColor(verticalBorderColor);
            cellComments.setBorderWidthLeft(verticalBorderWidth);

            tableMeeting.addCell(cellComments);

            String protocolComments = protocol.getComments();
            if (protocolComments.trim().equals("")) {
                protocolComments = "--";
            }

            phraseComments = new Phrase(protocolComments, italicFont);
            phraseComments.setLeading(leading);
            cellComments = new PdfPCell();
            cellComments.addElement(phraseComments);
            cellComments.setBorderWidth(0);
            cellComments.setPadding(padding);
            cellComments.setPaddingBottom(padding * 1.8f);
            cellComments.setBorderColor(verticalBorderColor);
            cellComments.setBorderWidthLeft(verticalBorderWidth);

            tableMeeting.addCell(cellComments);

            /*
             * Strut cell
             */
            tableMeeting.addCell(createVerticalStrut(PDFTools.cmToPt(1.3f), 2));

            /*
             * Write attendees
             */
            if (protMgmt.getAttendees(protocol).size() > 0) {
                PdfPCell cellAtt = new PdfPCell(new Phrase(
                        translate("The following attendees participated") + " ("
                                + protMgmt.getAttendees(protocol).size() + " " + translate("attendees") + "):",
                        boldItalicFont));
                cellAtt.setColspan(2);
                cellAtt.setPadding(0);
                cellAtt.setBorderWidth(0);
                cellAtt.setPadding(padding);
                cellAtt.setPaddingBottom(PDFTools.cmToPt(0.8f));

                tableMeeting.addCell(cellAtt);
            }

            pdfDoc.add(tableMeeting);

            if (protMgmt.getAttendees(protocol).size() > 0) {
                writeAttendees(protocol, true, true, showSignatureFields);
            }

            /*
             * If there isn't any finding, finish the export here.
             */
            if (findMgmt.getNumberOfFindings(protocol) == 0) {
                return;
            } else if (findMgmt.getNumberOfFindings(protocol) == 1) {
                Finding find = findMgmt.getFindings(protocol).get(0);

                if (find.getDescription().trim().equals("") && find.getExternalReferences().size() == 0
                        && find.getReferences().size() == 0 && find.getAspects().size() == 0) {
                    return;
                }
            }

            /*
             * Write findings
             */
            pdfDoc.newPage();

            PdfPTable tableFindIntro = new PdfPTable(1);
            tableFindIntro.setWidthPercentage(100);

            Phrase phraseFindIntro = new Phrase(
                    translate("The following findings were recorded by the participating reviewers") + " ("
                            + findMgmt.getNumberOfFindings(protocol) + " " + translate("findings") + "): ",
                    boldItalicFont);
            phraseFindIntro.setLeading(leading);

            PdfPCell cellFindIntro = new PdfPCell();
            cellFindIntro.addElement(phraseFindIntro);
            cellFindIntro.setBorderWidth(0);
            cellFindIntro.setPadding(0);
            cellFindIntro.setPaddingBottom(PDFTools.cmToPt(0.1f));

            tableFindIntro.addCell(cellFindIntro);

            pdfDoc.add(tableFindIntro);

            writeFindings(protocol, attachExtRefs);
        } catch (Exception e) {
            /*
             * Not part of unit testing because this exception is only
             * thrown if an internal error occurs.
             */
            throw new ExportException(translate("Cannot put the selected review meeting in the PDF document."));
        }
    }
}

From source file:org.revager.export.ProtocolPDFExporter.java

License:Open Source License

/**
 * Writes the given attendees to the protocol.
 * /*from ww w. j ava 2  s  .c o  m*/
 * @param protocol
 *            the protocol
 * @param showAttendeesAspects
 *            true, if the aspects of the reviewers should be part of the
 *            protocol
 * @param showAttendeesPrepTime
 *            true, if the preparation time of the reviewers should be part
 *            of the protocol
 * @param showSignatureFields
 *            ture, if the signature fields should be part of the protocol
 * 
 * @throws ExportException
 *             If an error occurs while writing the attendees to the
 *             protocol
 */
protected void writeAttendees(Protocol protocol, boolean showAttendeesAspects, boolean showAttendeesPrepTime,
        boolean showSignatureFields) throws ExportException {
    List<Attendee> atts;

    if (protocol != null) {
        atts = protMgmt.getAttendees(protocol);
    } else {
        atts = Application.getInstance().getAttendeeMgmt().getAttendees();
    }

    /*
     * Sort the attendees by their role into different lists
     */
    List<Attendee> reviewers = new ArrayList<Attendee>();
    List<Attendee> moderators = new ArrayList<Attendee>();
    List<Attendee> scribes = new ArrayList<Attendee>();
    List<Attendee> authors = new ArrayList<Attendee>();
    List<Attendee> customers = new ArrayList<Attendee>();
    List<Attendee> others = new ArrayList<Attendee>();

    for (Attendee att : atts) {
        switch (att.getRole()) {
        case AUTHOR:
            authors.add(att);
            break;
        case CUSTOMER:
            customers.add(att);
            break;
        case MODERATOR:
            moderators.add(att);
            break;
        case REVIEWER:
            reviewers.add(att);
            break;
        case SCRIBE:
            scribes.add(att);
            break;
        default:
            others.add(att);
            break;
        }
    }

    List<List<Attendee>> attendees = new ArrayList<List<Attendee>>();
    attendees.add(moderators);
    attendees.add(scribes);
    attendees.add(authors);
    attendees.add(customers);
    attendees.add(reviewers);
    attendees.add(others);

    /*
     * Write attendees
     */
    try {
        Font contactFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED),
                10);

        Font nameFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        Font roleFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        Font aspectsFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 8);

        Font aspectsTitleFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 8);

        /*
         * Build base table for all attendees
         */
        PdfPTable tableAttendees = new PdfPTable(1);
        tableAttendees.setWidthPercentage(100);
        tableAttendees.setSplitRows(false);
        tableAttendees.getDefaultCell().setBorderWidth(0);
        tableAttendees.getDefaultCell().setPadding(0);

        boolean grayBackground = true;

        for (List<Attendee> attList : attendees) {
            for (Attendee att : attList) {
                /*
                 * Build table for one attendee
                 */
                PdfPTable tableAttendee = new PdfPTable(new float[] { 0.80f, 0.20f });
                tableAttendee.setWidthPercentage(100);
                tableAttendee.getDefaultCell().setBorderWidth(0);
                tableAttendee.getDefaultCell().setPadding(0);

                PdfPCell cellAttendee = new PdfPCell();
                cellAttendee.setPadding(0);
                cellAttendee.setBorder(0);

                /*
                 * Name of the attendee
                 */
                PdfPCell cell = new PdfPCell();
                cell.setBorderWidth(0);
                cell.setPadding(padding * 0.4f);
                cell.setPaddingBottom(padding * 1.5f);
                cell.addElement(new Phrase(att.getName(), nameFont));
                cell.addElement(new Phrase(att.getContact(), contactFont));

                Phrase phraseStrut = new Phrase(" ");
                phraseStrut.setLeading(leading * 0.6f);

                /*
                 * Aspects of this attendee
                 */
                if (!attMgmt.getAspects(att).isEmpty() && showAttendeesAspects) {
                    String separator = "";

                    cell.addElement(phraseStrut);

                    cell.addElement(new Phrase(translate("Assigned aspects:") + " ", aspectsTitleFont));

                    Phrase phraseAspects = new Phrase();
                    phraseAspects.setLeading(leading);
                    phraseAspects.setFont(aspectsFont);

                    for (Aspect asp : attMgmt.getAspects(att)) {
                        phraseAspects.add(new Chunk(
                                separator + asp.getDirective() + " (" + asp.getCategory() + ")", aspectsFont));

                        separator = "    ";
                    }

                    cell.addElement(phraseAspects);
                }

                /*
                 * Preparation time of the attendee
                 */
                Duration prepTime;
                if (protocol != null) {
                    prepTime = protMgmt.getAttendeePrepTime(att, protocol);
                } else {
                    prepTime = null;
                }

                if (prepTime != null && showAttendeesPrepTime) {
                    cell.addElement(phraseStrut);

                    cell.addElement(new Phrase(translate("Preparation time:") + " ", aspectsTitleFont));

                    Phrase phrasePrepTime = new Phrase();
                    phrasePrepTime.setLeading(leading);
                    phrasePrepTime.setFont(aspectsFont);

                    String prep = "";
                    String separator = "";

                    if (prepTime.getDays() > 0) {
                        prep = prep + prepTime.getDays() + " " + translate("Day(s)");

                        separator = ", ";
                    }

                    if (prepTime.getHours() > 0) {
                        prep = prep + separator + prepTime.getHours() + " " + translate("Hour(s)");

                        separator = ", ";
                    }

                    if (prepTime.getMinutes() >= 0) {
                        prep = prep + separator + prepTime.getMinutes() + " " + translate("Minute(s)");

                        separator = ", ";
                    }

                    phrasePrepTime.add(new Chunk(prep, aspectsFont));

                    cell.addElement(phrasePrepTime);
                }

                /*
                 * Signature field for the attendee
                 */
                if (showSignatureFields) {
                    cell.addElement(phraseStrut);
                    cell.addElement(phraseStrut);
                    cell.addElement(phraseStrut);
                    cell.addElement(phraseStrut);

                    cell.addElement(new Phrase("________________________________________", aspectsFont));

                    cell.addElement(
                            new Phrase(translate("Date, Signature") + " (" + att.getName() + ")", aspectsFont));
                }

                tableAttendee.addCell(cell);

                /*
                 * role of the attendee
                 */
                cell = new PdfPCell(new Phrase(translate(att.getRole().toString()), roleFont));
                cell.setBorderWidth(0);
                cell.setPadding(padding * 0.4f);
                cell.setPaddingTop(padding * 1.1f);
                cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

                tableAttendee.addCell(cell);

                cellAttendee.addElement(tableAttendee);
                cellAttendee.setPadding(0);
                cellAttendee.setPaddingLeft(padding);
                cellAttendee.setPaddingRight(padding);

                if (grayBackground == true) {
                    grayBackground = false;
                    cellAttendee.setBackgroundColor(cellBackground);
                } else {
                    grayBackground = true;
                }

                /*
                 * Add attendee to the list
                 */
                tableAttendees.addCell(cellAttendee);
            }
        }

        PdfPCell cellBottomLine = new PdfPCell();
        cellBottomLine.setPadding(0);
        cellBottomLine.setBorderWidth(0);
        cellBottomLine.setBorderWidthBottom(1);
        cellBottomLine.setBorderColor(cellBackground);

        tableAttendees.addCell(cellBottomLine);

        /*
         * Add the attendee base table to the document
         */
        pdfDoc.add(tableAttendees);
    } catch (Exception e) {
        /*
         * Not part of unit testing because this exception is only thrown if
         * an internal error occurs.
         */
        throw new ExportException(translate("Cannot put attendees into the PDF document."));
    }
}

From source file:org.revager.export.ProtocolPDFExporter.java

License:Open Source License

/**
 * Write the findings to the protocol.//ww w. j  a va2 s.co m
 * 
 * @param protocol
 *            the protocol
 * @param attachExtRefs
 *            true if the external references should be part of the protocol
 * 
 * @throws ExportException
 *             If an error occurs while writing the findings to the protocol
 */
protected void writeFindings(Protocol protocol, boolean attachExtRefs) throws ExportException {
    try {
        /*
         * Define fonts
         */
        Font plainFontTitle = new Font(
                BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 9, Font.NORMAL,
                Color.WHITE);

        Font boldFontTitle = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10,
                Font.NORMAL, Color.WHITE);

        Font plainFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED),
                10);

        Font boldFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        Font italicFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        Font boldItalicFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        /*
         * Write findings
         */
        PdfPTable tableBase = new PdfPTable(1);
        tableBase.setWidthPercentage(100);
        tableBase.setSplitRows(false);
        tableBase.getDefaultCell().setBorderWidth(0);
        tableBase.getDefaultCell().setPadding(0);

        for (Finding f : protocol.getFindings()) {
            tableBase.addCell(createVerticalStrut(PDFTools.cmToPt(0.7f), 1));
            PdfPCell cellFinding = new PdfPCell();
            cellFinding.setBorderColor(Color.GRAY);
            cellFinding.setBorderWidth(0.5f);

            PdfPTable tableTitle = new PdfPTable(3);
            tableTitle.setWidthPercentage(100);

            /*
             * Print title of the finding
             */
            Phrase phraseTitle = new Phrase(translate("Finding") + " " + f.getId(), boldFontTitle);

            PdfPCell cellTitle = new PdfPCell(phraseTitle);
            cellTitle.setBackgroundColor(bgColorTitle);
            cellTitle.setBorderWidth(0);
            cellTitle.setPadding(padding);
            cellTitle.setPaddingBottom(padding * 1.5f);
            cellTitle.setHorizontalAlignment(Element.ALIGN_LEFT);

            tableTitle.addCell(cellTitle);

            /*
             * Print severity of the finding
             */
            Phrase phraseSeverity = new Phrase(findMgmt.getLocalizedSeverity(f), plainFontTitle);

            PdfPCell cellSeverity = new PdfPCell(phraseSeverity);
            cellSeverity.setBackgroundColor(bgColorTitle);
            cellSeverity.setBorderWidth(0);
            cellSeverity.setPadding(padding);
            cellSeverity.setPaddingTop(padding * 1.1f);
            cellSeverity.setHorizontalAlignment(Element.ALIGN_CENTER);

            tableTitle.addCell(cellSeverity);

            /*
             * Print the meeting date and time of the finding
             */
            String meetingDate = sdfDate.format(protocol.getDate().getTime());

            PdfPCell cellMeeting = new PdfPCell(new Phrase(meetingDate, plainFontTitle));
            cellMeeting.setBackgroundColor(bgColorTitle);
            cellMeeting.setBorderWidth(0);
            cellMeeting.setPadding(padding);
            cellMeeting.setPaddingTop(padding * 1.1f);
            cellMeeting.setHorizontalAlignment(Element.ALIGN_RIGHT);

            tableTitle.addCell(cellMeeting);

            /*
             * Description
             */
            Phrase phraseDesc = new Phrase(f.getDescription(), plainFont);
            phraseDesc.setLeading(leading);

            PdfPCell cellDesc = new PdfPCell();
            cellDesc.addElement(phraseDesc);
            cellDesc.setBorderWidth(0);
            cellDesc.setPadding(padding);
            cellDesc.setColspan(3);

            tableTitle.addCell(cellDesc);

            cellFinding.addElement(tableTitle);

            /*
             * List point used for lists
             */
            Phrase phraseListPoint = new Phrase("", boldFont);
            phraseListPoint.setLeading(leading * 0.93f);

            PdfPCell cellListPoint = new PdfPCell();
            cellListPoint.addElement(phraseListPoint);
            cellListPoint.setBorderWidth(0);
            cellListPoint.setPadding(padding);
            cellListPoint.setPaddingLeft(padding * 2);

            /*
             * Table of references
             */
            if (f.getReferences().size() > 0
                    || (f.getExternalReferences().size() > 0 && attachExtRefs == true)) {
                PdfPTable tableRefs = new PdfPTable(new float[] { 0.04f, 0.96f });
                tableRefs.setWidthPercentage(100);

                PdfPCell cellRefTitle = new PdfPCell(new Phrase(translate("References:"), boldItalicFont));
                cellRefTitle.setBorderWidth(0);
                cellRefTitle.setPadding(padding);
                cellRefTitle.setPaddingTop(padding * 3);
                cellRefTitle.setPaddingBottom(0);
                cellRefTitle.setColspan(2);

                tableRefs.addCell(cellRefTitle);

                /*
                 * Textual references
                 */
                for (String ref : f.getReferences()) {
                    Phrase phraseRef = new Phrase(ref, plainFont);
                    phraseRef.setLeading(leading);

                    PdfPCell cellRef = new PdfPCell();
                    cellRef.addElement(phraseRef);
                    cellRef.setBorderWidth(0);
                    cellRef.setPadding(padding);

                    tableRefs.addCell(cellListPoint);

                    tableRefs.addCell(cellRef);
                }

                /*
                 * External file references
                 */
                if (attachExtRefs == true) {
                    for (File ref : findMgmt.getExtReferences(f)) {
                        Phrase phraseRef = new Phrase();
                        phraseRef.add(new Chunk(ref.getName(), plainFont));
                        phraseRef.add(new Chunk(" (" + translate("File Attachment") + ")", italicFont));
                        phraseRef.setFont(plainFont);
                        phraseRef.setLeading(leading);

                        PdfPCell cellRef = new PdfPCell();
                        cellRef.addElement(phraseRef);
                        cellRef.setBorderWidth(0);
                        cellRef.setPadding(padding);

                        tableRefs.addCell(cellListPoint);

                        cellRef.setCellEvent(new PDFCellEventExtRef(pdfWriter, ref));

                        tableRefs.addCell(cellRef);
                    }
                }

                cellFinding.addElement(tableRefs);
            }

            /*
             * Table of aspects
             */
            if (f.getAspects().size() > 0) {
                PdfPTable tableAspects = new PdfPTable(new float[] { 0.04f, 0.96f });
                tableAspects.setWidthPercentage(100);

                PdfPCell cellAspTitle = new PdfPCell(new Phrase(translate("Aspects:"), boldItalicFont));
                cellAspTitle.setBorderWidth(0);
                cellAspTitle.setPadding(padding);
                cellAspTitle.setPaddingTop(padding * 3);
                cellAspTitle.setPaddingBottom(0);
                cellAspTitle.setColspan(2);

                tableAspects.addCell(cellAspTitle);

                for (String asp : f.getAspects()) {
                    Phrase phraseAsp = new Phrase(asp, plainFont);
                    phraseAsp.setLeading(leading);

                    PdfPCell cellAsp = new PdfPCell();
                    cellAsp.addElement(phraseAsp);
                    cellAsp.setBorderWidth(0);
                    cellAsp.setPadding(padding);

                    tableAspects.addCell(cellListPoint);

                    tableAspects.addCell(cellAsp);
                }

                cellFinding.addElement(tableAspects);
            }

            /*
             * Vertical strut at the end of the table
             */
            PdfPTable tableStrut = new PdfPTable(1);
            tableStrut.setWidthPercentage(100);
            tableStrut.addCell(createVerticalStrut(padding, 1));

            cellFinding.addElement(tableStrut);

            tableBase.addCell(cellFinding);
        }

        pdfDoc.add(tableBase);
    } catch (Exception e) {
        /*
         * Not part of unit testing because this exception is only thrown if
         * an internal error occurs.
         */
        throw new ExportException(translate("Cannot put findings into the PDF document."));
    }
}

From source file:org.sonar.report.pdf.DefaultPDFReporter.java

License:Open Source License

private void printDashboard(Project project, Section section) throws DocumentException {
    PdfPTable dashboard = new PdfPTable(3);
    dashboard.getDefaultCell().setBorderColor(Color.WHITE);
    Font titleFont = new Font(Font.TIMES_ROMAN, 14, Font.BOLD, Color.BLACK);
    Font dataFont = new Font(Font.TIMES_ROMAN, 14, Font.BOLD, Color.GRAY);
    Font dataFont2 = new Font(Font.TIMES_ROMAN, 10, Font.BOLD, new Color(100, 150, 190));

    PdfPTable linesOfCode = new PdfPTable(1);
    linesOfCode.getDefaultCell().setBorderColor(Color.WHITE);
    linesOfCode.addCell(new Phrase(getTextProperty("general.lines_of_code"), titleFont));
    linesOfCode.addCell(new Phrase(project.getMeasure("ncss").getFormatValue(), dataFont));
    linesOfCode.addCell(//from   w  w w. jav a 2  s  .c o  m
            new Phrase(project.getMeasure("packages_count").getFormatValue() + " packages", dataFont2));
    linesOfCode
            .addCell(new Phrase(project.getMeasure("classes_count").getFormatValue() + " classes", dataFont2));
    linesOfCode.addCell(
            new Phrase(project.getMeasure("functions_count").getFormatValue() + " methods", dataFont2));
    linesOfCode.addCell(new Phrase(
            project.getMeasure("duplicated_lines_ratio").getFormatValue() + " duplicated lines", dataFont2));

    PdfPTable comments = new PdfPTable(1);
    comments.getDefaultCell().setBorderColor(Color.WHITE);
    comments.addCell(new Phrase(getTextProperty("general.comments"), titleFont));
    comments.addCell(new Phrase(project.getMeasure("comment_ratio").getFormatValue(), dataFont));
    comments.addCell(
            new Phrase(project.getMeasure("comment_lines").getFormatValue() + " comment lines", dataFont2));

    PdfPTable codeCoverage = new PdfPTable(1);
    codeCoverage.getDefaultCell().setBorderColor(Color.WHITE);
    codeCoverage.addCell(new Phrase(getTextProperty("general.test_count"), titleFont));
    codeCoverage.addCell(new Phrase(project.getMeasure("test_count").getFormatValue(), dataFont));
    codeCoverage.addCell(
            new Phrase(project.getMeasure("test_success_percentage").getFormatValue() + " success", dataFont2));
    codeCoverage
            .addCell(new Phrase(project.getMeasure("code_coverage").getFormatValue() + " coverage", dataFont2));

    PdfPTable complexity = new PdfPTable(1);
    complexity.getDefaultCell().setBorderColor(Color.WHITE);
    complexity.addCell(new Phrase(getTextProperty("general.complexity"), titleFont));
    complexity.addCell(new Phrase(project.getMeasure("ccn_function").getFormatValue(), dataFont));
    complexity.addCell(new Phrase(project.getMeasure("ccn_class").getFormatValue() + " /class", dataFont2));
    complexity.addCell(new Phrase(project.getMeasure("ccn").getFormatValue() + " decision points", dataFont2));

    PdfPTable rulesCompliance = new PdfPTable(1);
    rulesCompliance.getDefaultCell().setBorderColor(Color.WHITE);
    rulesCompliance.addCell(new Phrase(getTextProperty("general.rules_compliance"), titleFont));
    rulesCompliance.addCell(new Phrase(project.getMeasure("rules_compliance").getFormatValue(), dataFont));

    PdfPTable violations = new PdfPTable(1);
    violations.getDefaultCell().setBorderColor(Color.WHITE);
    violations.addCell(new Phrase(getTextProperty("general.violations"), titleFont));
    violations.addCell(new Phrase(project.getMeasure("rules_violations").getFormatValue(), dataFont));

    dashboard.addCell(linesOfCode);
    dashboard.addCell(comments);
    dashboard.addCell(codeCoverage);
    dashboard.addCell(complexity);
    dashboard.addCell(rulesCompliance);
    dashboard.addCell(violations);
    dashboard.setSpacingBefore(8);
    section.add(dashboard);
    Image ccnDistGraph = getCCNDistribution(project);
    if (ccnDistGraph != null) {
        section.add(ccnDistGraph);
        Paragraph imageFoot = new Paragraph(getTextProperty("metrics.ccn_classes_count_distribution"),
                Style.FOOT_FONT);
        imageFoot.setAlignment(Paragraph.ALIGN_CENTER);
        section.add(imageFoot);
    }
}

From source file:org.sonar.report.pdf.DefaultPDFReporter.java

License:Open Source License

private void printMeasures(Measures measures, Section section)
        throws org.dom4j.DocumentException, DocumentException {

    PdfPTable versioningTable = new PdfPTable(2);
    formatTable(versioningTable);/*from   w  w w .  jav  a  2s  .c o m*/
    versioningTable.getDefaultCell().setColspan(2);
    versioningTable
            .addCell(new Phrase(super.getTextProperty("general.versioning_information"), Style.TITLE_FONT));
    versioningTable.addCell(measures.getVersion());
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd - HH:mm:ss");
    versioningTable.addCell(df.format(measures.getDate()));

    PdfPTable measuresTable = new PdfPTable(2);
    formatTable(measuresTable);

    Iterator<String> it = measures.getMeasuresKeys().iterator();
    measuresTable.addCell(new Phrase(super.getTextProperty("general.metric"), Style.TITLE_FONT));
    measuresTable.addCell(new Phrase(super.getTextProperty("general.value"), Style.TITLE_FONT));
    boolean colorEnabled = true;
    while (it.hasNext()) {
        String measureKey = it.next();
        if (colorEnabled) {
            measuresTable.getDefaultCell().setGrayFill(0.9f);
            colorEnabled = false;
        } else {
            measuresTable.getDefaultCell().setGrayFill(1);
            colorEnabled = true;
        }
        if (!measureKey.equals("ccn_classes_count_distribution")
                && !measureKey.equals("ccn_classes_percent_distribution")) {
            measuresTable.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
            measuresTable.addCell(super.getTextProperty("metrics." + measureKey));
            measuresTable.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
            measuresTable.addCell(measures.getMeasure(measureKey).getFormatValue());
        }
    }
    measuresTable.setHeaderRows(1);
    section.add(versioningTable);
    section.add(measuresTable);

}

From source file:org.sonar.report.pdf.DefaultPDFReporter.java

License:Open Source License

private void formatTable(PdfPTable table) {
    Rectangle page = document.getPageSize();
    table.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE);
    table.getDefaultCell().setPaddingBottom(tablePaddingBottom);
    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
    table.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
    table.setSpacingBefore(20);/*from www.j a v a 2  s . com*/
}

From source file:org.sonar.report.pdf.DefaultPDFReporter.java

License:Open Source License

@Override
protected void printFrontPage(Document frontPageDocument, PdfWriter frontPageWriter)
        throws org.dom4j.DocumentException, ReportException {
    try {/*from ww  w.jav a2  s.c o m*/
        URL largeLogo;
        if (super.getConfigProperty("front.page.logo").startsWith("http://")) {
            largeLogo = new URL(super.getConfigProperty("front.page.logo"));
        } else {
            largeLogo = this.getClass().getClassLoader()
                    .getResource(super.getConfigProperty("front.page.logo"));
        }
        Image logoImage = Image.getInstance(largeLogo);
        Rectangle pageSize = frontPageDocument.getPageSize();
        float positionX = pageSize.getWidth() / 2f - logoImage.getWidth() / 2f;
        logoImage.setAbsolutePosition(positionX, pageSize.getHeight() - logoImage.getHeight() - 100);
        frontPageDocument.add(logoImage);

        PdfPTable title = new PdfPTable(1);
        title.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        title.getDefaultCell().setBorder(Rectangle.NO_BORDER);

        String projectRow = super.getTextProperty("general.project") + ": " + super.getProject().getName();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String dateRow = df.format(super.getProject().getMeasures().getDate());
        String descriptionRow = super.getProject().getDescription();

        title.addCell(new Phrase(projectRow, Style.FRONTPAGE_FONT_1));
        title.addCell(new Phrase(descriptionRow, Style.FRONTPAGE_FONT_2));
        title.addCell(new Phrase(dateRow, Style.FRONTPAGE_FONT_3));
        title.setTotalWidth(
                pageSize.getWidth() - frontPageDocument.leftMargin() - frontPageDocument.rightMargin());
        title.writeSelectedRows(0, -1, frontPageDocument.leftMargin(),
                pageSize.getHeight() - logoImage.getHeight() - 150, frontPageWriter.getDirectContent());

    } catch (IOException e) {
        e.printStackTrace();
    } catch (BadElementException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:org.sonar.report.pdf.ExecutivePDFReporter.java

License:Open Source License

@Override
protected void printFrontPage(Document frontPageDocument, PdfWriter frontPageWriter)
        throws org.dom4j.DocumentException, ReportException {
    try {//ww  w  .ja  v  a  2s. c om
        URL largeLogo;
        if (super.getConfigProperty("front.page.logo").startsWith("http://")) {
            largeLogo = new URL(super.getConfigProperty("front.page.logo"));
        } else {
            largeLogo = this.getClass().getClassLoader()
                    .getResource(super.getConfigProperty("front.page.logo"));
        }
        Image logoImage = Image.getInstance(largeLogo);
        logoImage.scaleAbsolute(360, 200);
        Rectangle pageSize = frontPageDocument.getPageSize();
        logoImage.setAbsolutePosition(Style.FRONTPAGE_LOGO_POSITION_X, Style.FRONTPAGE_LOGO_POSITION_Y);
        frontPageDocument.add(logoImage);

        PdfPTable title = new PdfPTable(1);
        title.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        title.getDefaultCell().setBorder(Rectangle.NO_BORDER);

        String projectRow = super.getProject().getName();
        String versionRow = super.getProject().getMeasures().getVersion();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String dateRow = df.format(super.getProject().getMeasures().getDate());
        String descriptionRow = super.getProject().getDescription();

        title.addCell(new Phrase(projectRow, Style.FRONTPAGE_FONT_1));
        title.addCell(new Phrase(versionRow, Style.FRONTPAGE_FONT_1));
        title.addCell(new Phrase(descriptionRow, Style.FRONTPAGE_FONT_2));
        title.addCell(new Phrase(super.getProject().getMeasure(MetricKeys.PROFILE).getDataValue(),
                Style.FRONTPAGE_FONT_3));
        title.addCell(new Phrase(dateRow, Style.FRONTPAGE_FONT_3));
        title.setTotalWidth(
                pageSize.getWidth() - frontPageDocument.leftMargin() - frontPageDocument.rightMargin());
        title.writeSelectedRows(0, -1, frontPageDocument.leftMargin(), Style.FRONTPAGE_LOGO_POSITION_Y - 150,
                frontPageWriter.getDirectContent());

    } catch (IOException e) {
        e.printStackTrace();
    } catch (BadElementException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:org.sonar.report.pdf.ExecutivePDFReporter.java

License:Open Source License

protected void printDashboard(Project project, Section section) throws DocumentException {

    // Static Analysis
    Paragraph staticAnalysis = new Paragraph(getTextProperty("general.static_analysis"), Style.UNDERLINED_FONT);
    PdfPTable staticAnalysisTable = new PdfPTable(3);
    staticAnalysisTable.getDefaultCell().setBorderColor(Color.WHITE);

    PdfPTable linesOfCode = new PdfPTable(1);
    Style.noBorderTable(linesOfCode);
    linesOfCode.addCell(new Phrase(getTextProperty("general.lines_of_code"), Style.DASHBOARD_TITLE_FONT));
    PdfPTable linesOfCodeTendency = new PdfPTable(2);
    Style.noBorderTable(linesOfCodeTendency);
    linesOfCodeTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT);
    linesOfCodeTendency.addCell(/*from  w  w  w . j av  a2s  .c  o  m*/
            new Phrase(project.getMeasure(MetricKeys.NCLOC).getFormatValue(), Style.DASHBOARD_DATA_FONT));
    linesOfCodeTendency.addCell(getTendencyImage(project.getMeasure(MetricKeys.NCLOC).getQualitativeTendency(),
            project.getMeasure(MetricKeys.NCLOC).getQuantitativeTendency()));

    linesOfCode.addCell(linesOfCodeTendency);
    linesOfCode.addCell(new Phrase(project.getMeasure(MetricKeys.PACKAGES).getFormatValue() + " packages",
            Style.DASHBOARD_DATA_FONT_2));
    linesOfCode.addCell(new Phrase(project.getMeasure(MetricKeys.CLASSES).getFormatValue() + " classes",
            Style.DASHBOARD_DATA_FONT_2));
    linesOfCode.addCell(new Phrase(project.getMeasure(MetricKeys.FUNCTIONS).getFormatValue() + " methods",
            Style.DASHBOARD_DATA_FONT_2));
    linesOfCode.addCell(new Phrase(
            project.getMeasure(MetricKeys.DUPLICATED_LINES_DENSITY).getFormatValue() + " duplicated lines",
            Style.DASHBOARD_DATA_FONT_2));

    PdfPTable comments = new PdfPTable(1);
    Style.noBorderTable(comments);
    comments.addCell(new Phrase(getTextProperty("general.comments"), Style.DASHBOARD_TITLE_FONT));
    PdfPTable commentsTendency = new PdfPTable(2);
    commentsTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT);
    Style.noBorderTable(commentsTendency);
    commentsTendency.addCell(new Phrase(project.getMeasure(MetricKeys.COMMENT_LINES_DENSITY).getFormatValue(),
            Style.DASHBOARD_DATA_FONT));
    commentsTendency.addCell(
            getTendencyImage(project.getMeasure(MetricKeys.COMMENT_LINES_DENSITY).getQualitativeTendency(),
                    project.getMeasure(MetricKeys.COMMENT_LINES_DENSITY).getQuantitativeTendency()));
    comments.addCell(commentsTendency);
    comments.addCell(
            new Phrase(project.getMeasure(MetricKeys.COMMENT_LINES).getFormatValue() + " comment lines",
                    Style.DASHBOARD_DATA_FONT_2));

    PdfPTable complexity = new PdfPTable(1);
    Style.noBorderTable(complexity);
    complexity.addCell(new Phrase(getTextProperty("general.complexity"), Style.DASHBOARD_TITLE_FONT));
    PdfPTable complexityTendency = new PdfPTable(2);
    complexityTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT);
    Style.noBorderTable(complexityTendency);
    complexityTendency.addCell(new Phrase(project.getMeasure(MetricKeys.FUNCTION_COMPLEXITY).getFormatValue(),
            Style.DASHBOARD_DATA_FONT));
    complexityTendency.addCell(
            getTendencyImage(project.getMeasure(MetricKeys.FUNCTION_COMPLEXITY).getQualitativeTendency(),
                    project.getMeasure(MetricKeys.FUNCTION_COMPLEXITY).getQuantitativeTendency()));
    complexity.addCell(complexityTendency);
    complexity.addCell(new Phrase(project.getMeasure(MetricKeys.CLASS_COMPLEXITY).getFormatValue() + " /class",
            Style.DASHBOARD_DATA_FONT_2));
    complexity
            .addCell(new Phrase(project.getMeasure(MetricKeys.COMPLEXITY).getFormatValue() + " decision points",
                    Style.DASHBOARD_DATA_FONT_2));

    staticAnalysisTable.setSpacingBefore(10);
    staticAnalysisTable.addCell(linesOfCode);
    staticAnalysisTable.addCell(comments);
    staticAnalysisTable.addCell(complexity);
    staticAnalysisTable.setSpacingAfter(20);

    // Dynamic Analysis
    Paragraph dynamicAnalysis = new Paragraph(getTextProperty("general.dynamic_analysis"),
            Style.UNDERLINED_FONT);
    PdfPTable dynamicAnalysisTable = new PdfPTable(3);
    Style.noBorderTable(dynamicAnalysisTable);

    PdfPTable codeCoverage = new PdfPTable(1);
    Style.noBorderTable(codeCoverage);
    codeCoverage.addCell(new Phrase(getTextProperty("general.code_coverage"), Style.DASHBOARD_TITLE_FONT));
    PdfPTable codeCoverageTendency = new PdfPTable(2);
    Style.noBorderTable(codeCoverageTendency);
    codeCoverageTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT);
    codeCoverageTendency.addCell(new Phrase(
            project.getMeasure(MetricKeys.COVERAGE).getFormatValue() + " coverage", Style.DASHBOARD_DATA_FONT));
    codeCoverageTendency
            .addCell(getTendencyImage(project.getMeasure(MetricKeys.COVERAGE).getQualitativeTendency(),
                    project.getMeasure(MetricKeys.COVERAGE).getQuantitativeTendency()));
    codeCoverage.addCell(codeCoverageTendency);
    codeCoverage.addCell(new Phrase(project.getMeasure(MetricKeys.TESTS).getFormatValue() + " tests",
            Style.DASHBOARD_DATA_FONT_2));

    PdfPTable testSuccess = new PdfPTable(1);
    Style.noBorderTable(testSuccess);
    testSuccess.addCell(new Phrase(getTextProperty("general.test_success"), Style.DASHBOARD_TITLE_FONT));
    PdfPTable testSuccessTendency = new PdfPTable(2);
    Style.noBorderTable(testSuccessTendency);
    testSuccessTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT);
    testSuccessTendency.addCell(new Phrase(project.getMeasure(MetricKeys.TEST_SUCCESS_DENSITY).getFormatValue(),
            Style.DASHBOARD_DATA_FONT));
    testSuccessTendency.addCell(
            getTendencyImage(project.getMeasure(MetricKeys.TEST_SUCCESS_DENSITY).getQualitativeTendency(),
                    project.getMeasure(MetricKeys.TEST_SUCCESS_DENSITY).getQuantitativeTendency()));
    testSuccess.addCell(testSuccessTendency);
    testSuccess.addCell(new Phrase(project.getMeasure(MetricKeys.TEST_FAILURES).getFormatValue() + " failures",
            Style.DASHBOARD_DATA_FONT_2));
    testSuccess.addCell(new Phrase(project.getMeasure(MetricKeys.TEST_ERRORS).getFormatValue() + " errors",
            Style.DASHBOARD_DATA_FONT_2));

    dynamicAnalysisTable.setSpacingBefore(10);
    dynamicAnalysisTable.addCell(codeCoverage);
    dynamicAnalysisTable.addCell(testSuccess);
    dynamicAnalysisTable.addCell("");
    dynamicAnalysisTable.setSpacingAfter(20);

    Paragraph codingRulesViolations = new Paragraph(getTextProperty("general.coding_rules_violations"),
            Style.UNDERLINED_FONT);
    PdfPTable codingRulesViolationsTable = new PdfPTable(3);
    Style.noBorderTable(codingRulesViolationsTable);

    PdfPTable rulesCompliance = new PdfPTable(1);
    Style.noBorderTable(rulesCompliance);
    rulesCompliance
            .addCell(new Phrase(getTextProperty("general.rules_compliance"), Style.DASHBOARD_TITLE_FONT));
    PdfPTable rulesComplianceTendency = new PdfPTable(2);
    Style.noBorderTable(rulesComplianceTendency);
    rulesComplianceTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT);
    rulesComplianceTendency.addCell(new Phrase(
            project.getMeasure(MetricKeys.VIOLATIONS_DENSITY).getFormatValue(), Style.DASHBOARD_DATA_FONT));

    // Workarround for avoid resizing
    Image tendencyRulesResize = getTendencyImage(
            project.getMeasure(MetricKeys.VIOLATIONS_DENSITY).getQualitativeTendency(),
            project.getMeasure(MetricKeys.VIOLATIONS_DENSITY).getQuantitativeTendency());
    tendencyRulesResize.scaleAbsolute(Style.TENDENCY_ICONS_HEIGHT, Style.TENDENCY_ICONS_HEIGHT);
    PdfPCell tendencyRulesCell = new PdfPCell(tendencyRulesResize);
    tendencyRulesCell.setBorder(0);
    rulesComplianceTendency.addCell(tendencyRulesCell);
    rulesCompliance.addCell(rulesComplianceTendency);

    PdfPTable violations = new PdfPTable(1);
    Style.noBorderTable(violations);
    violations.addCell(new Phrase(getTextProperty("general.violations"), Style.DASHBOARD_TITLE_FONT));
    PdfPTable violationsTendency = new PdfPTable(2);
    Style.noBorderTable(violationsTendency);
    violationsTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT);
    violationsTendency.addCell(
            new Phrase(project.getMeasure(MetricKeys.VIOLATIONS).getFormatValue(), Style.DASHBOARD_DATA_FONT));

    // Workarround for avoid resizing
    Image tendencyResize = getTendencyImage(project.getMeasure(MetricKeys.VIOLATIONS).getQualitativeTendency(),
            project.getMeasure(MetricKeys.VIOLATIONS).getQuantitativeTendency());
    tendencyResize.scaleAbsolute(Style.TENDENCY_ICONS_HEIGHT, Style.TENDENCY_ICONS_HEIGHT);
    PdfPCell tendencyCell = new PdfPCell(tendencyResize);
    tendencyCell.setBorder(0);
    violationsTendency.addCell(tendencyCell);

    violations.addCell(violationsTendency);

    codingRulesViolationsTable.setSpacingBefore(10);
    codingRulesViolationsTable.addCell(rulesCompliance);
    codingRulesViolationsTable.addCell(violations);
    codingRulesViolationsTable.addCell("");
    codingRulesViolationsTable.setSpacingAfter(20);

    section.add(Chunk.NEWLINE);
    section.add(staticAnalysis);
    section.add(staticAnalysisTable);
    section.add(dynamicAnalysis);
    section.add(dynamicAnalysisTable);
    section.add(codingRulesViolations);
    section.add(codingRulesViolationsTable);
}

From source file:org.sonar.report.pdf.Header.java

License:Open Source License

public void onEndPage(PdfWriter writer, Document document) {
    try {//from www .ja va2 s .c om
        Image logoImage = Image.getInstance(logo);
        Rectangle page = document.getPageSize();
        PdfPTable head = new PdfPTable(4);
        head.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE);
        head.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
        head.addCell(logoImage);
        Phrase projectName = new Phrase(project.getName(),
                FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, Color.GRAY));
        Phrase phrase = new Phrase("Sonar PDF Report",
                FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, Color.GRAY));
        head.getDefaultCell().setColspan(2);
        head.addCell(phrase);
        head.getDefaultCell().setColspan(1);
        head.addCell(projectName);
        head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
        head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - 20, writer.getDirectContent());
        head.setSpacingAfter(10);
    } catch (BadElementException e) {
        e.printStackTrace();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}