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

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

Introduction

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

Prototype

public void addElement(Element element) 

Source Link

Document

Adds an iText element to the cell.

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 av a  2  s. co 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   w ww.ja v  a2  s .  com
 * @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.//from   ww w . ja  v a  2s  .  com
 * 
 * @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.sakaiproject.tool.assessment.pdf.itext.HTMLWorker.java

License:Mozilla Public License

public void startElement(String tag, HashMap h) {
    if (!tagsSupported.containsKey(tag))
        return;//  www . j  av  a2  s  .  c o  m
    try {
        style.applyStyle(tag, h);
        String follow = (String) FactoryProperties.followTags.get(tag);
        if (follow != null) {
            HashMap prop = new HashMap();
            prop.put(follow, null);
            cprops.addToChain(follow, prop);
            return;
        }
        FactoryProperties.insertStyle(h);
        if (tag.equals("a")) {
            cprops.addToChain(tag, h);
            if (currentParagraph == null)
                currentParagraph = new Paragraph();
            stack.push(currentParagraph);
            currentParagraph = new Paragraph();
            return;
        }
        if (tag.equals("br")) {
            if (currentParagraph == null)
                currentParagraph = new Paragraph();
            currentParagraph.add(factoryProperties.createChunk("\n", cprops));
            return;
        }
        if (tag.equals("hr")) {

            PdfPTable hr = new PdfPTable(1);
            hr.setHorizontalAlignment(Element.ALIGN_CENTER);
            hr.setWidthPercentage(100f);
            hr.setSpacingAfter(0f);
            hr.setSpacingBefore(0f);
            PdfPCell cell = new PdfPCell();
            cell.setUseVariableBorders(true);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorder(PdfPCell.BOTTOM);
            cell.setBorderWidth(1f);
            cell.setPadding(0);
            cell.addElement(factoryProperties.createChunk("\n", cprops));

            hr.addCell(cell);
            // paragraphs can't have tables? really? without it hr's may be rendered a bit early..
            //if (currentParagraph != null)
            //    currentParagraph.add(hr);
            //else
            document.add(hr);
            return;

        }
        if (tag.equals("font") || tag.equals("span")) {
            cprops.addToChain(tag, h);
            return;
        }
        if (tag.equals("img")) {
            String src = (String) h.get("src");
            if (src == null)
                return;
            cprops.addToChain(tag, h);
            Image img = null;
            if (interfaceProps != null) {
                HashMap images = (HashMap) interfaceProps.get("img_static");
                if (images != null) {
                    Image tim = (Image) images.get(src);
                    if (tim != null)
                        img = Image.getInstance(tim);
                } else {
                    if (!src.startsWith("http")) { // relative src references only
                        String baseurl = (String) interfaceProps.get("img_baseurl");
                        if (baseurl != null) {
                            src = baseurl + src;
                            img = Image.getInstance(src);
                        }
                    }
                }
            }
            if (img == null) {
                if (!src.startsWith("http")) {
                    String path = cprops.getProperty("image_path");
                    if (path == null)
                        path = "";
                    src = new File(path, src).getPath();
                    img = Image.getInstance(src);
                } else {
                    byte[] buffer;
                    String srcResource = src.substring(src.indexOf("/content", 0)).replaceAll("/content", "");
                    buffer = getImageStream(URLDecoder.decode(srcResource));
                    img = Image.getInstance(buffer);
                }
            }

            String align = (String) h.get("align");
            String width = (String) h.get("width");
            String height = (String) h.get("height");
            String border = (String) h.get("border");
            String hspace = (String) h.get("hspace");
            String vspace = (String) h.get("vspace");
            String before = cprops.getProperty("before");
            String after = cprops.getProperty("after");
            float wp = 0.0f;
            float lp = 0.0f;
            if (maxWidth > 0 && ((width != null && Integer.parseInt(width) > maxWidth)
                    || (width == null && (int) img.getWidth() > maxWidth))) {
                wp = lengthParse(String.valueOf(maxWidth), (int) img.getWidth());
                lp = wp;
            } else {
                wp = lengthParse(width, (int) img.getWidth());
                lp = lengthParse(height, (int) img.getHeight());
            }
            if (wp > 0 && lp > 0)
                img.scalePercent(wp, lp);
            else if (wp > 0)
                img.scalePercent(wp);
            else if (lp > 0)
                img.scalePercent(lp);
            img.setWidthPercentage(0);
            // border
            if (border != null && !"".equals(border)) {
                try {
                    img.setBorderWidth(Integer.parseInt(border));
                    img.setBorder(Image.BOX);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            // horizonatal space
            if (hspace != null && !"".equals(hspace)) {
                try {
                    img.setSpacingAfter(Float.parseFloat(hspace));
                    img.setSpacingBefore(Float.parseFloat(hspace));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            // horizontal alignment
            if (align != null && (align.equalsIgnoreCase("left") || align.equalsIgnoreCase("right"))) {
                endElement("p");
                int ralign = Image.LEFT;
                if (align.equalsIgnoreCase("right"))
                    ralign = Image.RIGHT;
                img.setAlignment(ralign | Image.TEXTWRAP);
                Img i = null;
                boolean skip = false;
                if (interfaceProps != null) {
                    i = (Img) interfaceProps.get("img_interface");
                    if (i != null)
                        skip = i.process(img, h, cprops, document);
                }
                if (!skip)
                    document.add(img);
                cprops.removeChain(tag);
            }
            // vertical alignment (or none)
            else {
                img.setAlignment(Image.TEXTWRAP);

                float bottom = 0.0f;
                float top = img.getTop();
                float prevHeight = 0.0f;
                float prevRise = 0.0f;

                if (currentParagraph != null) {
                    ArrayList chunks = currentParagraph.getChunks();
                    Chunk sibling = null;

                    for (int k = chunks.size() - 1; k >= 0; k--) {
                        if (chunks.get(k) != null)
                            sibling = (Chunk) chunks.get(k);
                    }

                    if (sibling != null) {
                        if (sibling.hasAttributes())
                            prevRise = sibling.getTextRise();
                        prevHeight = 0.0f;
                        if (sibling.getFont() != null) {
                            prevHeight = sibling.getFont().getCalculatedSize();
                        }
                    }
                }

                if ("absMiddle".equalsIgnoreCase(align)) {
                    if (prevHeight > 0)
                        bottom += (img.getScaledHeight() / 2.0f) - (prevHeight / 2.0f);
                    else if (img.getScaledHeight() > 0)
                        bottom += img.getScaledHeight() / 2.0f;
                } else if ("middle".equalsIgnoreCase(align)) {
                    if (img.getScaledHeight() > 0)
                        bottom += (img.getScaledHeight() / 2.0f);
                } else if ("bottom".equalsIgnoreCase(align) || "baseline".equalsIgnoreCase(align)
                        || "absbottom".equalsIgnoreCase(align)) {
                    //baseline and absbottom should have some slight tweeking from bottom, but not sure what??
                } else if ("top".equalsIgnoreCase(align)) {
                    bottom += img.getScaledHeight() - prevHeight;
                } else if ("texttop".equalsIgnoreCase(align)) {
                    bottom += img.getScaledHeight() - (prevHeight - prevRise);
                }

                cprops.removeChain(tag);
                if (currentParagraph == null) {
                    currentParagraph = FactoryProperties.createParagraph(cprops);
                    bottom = 0f;
                } else if (currentParagraph.isEmpty()) {
                    bottom = 0f;
                }

                currentParagraph.setLeading(2f + bottom, 1.00f);
                currentParagraph.add(new Chunk(img, 0, 0 - bottom));
            }
            return;
        }
        if (tag.equals("blockquote")) {
            cprops.addToChain(tag, h);
            inBLOCK = true;
            if (currentParagraph != null)
                endElement("p");
            currentParagraph = FactoryProperties.createParagraph(cprops);
            currentParagraph.add(factoryProperties.createChunk("\n", cprops));
            return;
        }
        endElement("p");
        if (tag.equals("h1") || tag.equals("h2") || tag.equals("h3") || tag.equals("h4") || tag.equals("h5")
                || tag.equals("h6")) {
            if (!h.containsKey("size")) {
                int v = 8 - Integer.parseInt(tag.substring(1));
                h.put("size", Integer.toString(v));
            }
            cprops.addToChain(tag, h);
            return;
        }
        if (tag.equals("ul")) {
            if (pendingLI)
                endElement("li");
            skipText = true;
            cprops.addToChain(tag, h);
            com.lowagie.text.List list = new com.lowagie.text.List(false, 10);
            list.setListSymbol("\u2022");
            stack.push(list);
            return;
        }
        if (tag.equals("ol")) {
            if (pendingLI)
                endElement("li");
            skipText = true;
            cprops.addToChain(tag, h);
            com.lowagie.text.List list = new com.lowagie.text.List(true, 10);
            stack.push(list);
            return;
        }
        if (tag.equals("li")) {
            if (pendingLI)
                endElement("li");
            skipText = false;
            pendingLI = true;
            cprops.addToChain(tag, h);
            stack.push(FactoryProperties.createListItem(cprops));
            return;
        }
        if (tag.equals("div") || tag.equals("body")) {
            cprops.addToChain(tag, h);
            return;
        }
        if (tag.equals("pre")) {
            if (!h.containsKey("face")) {
                h.put("face", "Courier");
            }
            cprops.addToChain(tag, h);
            isPRE = true;
            return;
        }
        if (tag.equals("p")) {
            cprops.addToChain(tag, h);
            currentParagraph = FactoryProperties.createParagraph(cprops);
            if (inBLOCK) {
                currentParagraph.setIndentationLeft(currentParagraph.getIndentationLeft() + 40.0F);
            }
            return;
        }
        if (tag.equals("tr")) {
            if (pendingTR)
                endElement("tr");
            skipText = true;
            pendingTR = true;
            cprops.addToChain("tr", h);
            return;
        }
        if (tag.equals("td") || tag.equals("th")) {
            if (pendingTD)
                endElement(tag);
            skipText = false;
            pendingTD = true;
            cprops.addToChain("td", h);
            stack.push(new IncCell(tag, cprops));
            return;
        }
        if (tag.equals("table")) {
            cprops.addToChain("table", h);
            IncTable table = new IncTable(h);
            stack.push(table);
            tableState.push(new boolean[] { pendingTR, pendingTD });
            pendingTR = pendingTD = false;
            skipText = true;
            return;
        }
    } catch (Exception e) {
        e.printStackTrace();
        //throw new ExceptionConverter(e);
    }
}

From source file:org.tellervo.desktop.print.SeriesReport.java

License:Open Source License

private void getTableKey() throws DocumentException, IOException, IOException {
    PdfPTable mainTable = new PdfPTable(12);
    float[] widths = { 0.1f, 0.1f, 0.8f, 0.1f, 0.1f, 0.8f, 0.1f, 0.1f, 0.8f, 0.1f, 0.1f, 0.8f };
    mainTable.setWidths(widths);//w w  w . j ava 2  s  .c  o  m
    mainTable.setWidthPercentage(100);

    PdfPTable userRemarksTable = new PdfPTable(2);
    float[] widths2 = { 0.083f, 0.92f };
    userRemarksTable.setWidths(widths2);
    userRemarksTable.setWidthPercentage(100);

    Boolean userRemarkUsed = false;

    DecadalModel model;
    model = new UnitAwareDecadalModel(s);
    int rows = model.getRowCount();
    List<TridasRemark> masterList = null;

    // Loop through rows
    for (int row = 0; row < rows; row++) {
        // Loop through columns
        for (int col = 0; col < 11; col++) {
            org.tellervo.desktop.Year year = model.getYear(row, col);
            List<TridasRemark> remarksList = null;
            remarksList = s.getRemarksForYear(year);

            // If masterlist is still null initialize it with this remarks list
            if (remarksList.size() > 0 && masterList == null)
                masterList = remarksList;

            for (TridasRemark remark : remarksList) {
                if (!masterList.contains(remark))
                    masterList.add(remark);
            }
        }
    }

    for (TridasRemark remark : masterList) {
        PdfPCell iconCell = new PdfPCell();
        PdfPCell equalsCell = new PdfPCell();
        PdfPCell descriptionCell = new PdfPCell();

        iconCell.setBorder(0);
        equalsCell.setBorder(0);
        descriptionCell.setBorder(0);

        iconCell.setVerticalAlignment(Element.ALIGN_TOP);
        equalsCell.setVerticalAlignment(Element.ALIGN_TOP);
        descriptionCell.setVerticalAlignment(Element.ALIGN_TOP);

        Image icon = null;
        String remarkStr = null;

        // Get actual icon (either tridas or tellervo)
        if (remark.isSetNormalTridas()) {
            remarkStr = remark.getNormalTridas().toString().toLowerCase();
            remarkStr = remarkStr.replace("_", " ");
            icon = getTridasIcon(remark.getNormalTridas());
            if (icon == null)
                icon = Builder.getITextImageMissingIcon();
        } else if (TELLERVO.equals(remark.getNormalStd())) {
            remarkStr = remark.getNormal();
            icon = getCorinaIcon(remark.getNormal());
            if (icon == null)
                icon = Builder.getITextImageMissingIcon();
        } else {
            if (!userRemarkUsed) {
                remarkStr = "User Remark (See Below)";
                icon = Builder.getITextImageIcon("user.png");
                userRemarkUsed = true;
            } else {
                // User remark and we already have a key for this so continue
                continue;
            }
        }

        iconCell.addElement(icon);
        equalsCell.addElement(new Phrase("=", tableBodyFont));
        descriptionCell.addElement(new Phrase(WordUtils.capitalize(remarkStr), tableBodyFont));

        mainTable.addCell(iconCell);
        mainTable.addCell(equalsCell);
        mainTable.addCell(descriptionCell);
    }

    // Pad out empty cells
    PdfPCell blankCell = new PdfPCell();
    blankCell.addElement(new Phrase(""));
    blankCell.setBorder(0);
    for (int i = 0; i < 12; i++) {
        mainTable.addCell(blankCell);
    }

    document.add(mainTable);

    if (userRemarkUsed) {
        PdfPCell yearCell = new PdfPCell();
        yearCell.setBorder(0);
        yearCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        yearCell.addElement(new Phrase("Year", tableHeaderFont));
        userRemarksTable.addCell(yearCell);

        PdfPCell remarkCell = new PdfPCell();
        remarkCell.setBorder(0);
        remarkCell.addElement(new Phrase("User ring remarks", tableHeaderFont));
        userRemarksTable.addCell(remarkCell);

        for (int row = 0; row < rows; row++) {
            // Loop through columns
            for (int col = 0; col < 11; col++) {
                org.tellervo.desktop.Year year = model.getYear(row, col);
                List<TridasRemark> remarksList = null;
                remarksList = s.getRemarksForYear(year);

                for (TridasRemark remark : remarksList) {
                    if (remark.isSetNormalTridas() || remark.isSetNormalStd())
                        continue;

                    yearCell = new PdfPCell();
                    yearCell.setBorder(0);
                    yearCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    yearCell.addElement(new Phrase(year.toString(), tableHeaderFont));
                    userRemarksTable.addCell(yearCell);

                    remarkCell = new PdfPCell();
                    remarkCell.setBorder(0);
                    remarkCell.addElement(new Phrase(remark.getValue(), tableBodyFont));
                    userRemarksTable.addCell(remarkCell);
                }
            }
        }

        document.add(userRemarksTable);
    }
}

From source file:org.tellervo.desktop.print.SeriesReport.java

License:Open Source License

/**
 * Get PdfPTable containing the ring width data for this series
 * //from w w  w  .  ja  v  a 2 s.  com
 * @return PdfPTable
 * @throws DocumentException 
 * @throws IOException 
 * @throws MalformedURLException 
 */
private void getDataTable(Boolean wj) throws DocumentException, MalformedURLException, IOException {
    // THE actual table
    PdfPTable mainTable = new PdfPTable(11);
    // Cell for column headers
    PdfPCell colHeadCell = new PdfPCell();
    // Model for data
    DecadalModel model;
    // Flag to show if there are *any* ring remarks
    Boolean hasRemarks = false;

    float[] columnWidths = new float[] { 20f, 8f, 8f, 8f, 8f, 8f, 8f, 8f, 8f, 8f, 8f };
    mainTable.setWidths(columnWidths);
    mainTable.setWidthPercentage(100f);

    if (wj == true) {
        if (s.hasWeiserjahre() == true) {
            model = new WJTableModel(s);
            document.add(new Chunk("Weiserjahre:", subSubSectionFont));
        } else {
            return;
        }
    } else {
        model = new UnitAwareDecadalModel(s);
        document.add(new Chunk("Ring widths:", subSubSectionFont));
    }

    int rows = model.getRowCount();

    // Do column headers
    if (wj == true) {
        colHeadCell.setPhrase(new Phrase("inc/dec", tableHeaderFont));
    } else if (this.s.getTridasUnits() == null) {
        // Unitless
        colHeadCell.setPhrase(new Phrase(" ", tableHeaderFont));
    } else {
        // Normal tridas units
        try {
            /*if(this.s.getTridasUnits().getNormalTridas().equals(NormalTridasUnit.MICROMETRES))
            {
               colHeadCell.setPhrase(new Phrase("microns", tableHeaderFont));
            }*/

            // Use the current default display units

            colHeadCell.setPhrase(new Phrase(displayUnits.value(), tableHeaderFont));

            /*if(displayUnits.equals(NormalTridasUnit.MICROMETRES))
            {
               colHeadCell.setPhrase(new Phrase("microns", tableHeaderFont));
            }
            else if(displayUnits.equals(NormalTridasUnit.HUNDREDTH_MM))
            {
               colHeadCell.setPhrase(new Phrase("1/100th mm", tableHeaderFont));
            }
            */

        } catch (Exception e) {
            colHeadCell.setPhrase(new Phrase(" ", tableHeaderFont));
        }
    }
    colHeadCell.setBorderWidthBottom(headerLineWidth);
    colHeadCell.setBorderWidthTop(headerLineWidth);
    colHeadCell.setBorderWidthLeft(headerLineWidth);
    colHeadCell.setBorderWidthRight(headerLineWidth);
    mainTable.addCell(colHeadCell);
    for (int i = 0; i < 10; i++) {
        colHeadCell.setPhrase(new Phrase(Integer.toString(i), tableHeaderFont));
        colHeadCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        colHeadCell.setBorderWidthBottom(headerLineWidth);
        colHeadCell.setBorderWidthTop(headerLineWidth);
        colHeadCell.setBorderWidthLeft(lineWidth);
        colHeadCell.setBorderWidthRight(lineWidth);

        if (i == 0)
            colHeadCell.setBorderWidthLeft(headerLineWidth);
        if (i == 9)
            colHeadCell.setBorderWidthRight(headerLineWidth);
        mainTable.addCell(colHeadCell);
    }

    // Loop through rows
    for (int row = 0; row < rows; row++) {
        // Loop through columns
        for (int col = 0; col < 11; col++) {
            // Mini table to hold remark icons
            PdfPTable remarksMiniTable = new PdfPTable(3);
            float[] widths = { 0.3f, 0.3f, 0.6f };
            remarksMiniTable.setWidths(widths);
            remarksMiniTable.setWidthPercentage(100);

            // Get ring value or year number for first column
            Phrase cellValuePhrase = null;
            Object value = model.getValueAt(row, col);
            if (value == null) {
                cellValuePhrase = new Phrase("");
            } else {
                /*if(displayUnits.equals(NormalTridasUnit.HUNDREDTH_MM))
                {
                   try{
                   Integer val = (Integer) value;
                   val =val/10;
                   cellValuePhrase = new Phrase(String.valueOf(val), getTableFont(col));
                   } catch (Exception e){
                      cellValuePhrase = new Phrase(value.toString(), getTableFont(col));
                        
                   }
                }
                else if(displayUnits.equals(NormalTridasUnit.FIFTIETH_MM))
                {
                   try{
                   Integer val = (Integer) value;
                   val =val/20;
                   cellValuePhrase = new Phrase(String.valueOf(val), getTableFont(col));
                   } catch (Exception e){
                      cellValuePhrase = new Phrase(value.toString(), getTableFont(col));
                        
                   }               
                }
                else if(displayUnits.equals(NormalTridasUnit.TWENTIETH_MM))
                {
                   try{
                   Integer val = (Integer) value;
                   val =val/50;
                   cellValuePhrase = new Phrase(String.valueOf(val), getTableFont(col));
                   } catch (Exception e){
                      cellValuePhrase = new Phrase(value.toString(), getTableFont(col));
                        
                   }               
                }
                else if(displayUnits.equals(NormalTridasUnit.TENTH_MM))
                {
                   try{
                   Integer val = (Integer) value;
                   val =val/100;
                   cellValuePhrase = new Phrase(String.valueOf(val), getTableFont(col));
                   } catch (Exception e){
                      cellValuePhrase = new Phrase(value.toString(), getTableFont(col));
                        
                   }               
                }
                else if(displayUnits.equals(NormalTridasUnit.MICROMETRES))
                {*/
                cellValuePhrase = new Phrase(value.toString(), getTableFont(col));
                //}
            }

            // Get any remarks and compile them into a mini table
            org.tellervo.desktop.Year year = model.getYear(row, col);
            List<TridasRemark> remarksList = null;
            remarksList = s.getRemarksForYear(year);

            // If there are remarks, cycle through them adding cells to the mini table
            if (col != 0 && remarksList.size() > 0) {
                hasRemarks = true;
                // Get icons for remarks
                int cellnum = 1;
                int remarknum = 0;
                for (TridasRemark remark : remarksList) {
                    // Keep track of which remark we are on.
                    remarknum++;
                    // String for holding remark name for debugging
                    String remstr = "?";
                    // The actual remark icon
                    Image icon = null;
                    // A table cell for the remark
                    PdfPCell remarkCell = new PdfPCell();

                    // Set default attributes for remark and value cells
                    remarkCell.setBorderWidthBottom(0);
                    remarkCell.setBorderWidthTop(0);
                    remarkCell.setBorderWidthLeft(0);
                    remarkCell.setBorderWidthRight(0);
                    remarkCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    remarkCell.setPadding(0);
                    remarkCell.setUseBorderPadding(true);

                    // A table cell for the ring width value
                    PdfPCell valueCell = new PdfPCell();
                    valueCell = remarkCell;

                    // Get actual icon (either tridas or tellervo)
                    if (remark.isSetNormalTridas()) {
                        remstr = remark.getNormalTridas().toString();
                        icon = getTridasIcon(remark.getNormalTridas());
                        if (icon == null)
                            icon = Builder.getITextImageMissingIcon();
                    } else if (TELLERVO.equals(remark.getNormalStd())) {
                        remstr = remark.getNormal();
                        icon = getCorinaIcon(remark.getNormal());
                        if (icon == null)
                            icon = Builder.getITextImageMissingIcon();
                    } else {
                        if (remark.isSetValue()) {
                            remstr = remark.getValue();
                        } else if (remark.isSetNormal()) {
                            remstr = remark.getNormal();
                        } else {
                            remstr = "Unknown";
                        }
                        icon = Builder.getITextImageIcon("user.png");

                    }

                    // Print debug info for this remark
                    String errStr = "Getting icon for " + remstr + " for year " + year.toString()
                            + "(cell value = " + cellnum + ")";
                    System.out.print(errStr);

                    // Shrink the icon a bit
                    icon.scalePercent(20);

                    // Add icon to minitable
                    remarkCell.addElement(icon);
                    remarksMiniTable.addCell(remarkCell);
                    cellnum++;

                    if (cellnum == 1 && remarksList.size() < cellnum) {
                        // First cell and no remark so print blank
                        valueCell.setPhrase(new Phrase(""));
                        remarksMiniTable.addCell(valueCell);
                        cellnum++;
                    }
                    if (cellnum == 2 && remarksList.size() < cellnum) {
                        // Second cell and no remark so print blank
                        valueCell.setPhrase(new Phrase(""));
                        remarksMiniTable.addCell(valueCell);
                        cellnum++;
                    }
                    if (cellnum == 3) {
                        // In third cell so print value
                        valueCell.setPhrase(cellValuePhrase);
                        remarksMiniTable.addCell(valueCell);
                        cellnum++;
                    } else if (cellnum % 3 == 0) {
                        // In third column so print blank
                        valueCell.setPhrase(new Phrase(""));
                        remarksMiniTable.addCell(valueCell);
                        cellnum++;
                    }

                    if (remarknum == remarksList.size()) {
                        valueCell.setPhrase(new Phrase(""));
                        remarksMiniTable.addCell(valueCell);
                        remarksMiniTable.addCell(valueCell);
                    }

                    remarkCell = null;
                    valueCell = null;
                }
            } else {
                // No remarks so make mini table have blank, blank, value

                // Create blank and value cells
                PdfPCell blankCell = new PdfPCell();
                PdfPCell valueCell = new PdfPCell();

                // Set up style
                blankCell.setBorderWidthBottom(0);
                blankCell.setBorderWidthTop(0);
                blankCell.setBorderWidthLeft(0);
                blankCell.setBorderWidthRight(0);
                blankCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                blankCell.setPadding(0);
                blankCell.setUseBorderPadding(true);
                valueCell = blankCell;

                // Add cells to mini table
                remarksMiniTable.addCell(blankCell);
                remarksMiniTable.addCell(blankCell);
                valueCell.setPhrase(cellValuePhrase);
                remarksMiniTable.addCell(valueCell);
            }

            // Set border styles depending on where we are in the table

            // Defaults
            PdfPCell mainTableCell = new PdfPCell();
            mainTableCell.setBorderWidthBottom(lineWidth);
            mainTableCell.setBorderWidthTop(lineWidth);
            mainTableCell.setBorderWidthLeft(lineWidth);
            mainTableCell.setBorderWidthRight(lineWidth);
            mainTableCell.setHorizontalAlignment(Element.ALIGN_RIGHT);

            // Row headers
            if (col == 0) {
                mainTableCell.setHorizontalAlignment(Element.ALIGN_LEFT);
                mainTableCell.setBorderWidthLeft(headerLineWidth);
                mainTableCell.setBorderWidthRight(headerLineWidth);
            }

            // First data column
            if (col == 1) {
                mainTableCell.setBorderWidthLeft(headerLineWidth);
            }

            // Last data column
            if (col == 10) {
                mainTableCell.setBorderWidthRight(headerLineWidth);
            }

            // Last row
            if (row == model.getRowCount() - 1) {
                mainTableCell.setBorderWidthBottom(headerLineWidth);
            }

            // Write mini table to cell       
            mainTableCell.addElement(remarksMiniTable);

            //mainTableCell.addElement(userRemarksMiniTable);

            // Write cell to main table
            mainTable.addCell(mainTableCell);

        }
    }

    // Add table to document
    document.add(mainTable);

    if (!wj && hasRemarks)
        getTableKey();
}

From source file:org.tellervo.desktop.util.labels.PDFLabelMaker.java

License:Open Source License

public void addLabelsForSamples(List<TridasSample> samples) {

    // Loop through samples in list
    for (TridasSample s : samples) {
        Barcode128 barcode = new LabBarcode(LabBarcode.Type.SAMPLE,
                UUID.fromString(s.getIdentifier().getValue().toString()));

        // if it's tiny, hide the label
        if (margins.getLabelHeight() * .80f < barcode.getBarHeight()) {
            barcode.setBarHeight(margins.getLabelHeight() * .45f);
            barcode.setX(1.8f);/*from   w ww.  j av a2 s.c o  m*/
            barcode.setN(10f);
            barcode.setSize(10f);
            barcode.setBaseline(10f);
            barcode.setBarHeight(50f);
            barcode.setFont(null);
        } else {
            barcode.setBarHeight(margins.getLabelHeight() * .45f);
            barcode.setX(0.6f);
            barcode.setSize(4.0f);

        }

        PdfPCell lbcell = new PdfPCell();

        lbcell.setVerticalAlignment(Element.ALIGN_TOP);
        lbcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        Phrase p = new Phrase();

        String labelText;
        TridasGenericField labcodeField = GenericFieldUtils.findField(s, "tellervo.internal.labcodeText");

        if (labcodeField == null) {
            log.warn("labcode missing from sample.  Can't print!");
            continue;
        }
        labelText = (labcodeField != null) ? labcodeField.getValue() : s.getTitle();

        p.add(new Chunk(labelText, labelfont));
        //p.add(new Chunk("bbb", labelfont));
        //p.add(new Chunk(s.getIdentifier().getValue().toString(), uuidfont));

        //barcode.setFont(null);
        Image img = barcode.createImageWithBarcode(contentb, Color.black, Color.gray);

        PdfPCell labcell = new PdfPCell();

        if (App.getLabName() != null) {
            labcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            labcell.setVerticalAlignment(Element.ALIGN_TOP);
            Phrase labPhrase = new Phrase(App.getLabName().toUpperCase(), tinyfont);
            labcell.addElement(labPhrase);
        }
        addCell(labcell);

        PdfPCell bccell = new PdfPCell();
        bccell.setHorizontalAlignment(Element.ALIGN_MIDDLE);

        bccell.addElement(img);
        bccell.addElement(p);
        addCell(bccell);

        lbcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        lbcell.addElement(p);
        addCell(lbcell);

        //addCell(new PdfPCell());

        /**   PdfPTable tbl = new PdfPTable(2);
                   
           tbl.addCell(bccell);
           tbl.addCell(lbcell);*/

    }

}

From source file:org.tellervo.desktop.util.labels.PDFLabelMaker.java

License:Open Source License

public void addTable(PdfPTable ntable) {

    PdfPCell cell = new PdfPCell();
    cell.addElement(ntable);
    cell.addElement(new Phrase("boo"));

    addCell(cell);// w ww  . j av a2 s  . co  m

}

From source file:org.unitime.timetable.export.PDFPrinter.java

License:Open Source License

@Override
public void printHeader(String... fields) {
    iTable = new PdfPTable(fields.length - iHiddenColumns.size());
    iMaxWidth = new float[fields.length];
    iTable.setHeaderRows(1);//w  w w.  ja  va2 s .co  m
    iTable.setWidthPercentage(100);

    for (int idx = 0; idx < fields.length; idx++) {
        if (iHiddenColumns.contains(idx))
            continue;
        String f = fields[idx];

        PdfPCell cell = new PdfPCell();
        cell.setBorder(Rectangle.BOTTOM);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);

        Font font = PdfFont.getFont(true);
        cell.addElement(new Chunk(f, font));
        iTable.addCell(cell);

        float width = 0;
        if (f.indexOf('\n') >= 0) {
            for (StringTokenizer s = new StringTokenizer(f, "\n"); s.hasMoreTokens();)
                width = Math.max(width, font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize()));
        } else
            width = Math.max(width, font.getBaseFont().getWidthPoint(f, font.getSize()));
        iMaxWidth[idx] = width;
    }
}

From source file:questions.tables.RotateCell.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4);
    try {/*  w  ww. j  a v a  2s. c  o  m*/
        PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();
        Paragraph paragraphA = new Paragraph();
        paragraphA.add(new Phrase("TestA"));
        Paragraph paragraphB = new Paragraph();
        paragraphB.add(new Phrase("\u00a0"));
        Paragraph paragraphC = new Paragraph();
        paragraphC.add(new Phrase("TestB"));

        PdfPTable table = new PdfPTable(1);
        PdfPCell cell = new PdfPCell();
        cell.addElement(paragraphA);
        cell.addElement(paragraphB);
        cell.addElement(paragraphC);
        cell.setRotation(90);
        table.addCell(cell);

        document.add(table);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}