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

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

Introduction

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

Prototype

public void setBorderWidthLeft(float borderWidthLeft) 

Source Link

Document

Sets the width of the left border.

Usage

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

License:Open Source License

public static void setBorder(StyleBorder border, PdfPCell pdfPCell, int borderSide) {
    if (border == null) {
        return;//from ww w  . j a  v  a2  s .  com
    }
    // boolean noBorder = (STBorder.NONE == border.getVal());

    // No border

    float size = -1;
    BigInteger borderSize = border.getWidth();
    if (borderSize != null) {
        size = dxa2points(borderSize);
    }

    Color borderColor = border.getColor();

    switch (borderSide) {
    case Rectangle.TOP:
        if (size != -1) {
            pdfPCell.setBorderWidthTop(size);
        }
        if (borderColor != null) {

            pdfPCell.setBorderColorTop(borderColor);
        }
        break;
    case Rectangle.BOTTOM:
        if (size != -1) {
            pdfPCell.setBorderWidthBottom(size);
        }
        if (borderColor != null) {
            pdfPCell.setBorderColorBottom(borderColor);
        }
        break;
    case Rectangle.LEFT:
        if (size != -1) {
            pdfPCell.setBorderWidthLeft(size);
        }
        if (borderColor != null) {
            pdfPCell.setBorderColorLeft(borderColor);
        }
        break;
    case Rectangle.RIGHT:
        if (size != -1) {
            pdfPCell.setBorderWidthRight(size);
        }
        if (borderColor != null) {
            pdfPCell.setBorderColorRight(borderColor);
        }
        break;
    }

}

From source file:org.mapfish.print.config.layout.CellConfig.java

License:Open Source License

protected void apply(PdfPCell cell, RenderingContext context, PJsonObject params) {
    if (paddingLeft != null)
        cell.setPaddingLeft(paddingLeft.floatValue());
    if (paddingRight != null)
        cell.setPaddingRight(paddingRight.floatValue());
    if (paddingTop != null)
        cell.setPaddingTop(paddingTop.floatValue());
    if (paddingBottom != null)
        cell.setPaddingBottom(paddingBottom.floatValue());

    if (borderWidthLeft != null)
        cell.setBorderWidthLeft(borderWidthLeft.floatValue());
    if (borderWidthRight != null)
        cell.setBorderWidthRight(borderWidthRight.floatValue());
    if (borderWidthTop != null)
        cell.setBorderWidthTop(borderWidthTop.floatValue());
    if (borderWidthBottom != null)
        cell.setBorderWidthBottom(borderWidthBottom.floatValue());

    if (getBorderColorLeftVal(context, params) != null)
        cell.setBorderColorLeft(getBorderColorLeftVal(context, params));
    if (getBorderColorRightVal(context, params) != null)
        cell.setBorderColorRight(getBorderColorRightVal(context, params));
    if (getBorderColorTopVal(context, params) != null)
        cell.setBorderColorTop(getBorderColorTopVal(context, params));
    if (getBorderColorBottomVal(context, params) != null)
        cell.setBorderColorBottom(getBorderColorBottomVal(context, params));

    if (getBackgroundColorVal(context, params) != null)
        cell.setBackgroundColor(getBackgroundColorVal(context, params));

    if (align != null)
        cell.setHorizontalAlignment(align.getCode());
    if (vertAlign != null)
        cell.setVerticalAlignment(vertAlign.getCode());

}

From source file:org.mapfish.print.config.layout.TableConfig.java

License:Open Source License

public void apply(PdfPCell cell, int row, int col, int nbRows, int nbCols, RenderingContext context,
        PJsonObject params) {//w w w  . ja va2 s .  c  o m
    if (cells != null) {
        for (int i = 0; i < cells.size(); i++) {
            CellException cellException = cells.get(i);
            if (cellException.matches(row, col)) {
                cellException.apply(cell, context, params);
            }
        }
    }

    if (row == 0) {
        if (borderWidthTop != null)
            cell.setBorderWidthTop(borderWidthTop.floatValue());
        if (getBorderColorTopVal(context, params) != null)
            cell.setBorderColorTop(getBorderColorTopVal(context, params));
    }

    if (col == 0) {
        if (borderWidthLeft != null)
            cell.setBorderWidthLeft(borderWidthLeft.floatValue());
        if (getBorderColorLeftVal(context, params) != null)
            cell.setBorderColorLeft(getBorderColorLeftVal(context, params));
    }

    if (row == nbRows - 1) {
        if (borderWidthBottom != null)
            cell.setBorderWidthBottom(borderWidthBottom.floatValue());
        if (getBorderColorBottomVal(context, params) != null)
            cell.setBorderColorBottom(getBorderColorBottomVal(context, params));
    }

    if (col == nbCols - 1) {
        if (borderWidthRight != null)
            cell.setBorderWidthRight(borderWidthRight.floatValue());
        if (getBorderColorRightVal(context, params) != null)
            cell.setBorderColorRight(getBorderColorRightVal(context, params));
    }

}

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

License:Open Source License

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

    try {//from  w w  w. ja v a 2  s.c o m
        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

/**
 * Write the title page of the protocol.
 * //from  w  w w  . j av  a 2  s  .c  o m
 * @param meetings
 *            the meetings
 * @param attachProdExtRefs
 *            true, if the external reference of the product should be part
 *            of the protocol
 * 
 * @throws ExportException
 *             If an error occurs while writing the title page
 */
protected void writeTitlePage(List<Meeting> meetings, boolean attachProdExtRefs) throws ExportException {
    try {
        Font plainFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED),
                10);

        Font plainFontSmall = new Font(
                BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 8);

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

        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), 8);

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

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

        Font protocolFontTitle = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 20);

        Font reviewFontTitle = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 15);

        Font meetingFontTitle = new Font(
                BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 13);

        /*
         * Title of the protocol
         */
        PdfPTable tableTitlePage = new PdfPTable(new float[] { 0.6f, 0.4f });
        tableTitlePage.setWidthPercentage(100);
        tableTitlePage.setSplitRows(false);
        tableTitlePage.getDefaultCell().setBorder(0);
        tableTitlePage.getDefaultCell().setPadding(0);

        String protocolTitle = translate("Findings List of the Review");

        if (meetings.size() == 1) {
            protocolTitle = translate("Findings List of the Review Meeting");
        }

        PdfPCell cellProtocol = new PdfPCell(new Phrase(protocolTitle, protocolFontTitle));
        cellProtocol.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellProtocol.setColspan(2);
        cellProtocol.setBorderWidth(0);
        cellProtocol.setPaddingTop(PDFTools.cmToPt(0.4f));
        cellProtocol.setPaddingBottom(PDFTools.cmToPt(0.2f));

        tableTitlePage.addCell(cellProtocol);

        /*
         * Name of the review
         */
        PdfPCell cellRevName = new PdfPCell(
                new Phrase(Application.getInstance().getReviewMgmt().getReviewName(), reviewFontTitle));
        cellRevName.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellRevName.setColspan(2);
        cellRevName.setBorderWidth(0);
        cellRevName.setPaddingBottom(PDFTools.cmToPt(1.6f));

        tableTitlePage.addCell(cellRevName);

        /*
         * Review meeting date and location
         */
        if (meetings.size() == 1) {
            sdfDate.setTimeZone(meetings.get(0).getProtocol().getDate().getTimeZone());
            sdfTime.setTimeZone(meetings.get(0).getProtocol().getDate().getTimeZone());

            String meetingDate = sdfDate.format(meetings.get(0).getProtocol().getDate().getTime());

            String meetingTime = sdfTime.format(meetings.get(0).getProtocol().getStart().getTime()) + " - "
                    + sdfTime.format(meetings.get(0).getProtocol().getEnd().getTime()) + " ["
                    + meetings.get(0).getProtocol().getEnd().getTimeZone().getDisplayName() + "]";

            Phrase phraseMeeting = new Phrase(meetingDate + " (" + meetingTime + ")", meetingFontTitle);

            PdfPCell cellMeeting = new PdfPCell(phraseMeeting);
            cellMeeting.setColspan(2);
            cellMeeting.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellMeeting.setPadding(0);
            cellMeeting.setBorderWidth(0);

            tableTitlePage.addCell(cellMeeting);

            String location = meetings.get(0).getProtocol().getLocation();

            if (location.trim().equals("")) {
                location = "--";
            }
            cellMeeting = new PdfPCell(new Phrase(translate("Location") + ": " + location, meetingFontTitle));
            cellMeeting.setColspan(2);
            cellMeeting.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellMeeting.setPadding(0);
            cellMeeting.setBorderWidth(0);
            cellMeeting.setPaddingTop(PDFTools.cmToPt(0.15f));
            cellMeeting.setPaddingBottom(PDFTools.cmToPt(1.9f));

            tableTitlePage.addCell(cellMeeting);
        }

        /*
         * Review description and comments
         */
        PdfPCell cellRevDesc = new PdfPCell(new Phrase(translate("Review Description:"), boldItalicFont));
        cellRevDesc.setBorderWidth(0);
        cellRevDesc.setPadding(padding);

        tableTitlePage.addCell(cellRevDesc);

        cellRevDesc = new PdfPCell(new Phrase(translate("Review Comments"), boldFont));
        cellRevDesc.setBorderWidth(0);
        cellRevDesc.setPadding(padding);
        cellRevDesc.setBackgroundColor(cellBackground);

        tableTitlePage.addCell(cellRevDesc);

        String revDesc = Application.getInstance().getReviewMgmt().getReviewDescription();
        if (revDesc.trim().equals("")) {
            revDesc = "--";
        }

        Phrase phrDesc = new Phrase(revDesc, plainFont);
        phrDesc.setLeading(leading);
        cellRevDesc = new PdfPCell();
        cellRevDesc.addElement(phrDesc);
        cellRevDesc.setBorderWidth(0);
        cellRevDesc.setPadding(padding);
        cellRevDesc.setPaddingBottom(padding * 1.8f);

        tableTitlePage.addCell(cellRevDesc);

        String revComm = Application.getInstance().getReviewMgmt().getReviewComments();
        if (revComm.trim().equals("")) {
            revComm = "--";
        }

        Phrase phrComm = new Phrase(revComm, italicFont);
        phrComm.setLeading(leading);
        cellRevDesc = new PdfPCell();
        cellRevDesc.addElement(phrComm);
        cellRevDesc.setBorderWidth(0);
        cellRevDesc.setPadding(padding);
        cellRevDesc.setPaddingBottom(padding * 1.8f);
        cellRevDesc.setBackgroundColor(cellBackground);

        tableTitlePage.addCell(cellRevDesc);

        tableTitlePage.addCell(createVerticalStrut(PDFTools.cmToPt(1.0f), 2));

        /*
         * Product title
         */
        PdfPTable tableProduct = new PdfPTable(new float[] { 0.07f, 0.93f });
        tableProduct.setWidthPercentage(100);
        tableProduct.setSplitRows(false);
        tableProduct.getDefaultCell().setBorderWidth(0);
        tableProduct.getDefaultCell().setPadding(0);

        PdfPCell cellProdTitle = new PdfPCell(new Phrase(translate("Reviewed Product:"), boldItalicFont));
        cellProdTitle.setColspan(2);
        cellProdTitle.setPadding(padding);
        cellProdTitle.setBorder(0);

        tableProduct.addCell(cellProdTitle);

        /*
         * 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);

        /*
         * Write name and version of the reviewed product
         */
        String prodName = Data.getInstance().getResiData().getReview().getProduct().getName();

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

        Phrase phrName = new Phrase(translate("Product Name") + ": " + prodName, plainFont);
        phrName.setLeading(leading);

        PdfPCell cellName = new PdfPCell();
        cellName.addElement(phrName);
        cellName.setBorderWidth(0);
        cellName.setPadding(padding);
        cellName.setPaddingBottom(0);

        tableProduct.addCell(cellListPoint);

        tableProduct.addCell(cellName);

        String prodVersion = Data.getInstance().getResiData().getReview().getProduct().getVersion();

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

        Phrase phrVersion = new Phrase(translate("Product Version") + ": " + prodVersion, plainFont);
        phrVersion.setLeading(leading);

        PdfPCell cellVersion = new PdfPCell();
        cellVersion.addElement(phrVersion);
        cellVersion.setBorderWidth(0);
        cellVersion.setPadding(padding);
        cellVersion.setPaddingBottom(0);

        tableProduct.addCell(cellListPoint);

        tableProduct.addCell(cellVersion);

        if (Application.getInstance().getReviewMgmt().getNumberOfProdRefs() > 0) {
            /*
             * Table of product references
             */
            PdfPCell cellRefTitle = new PdfPCell(new Phrase(translate("Product References:"), boldItalicFont));
            cellRefTitle.setBorderWidth(0);
            cellRefTitle.setPadding(padding);
            cellRefTitle.setPaddingTop(padding * 4);
            cellRefTitle.setColspan(2);

            tableProduct.addCell(cellRefTitle);

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

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

                tableProduct.addCell(cellListPoint);

                tableProduct.addCell(cellRef);
            }

            /*
             * External file references
             */
            for (File ref : Application.getInstance().getReviewMgmt().getExtProdReferences()) {
                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);
                cellRef.setPaddingBottom(0);

                tableProduct.addCell(cellListPoint);

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

                tableProduct.addCell(cellRef);
            }
        }

        /*
         * Add the product table to the base table
         */
        PdfPCell cellProduct = new PdfPCell(tableProduct);
        cellProduct.setBorder(0);
        cellProduct.setPadding(0);

        tableTitlePage.addCell(cellProduct);

        /*
         * List the meetings of this review
         */
        PdfPCell cellInfos = new PdfPCell();
        cellInfos.setBorder(0);
        cellInfos.setPadding(0);

        /*
         * meeting list title or meeting info title
         */
        PdfPTable tableInfos = new PdfPTable(new float[] { 0.09f, 0.91f });
        tableInfos.setWidthPercentage(100);
        tableInfos.setSplitRows(false);
        tableInfos.getDefaultCell().setBorderWidth(0);
        tableInfos.getDefaultCell().setPadding(0);

        String title = translate("Meeting Information:");

        if (meetings.size() > 1) {
            title = translate("Findings Lists of the Review Meetings:");
        }

        PdfPCell cellInfosTitle = new PdfPCell(new Phrase(title, boldFont));
        cellInfosTitle.setColspan(2);
        cellInfosTitle.setPadding(padding);
        cellInfosTitle.setBorder(0);

        tableInfos.addCell(cellInfosTitle);

        if (meetings.size() > 1) {
            /*
             * list the meetings of this review (for review protocols)
             */
            for (Meeting m : meetings) {
                Protocol protocol = m.getProtocol();
                if (protocol != null) {
                    String meetingDate = sdfDate.format(protocol.getDate().getTime());

                    String meetingTime = sdfTime.format(protocol.getStart().getTime()) + " - "
                            + sdfTime.format(protocol.getEnd().getTime()) + " ["
                            + protocol.getEnd().getTimeZone().getDisplayName() + "]";
                    String protLoc = protocol.getLocation();
                    if (protLoc.trim().equals("")) {
                        protLoc = "--";
                    }

                    Phrase phraseMeet = new Phrase(
                            translate("Date") + ": " + meetingDate + "\n" + translate("Time") + ": "
                                    + meetingTime + "\n" + translate("Location") + ": " + protLoc,
                            italicFont);

                    Paragraph paraMeet = new Paragraph();
                    paraMeet.setLeading(leading);

                    Anchor anchor = new Anchor(phraseMeet);
                    anchor.setReference("#" + Long.toString(
                            protocol.getDate().getTimeInMillis() + protocol.getStart().getTimeInMillis()));

                    paraMeet.add(anchor);

                    PdfPCell cellMeet = new PdfPCell();
                    cellMeet.addElement(paraMeet);
                    cellMeet.setBorderWidth(0);
                    cellMeet.setPadding(padding);

                    tableInfos.addCell(cellListPoint);

                    tableInfos.addCell(cellMeet);
                }
            }
        } else {
            Protocol prot = meetings.get(0).getProtocol();
            Duration meetDur = DatatypeFactory.newInstance()
                    .newDuration(prot.getEnd().getTimeInMillis() - prot.getStart().getTimeInMillis());

            Phrase phraseMeetInfo = new Phrase(
                    translate("Duration of the meeting") + ":\n" + meetDur.getHours() + " "
                            + translate("Hour(s)") + ", " + meetDur.getMinutes() + " " + translate("Minute(s)"),
                    italicFont);
            phraseMeetInfo.setLeading(leading);

            PdfPCell cellMeetInfo = new PdfPCell();
            cellMeetInfo.addElement(phraseMeetInfo);
            cellMeetInfo.setBorderWidth(0);
            cellMeetInfo.setPadding(padding);

            tableInfos.addCell(cellListPoint);

            tableInfos.addCell(cellMeetInfo);

            /*
             * meeting number of findings
             */
            phraseMeetInfo = new Phrase(translate("Number of findings") + ": " + prot.getFindings().size(),
                    italicFont);
            phraseMeetInfo.setLeading(leading);

            cellMeetInfo = new PdfPCell();
            cellMeetInfo.addElement(phraseMeetInfo);
            cellMeetInfo.setBorderWidth(0);
            cellMeetInfo.setPadding(padding);

            tableInfos.addCell(cellListPoint);

            tableInfos.addCell(cellMeetInfo);

            /*
             * meeting number of attendees
             */
            phraseMeetInfo = new Phrase(
                    translate("Number of attendees") + ": " + protMgmt.getAttendees(prot).size(), italicFont);
            phraseMeetInfo.setLeading(leading);

            cellMeetInfo = new PdfPCell();
            cellMeetInfo.addElement(phraseMeetInfo);
            cellMeetInfo.setBorderWidth(0);
            cellMeetInfo.setPadding(padding);

            tableInfos.addCell(cellListPoint);

            tableInfos.addCell(cellMeetInfo);
        }

        cellInfos.addElement(tableInfos);
        cellInfos.setBackgroundColor(cellBackground);
        cellInfos.setPaddingBottom(padding);

        tableTitlePage.addCell(cellInfos);

        /*
         * Insert vertical strut
         */
        tableTitlePage.addCell(createVerticalStrut(PDFTools.cmToPt(1.0f), 2));

        /*
         * Write general impression and recommendation
         */
        PdfPTable tableRevInfo = new PdfPTable(new float[] { 0.5f, 0.5f });
        tableRevInfo.setWidthPercentage(100);
        tableRevInfo.setSplitRows(false);
        tableRevInfo.getDefaultCell().setBorderWidth(0);
        tableRevInfo.getDefaultCell().setPadding(0);

        /*
         * Insert vertical strut
         */
        tableRevInfo.addCell(createVerticalStrut(PDFTools.cmToPt(0.5f), 2));

        PdfPCell cellImpr = new PdfPCell(
                new Phrase(translate("General impressions of the product:"), boldFont));
        cellImpr.setBorderWidth(0);
        cellImpr.setPadding(padding);
        cellImpr.setBorderColor(verticalBorderColor);
        cellImpr.setBorderWidthLeft(verticalBorderWidth);

        tableRevInfo.addCell(cellImpr);

        PdfPCell cellReco = new PdfPCell(
                new Phrase(translate("Final recommendation for the product:"), boldFont));
        cellReco.setBorderWidth(0);
        cellReco.setPadding(padding);
        cellReco.setBorderColor(verticalBorderColor);
        cellReco.setBorderWidthLeft(verticalBorderWidth);

        tableRevInfo.addCell(cellReco);

        String impression = Application.getInstance().getReviewMgmt().getImpression();
        if (impression.trim().equals("")) {
            impression = "--";
        }

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

        tableRevInfo.addCell(cellImpr);

        String recommendation = Application.getInstance().getReviewMgmt().getRecommendation();
        if (recommendation.trim().equals("")) {
            recommendation = "--";
        }

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

        tableRevInfo.addCell(cellReco);

        /*
         * Add vertical strut
         */
        tableRevInfo.addCell(createVerticalStrut(PDFTools.cmToPt(0.8f), 2));

        /*
         * Write possible severities for this review
         */
        String severities = "";
        String separator = "";
        for (String sev : Application.getInstance().getSeverityMgmt().getSeverities()) {
            severities = severities + separator + sev;
            separator = "; ";
        }

        Phrase phrSeverities = new Phrase();
        phrSeverities.add(new Chunk(
                translate("The severities of the findings in this review (descending order of importance):"),
                italicFontSmall));
        phrSeverities.add(new Chunk(" " + severities, boldItalicFontSmall));
        phrSeverities.setLeading(leading);
        PdfPCell cellSevs = new PdfPCell();
        cellSevs.setColspan(2);
        cellSevs.addElement(phrSeverities);
        cellSevs.setBorderWidth(0);
        cellSevs.setPadding(padding);

        tableRevInfo.addCell(cellSevs);

        /*
         * Short review statistics
         */
        if (meetings.size() > 1) {
            Phrase phrRevStat = new Phrase(MessageFormat.format(translate(
                    "This review consists of {0} attendees, {1} findings, {2} meetings and {3} aspects."),
                    Application.getInstance().getReviewMgmt().getNumberOfAttendees(),
                    Application.getInstance().getReviewMgmt().getNumberOfFindings(),
                    Application.getInstance().getReviewMgmt().getNumberOfMeetings(),
                    Application.getInstance().getReviewMgmt().getNumberOfAspects()), italicFontSmall);
            phrRevStat.setLeading(leading);
            PdfPCell cellRevStat = new PdfPCell();
            cellRevStat.setColspan(2);
            cellRevStat.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellRevStat.addElement(phrRevStat);
            cellRevStat.setBorderWidth(0);
            cellRevStat.setPadding(padding);
            cellRevStat.setPaddingTop(0);

            tableRevInfo.addCell(cellRevStat);
        }

        /*
         * Write the date of creation
         */
        String creationDate = sdfDate.format(new Date().getTime());

        Phrase phrCreationDate = new Phrase(
                translate("This finding has been created with RevAger on") + " " + creationDate,
                plainFontSmall);
        phrCreationDate.setLeading(leading);
        PdfPCell cellCrDate = new PdfPCell();
        cellCrDate.setColspan(2);
        cellCrDate.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellCrDate.addElement(phrCreationDate);
        cellCrDate.setBorderWidth(0);
        cellCrDate.setPadding(0);
        cellCrDate.setPaddingLeft(padding);
        cellCrDate.setPaddingRight(padding);

        tableRevInfo.addCell(cellCrDate);

        /*
         * Add content to the base table
         */
        PdfPCell cellRevInfo = new PdfPCell();
        cellRevInfo.setColspan(2);
        cellRevInfo.setBorder(0);
        cellRevInfo.setPadding(0);
        cellRevInfo.addElement(tableRevInfo);

        tableTitlePage.addCell(cellRevInfo);

        pdfDoc.add(tableTitlePage);
    } 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.ProtocolPDFExporter.java

License:Open Source License

/**
 * Writes the given meeting to the protocol.
 * //from  www .  j ava 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.tellervo.desktop.print.BasicBoxLabel.java

License:Open Source License

/**
 * Get PdfPTable containing the samples per object
 * //from   w ww .  ja v a2  s. c  om
 * @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

/**
 * Get PdfPTable containing the samples per object
 * /*from ww w .  ja v a 2s .com*/
 * @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

/**
 * Get PdfPTable containing the ring width data for this series
 * /*from   w  w w  .j av a  2  s .  co  m*/
 * @return PdfPTable
 * @throws DocumentException 
 */
private void getElementTable() throws DocumentException {

    PdfPTable tbl = new PdfPTable(5);

    PdfPCell headerCell = new PdfPCell();

    tbl.setWidthPercentage(100f);
    float[] widths = { 0.1f, 0.4f, 0.2f, 0.1f, 0.2f };

    tbl.setWidths(widths);

    // Set up header
    headerCell.setPhrase(new Phrase("Element", tableHeaderFont));
    headerCell.setBorderWidthBottom(headerLineWidth);
    headerCell.setBorderWidthTop(headerLineWidth);
    headerCell.setBorderWidthLeft(0);
    headerCell.setBorderWidthRight(0);
    headerCell.setPaddingTop(5);
    headerCell.setPaddingBottom(5);
    tbl.addCell(headerCell);

    headerCell.setPhrase(new Phrase("Comments", tableHeaderFont));
    tbl.addCell(headerCell);

    headerCell.setPhrase(new Phrase("Taxon", tableHeaderFont));
    tbl.addCell(headerCell);

    headerCell.setPhrase(new Phrase("# Rings", tableHeaderFont));
    tbl.addCell(headerCell);

    headerCell.setPhrase(new Phrase("Dates", tableHeaderFont));
    tbl.addCell(headerCell);

    // Loop through rows
    for (org.tellervo.desktop.sample.Element e : this.elements) {
        Sample s = null;

        try {
            s = e.load();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
            continue;
        }

        // Find element details for this series 
        SearchParameters param = new SearchParameters(SearchReturnObject.DERIVED_SERIES);
        param.addSearchConstraint(SearchParameterName.SERIESDBID, SearchOperator.EQUALS,
                s.getIdentifier().getValue().toString());

        EntitySearchResource<TridasObject> searchResource = new EntitySearchResource<TridasObject>(param,
                TridasObject.class);
        searchResource.setProperty(TellervoResourceProperties.ENTITY_REQUEST_FORMAT,
                TellervoRequestFormat.COMPREHENSIVE);
        TellervoResourceAccessDialog dialog = new TellervoResourceAccessDialog(searchResource);
        searchResource.query();
        dialog.setVisible(true);

        List<TridasObject> oblist = searchResource.getAssociatedResult();

        if (oblist.size() != 1) {
            System.out.println(e.getName() + " has more than one (or no) associated objects so skipping");
            continue;
        }
        TridasObject obj = oblist.get(0);

        List<TridasElement> ellist = obj.getElements();
        if (ellist.size() != 1) {
            System.out.println(e.getName() + " has more than one (or no) associated element so skipping");
            continue;
        }
        TridasElement el = ellist.get(0);

        // make lab code
        LabCode labcode = new LabCode();
        labcode.appendSiteCode(((TridasObjectEx) obj).getLabCode());
        labcode.setElementCode(el.getTitle());

        PdfPCell dataCell = new PdfPCell();
        dataCell.setBorderWidthBottom(0);
        dataCell.setBorderWidthTop(0);
        dataCell.setBorderWidthLeft(0);
        dataCell.setBorderWidthRight(0);
        dataCell.setPaddingTop(5);
        dataCell.setPaddingBottom(5);
        dataCell.setHorizontalAlignment(Element.ALIGN_LEFT);

        // Title Column
        dataCell.setPhrase(new Phrase(LabCodeFormatter.getSamplePrefixFormatter().format(labcode).toString(),
                tableBodyFont));
        tbl.addCell(dataCell);

        // Comments Column
        if (el.getComments() != null)
            dataCell.setPhrase(new Phrase(el.getComments(), tableBodyFont));
        else
            dataCell.setPhrase(new Phrase(" ", tableBodyFont));
        tbl.addCell(dataCell);

        // Taxon Column
        dataCell.setHorizontalAlignment(Element.ALIGN_LEFT);
        dataCell.setPhrase(new Phrase(el.getTaxon().getNormal().toString(), tableBodyFont));
        tbl.addCell(dataCell);

        // Rings Column
        dataCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        dataCell.setPhrase(new Phrase(String.valueOf(s.countRings()), tableBodyFont));
        tbl.addCell(dataCell);

        // Dates column
        String datingLabel;
        String datingType = s.getSeries().getInterpretation().getDating().getType().value().toString();
        datingLabel = s.getSeries().getInterpretation().getFirstYear().getValue().toString();
        if (datingType == "Absolute") {
            datingLabel += s.getSeries().getInterpretation().getFirstYear().getSuffix().toString();
        }
        datingLabel += " - " + String.valueOf(
                s.getSeries().getInterpretation().getFirstYear().getValue().intValue() + s.countRings() - 1);
        if (datingType == "Relative") {
            datingLabel += " (Rel. Date)";
        }

        dataCell.setHorizontalAlignment(Element.ALIGN_LEFT);
        dataCell.setPhrase(new Phrase(datingLabel, tableBodyFont));
        tbl.addCell(dataCell);
    }

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

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

License:Open Source License

/**
 * Get PdfPTable containing the ring width data for this series
 * /*from   ww  w . j ava2 s.  c  o  m*/
 * @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();
}