Example usage for com.lowagie.text Element ALIGN_RIGHT

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

Introduction

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

Prototype

int ALIGN_RIGHT

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

Click Source Link

Document

A possible value for paragraph alignment.

Usage

From source file:org.pz.platypus.plugin.pdf.PdfOutfile.java

License:Open Source License

/**
 * Implement the paragraph alignment//from  w ww.  j  a  va  2  s  .co m
 *
 * @param para the paragraph to align
 * @param pData the PdfData container holding the current settings of the PDF output
 */
void doParagraphAlignment(final Paragraph para, final PdfData pData) {
    switch (pData.getAlignment()) {
    case Alignment.CENTER:
        para.setAlignment(Element.ALIGN_CENTER);
        break;
    case Alignment.JUST:
        para.setAlignment(Element.ALIGN_JUSTIFIED);
        break;
    case Alignment.LEFT:
        para.setAlignment(Element.ALIGN_LEFT);
        break;
    case Alignment.RIGHT:
        para.setAlignment(Element.ALIGN_RIGHT);
        break;
    default: // ignore in case of other possibility
        break;
    }
}

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

License:Open Source License

/**
 * Write the title page of the PDF document.
 * /*  w w  w.  j av a2s .  co m*/
 * @throws ExportException
 *             If an error occurs while creating the title page
 */
private void writeTitlePage() throws ExportException {
    try {
        Font plainFontTitle = new Font(
                BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 12);

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

        Font boldItalicFontTitle = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 12);

        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 boldItalicFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

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

        Font italicFontSmall = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 9);

        Phrase phraseStrut = new Phrase(" ");
        phraseStrut.setLeading(leading);

        /*
         * date and time of the meeting
         */
        String meetingDate = sdfDate.format(meeting.getPlannedDate().getTime());

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

        /*
         * Base table
         */
        PdfPTable table = new PdfPTable(new float[] { 0.04f, 0.96f });
        table.setWidthPercentage(100);
        table.setSplitRows(false);
        table.getDefaultCell().setBorderWidth(0);
        table.getDefaultCell().setPadding(0);

        /*
         * recipient of the invitation
         */
        PdfPCell cell = new PdfPCell();
        cell.setBorder(0);
        cell.setColspan(2);
        cell.setPadding(padding);

        cell.addElement(phraseStrut);

        PdfPTable tableRecipient = new PdfPTable(2);
        tableRecipient.setWidthPercentage(100);
        tableRecipient.setSplitRows(false);
        tableRecipient.getDefaultCell().setBorderWidth(0);
        tableRecipient.getDefaultCell().setPadding(0);

        PdfPCell cellRecipient = new PdfPCell();
        cellRecipient.setBorder(0);
        cellRecipient.setPadding(0);
        cellRecipient.addElement(new Phrase(translate("To:"), plainFontTitle));
        cellRecipient.addElement(new Phrase(attendee.getName(), boldFontTitle));

        tableRecipient.addCell(cellRecipient);

        PdfPCell cellDate = new PdfPCell(new Phrase(sdfDate.format(new Date().getTime()), plainFont));
        cellDate.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cellDate.setBorder(0);
        cellDate.setPadding(0);
        cellDate.setPaddingTop(7);

        tableRecipient.addCell(cellDate);

        cell.addElement(tableRecipient);

        cell.addElement(phraseStrut);
        cell.addElement(phraseStrut);
        cell.addElement(phraseStrut);

        /*
         * subject
         */
        cell.addElement(new Phrase(translate("Invitation for the Meeting on") + " " + meetingDate,
                boldItalicFontTitle));

        cell.addElement(phraseStrut);

        /*
         * invitation text
         */
        Phrase phrase = new Phrase(
                Data.getInstance().getAppData().getSetting(AppSettingKey.PDF_INVITATION_TEXT), plainFont);
        phrase.setLeading(leading);

        cell.addElement(phrase);

        cell.addElement(phraseStrut);

        table.addCell(cell);

        /*
         * meeting date, time and location
         */
        cell = new PdfPCell(new Phrase(meetingDate, boldItalicFont));
        cell.setBorder(0);
        cell.setColspan(2);
        cell.setPadding(padding);
        cell.setPaddingBottom(0);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);

        table.addCell(cell);

        cell = new PdfPCell(new Phrase(meetingTime, italicFont));
        cell.setBorder(0);
        cell.setColspan(2);
        cell.setPadding(padding);
        cell.setPaddingBottom(0);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);

        table.addCell(cell);

        if (!meeting.getPlannedLocation().equals("")) {
            cell = new PdfPCell(
                    new Phrase(translate("Location") + ": " + meeting.getPlannedLocation(), italicFont));
            cell.setBorder(0);
            cell.setColspan(2);
            cell.setPadding(padding);
            cell.setPaddingBottom(0);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);

            table.addCell(cell);
        }

        /*
         * role; review title and description
         */
        cell = new PdfPCell();
        cell.setBorder(0);
        cell.setColspan(2);
        cell.setPadding(padding);

        cell.addElement(phraseStrut);
        cell.addElement(phraseStrut);

        phrase = new Phrase();
        phrase.setLeading(leading);
        phrase.add(new Chunk(MessageFormat.format(translate("You are invited as {0} to this review ({1})."),
                translate(attendee.getRole().toString()), getReviewTitle()), boldFont));

        cell.addElement(phrase);

        cell.addElement(phraseStrut);

        cell.addElement(new Phrase(resiData.getReview().getDescription(), italicFont));

        cell.addElement(phraseStrut);

        /*
         * Predecessor meeting
         */
        if (meetMgmt.getPredecessorMeeting(meeting) != null) {
            String preMeetingDate = sdfDate
                    .format(meetMgmt.getPredecessorMeeting(meeting).getProtocol().getDate().getTime());

            cell.addElement(new Phrase(MessageFormat
                    .format(translate("This meeting ties up to the review meeting of {0}."), preMeetingDate),
                    plainFont));

            cell.addElement(phraseStrut);
        }

        /*
         * If there is a product name defined
         */
        if (!Data.getInstance().getResiData().getReview().getProduct().getName().trim().equals("")) {
            /*
             * the product of this review
             */
            cell.addElement(new Phrase(translate("The following product will be reviewed:"), plainFont));
            cell.addElement(phraseStrut);

            table.addCell(cell);

            /*
             * Write name and version of the reviewed product
             */
            Phrase phrName = new Phrase(Data.getInstance().getResiData().getReview().getProduct().getName(),
                    boldItalicFont);
            phrName.setLeading(leading);

            PdfPCell cellName = new PdfPCell(phrName);
            cellName.setColspan(2);
            cellName.setBorderWidth(0);
            cellName.setPadding(padding);
            cellName.setPaddingBottom(0);
            cellName.setHorizontalAlignment(Element.ALIGN_CENTER);

            table.addCell(cellName);

            /*
             * If there is a product version defined
             */
            if (!Data.getInstance().getResiData().getReview().getProduct().getVersion().trim().equals("")) {
                Phrase phrVersion = new Phrase(
                        translate("Product Version") + ": "
                                + Data.getInstance().getResiData().getReview().getProduct().getVersion(),
                        italicFont);
                phrVersion.setLeading(leading);

                PdfPCell cellVersion = new PdfPCell(phrVersion);
                cellVersion.setColspan(2);
                cellVersion.setBorderWidth(0);
                cellVersion.setPadding(padding);
                cellVersion.setPaddingBottom(0);
                cellVersion.setHorizontalAlignment(Element.ALIGN_CENTER);

                table.addCell(cellVersion);
            }

            table.addCell(createVerticalStrut(PDFTools.cmToPt(0.7f), 2));
        } else {
            table.addCell(cell);
        }

        boolean showBottomStrut = false;

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

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

        /*
         * Textual references
         */
        for (String ref : Application.getInstance().getReviewMgmt().getProductReferences()) {
            Phrase phraseRef = new Phrase(ref, italicFontSmall);
            phraseRef.setLeading(leading);

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

            table.addCell(cellListPoint);

            table.addCell(cellRef);

            showBottomStrut = true;
        }

        /*
         * External file references
         */
        for (File ref : Application.getInstance().getReviewMgmt().getExtProdReferences()) {
            Phrase phraseRef = new Phrase();
            phraseRef.add(new Chunk(ref.getName(), italicFontSmall));
            phraseRef.add(new Chunk(" (" + translate("File Attachment") + ")", italicFontSmall));
            phraseRef.setFont(plainFont);
            phraseRef.setLeading(leading);

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

            table.addCell(cellListPoint);

            if (attachProdExtRefs) {
                cellRef.setCellEvent(new PDFCellEventExtRef(pdfWriter, ref));
            }

            table.addCell(cellRef);

            showBottomStrut = true;
        }

        if (showBottomStrut) {
            table.addCell(createVerticalStrut(PDFTools.cmToPt(0.4f), 2));
        }

        /*
         * "please prepare" for the reviwers; on questions ask moderators
         */
        cell = new PdfPCell();
        cell.setBorder(0);
        cell.setColspan(2);
        cell.setPadding(padding);

        phrase = new Phrase();
        phrase.setLeading(leading);

        if (attendee.getAspects() != null) {
            phrase.add(new Chunk(translate(
                    "Please prepare for the review meeting by checking the product for the aspects which are associated to you.")
                    + " ", plainFont));
        }

        List<Attendee> moderators = new ArrayList<Attendee>();
        for (Attendee a : Application.getInstance().getAttendeeMgmt().getAttendees()) {
            if (a.getRole() == Role.MODERATOR) {
                moderators.add(a);
            }
        }

        if (moderators.size() == 1 && attendee.getRole() != Role.MODERATOR) {
            phrase.add(new Chunk(translate(
                    "Please do not hesitate to contact the review moderator if you have any questions:") + " ",
                    plainFont));
        } else if (moderators.size() > 1 && attendee.getRole() != Role.MODERATOR) {
            phrase.add(new Chunk(translate(
                    "Please do not hesitate to contact one of the review moderators if you have any questions:")
                    + " ", plainFont));
        }

        cell.addElement(phrase);

        Phrase phraseStrutSmall = new Phrase(" ");
        phraseStrutSmall.setLeading(leading / 2);

        if (moderators.size() > 0 && attendee.getRole() != Role.MODERATOR) {
            for (Attendee mod : moderators) {
                cell.addElement(phraseStrutSmall);
                cell.addElement(new Phrase(mod.getName(), boldFont));
                cell.addElement(new Phrase(mod.getContact(), italicFont));
            }
        }

        table.addCell(cell);

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

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

License:Open Source License

/**
 * Write the aspects./*www . j  a va 2 s.  c  o m*/
 * 
 * @throws ExportException
 *             If an error occurs while writing the aspects
 */
private void writeAspects() throws ExportException {
    /*
     * If the role of the attendee is not reviewer show all aspects
     */
    List<Aspect> aspects = null;

    if (attendee.getRole() == Role.REVIEWER) {
        aspects = attMgmt.getAspects(attendee);
    } else {
        aspects = aspMgmt.getAspects();
    }

    if (aspects.size() == 0) {
        return;
    }

    try {
        Font descriptionFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

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

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

        Font reviewerFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 9);

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

        boolean grayBackground = true;

        for (Aspect asp : aspects) {
            /*
             * Build table for one aspect
             */
            PdfPTable tableAspect = new PdfPTable(new float[] { 0.70f, 0.30f });
            tableAspect.setWidthPercentage(100);
            tableAspect.getDefaultCell().setBorderWidth(0);
            tableAspect.getDefaultCell().setPadding(0);

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

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

            /*
             * directive and description of the aspect
             */
            PdfPCell cell = new PdfPCell();
            cell.setBorderWidth(0);
            cell.setPadding(padding * 0.4f);
            cell.setPaddingBottom(padding * 1.5f);
            cell.addElement(new Phrase(asp.getDirective(), directiveFont));
            cell.addElement(phraseStrut);
            cell.addElement(new Phrase(asp.getDescription(), descriptionFont));

            /*
             * the reviewers of this aspect (moderator only)
             */
            if (attendee.getRole() == Role.MODERATOR) {
                cell.addElement(phraseStrut);
                cell.addElement(phraseStrut);

                String separator = "";

                Phrase phraseReviewers = new Phrase();
                phraseReviewers.setLeading(leading);
                phraseReviewers.setFont(reviewerFont);

                for (Attendee att : attMgmt.getAttendees()) {
                    if (attMgmt.hasAspect(asp, att)) {
                        phraseReviewers.add(new Chunk(separator + att.getName(), reviewerFont));

                        separator = "    ";
                    }
                }

                cell.addElement(phraseReviewers);
            }

            tableAspect.addCell(cell);

            /*
             * category of the aspect
             */
            cell = new PdfPCell(new Phrase(asp.getCategory(), categoryFont));
            cell.setBorderWidth(0);
            cell.setPadding(padding * 0.4f);
            cell.setPaddingTop(padding * 1.1f);
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

            tableAspect.addCell(cell);

            cellAspect.addElement(tableAspect);
            cellAspect.setPadding(0);
            cellAspect.setPaddingLeft(padding);
            cellAspect.setPaddingRight(padding);

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

            /*
             * Add aspect to the list
             */
            tableAspects.addCell(cellAspect);
        }

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

        tableAspects.addCell(cellBottomLine);

        /*
         * Add the attendee base table to the document
         */
        pdfDoc.add(tableAspects);
    } 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 aspects into the PDF document."));
    }
}

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

License:Open Source License

@Override
public void onEndPage(PdfWriter writer, Document document) {
    int columnNumber;

    try {//from ww w.j a  v  a  2 s  .c  om
        Rectangle page = document.getPageSize();
        float pageWidth = page.getWidth() - document.leftMargin() - document.rightMargin();

        /*
         * Write marks
         */
        setMarks(writer, document);

        /*
         * Define fonts
         */
        headBaseFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        Font headFont = new Font(headBaseFont, headFontSize);

        footBaseFont = BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED);
        Font footFont = new Font(footBaseFont, footFontSize);

        /*
         * Cell fill for space between head/foot and content
         */
        PdfPCell cellFill = new PdfPCell();
        cellFill.setMinimumHeight(PDFTools.cmToPt(0.8f));
        cellFill.setBorderWidth(0);

        /*
         * Write head
         */
        if (headLogoPath != null) {
            columnNumber = 2;
        } else {
            columnNumber = 1;
        }

        PdfPTable head = new PdfPTable(columnNumber);

        Phrase phraseTitle = new Phrase(headTitle, headFont);

        PdfPCell cellTitle = new PdfPCell(phraseTitle);
        cellTitle.setHorizontalAlignment(Element.ALIGN_LEFT);
        cellTitle.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cellTitle.setPaddingTop(0);
        cellTitle.setPaddingBottom(PDFTools.cmToPt(0.2f));
        cellTitle.setPaddingLeft(0);
        cellTitle.setPaddingRight(0);
        cellTitle.setBorderWidthTop(0);
        cellTitle.setBorderWidthBottom(0.5f);
        cellTitle.setBorderWidthLeft(0);
        cellTitle.setBorderWidthRight(0);

        head.addCell(cellTitle);

        if (headLogoPath != null) {
            Image headLogo = Image.getInstance(headLogoPath);
            headLogo.scaleToFit(PDFTools.cmToPt(5.0f), PDFTools.cmToPt(1.1f));

            PdfPCell cellLogo = new PdfPCell(headLogo);
            cellLogo.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cellLogo.setVerticalAlignment(Element.ALIGN_BOTTOM);
            cellLogo.setPaddingTop(0);
            cellLogo.setPaddingBottom(PDFTools.cmToPt(0.15f));
            cellLogo.setPaddingLeft(0);
            cellLogo.setPaddingRight(0);
            cellLogo.setBorderWidthTop(0);
            cellLogo.setBorderWidthBottom(0.5f);
            cellLogo.setBorderWidthLeft(0);
            cellLogo.setBorderWidthRight(0);

            head.addCell(cellLogo);

            head.addCell(cellFill);
        }

        head.addCell(cellFill);

        head.setTotalWidth(pageWidth);
        head.writeSelectedRows(0, -1, document.leftMargin(),
                page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());

        /*
         * Write foot
         */
        if (footText == null) {
            footText = " ";
        }

        PdfPTable foot = new PdfPTable(1);

        foot.addCell(cellFill);

        PdfPCell cellFootText = new PdfPCell(new Phrase(footText, footFont));
        cellFootText.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cellFootText.setVerticalAlignment(Element.ALIGN_TOP);
        cellFootText.setPaddingTop(PDFTools.cmToPt(0.15f));
        cellFootText.setPaddingBottom(0);
        cellFootText.setPaddingLeft(0);
        cellFootText.setPaddingRight(0);
        cellFootText.setBorderWidthTop(0.5f);
        cellFootText.setBorderWidthBottom(0);
        cellFootText.setBorderWidthLeft(0);
        cellFootText.setBorderWidthRight(0);

        foot.addCell(cellFootText);

        /*
         * Print page numbers
         */
        PdfContentByte contentByte = writer.getDirectContent();
        contentByte.saveState();

        String text = MessageFormat.format(translate("Page {0} of") + " ", writer.getPageNumber());

        float textSize = footBaseFont.getWidthPoint(text, footFontSize);
        float textBase = document.bottom() - PDFTools.cmToPt(1.26f);
        contentByte.beginText();
        contentByte.setFontAndSize(footBaseFont, footFontSize);

        float adjust;
        if (footText.trim().equals("")) {
            adjust = (pageWidth / 2) - (textSize / 2) - footBaseFont.getWidthPoint("0", footFontSize);
        } else {
            adjust = 0;
        }

        contentByte.setTextMatrix(document.left() + adjust, textBase);
        contentByte.showText(text);
        contentByte.endText();
        contentByte.addTemplate(template, document.left() + adjust + textSize, textBase);

        contentByte.stroke();
        contentByte.restoreState();

        foot.setTotalWidth(pageWidth);
        foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                writer.getDirectContent());
    } catch (Exception e) {
        /*
         * Not part of unit testing because this exception is only thrown if
         * an internal error occurs.
         */
        throw new ExceptionConverter(e);
    }
}

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

License:Open Source License

/**
 * Writes the given attendees to the protocol.
 * //from w w w.j av a  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.//  www .  j  av  a  2s . c om
 * 
 * @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.tellervo.desktop.print.BasicBoxLabel.java

License:Open Source License

/**
 * Get PdfPTable containing the samples per object
 * //from  www . j  a  v a 2s. c o m
 * @return PdfPTable
 * @throws DocumentException 
 */
private void addTable(WSIBox b) throws DocumentException {
    float[] widths = { 0.15f, 0.75f, 0.2f };
    PdfPTable tbl = new PdfPTable(widths);
    PdfPCell headerCell = new PdfPCell();

    tbl.setWidthPercentage(100f);

    // Write header cells of table
    headerCell.setBorderWidthBottom(headerLineWidth);
    headerCell.setBorderWidthTop(headerLineWidth);
    headerCell.setBorderWidthLeft(0);
    headerCell.setBorderWidthRight(0);
    headerCell.setPhrase(new Phrase("Object", tableHeaderFontLarge));
    headerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    tbl.addCell(headerCell);
    headerCell.setPhrase(new Phrase("Elements", tableHeaderFontLarge));
    headerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    tbl.addCell(headerCell);
    headerCell.setPhrase(new Phrase("# Samples", tableHeaderFontLarge));
    headerCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tbl.addCell(headerCell);

    // Find all objects associated with samples in this box
    SearchParameters objparam = new SearchParameters(SearchReturnObject.OBJECT);
    objparam.addSearchConstraint(SearchParameterName.SAMPLEBOXID, SearchOperator.EQUALS,
            b.getIdentifier().getValue().toString());
    EntitySearchResource<TridasObject> objresource = new EntitySearchResource<TridasObject>(objparam);
    objresource.setProperty(TellervoResourceProperties.ENTITY_REQUEST_FORMAT,
            TellervoRequestFormat.COMPREHENSIVE);
    TellervoResourceAccessDialog dialog = new TellervoResourceAccessDialog(objresource);

    objresource.query();
    dialog.setVisible(true);
    if (!dialog.isSuccessful()) {
        System.out.println("oopsey doopsey.  Error getting objects");
        return;
    }
    List<TridasObject> obj = objresource.getAssociatedResult();

    // Check that there are not too many objects to fit on box label
    if (obj.size() > 10) {
        System.out.println("Warning this label has " + Integer.toString(obj.size())
                + " objects associated with it so is unlikely to fit and may take some time to produce!");
    }

    if (obj.size() < 4) {
        // Not many objects so add some space to the table for prettiness sake
        headerCell.setBorder(0);
        headerCell.setPhrase(new Phrase(" "));
        tbl.addCell(headerCell);
        tbl.addCell(headerCell);
        tbl.addCell(headerCell);
    }

    // Sort objects into alphabetically order based on labcode
    TridasComparator sorter = new TridasComparator();
    Collections.sort(obj, sorter);

    Integer sampleCountInBox = 0;

    // Loop through objects
    List<TridasObject> objdone = new ArrayList<TridasObject>(); // Array of top level objects that have already been dealt with
    mainobjloop: for (TridasObject myobj : obj) {
        // Need to check if this object has already been done as there will be duplicate top level objects if there are samples 
        // from more than one subobject in the box 
        if (objdone.size() > 0) {
            try {
                for (TridasObject tlo : objdone) {
                    TridasObjectEx tloex = (TridasObjectEx) tlo;
                    TridasObjectEx myobjex = (TridasObjectEx) myobj;

                    if (tloex.getLabCode().compareTo(myobjex.getLabCode()) == 0) {
                        // Object already been done so skip to next
                        continue mainobjloop;
                    } else {
                        // Object has not been done so add to the done list and keep going
                        objdone.add(myobj);
                    }
                }
            } catch (Exception e) {
            }

        } else {
            objdone.add(myobj);
        }

        // Add object code to first column         
        PdfPCell dataCell = new PdfPCell();
        dataCell.setBorderWidthBottom(0);
        dataCell.setBorderWidthTop(0);
        dataCell.setBorderWidthLeft(0);
        dataCell.setBorderWidthRight(0);
        dataCell.setHorizontalAlignment(Element.ALIGN_LEFT);
        String objCode = null;

        if (myobj instanceof TridasObjectEx)
            objCode = ((TridasObjectEx) myobj).getLabCode();
        dataCell.setPhrase(new Phrase(objCode, bodyFontLarge));
        tbl.addCell(dataCell);

        // Search for elements associated with this object
        System.out.println("Starting search for elements associated with " + myobj.getTitle().toString());
        SearchParameters sp = new SearchParameters(SearchReturnObject.ELEMENT);
        sp.addSearchConstraint(SearchParameterName.SAMPLEBOXID, SearchOperator.EQUALS,
                b.getIdentifier().getValue());
        sp.addSearchConstraint(SearchParameterName.ANYPARENTOBJECTID, SearchOperator.EQUALS,
                myobj.getIdentifier().getValue());
        EntitySearchResource<TridasElement> resource = new EntitySearchResource<TridasElement>(sp);
        resource.setProperty(TellervoResourceProperties.ENTITY_REQUEST_FORMAT, TellervoRequestFormat.SUMMARY);
        TellervoResourceAccessDialog dialog2 = new TellervoResourceAccessDialog(resource);
        resource.query();
        dialog2.setVisible(true);
        if (!dialog2.isSuccessful()) {
            System.out.println("oopsey doopsey.  Error getting elements");
            return;
        }
        //XMLDebugView.showDialog();
        List<TridasElement> elements = resource.getAssociatedResult();
        TridasComparator numSorter = new TridasComparator(TridasComparator.Type.TITLES,
                TridasComparator.NullBehavior.NULLS_LAST,
                TridasComparator.CompareBehavior.AS_NUMBERS_THEN_STRINGS);
        Collections.sort(elements, numSorter);

        // Loop through elements 
        Integer smpCnt = 0;
        ArrayList<String> numlist = new ArrayList<String>();
        for (TridasElement myelem : elements) {
            // Add element title to string
            if (myelem.getTitle() != null) {
                String mytitle = myelem.getTitle();
                numlist.add(mytitle);
            }

            // Grab associated samples and add count to running total
            List<TridasSample> samples = myelem.getSamples();
            smpCnt += samples.size();
        }

        // Add element names to second column
        dataCell.setPhrase(new Phrase(hyphenSummarize(numlist), bodyFontLarge));
        tbl.addCell(dataCell);

        // Add sample count to third column
        dataCell.setPhrase(new Phrase(smpCnt.toString(), bodyFontLarge));
        dataCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        tbl.addCell(dataCell);

        sampleCountInBox += smpCnt;

    }

    if (obj.size() < 4) {
        // Not many objects so add some space to the table for prettiness sake
        headerCell.setBorder(0);
        headerCell.setPhrase(new Phrase(" "));
        tbl.addCell(headerCell);
        tbl.addCell(headerCell);
        tbl.addCell(headerCell);
    }

    headerCell.setBorderWidthBottom(headerLineWidth);
    headerCell.setBorderWidthTop(headerLineWidth);
    headerCell.setBorderWidthLeft(0);
    headerCell.setBorderWidthRight(0);

    headerCell.setPhrase(new Phrase(" ", bodyFontLarge));
    tbl.addCell(headerCell);
    headerCell.setPhrase(new Phrase("Grand Total", tableHeaderFontLarge));
    headerCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tbl.addCell(headerCell);
    headerCell.setPhrase(new Phrase(sampleCountInBox.toString(), bodyFontLarge));
    tbl.addCell(headerCell);

    // Add table to document
    document.add(tbl);
}

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

License:Open Source License

public void generateBoxLabel(OutputStream output) {

    try {/*from w w w .  ja va 2  s . co m*/

        PdfWriter writer = PdfWriter.getInstance(document, output);

        document.setPageSize(PageSize.LETTER);
        document.open();

        cb = writer.getDirectContent();

        // Set basic metadata
        document.addAuthor("Peter Brewer");
        document.addSubject("Box Label");

        for (WSIBox b : this.boxlist) {

            // Title Left      
            ColumnText ct = new ColumnText(cb);
            ct.setSimpleColumn(document.left(), document.top(15) - 210, 368, document.top(15), 20,
                    Element.ALIGN_LEFT);
            ct.addText(getTitlePDF(b));
            ct.go();

            // Barcode
            ColumnText ct2 = new ColumnText(cb);
            ct2.setSimpleColumn(370, document.top(15) - 100, document.right(0), document.top(0), 20,
                    Element.ALIGN_RIGHT);
            ct2.addElement(getBarCode(b));
            ct2.go();

            // Timestamp
            ColumnText ct3 = new ColumnText(cb);
            ct3.setSimpleColumn(document.left(), document.top(15) - 223, 350, document.top(15) - 60, 20,
                    Element.ALIGN_LEFT);
            ct3.setLeading(0, 1.2f);
            ct3.addText(getTimestampPDF(b));
            ct3.go();

            // Pad text
            document.add(new Paragraph(" "));
            Paragraph p2 = new Paragraph();
            p2.setSpacingBefore(70);
            p2.setSpacingAfter(10);
            p2.add(new Chunk(" ", bodyFontLarge));
            document.add(new Paragraph(p2));

            // Ring samples table
            addTable(b);
            document.add(getParagraphSpace());

            document.add(getComments(b));

            document.newPage();

        }

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    }

    // Close the document
    document.close();
}

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

License:Open Source License

/**
 * Get PdfPTable containing the samples per object
 * // ww w  .j a  v  a 2s  .c o m
 * @return PdfPTable
 * @throws DocumentException 
 */
private void addTable(WSIBox b) throws DocumentException {
    float[] widths = { 0.15f, 0.75f, 0.2f };
    PdfPTable tbl = new PdfPTable(widths);
    PdfPCell headerCell = new PdfPCell();

    tbl.setWidthPercentage(100f);

    // Write header cells of table
    headerCell.setBorderWidthBottom(headerLineWidth);
    headerCell.setBorderWidthTop(headerLineWidth);
    headerCell.setBorderWidthLeft(0);
    headerCell.setBorderWidthRight(0);
    headerCell.setPhrase(new Phrase("Object", tableHeaderFontLarge));
    headerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    tbl.addCell(headerCell);
    headerCell.setPhrase(new Phrase("Elements", tableHeaderFontLarge));
    headerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    tbl.addCell(headerCell);
    headerCell.setPhrase(new Phrase("# Samples", tableHeaderFontLarge));
    headerCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tbl.addCell(headerCell);

    // Find all objects associated with samples in this box
    SearchParameters objparam = new SearchParameters(SearchReturnObject.OBJECT);
    objparam.addSearchConstraint(SearchParameterName.SAMPLEBOXID, SearchOperator.EQUALS,
            b.getIdentifier().getValue().toString());
    EntitySearchResource<TridasObject> objresource = new EntitySearchResource<TridasObject>(objparam);
    objresource.setProperty(TellervoResourceProperties.ENTITY_REQUEST_FORMAT,
            TellervoRequestFormat.COMPREHENSIVE);
    TellervoResourceAccessDialog dialog = new TellervoResourceAccessDialog(objresource);

    objresource.query();
    dialog.setVisible(true);
    if (!dialog.isSuccessful()) {
        System.out.println("oopsey doopsey.  Error getting objects");
        return;
    }
    List<TridasObject> obj = objresource.getAssociatedResult();

    // Check that there are not too many objects to fit on box label
    if (obj.size() > 10) {
        System.out.println("Warning this label has " + Integer.toString(obj.size())
                + " objects associated with it so is unlikely to fit and may take some time to produce!");
    }

    if (obj.size() < 4) {
        // Not many objects so add some space to the table for prettiness sake
        headerCell.setBorder(0);
        headerCell.setPhrase(new Phrase(" "));
        tbl.addCell(headerCell);
        tbl.addCell(headerCell);
        tbl.addCell(headerCell);
    }

    // Sort objects into alphabetically order based on labcode
    TridasComparator sorter = new TridasComparator();
    Collections.sort(obj, sorter);

    Integer sampleCountInBox = 0;

    // Loop through objects
    List<TridasObject> objlist = new ArrayList<TridasObject>(); // Array of top level objects that have already been dealt with

    for (TridasObject myobj : obj) {
        objlist.add(myobj);
        if (myobj.isSetObjects()) {
            for (TridasObject obj2 : myobj.getObjects()) {
                objlist.add(obj2);
            }
        }
    }

    Collections.sort(objlist, sorter);

    mainobjloop: for (TridasObject myobj : objlist) {
        // Need to check if this object has already been done as there will be duplicate top level objects if there are samples 
        // from more than one subobject in the box 
        /*if(objdone.size()>0)
        {
           try{for(TridasObject tlo : objdone){
              TridasObjectEx tloex = (TridasObjectEx) tlo;
              TridasObjectEx myobjex = (TridasObjectEx) myobj;
                      
              //if (tloex.getLabCode().compareTo(myobjex.getLabCode())==0){
          // Object already been done so skip to next
              //   continue mainobjloop;
              //}
              //else {
          // Object has not been done so add to the done list and keep going
          objdone.add(myobj);
              //}
           }} catch (Exception e){}
                   
        }
        else
        {
           objdone.add(myobj);
        }*/

        // Add object code to first column         
        PdfPCell dataCell = new PdfPCell();
        dataCell.setBorderWidthBottom(0);
        dataCell.setBorderWidthTop(0);
        dataCell.setBorderWidthLeft(0);
        dataCell.setBorderWidthRight(0);
        dataCell.setHorizontalAlignment(Element.ALIGN_LEFT);
        String objCode = null;

        if (myobj instanceof TridasObjectEx)
            objCode = ((TridasObjectEx) myobj).getMultiLevelLabCode();

        // Search for elements associated with this object
        System.out.println("Starting search for elements associated with " + myobj.getTitle().toString());
        SearchParameters sp = new SearchParameters(SearchReturnObject.ELEMENT);
        sp.addSearchConstraint(SearchParameterName.SAMPLEBOXID, SearchOperator.EQUALS,
                b.getIdentifier().getValue());
        sp.addSearchConstraint(SearchParameterName.OBJECTID, SearchOperator.EQUALS,
                myobj.getIdentifier().getValue());
        EntitySearchResource<TridasElement> resource = new EntitySearchResource<TridasElement>(sp);
        resource.setProperty(TellervoResourceProperties.ENTITY_REQUEST_FORMAT, TellervoRequestFormat.SUMMARY);
        TellervoResourceAccessDialog dialog2 = new TellervoResourceAccessDialog(resource);
        resource.query();
        dialog2.setVisible(true);
        if (!dialog2.isSuccessful()) {
            System.out.println("oopsey doopsey.  Error getting elements");
            return;
        }
        //XMLDebugView.showDialog();
        List<TridasElement> elements = resource.getAssociatedResult();

        if (elements == null || elements.size() == 0)
            continue;

        dataCell.setPhrase(new Phrase(objCode, bodyFontLarge));
        tbl.addCell(dataCell);

        TridasComparator numSorter = new TridasComparator(TridasComparator.Type.TITLES,
                TridasComparator.NullBehavior.NULLS_LAST,
                TridasComparator.CompareBehavior.AS_NUMBERS_THEN_STRINGS);
        Collections.sort(elements, numSorter);

        // Loop through elements 
        Integer smpCnt = 0;
        ArrayList<String> numlist = new ArrayList<String>();
        for (TridasElement myelem : elements) {
            // Add element title to string
            if (myelem.getTitle() != null) {
                String mytitle = myelem.getTitle();
                numlist.add(mytitle);
            }

            // Grab associated samples and add count to running total
            List<TridasSample> samples = myelem.getSamples();
            smpCnt += samples.size();
        }

        // Add element names to second column
        dataCell.setPhrase(new Phrase(hyphenSummarize(numlist), bodyFontLarge));
        tbl.addCell(dataCell);

        // Add sample count to third column
        dataCell.setPhrase(new Phrase(smpCnt.toString(), bodyFontLarge));
        dataCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        tbl.addCell(dataCell);

        sampleCountInBox += smpCnt;

    }

    if (obj.size() < 4) {
        // Not many objects so add some space to the table for prettiness sake
        headerCell.setBorder(0);
        headerCell.setPhrase(new Phrase(" "));
        tbl.addCell(headerCell);
        tbl.addCell(headerCell);
        tbl.addCell(headerCell);
    }

    headerCell.setBorderWidthBottom(headerLineWidth);
    headerCell.setBorderWidthTop(headerLineWidth);
    headerCell.setBorderWidthLeft(0);
    headerCell.setBorderWidthRight(0);

    headerCell.setPhrase(new Phrase(" ", bodyFontLarge));
    tbl.addCell(headerCell);
    headerCell.setPhrase(new Phrase("Grand Total", tableHeaderFontLarge));
    headerCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tbl.addCell(headerCell);
    headerCell.setPhrase(new Phrase(sampleCountInBox.toString(), bodyFontLarge));
    tbl.addCell(headerCell);

    // Add table to document
    document.add(tbl);
}

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

License:Open Source License

private void generateProSheet(OutputStream output) {

    Paragraph spacingPara = new Paragraph();
    spacingPara.setSpacingBefore(10);/*from w  w w .j  av a  2 s.c  o m*/
    spacingPara.add(new Chunk(" ", bodyFont));

    try {

        PdfWriter writer = PdfWriter.getInstance(document, output);
        document.setPageSize(PageSize.LETTER);

        // Set basic metadata
        document.addAuthor("Peter Brewer");
        document.addSubject("Corina Provenience Sheet for " + o.getTitle());

        HeaderFooter footer = new HeaderFooter(new Phrase(""), new Phrase(""));
        footer.setAlignment(Element.ALIGN_RIGHT);
        footer.setBorder(0);
        document.setFooter(footer);

        HeaderFooter header = new HeaderFooter(new Phrase(o.getLabCode() + " - " + o.getTitle(), bodyFont),
                false);
        header.setAlignment(Element.ALIGN_RIGHT);
        header.setBorder(0);
        document.setHeader(header);

        document.open();
        cb = writer.getDirectContent();

        // Title Left      
        ColumnText ct = new ColumnText(cb);
        ct.setSimpleColumn(document.left(), document.top() - 193, document.right(), document.top() - 20, 20,
                Element.ALIGN_LEFT);
        ct.addText(getTitlePDF());
        ct.go();

        // Timestamp
        ColumnText ct3 = new ColumnText(cb);
        ct3.setSimpleColumn(document.left(), document.top() - 223, 283, document.top() - 60, 20,
                Element.ALIGN_LEFT);
        ct3.setLeading(0, 1.2f);
        ct3.addText(getTimestampPDF());
        ct3.go();

        // Pad text
        document.add(spacingPara);
        document.add(getObjectDescription());
        document.add(getObjectComments());

        document.add(spacingPara);

        getElementTable();

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    }

    // Close the document
    document.close();
}