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

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

Introduction

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

Prototype

public void setBorderWidthBottom(float borderWidthBottom) 

Source Link

Document

Sets the width of the bottom border.

Usage

From source file:org.oscarehr.web.reports.ocan.SummaryOfActionsAndCommentsReportGenerator.java

License:Open Source License

private void createOcanEntry(PdfPTable table, SummaryOfActionsAndCommentsOCANBean ocanBean) {
    Font f = new Font(Font.HELVETICA, 12, Font.BOLD, Color.BLACK);
    //header//from   w  ww .  j  a  v a 2s.  com
    PdfPCell c1 = new PdfPCell();
    c1.setBackgroundColor(Color.LIGHT_GRAY);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setPhrase(new Phrase("Rating", f));
    table.addCell(c1);
    c1 = new PdfPCell();
    c1.setColspan(2);
    c1.setBackgroundColor(Color.LIGHT_GRAY);
    c1.setPhrase(new Phrase(ocanBean.getOcanName() + " - " + dateFormatter.format(ocanBean.getOcanDate()), f));
    table.addCell(c1);

    //actions
    c1 = new PdfPCell();
    c1.setBackgroundColor(Color.LIGHT_GRAY);
    c1.setBorderWidthBottom(0);
    table.addCell(c1);
    c1 = new PdfPCell();
    c1.setColspan(1);
    c1.setBackgroundColor(Color.LIGHT_GRAY);
    c1.setPhrase(new Phrase("Actions", f));
    table.addCell(c1);
    c1 = new PdfPCell();
    c1.setColspan(1);
    c1.setPhrase(new Phrase(ocanBean.getActions(), normalText));
    table.addCell(c1);

    //By Whom
    c1 = new PdfPCell();
    c1.setBackgroundColor(Color.LIGHT_GRAY);
    c1.setBorderWidthBottom(0);
    table.addCell(c1);
    c1 = new PdfPCell();
    c1.setColspan(1);
    c1.setBackgroundColor(Color.LIGHT_GRAY);
    c1.setPhrase(new Phrase("By Whom", f));
    table.addCell(c1);
    c1 = new PdfPCell();
    c1.setColspan(1);
    c1.setPhrase(new Phrase(ocanBean.getByWhom(), normalText));
    table.addCell(c1);

    //review date
    c1 = new PdfPCell();
    c1.setBackgroundColor(Color.LIGHT_GRAY);
    c1.setBorderWidthBottom(0);
    table.addCell(c1);
    c1 = new PdfPCell();
    c1.setColspan(1);
    c1.setBackgroundColor(Color.LIGHT_GRAY);
    c1.setPhrase(new Phrase("Review Date", f));
    table.addCell(c1);
    c1 = new PdfPCell();
    c1.setColspan(1);
    c1.setPhrase(new Phrase(ocanBean.getReviewDate(), normalText));
    table.addCell(c1);

    //consumer
    c1 = new PdfPCell();
    c1.setBackgroundColor(Color.LIGHT_GRAY);
    c1.setPhrase(new Phrase(convertNeedToWord(ocanBean.getConsumerNeedRating()), boldText));
    table.addCell(c1);
    c1 = new PdfPCell();
    c1.setColspan(1);
    c1.setBackgroundColor(Color.LIGHT_GRAY);
    c1.setPhrase(new Phrase("Consumer Comments", f));
    table.addCell(c1);
    c1 = new PdfPCell();
    c1.setColspan(1);
    c1.setPhrase(new Phrase(includeComments ? ocanBean.getConsumerComments() : "", normalText));
    table.addCell(c1);

    //staff
    c1 = new PdfPCell();
    c1.setBackgroundColor(Color.LIGHT_GRAY);
    c1.setPhrase(new Phrase(convertNeedToWord(ocanBean.getStaffNeedRating()), boldText));
    table.addCell(c1);
    c1 = new PdfPCell();
    c1.setColspan(1);
    c1.setBackgroundColor(Color.LIGHT_GRAY);
    c1.setPhrase(new Phrase("Staff Comments", f));
    table.addCell(c1);
    c1 = new PdfPCell();
    c1.setColspan(1);
    c1.setPhrase(new Phrase(includeComments ? ocanBean.getStaffComments() : "", normalText));
    table.addCell(c1);
}

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

License:Open Source License

/**
 * Write the aspects./*from  w ww .  ja  v  a 2s.  co 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 {/*  w w  w  .j  a  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

/**
 * Writes the given attendees to the protocol.
 * //w ww .jav a 2s .  co  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.tellervo.desktop.print.BasicBoxLabel.java

License:Open Source License

/**
 * Get PdfPTable containing the samples per object
 * // w ww.  j  a  va2s  .  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   w w  w.  j a  v  a2s . 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

/**
 * Get PdfPTable containing the ring width data for this series
 * /*from w ww  .  java 2  s  . c  om*/
 * @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
 * /* ww  w .ja  v  a  2  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();
}

From source file:org.unitime.timetable.webutil.pdf.PdfEventTableBuilder.java

License:Open Source License

public PdfPCell createCell() {
    PdfPCell cell = new PdfPCell();
    cell.setBorderColor(Color.BLACK);
    cell.setPadding(3);/* www  . j ava2  s.  c  o  m*/
    cell.setBorderWidth(0);
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(iBgColor);
    if (iUnderline)
        cell.setBorderWidthBottom(1);
    if (iOverline)
        cell.setBorderWidthTop(0.5f);
    return cell;
}

From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java

License:Open Source License

protected void pdfBuildTableHeader(Long sessionId) {
    iBgColor = sBgColorHeader;//from w  w w  .  j av  a 2  s  .c om
    //first line
    if (isShowLabel()) {
        PdfPCell c = createCell();
        addText(c, LABEL, true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (isShowDivSec()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnExternalId(), true, Element.ALIGN_RIGHT);
        iPdfTable.addCell(c);
    }
    if (isShowDemand()) {
        PdfPCell c = createCell();
        if (StudentClassEnrollment.sessionHasEnrollments(sessionId)) {
            addText(c, MSG.columnDemand(), true, Element.ALIGN_RIGHT);
        } else {
            addText(c, MSG.columnLastDemand(), true, Element.ALIGN_RIGHT);
        }
        iPdfTable.addCell(c);
    }
    if (isShowProjectedDemand()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnProjectedDemand(), true, Element.ALIGN_RIGHT);
        iPdfTable.addCell(c);
    }
    if (isShowLimit()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnLimit(), true, Element.ALIGN_RIGHT);
        iPdfTable.addCell(c);
    }
    if (isShowRoomRatio()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnRoomRatio(), true, Element.ALIGN_RIGHT);
        iPdfTable.addCell(c);
    }
    if (isShowManager()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnManager(), true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (isShowDatePattern()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnDatePattern(), true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (isShowMinPerWk()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnMinPerWk(), true, Element.ALIGN_RIGHT);
        iPdfTable.addCell(c);
    }
    if (isShowTimePattern()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnTimePattern(), true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (isShowPreferences()) {
        PdfPCell c = createCell();
        c.setColspan(PREFERENCE_COLUMN_ORDER.length + (getDisplayDistributionPrefs() ? 0 : -1));
        addText(c, "----" + MSG.columnPreferences() + "----", true, Element.ALIGN_CENTER);
        iPdfTable.addCell(c);
    }
    if (isShowInstructor()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnInstructor(), true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (getDisplayTimetable() && isShowTimetable()) {
        PdfPCell c = createCell();
        c.setColspan(TIMETABLE_COLUMN_ORDER.length);
        addText(c, "--------" + MSG.columnTimetable() + "--------", true, Element.ALIGN_CENTER);
        iPdfTable.addCell(c);
    }
    if (isShowTitle()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnTitle(), true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (isShowCredit()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnOfferingCredit(), true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (isShowSubpartCredit()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnSubpartCredit(), true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (isShowConsent()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnConsent(), true, Element.ALIGN_CENTER);
        iPdfTable.addCell(c);
    }
    if (isShowSchedulePrintNote()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnSchedulePrintNote(), true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (isShowNote()) {
        PdfPCell c = createCell();
        addText(c, MSG.columnNote(), true, Element.ALIGN_LEFT);
        iPdfTable.addCell(c);
    }
    if (isShowExam()) {
        PdfPCell c = createCell();
        c.setColspan((isShowExamName() ? 1 : 0) + (isShowExamTimetable() ? 2 : 0));
        addText(c, "--------" + MSG.columnExam() + "--------", true, Element.ALIGN_CENTER);
        iPdfTable.addCell(c);
    }

    //second line
    if (isShowLabel()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowDivSec()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowDemand()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowProjectedDemand()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowLimit()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowRoomRatio()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowManager()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowDatePattern()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowMinPerWk()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowTimePattern()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowPreferences()) {
        for (int j = 0; j < PREFERENCE_COLUMN_ORDER.length + (getDisplayDistributionPrefs() ? 0 : -1); j++) {
            PdfPCell c = createCell();
            c.setBorderWidthBottom(1);
            addText(c, PREFERENCE_COLUMN_ORDER[j], true, Element.ALIGN_LEFT);
            iPdfTable.addCell(c);
        }
    }
    if (isShowInstructor()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (getDisplayTimetable() && isShowTimetable()) {
        for (int j = 0; j < TIMETABLE_COLUMN_ORDER.length; j++) {
            PdfPCell c = createCell();
            c.setBorderWidthBottom(1);
            addText(c, TIMETABLE_COLUMN_ORDER[j], true, Element.ALIGN_LEFT);
            iPdfTable.addCell(c);
        }
    }
    if (isShowTitle()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowCredit()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowSubpartCredit()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowConsent()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowSchedulePrintNote()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowNote()) {
        PdfPCell c = createCell();
        c.setBorderWidthBottom(1);
        iPdfTable.addCell(c);
    }
    if (isShowExam()) {
        if (isShowExamName()) {
            PdfPCell c = createCell();
            c.setBorderWidthBottom(1);
            addText(c, MSG.columnExamName(), true, Element.ALIGN_LEFT);
            iPdfTable.addCell(c);
        }
        if (isShowExamTimetable()) {
            PdfPCell c = createCell();
            c.setBorderWidthBottom(1);
            addText(c, MSG.columnExamPeriod(), true, Element.ALIGN_LEFT);
            iPdfTable.addCell(c);
            c = createCell();
            c.setBorderWidthBottom(1);
            addText(c, MSG.columnExamRoom(), true, Element.ALIGN_LEFT);
            iPdfTable.addCell(c);
        }
    }
    iPdfTable.setHeaderRows(2);
}