Example usage for com.lowagie.text Chunk Chunk

List of usage examples for com.lowagie.text Chunk Chunk

Introduction

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

Prototype

public Chunk(DrawInterface separator, float tabPosition) 

Source Link

Document

Creates a tab Chunk.

Usage

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

License:Open Source License

private void generateSeriesReport(OutputStream output) {

    displayUnits = NormalTridasUnit//  ww  w  .ja v  a  2s  . co m
            .valueOf(App.prefs.getPref(PrefKey.DISPLAY_UNITS, NormalTridasUnit.MICROMETRES.name().toString()));

    try {

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

        // Set basic metadata
        document.addAuthor("Peter Brewer");
        document.addSubject("Tellervo Series Report for " + s.getDisplayTitle());

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

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

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

        // Authorship
        ColumnText ct4 = new ColumnText(cb);
        ct4.setSimpleColumn(284, document.top() - 223, document.right(10), document.top() - 60, 20,
                Element.ALIGN_RIGHT);
        ct4.setLeading(0, 1.2f);
        ct4.addText(getAuthorshipPDF());
        ct4.go();

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

        // Ring width table
        getRingWidthTable();
        document.add(getParagraphSpace());

        if (s.getSeries() instanceof TridasMeasurementSeries) {
            // MEASUREMENT SERIES

            //document.add(getRingRemarks());
            document.add(getWoodCompletenessPDF());
            document.add(getParagraphSpace());
            document.add(getSeriesComments());
            document.add(getParagraphSpace());
            document.add(getInterpretationPDF());
            document.add(getParagraphSpace());
            document.add(getElementAndSampleInfo());
        } else {
            // DERIVED SERIES
            getWJTable();
            document.add(getParagraphSpace());
            document.add(getSeriesComments());
            document.add(getParagraphSpace());
            //document.add(getRingRemarks());

        }

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

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

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

License:Open Source License

/**
 * Get an iText Paragraph for the Title 
 * //from   w  w  w.jav  a 2s .  c  om
 * @return Paragraph
 */
private Paragraph getTitlePDF() {
    Paragraph p = new Paragraph();

    p.add(new Chunk(s.getDisplayTitle() + "\n", titleFont));

    // Add object name if this is a mSeries
    if (s.getSeries() instanceof TridasMeasurementSeries) {
        TridasObject tobj = s.getMeta(Metadata.OBJECT, TridasObject.class);

        p.add(new Chunk(tobj.getTitle(), subTitleFont));
    }
    return p;
}

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

License:Open Source License

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

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

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

    int rows = model.getRowCount();

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

            // Use the current default display units

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

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

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

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

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

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

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

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

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

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

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

                    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            //mainTableCell.addElement(userRemarksMiniTable);

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

        }
    }

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

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

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

License:Open Source License

/**
 * iText paragraph containing created and lastmodified timestamps
 * //w w w.  j a va2  s.co m
 * @return Paragraph
 */
private Paragraph getTimestampPDF() {
    // Set up calendar
    Date createdTimestamp = s.getSeries().getCreatedTimestamp().getValue().toGregorianCalendar().getTime();
    Date lastModifiedTimestamp = s.getSeries().getLastModifiedTimestamp().getValue().toGregorianCalendar()
            .getTime();
    DateFormat df1 = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT);

    Paragraph p = new Paragraph();

    p.add(new Chunk("Created: ", subSubSectionFont));
    p.add(new Chunk(df1.format(createdTimestamp), bodyFont));
    p.add(new Chunk("\nLast Modified: ", subSubSectionFont));
    p.add(new Chunk(df1.format(lastModifiedTimestamp), bodyFont));

    return p;

}

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

License:Open Source License

/**
 * iText Paragraph containing the various authorship fields
 * @return Paragraph//www.j av a 2 s .c  o  m
 */
private Paragraph getAuthorshipPDF() {
    Paragraph p = new Paragraph();

    ITridasSeries sss = s.getSeries();
    TridasMeasurementSeries mseries = null;
    TridasDerivedSeries dseries = null;

    if (sss instanceof TridasMeasurementSeries) {
        mseries = (TridasMeasurementSeries) sss;
        if (mseries.getAnalyst() != null) {
            p.add(new Chunk("Measured by: ", subSubSectionFont));
            p.add(new Chunk(mseries.getAnalyst(), bodyFont));
        }

        if (mseries.getDendrochronologist() != null) {
            p.add(new Chunk("\nSupervised by: ", subSubSectionFont));
            p.add(new Chunk(mseries.getDendrochronologist(), bodyFont));
        }
    } else {
        dseries = (TridasDerivedSeries) sss;
        p.add(new Chunk("Created by: ", subSubSectionFont));
        p.add(new Chunk(dseries.getAuthor(), bodyFont));

    }

    return p;

}

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

License:Open Source License

private Paragraph getSeriesComments() {

    Paragraph p = new Paragraph();

    if (s.getSeries().getComments() != null) {

        p.setLeading(0, 1.2f);/*w  w w.  jav  a2 s.c  om*/
        p.add(new Chunk("Comments: \n", subSubSectionFont));
        p.add(new Chunk(s.getSeries().getComments(), bodyFont));
        return p;
    } else {
        return p;
    }

}

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

License:Open Source License

private Paragraph getInterpretationPDF() {

    Paragraph p = new Paragraph();
    p.setLeading(0, 1.2f);//from   w  ww  .j a  va  2s . co  m
    Year firstyear = s.getSeries().getInterpretation().getFirstYear();
    Year pithYear = s.getSeries().getInterpretation().getPithYear();
    Year deathyear = s.getSeries().getInterpretation().getDeathYear();
    Boolean isRelativelyDated = false;
    p.add(new Chunk("Interpretation:", subSubSectionFont));

    String datingType = s.getSeries().getInterpretation().getDating().getType().toString();

    if (datingType == "RELATIVE")
        isRelativelyDated = true;

    if (firstyear != null) {
        p.add(new Chunk("\n- The first ring of this series begins in ", bodyFont));
        if (isRelativelyDated)
            p.add(new Chunk("relative year ", bodyFont));

        if (firstyear.getCertainty() != null) {
            p.add(new Chunk(firstyear.getCertainty().toString().toLowerCase() + " ", bodyFont));
        }
        p.add(new Chunk(firstyear.getValue().toString(), bodyFont));
        if (isRelativelyDated == false)
            p.add(new Chunk(firstyear.getSuffix().toString(), bodyFont));
        p.add(new Chunk(".\n", bodyFont));
    }

    if (pithYear != null && deathyear != null) {
        p.add(new Chunk("- The pith of this radius was laid down ", bodyFont));
        if (pithYear.getCertainty() != null) {
            p.add(certaintyToNaturalString(pithYear.getCertainty().toString()));
        }
        if (isRelativelyDated)
            p.add(new Chunk("relative year ", bodyFont));
        p.add(new Chunk(pithYear.getValue().toString(), bodyFont));
        if (isRelativelyDated == false)
            p.add(new Chunk(pithYear.getSuffix().toString(), bodyFont));
        p.add(new Chunk(" and died ", bodyFont));
        if (deathyear.getCertainty() != null) {
            p.add(certaintyToNaturalString(deathyear.getCertainty().toString()));
        }
        if (isRelativelyDated)
            p.add(new Chunk("relative year ", bodyFont));
        p.add(new Chunk(deathyear.getValue().toString(), bodyFont));
        if (isRelativelyDated == false)
            p.add(new Chunk(deathyear.getSuffix().toString(), bodyFont));
        p.add(new Chunk(".\n", bodyFont));

    }

    // Dated with...
    if (s.getSeries().getInterpretation().getDatingReference() != null) {
        p.add(new Chunk("\n- This series was dated using series: " + s.getSeries().getInterpretation()
                .getDatingReference().getLinkSeries().getIdentifier().getValue().toString(), bodyFont));
    }

    // Provence...
    if (s.getSeries().getInterpretation().getProvenance() != null) {
        p.add(new Chunk("\n- Provenance: " + s.getSeries().getInterpretation().getProvenance().toString(),
                bodyFont));
    }

    return p;
}

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

License:Open Source License

/**
 * iText paragraph for the TRiDaS wood completeness fields
 * //ww w .  java  2  s . co  m
 * @return Paragraph
 */
private Paragraph getWoodCompletenessPDF() {
    Paragraph p = new Paragraph();
    p.setLeading(0, 1.2f);
    TridasRadius trad = s.getMeta(Metadata.RADIUS, TridasRadius.class);
    TridasWoodCompleteness woodCompleteness = trad.getWoodCompleteness();

    String pithPresence = null;
    String barkPresence = null;

    p.add(new Chunk("Wood Completeness:\n", subSubSectionFont));

    // Extract pith info
    if (woodCompleteness.getPith() != null) {

        if (woodCompleteness.getPith().getPresence() != null) {
            pithPresence = woodCompleteness.getPith().getPresence().value();
        } else {
            pithPresence = "not specified";
        }

        p.add(new Chunk("- Pith is " + pithPresence + ".\n", bodyFont));
    } else {
        p.add(new Chunk("- No pith details were recorded.\n", bodyFont));
    }

    // Ring count 
    p.add(new Chunk("- A total of " + String.valueOf(s.countRings()) + " rings were measured.", bodyFont));

    // Unmeasured rings
    if (woodCompleteness.isSetNrOfUnmeasuredInnerRings() || woodCompleteness.isSetNrOfUnmeasuredOuterRings()) {
        String txt = " Additional rings were observed but not measured (";
        if (woodCompleteness.isSetNrOfUnmeasuredInnerRings()) {
            txt += String.valueOf(woodCompleteness.getNrOfUnmeasuredInnerRings()) + " towards the pith";
            if (woodCompleteness.isSetNrOfUnmeasuredOuterRings()) {
                txt += " and ";
            }
        }
        if (woodCompleteness.isSetNrOfUnmeasuredOuterRings()) {
            txt += String.valueOf(woodCompleteness.getNrOfUnmeasuredOuterRings()) + " towards the bark";
        }

        txt += ").";

        p.add(new Chunk(txt, bodyFont));
        p.add(new Chunk("\n"));
    } else {
        p.add(new Chunk("\n"));
    }

    // Extract Heartwood and sapwood info
    p.add(getHeartSapwoodDetails(woodCompleteness, WoodType.HEARTWOOD));
    p.add(getHeartSapwoodDetails(woodCompleteness, WoodType.SAPWOOD));

    // Extract last ring under bark info
    if (woodCompleteness.getSapwood().getLastRingUnderBark() != null) {
        TridasLastRingUnderBark lastRing = woodCompleteness.getSapwood().getLastRingUnderBark();
        if (lastRing.getPresence() != null) {
            if (lastRing.getPresence().equals(PresenceAbsence.PRESENT)) {
                p.add(new Chunk("- Last ring under bark is present", bodyFont));

                if (lastRing.getContent() != null) {
                    p.add(new Chunk(
                            " and the user has noted that it is: " + lastRing.getContent().toString() + ".\n",
                            bodyFont));
                } else {
                    p.add(new Chunk(".\n", bodyFont));
                }

            } else if (lastRing.getPresence().equals(PresenceAbsence.ABSENT)) {
                p.add(new Chunk("- Last ring under bark is absent.\n", bodyFont));
            }
        }

    }

    // Extract bark info
    if (woodCompleteness.getBark() != null) {
        if (woodCompleteness.getBark().getPresence().toString().toLowerCase() != null) {
            if (woodCompleteness.getBark().getPresence().value() == "present") {
                p.add(new Chunk("- Bark is present ", bodyFont));
                // Last ring info
                if (woodCompleteness.getSapwood().getLastRingUnderBark() != null) {
                    p.add(new Chunk("and the last ring before the bark is noted as: \""
                            + woodCompleteness.getSapwood().getLastRingUnderBark().getContent().toString()
                            + "\"", bodyFont));
                } else {
                    p.add(new Chunk("but no details about the last ring under the bark were recorded.\n",
                            bodyFont));
                }
            } else if (woodCompleteness.getBark().getPresence().value() == "absent") {

                // Calculate if we have waney edge
                if (woodCompleteness.getSapwood().getPresence().equals(ComplexPresenceAbsence.COMPLETE)) {
                    p.add(new Chunk("- Waney edge present\n", bodyFont));
                } else {
                    p.add(new Chunk("- Bark is absent.\n", bodyFont));
                }
            } else {
                barkPresence = woodCompleteness.getBark().getPresence().value();
                p.add(new Chunk("- Bark is " + barkPresence + "\n", bodyFont));
            }
        } else {
            p.add(new Chunk("- Bark information was not recorded.\n", bodyFont));
        }
    }

    return p;
}

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

License:Open Source License

private Paragraph getHeartSapwoodDetails(TridasWoodCompleteness woodCompleteness, WoodType type) {
    Paragraph p = new Paragraph();

    String presence = null;// ww  w . ja  v a 2 s.  c om
    String presenceStr = null;
    String missingRings = null;
    String missingRingsStr = null;
    String foundationStr = null;
    String woodTypeStr = null;
    Integer nrSapwoodRings = null;

    // Extract data from woodcompleteness based on type
    if (type == WoodType.HEARTWOOD) {
        // Extract Heartwood details
        woodTypeStr = "heartwood";
        if (woodCompleteness.getHeartwood() != null) {

            // Presence / Absence
            if (woodCompleteness.getHeartwood().getPresence() != null) {
                if (woodCompleteness.getHeartwood().getPresence().equals(ComplexPresenceAbsence.UNKNOWN)) {
                    // if heartwood presence is unknown all other details are irrelevant
                    p.add(new Chunk("- No " + woodTypeStr + " details recorded.", bodyFont));
                    return p;
                } else {
                    presence = woodCompleteness.getHeartwood().getPresence().value();
                }
            }

            // Missing rings
            if (woodCompleteness.getHeartwood().getMissingHeartwoodRingsToPith() != null) {
                missingRingsStr = woodCompleteness.getHeartwood().getMissingHeartwoodRingsToPith().toString();
                missingRings = missingRingsStr;
            } else {
                missingRingsStr = "an unknown number of";
            }

            // Missing rings foundation
            if (woodCompleteness.getHeartwood().getMissingHeartwoodRingsToPithFoundation() != null) {
                foundationStr = woodCompleteness.getHeartwood().getMissingHeartwoodRingsToPithFoundation()
                        .toString().toLowerCase();
            } else {
                foundationStr = "unspecified reasons";
            }

        } else {
            p.add(new Chunk("- No " + woodTypeStr + " details recorded.", bodyFont));
            return p;
        }
    } else if (type == WoodType.SAPWOOD) {
        // Extract Sapwood details
        woodTypeStr = "sapwood";
        if (woodCompleteness.getSapwood() != null) {

            // Presence / Absence
            if (woodCompleteness.getSapwood().getPresence() != null) {
                if (woodCompleteness.getSapwood().getPresence().equals(ComplexPresenceAbsence.UNKNOWN)) {
                    // if sapwood presence is unknown all other details are irrelevant
                    p.add(new Chunk("- No " + woodTypeStr + " details recorded.", bodyFont));
                    return p;
                } else {
                    presence = woodCompleteness.getSapwood().getPresence().value();
                }
            }

            // Missing rings
            if (woodCompleteness.getSapwood().getMissingSapwoodRingsToBark() != null) {
                missingRingsStr = woodCompleteness.getSapwood().getMissingSapwoodRingsToBark().toString();
                missingRings = missingRingsStr;
            } else {
                missingRingsStr = "an unknown number of";
            }

            // No. of rings present
            if (woodCompleteness.getSapwood().getNrOfSapwoodRings() != null) {
                nrSapwoodRings = woodCompleteness.getSapwood().getNrOfSapwoodRings();
            }

            // Missing rings foundation
            if (woodCompleteness.getSapwood().getMissingSapwoodRingsToBarkFoundation() != null) {
                foundationStr = woodCompleteness.getSapwood().getMissingSapwoodRingsToBarkFoundation()
                        .toString().toLowerCase();
            } else {
                foundationStr = "unspecified reasons";
            }
        } else {
            p.add(new Chunk("- No " + woodTypeStr + " details recorded.", bodyFont));
            return p;
        }

    } else {
        return null;
    }

    // Set output strings for presence/absence
    if (presence == "unknown") {
        //presenceStr = "- Whether " + woodTypeStr + " is present or not is unknown";
        presenceStr = "";
    } else if (presence == null) {
        //presenceStr = "- Presence of " + woodTypeStr + " has not been specified";
        presenceStr = "";
    } else {
        presenceStr = "- " + woodTypeStr.substring(0, 1).toUpperCase() + woodTypeStr.substring(1) + " is "
                + presence;
        if (woodTypeStr == "sapwood" && nrSapwoodRings != null) {
            presenceStr += ". A total of " + nrSapwoodRings + " sapwood rings were identified";
        }
    }

    // Compile paragraph   
    p.add(new Chunk(presenceStr, bodyFont));
    if (missingRings != null) {
        p.add(new Chunk(". The analyst records that " + missingRingsStr, bodyFont));
        if (missingRingsStr.equals("1")) {
            p.add(new Chunk(" ring is ", bodyFont));
        } else {
            p.add(new Chunk(" rings are ", bodyFont));
        }
        p.add(new Chunk("missing, the justification of which is noted as: \"" + foundationStr + "\".",
                bodyFont));
    } else if (presence == "complete") {
        // Wood is complete so no mention required about missing rings
        p.add(new Chunk(". ", bodyFont));
    } else {
        //p.add(new Chunk(". Details about missing " + woodTypeStr + " rings was not recorded.", bodyFont));
        p.add(new Chunk("", bodyFont));
    }

    return p;

}

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

License:Open Source License

/**
 * iText paragraph of element and sample info
 * @return Paragraph/*from   www .j a va  2  s  . c om*/
 */
private Paragraph getElementAndSampleInfo() {
    Paragraph p = new Paragraph();

    TridasElement telem = s.getMeta(Metadata.ELEMENT, TridasElement.class);
    TridasSample tsamp = s.getMeta(Metadata.SAMPLE, TridasSample.class);

    p.add(new Chunk("Element and sample details:\n", subSubSectionFont));

    p.add(new Chunk("- Taxon:  ", bodyFont));
    p.add(new Chunk(telem.getTaxon().getNormal() + "\n", bodyFontItalic));
    p.add(new Chunk("- Element type: " + telem.getType().getNormal() + "\n", bodyFont));
    p.add(new Chunk("- Sample type: " + tsamp.getType().getNormal() + "\n", bodyFont));
    return p;

}