Example usage for com.lowagie.text.pdf PdfPTable setSpacingBefore

List of usage examples for com.lowagie.text.pdf PdfPTable setSpacingBefore

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPTable setSpacingBefore.

Prototype

public void setSpacingBefore(float spacing) 

Source Link

Document

Sets the spacing before this table.

Usage

From source file:org.gtdfree.addons.PDFExportAddOn.java

License:Open Source License

private Element newSection(String s) throws DocumentException, IOException {
    Phrase c = fontSelectorB2.process(s);
    Paragraph p = new Paragraph(c);

    PdfPTable t = new PdfPTable(1);
    t.setSpacingBefore(15f);
    t.setSpacingAfter(7f);//from  w  w  w  . ja  v a 2s .c  om
    t.setWidthPercentage(100f);

    PdfPCell ce = newCell(p);
    ce.setBorder(PdfPCell.BOTTOM);
    ce.setBorderWidth(1f);
    ce.setPaddingLeft(0);
    ce.setPaddingRight(0);

    t.addCell(ce);

    return t;
}

From source file:org.gtdfree.addons.PDFExportAddOn.java

License:Open Source License

private Element newSubSection(String s) throws DocumentException, IOException {
    Phrase c = fontSelectorB.process(s);
    Paragraph p = new Paragraph(c);

    PdfPTable t = new PdfPTable(1);
    t.setSpacingBefore(7f);
    t.setSpacingAfter(5f);/* w  w w .  ja va 2 s .  c om*/
    t.setWidthPercentage(100f);

    PdfPCell ce = newCell(p);
    ce.setBorder(PdfPCell.BOTTOM);
    ce.setBorderWidth(0.75f);
    ce.setPaddingLeft(0);
    ce.setPaddingRight(0);

    t.addCell(ce);

    return t;
}

From source file:org.jmesa.view.pdfp.PdfPView.java

License:Apache License

@Override
public PdfPTable render() {

    PdfPTable pdfpTable = new PdfPTable(getTable().getRow().getColumns().size());
    pdfpTable.setSpacingBefore(3);

    Row row = getTable().getRow();/*w  w w . j av a  2 s  . c o  m*/

    List<Column> columns = row.getColumns();

    // build table headers
    for (Iterator<Column> iter = columns.iterator(); iter.hasNext();) {
        Column column = iter.next();
        PdfPCell cell = new PdfPCell(new Paragraph(column.getTitle(), getHeaderCellFont()));
        cell.setPadding(3.0f);
        cell.setBackgroundColor(getHeaderBackgroundColor());
        pdfpTable.addCell(cell);
    }

    // build table body
    Collection<?> items = getCoreContext().getPageItems();
    int rowcount = 0;
    for (Object item : items) {
        rowcount++;

        columns = row.getColumns();

        for (Iterator<Column> iter = columns.iterator(); iter.hasNext();) {
            Column column = iter.next();

            String property = column.getProperty();
            Object value = column.getCellEditor().getValue(item, property, rowcount);
            PdfPCell cell = new PdfPCell(
                    new Paragraph(value == null ? "" : String.valueOf(value), getCellFont()));
            cell.setPadding(3.0f);

            if (isRowEven(rowcount)) {
                cell.setBackgroundColor(getEvenCellBackgroundColor());
            } else {
                cell.setBackgroundColor(getOddCellBackgroundColor());
            }

            pdfpTable.addCell(cell);
        }
    }

    return pdfpTable;
}

From source file:org.jsondoc.springmvc.pdf.PdfExportView.java

License:Open Source License

public File getPdfFile(String filename) {
    try {//from   w  w  w.j a v a  2 s.  c  o  m
        File file = new File(filename + "-v" + jsonDoc.getVersion() + FILE_EXTENSION);
        FileOutputStream fileout = new FileOutputStream(file);
        Document document = new Document();
        PdfWriter.getInstance(document, fileout);

        // Header
        HeaderFooter header = new HeaderFooter(new Phrase("Copyright "
                + Calendar.getInstance().get(Calendar.YEAR) + " Paybay Networks - All rights reserved"), false);
        header.setBorder(Rectangle.NO_BORDER);
        header.setAlignment(Element.ALIGN_LEFT);
        document.setHeader(header);

        // Footer
        HeaderFooter footer = new HeaderFooter(new Phrase("Page "), true);
        footer.setBorder(Rectangle.NO_BORDER);
        footer.setAlignment(Element.ALIGN_CENTER);
        document.setFooter(footer);

        document.open();

        //init documentation
        apiDocs = buildApiDocList();
        apiMethodDocs = buildApiMethodDocList(apiDocs);

        Phrase baseUrl = new Phrase("Base url: " + jsonDoc.getBasePath());
        document.add(baseUrl);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);

        int pos = 1;
        for (ApiMethodDoc apiMethodDoc : apiMethodDocs) {
            Phrase phrase = new Phrase(/*"Description: " + */apiMethodDoc.getDescription());
            document.add(phrase);
            document.add(Chunk.NEWLINE);

            PdfPTable table = new PdfPTable(2);
            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
            table.setWidthPercentage(100);

            table.setWidths(new int[] { 50, 200 });

            // HEADER CELL START TABLE
            table.addCell(ITextUtils.getHeaderCell("URL"));
            table.addCell(ITextUtils.getHeaderCell("<baseUrl> " + apiMethodDoc.getPath()));
            table.completeRow();

            // FIRST CELL
            table.addCell(ITextUtils.getCell("Http Method", 0));
            table.addCell(ITextUtils.getCell(apiMethodDoc.getVerb().name(), pos));
            pos++;
            table.completeRow();

            // PRODUCES
            if (!apiMethodDoc.getProduces().isEmpty()) {
                table.addCell(ITextUtils.getCell("Produces", 0));
                table.addCell(ITextUtils.getCell(buildApiMethodProduces(apiMethodDoc), pos));
                pos++;
                table.completeRow();
            }

            // CONSUMES
            if (!apiMethodDoc.getConsumes().isEmpty()) {
                table.addCell(ITextUtils.getCell("Consumes", 0));
                table.addCell(ITextUtils.getCell(buildApiMethodConsumes(apiMethodDoc), pos));
                pos++;
                table.completeRow();
            }

            // HEADERS
            if (!apiMethodDoc.getHeaders().isEmpty()) {
                table.addCell(ITextUtils.getCell("Request headers", 0));

                PdfPTable pathParamsTable = new PdfPTable(3);
                pathParamsTable.setWidths(new int[] { 30, 20, 40 });

                pathParamsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                pathParamsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);

                for (ApiHeaderDoc apiHeaderDoc : apiMethodDoc.getHeaders()) {
                    PdfPCell boldCell = new PdfPCell();
                    Font fontbold = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
                    boldCell.setPhrase(new Phrase(apiHeaderDoc.getName(), fontbold));
                    boldCell.getPhrase().setFont(new Font(Font.BOLD));
                    boldCell.setBorder(Rectangle.NO_BORDER);
                    pathParamsTable.addCell(boldCell);

                    PdfPCell paramCell = new PdfPCell();

                    StringBuilder builder = new StringBuilder();

                    for (String value : apiHeaderDoc.getAllowedvalues())
                        builder.append(value).append(", ");

                    paramCell.setPhrase(new Phrase("Allowed values: " + builder.toString()));
                    paramCell.setBorder(Rectangle.NO_BORDER);

                    pathParamsTable.addCell(paramCell);

                    paramCell.setPhrase(new Phrase(apiHeaderDoc.getDescription()));

                    pathParamsTable.addCell(paramCell);
                    pathParamsTable.completeRow();
                }

                PdfPCell bluBorderCell = new PdfPCell(pathParamsTable);
                bluBorderCell.setBorder(Rectangle.NO_BORDER);
                bluBorderCell.setBorderWidthRight(1f);
                bluBorderCell.setBorderColorRight(Colors.CELL_BORDER_COLOR);

                table.addCell(ITextUtils.setOddEvenStyle(bluBorderCell, pos));
                pos++;
                table.completeRow();
            }

            // PATH PARAMS
            if (!apiMethodDoc.getPathparameters().isEmpty()) {
                table.addCell(ITextUtils.getCell("Path params", 0));

                PdfPTable pathParamsTable = new PdfPTable(3);
                pathParamsTable.setWidths(new int[] { 30, 15, 40 });

                pathParamsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                pathParamsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);

                for (ApiParamDoc apiParamDoc : apiMethodDoc.getPathparameters()) {
                    PdfPCell boldCell = new PdfPCell();
                    Font fontbold = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
                    boldCell.setPhrase(new Phrase(apiParamDoc.getName(), fontbold));
                    boldCell.getPhrase().setFont(new Font(Font.BOLD));
                    boldCell.setBorder(Rectangle.NO_BORDER);
                    pathParamsTable.addCell(boldCell);

                    PdfPCell paramCell = new PdfPCell();
                    paramCell.setPhrase(new Phrase(apiParamDoc.getJsondocType().getOneLineText()));
                    paramCell.setBorder(Rectangle.NO_BORDER);

                    pathParamsTable.addCell(paramCell);

                    paramCell.setPhrase(new Phrase(apiParamDoc.getDescription()));

                    pathParamsTable.addCell(paramCell);
                    pathParamsTable.completeRow();
                }

                PdfPCell bluBorderCell = new PdfPCell(pathParamsTable);
                bluBorderCell.setBorder(Rectangle.NO_BORDER);
                bluBorderCell.setBorderWidthRight(1f);
                bluBorderCell.setBorderColorRight(Colors.CELL_BORDER_COLOR);

                table.addCell(ITextUtils.setOddEvenStyle(bluBorderCell, pos));
                pos++;
                table.completeRow();
            }

            // QUERY PARAMS
            if (!apiMethodDoc.getQueryparameters().isEmpty()) {
                table.addCell(ITextUtils.getCell("Query params", 0));

                PdfPTable queryParamsTable = new PdfPTable(3);
                queryParamsTable.setWidths(new int[] { 30, 15, 40 });

                queryParamsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                queryParamsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);

                for (ApiParamDoc apiParamDoc : apiMethodDoc.getQueryparameters()) {
                    PdfPCell boldCell = new PdfPCell();
                    Font fontbold = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
                    boldCell.setPhrase(new Phrase(apiParamDoc.getName(), fontbold));
                    boldCell.getPhrase().setFont(new Font(Font.BOLD));
                    boldCell.setBorder(Rectangle.NO_BORDER);
                    queryParamsTable.addCell(boldCell);

                    PdfPCell paramCell = new PdfPCell();
                    paramCell.setPhrase(new Phrase(apiParamDoc.getJsondocType().getOneLineText()));
                    paramCell.setBorder(Rectangle.NO_BORDER);

                    queryParamsTable.addCell(paramCell);

                    paramCell.setPhrase(new Phrase(
                            apiParamDoc.getDescription() + ", mandatory: " + apiParamDoc.getRequired()));

                    queryParamsTable.addCell(paramCell);
                    queryParamsTable.completeRow();
                }

                PdfPCell bluBorderCell = new PdfPCell(queryParamsTable);
                bluBorderCell.setBorder(Rectangle.NO_BORDER);
                bluBorderCell.setBorderWidthRight(1f);
                bluBorderCell.setBorderColorRight(Colors.CELL_BORDER_COLOR);

                table.addCell(ITextUtils.setOddEvenStyle(bluBorderCell, pos));
                pos++;
                table.completeRow();
            }

            // BODY OBJECT
            if (null != apiMethodDoc.getBodyobject()) {
                table.addCell(ITextUtils.getCell("Body object:", 0));
                String jsonObject = buildJsonFromTemplate(apiMethodDoc.getBodyobject().getJsondocTemplate());
                table.addCell(ITextUtils.getCell(jsonObject, pos));
                pos++;
                table.completeRow();
            }

            // RESPONSE OBJECT
            table.addCell(ITextUtils.getCell("Json response:", 0));
            table.addCell(
                    ITextUtils.getCell(apiMethodDoc.getResponse().getJsondocType().getOneLineText(), pos));
            pos++;
            table.completeRow();

            // RESPONSE STATUS CODE
            table.addCell(ITextUtils.getCell("Status code:", 0));
            table.addCell(ITextUtils.getCell(apiMethodDoc.getResponsestatuscode(), pos));
            pos++;
            table.completeRow();

            table.setSpacingAfter(10f);
            table.setSpacingBefore(5f);
            document.add(table);
        }

        document.close();
        return file;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.kitodo.production.services.data.ProcessService.java

License:Open Source License

private PdfPTable getPdfTable(List<List<HSSFCell>> rowList) {
    // create formatter for cells with default locale
    DataFormatter formatter = new DataFormatter();

    PdfPTable table = new PdfPTable(9);
    table.setSpacingBefore(20);
    for (List<HSSFCell> row : rowList) {
        for (HSSFCell hssfCell : row) {
            String stringCellValue = formatter.formatCellValue(hssfCell);
            table.addCell(stringCellValue);
        }//from www  . jav a 2  s  . com
    }

    return table;
}

From source file:org.oscarehr.common.service.PdfRecordPrinter.java

License:Open Source License

public void printSpecsHistory(List<EyeformSpecsHistory> specsHistory) throws DocumentException {
    ProviderDao providerDao = (ProviderDao) SpringUtils.getBean("providerDao");

    /*/*from  ww  w  . j  ava 2  s .com*/
         if( getNewPage() )
    getDocument().newPage();
           else
    setNewPage(true);
    */

    Font obsfont = new Font(getBaseFont(), FONTSIZE, Font.UNDERLINE);

    Paragraph p = new Paragraph();
    p.setAlignment(Paragraph.ALIGN_LEFT);
    Phrase phrase = new Phrase(LEADING, "\n", getFont());
    p.add(phrase);
    phrase = new Phrase(LEADING, "Specs History", obsfont);
    p.add(phrase);
    getDocument().add(p);

    PdfPTable table = new PdfPTable(2);
    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
    table.setSpacingBefore(10f);
    table.setSpacingAfter(10f);
    table.setTotalWidth(new float[] { 10f, 60f });
    table.setTotalWidth(5f);
    table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);

    for (EyeformSpecsHistory specs : specsHistory) {
        PdfPCell cell1 = new PdfPCell(new Phrase(getFormatter().format(specs.getDate()), getFont()));
        cell1.setBorder(PdfPCell.NO_BORDER);
        cell1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        table.addCell(cell1);

        PdfPCell cell2 = new PdfPCell(new Phrase(specs.toString2(), getFont()));
        cell2.setBorder(PdfPCell.NO_BORDER);
        cell2.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        table.addCell(cell2);
    }

    getDocument().add(table);
}

From source file:org.sakaiproject.tool.assessment.pdf.itext.HTMLWorker.java

License:Mozilla Public License

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

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

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

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

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

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

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

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

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

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

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

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

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

From source file:org.sonar.report.pdf.DefaultPDFReporter.java

License:Open Source License

private void printDashboard(Project project, Section section) throws DocumentException {
    PdfPTable dashboard = new PdfPTable(3);
    dashboard.getDefaultCell().setBorderColor(Color.WHITE);
    Font titleFont = new Font(Font.TIMES_ROMAN, 14, Font.BOLD, Color.BLACK);
    Font dataFont = new Font(Font.TIMES_ROMAN, 14, Font.BOLD, Color.GRAY);
    Font dataFont2 = new Font(Font.TIMES_ROMAN, 10, Font.BOLD, new Color(100, 150, 190));

    PdfPTable linesOfCode = new PdfPTable(1);
    linesOfCode.getDefaultCell().setBorderColor(Color.WHITE);
    linesOfCode.addCell(new Phrase(getTextProperty("general.lines_of_code"), titleFont));
    linesOfCode.addCell(new Phrase(project.getMeasure("ncss").getFormatValue(), dataFont));
    linesOfCode.addCell(/*from ww  w .  j  a v a  2s. com*/
            new Phrase(project.getMeasure("packages_count").getFormatValue() + " packages", dataFont2));
    linesOfCode
            .addCell(new Phrase(project.getMeasure("classes_count").getFormatValue() + " classes", dataFont2));
    linesOfCode.addCell(
            new Phrase(project.getMeasure("functions_count").getFormatValue() + " methods", dataFont2));
    linesOfCode.addCell(new Phrase(
            project.getMeasure("duplicated_lines_ratio").getFormatValue() + " duplicated lines", dataFont2));

    PdfPTable comments = new PdfPTable(1);
    comments.getDefaultCell().setBorderColor(Color.WHITE);
    comments.addCell(new Phrase(getTextProperty("general.comments"), titleFont));
    comments.addCell(new Phrase(project.getMeasure("comment_ratio").getFormatValue(), dataFont));
    comments.addCell(
            new Phrase(project.getMeasure("comment_lines").getFormatValue() + " comment lines", dataFont2));

    PdfPTable codeCoverage = new PdfPTable(1);
    codeCoverage.getDefaultCell().setBorderColor(Color.WHITE);
    codeCoverage.addCell(new Phrase(getTextProperty("general.test_count"), titleFont));
    codeCoverage.addCell(new Phrase(project.getMeasure("test_count").getFormatValue(), dataFont));
    codeCoverage.addCell(
            new Phrase(project.getMeasure("test_success_percentage").getFormatValue() + " success", dataFont2));
    codeCoverage
            .addCell(new Phrase(project.getMeasure("code_coverage").getFormatValue() + " coverage", dataFont2));

    PdfPTable complexity = new PdfPTable(1);
    complexity.getDefaultCell().setBorderColor(Color.WHITE);
    complexity.addCell(new Phrase(getTextProperty("general.complexity"), titleFont));
    complexity.addCell(new Phrase(project.getMeasure("ccn_function").getFormatValue(), dataFont));
    complexity.addCell(new Phrase(project.getMeasure("ccn_class").getFormatValue() + " /class", dataFont2));
    complexity.addCell(new Phrase(project.getMeasure("ccn").getFormatValue() + " decision points", dataFont2));

    PdfPTable rulesCompliance = new PdfPTable(1);
    rulesCompliance.getDefaultCell().setBorderColor(Color.WHITE);
    rulesCompliance.addCell(new Phrase(getTextProperty("general.rules_compliance"), titleFont));
    rulesCompliance.addCell(new Phrase(project.getMeasure("rules_compliance").getFormatValue(), dataFont));

    PdfPTable violations = new PdfPTable(1);
    violations.getDefaultCell().setBorderColor(Color.WHITE);
    violations.addCell(new Phrase(getTextProperty("general.violations"), titleFont));
    violations.addCell(new Phrase(project.getMeasure("rules_violations").getFormatValue(), dataFont));

    dashboard.addCell(linesOfCode);
    dashboard.addCell(comments);
    dashboard.addCell(codeCoverage);
    dashboard.addCell(complexity);
    dashboard.addCell(rulesCompliance);
    dashboard.addCell(violations);
    dashboard.setSpacingBefore(8);
    section.add(dashboard);
    Image ccnDistGraph = getCCNDistribution(project);
    if (ccnDistGraph != null) {
        section.add(ccnDistGraph);
        Paragraph imageFoot = new Paragraph(getTextProperty("metrics.ccn_classes_count_distribution"),
                Style.FOOT_FONT);
        imageFoot.setAlignment(Paragraph.ALIGN_CENTER);
        section.add(imageFoot);
    }
}

From source file:org.sonar.report.pdf.DefaultPDFReporter.java

License:Open Source License

private void formatTable(PdfPTable table) {
    Rectangle page = document.getPageSize();
    table.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE);
    table.getDefaultCell().setPaddingBottom(tablePaddingBottom);
    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
    table.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
    table.setSpacingBefore(20);
}

From source file:org.sonar.report.pdf.ExecutivePDFReporter.java

License:Open Source License

protected void printDashboard(Project project, Section section) throws DocumentException {

    // Static Analysis
    Paragraph staticAnalysis = new Paragraph(getTextProperty("general.static_analysis"), Style.UNDERLINED_FONT);
    PdfPTable staticAnalysisTable = new PdfPTable(3);
    staticAnalysisTable.getDefaultCell().setBorderColor(Color.WHITE);

    PdfPTable linesOfCode = new PdfPTable(1);
    Style.noBorderTable(linesOfCode);
    linesOfCode.addCell(new Phrase(getTextProperty("general.lines_of_code"), Style.DASHBOARD_TITLE_FONT));
    PdfPTable linesOfCodeTendency = new PdfPTable(2);
    Style.noBorderTable(linesOfCodeTendency);
    linesOfCodeTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT);
    linesOfCodeTendency.addCell(// www  .  j av  a 2  s.c o  m
            new Phrase(project.getMeasure(MetricKeys.NCLOC).getFormatValue(), Style.DASHBOARD_DATA_FONT));
    linesOfCodeTendency.addCell(getTendencyImage(project.getMeasure(MetricKeys.NCLOC).getQualitativeTendency(),
            project.getMeasure(MetricKeys.NCLOC).getQuantitativeTendency()));

    linesOfCode.addCell(linesOfCodeTendency);
    linesOfCode.addCell(new Phrase(project.getMeasure(MetricKeys.PACKAGES).getFormatValue() + " packages",
            Style.DASHBOARD_DATA_FONT_2));
    linesOfCode.addCell(new Phrase(project.getMeasure(MetricKeys.CLASSES).getFormatValue() + " classes",
            Style.DASHBOARD_DATA_FONT_2));
    linesOfCode.addCell(new Phrase(project.getMeasure(MetricKeys.FUNCTIONS).getFormatValue() + " methods",
            Style.DASHBOARD_DATA_FONT_2));
    linesOfCode.addCell(new Phrase(
            project.getMeasure(MetricKeys.DUPLICATED_LINES_DENSITY).getFormatValue() + " duplicated lines",
            Style.DASHBOARD_DATA_FONT_2));

    PdfPTable comments = new PdfPTable(1);
    Style.noBorderTable(comments);
    comments.addCell(new Phrase(getTextProperty("general.comments"), Style.DASHBOARD_TITLE_FONT));
    PdfPTable commentsTendency = new PdfPTable(2);
    commentsTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT);
    Style.noBorderTable(commentsTendency);
    commentsTendency.addCell(new Phrase(project.getMeasure(MetricKeys.COMMENT_LINES_DENSITY).getFormatValue(),
            Style.DASHBOARD_DATA_FONT));
    commentsTendency.addCell(
            getTendencyImage(project.getMeasure(MetricKeys.COMMENT_LINES_DENSITY).getQualitativeTendency(),
                    project.getMeasure(MetricKeys.COMMENT_LINES_DENSITY).getQuantitativeTendency()));
    comments.addCell(commentsTendency);
    comments.addCell(
            new Phrase(project.getMeasure(MetricKeys.COMMENT_LINES).getFormatValue() + " comment lines",
                    Style.DASHBOARD_DATA_FONT_2));

    PdfPTable complexity = new PdfPTable(1);
    Style.noBorderTable(complexity);
    complexity.addCell(new Phrase(getTextProperty("general.complexity"), Style.DASHBOARD_TITLE_FONT));
    PdfPTable complexityTendency = new PdfPTable(2);
    complexityTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT);
    Style.noBorderTable(complexityTendency);
    complexityTendency.addCell(new Phrase(project.getMeasure(MetricKeys.FUNCTION_COMPLEXITY).getFormatValue(),
            Style.DASHBOARD_DATA_FONT));
    complexityTendency.addCell(
            getTendencyImage(project.getMeasure(MetricKeys.FUNCTION_COMPLEXITY).getQualitativeTendency(),
                    project.getMeasure(MetricKeys.FUNCTION_COMPLEXITY).getQuantitativeTendency()));
    complexity.addCell(complexityTendency);
    complexity.addCell(new Phrase(project.getMeasure(MetricKeys.CLASS_COMPLEXITY).getFormatValue() + " /class",
            Style.DASHBOARD_DATA_FONT_2));
    complexity
            .addCell(new Phrase(project.getMeasure(MetricKeys.COMPLEXITY).getFormatValue() + " decision points",
                    Style.DASHBOARD_DATA_FONT_2));

    staticAnalysisTable.setSpacingBefore(10);
    staticAnalysisTable.addCell(linesOfCode);
    staticAnalysisTable.addCell(comments);
    staticAnalysisTable.addCell(complexity);
    staticAnalysisTable.setSpacingAfter(20);

    // Dynamic Analysis
    Paragraph dynamicAnalysis = new Paragraph(getTextProperty("general.dynamic_analysis"),
            Style.UNDERLINED_FONT);
    PdfPTable dynamicAnalysisTable = new PdfPTable(3);
    Style.noBorderTable(dynamicAnalysisTable);

    PdfPTable codeCoverage = new PdfPTable(1);
    Style.noBorderTable(codeCoverage);
    codeCoverage.addCell(new Phrase(getTextProperty("general.code_coverage"), Style.DASHBOARD_TITLE_FONT));
    PdfPTable codeCoverageTendency = new PdfPTable(2);
    Style.noBorderTable(codeCoverageTendency);
    codeCoverageTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT);
    codeCoverageTendency.addCell(new Phrase(
            project.getMeasure(MetricKeys.COVERAGE).getFormatValue() + " coverage", Style.DASHBOARD_DATA_FONT));
    codeCoverageTendency
            .addCell(getTendencyImage(project.getMeasure(MetricKeys.COVERAGE).getQualitativeTendency(),
                    project.getMeasure(MetricKeys.COVERAGE).getQuantitativeTendency()));
    codeCoverage.addCell(codeCoverageTendency);
    codeCoverage.addCell(new Phrase(project.getMeasure(MetricKeys.TESTS).getFormatValue() + " tests",
            Style.DASHBOARD_DATA_FONT_2));

    PdfPTable testSuccess = new PdfPTable(1);
    Style.noBorderTable(testSuccess);
    testSuccess.addCell(new Phrase(getTextProperty("general.test_success"), Style.DASHBOARD_TITLE_FONT));
    PdfPTable testSuccessTendency = new PdfPTable(2);
    Style.noBorderTable(testSuccessTendency);
    testSuccessTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT);
    testSuccessTendency.addCell(new Phrase(project.getMeasure(MetricKeys.TEST_SUCCESS_DENSITY).getFormatValue(),
            Style.DASHBOARD_DATA_FONT));
    testSuccessTendency.addCell(
            getTendencyImage(project.getMeasure(MetricKeys.TEST_SUCCESS_DENSITY).getQualitativeTendency(),
                    project.getMeasure(MetricKeys.TEST_SUCCESS_DENSITY).getQuantitativeTendency()));
    testSuccess.addCell(testSuccessTendency);
    testSuccess.addCell(new Phrase(project.getMeasure(MetricKeys.TEST_FAILURES).getFormatValue() + " failures",
            Style.DASHBOARD_DATA_FONT_2));
    testSuccess.addCell(new Phrase(project.getMeasure(MetricKeys.TEST_ERRORS).getFormatValue() + " errors",
            Style.DASHBOARD_DATA_FONT_2));

    dynamicAnalysisTable.setSpacingBefore(10);
    dynamicAnalysisTable.addCell(codeCoverage);
    dynamicAnalysisTable.addCell(testSuccess);
    dynamicAnalysisTable.addCell("");
    dynamicAnalysisTable.setSpacingAfter(20);

    Paragraph codingRulesViolations = new Paragraph(getTextProperty("general.coding_rules_violations"),
            Style.UNDERLINED_FONT);
    PdfPTable codingRulesViolationsTable = new PdfPTable(3);
    Style.noBorderTable(codingRulesViolationsTable);

    PdfPTable rulesCompliance = new PdfPTable(1);
    Style.noBorderTable(rulesCompliance);
    rulesCompliance
            .addCell(new Phrase(getTextProperty("general.rules_compliance"), Style.DASHBOARD_TITLE_FONT));
    PdfPTable rulesComplianceTendency = new PdfPTable(2);
    Style.noBorderTable(rulesComplianceTendency);
    rulesComplianceTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT);
    rulesComplianceTendency.addCell(new Phrase(
            project.getMeasure(MetricKeys.VIOLATIONS_DENSITY).getFormatValue(), Style.DASHBOARD_DATA_FONT));

    // Workarround for avoid resizing
    Image tendencyRulesResize = getTendencyImage(
            project.getMeasure(MetricKeys.VIOLATIONS_DENSITY).getQualitativeTendency(),
            project.getMeasure(MetricKeys.VIOLATIONS_DENSITY).getQuantitativeTendency());
    tendencyRulesResize.scaleAbsolute(Style.TENDENCY_ICONS_HEIGHT, Style.TENDENCY_ICONS_HEIGHT);
    PdfPCell tendencyRulesCell = new PdfPCell(tendencyRulesResize);
    tendencyRulesCell.setBorder(0);
    rulesComplianceTendency.addCell(tendencyRulesCell);
    rulesCompliance.addCell(rulesComplianceTendency);

    PdfPTable violations = new PdfPTable(1);
    Style.noBorderTable(violations);
    violations.addCell(new Phrase(getTextProperty("general.violations"), Style.DASHBOARD_TITLE_FONT));
    PdfPTable violationsTendency = new PdfPTable(2);
    Style.noBorderTable(violationsTendency);
    violationsTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT);
    violationsTendency.addCell(
            new Phrase(project.getMeasure(MetricKeys.VIOLATIONS).getFormatValue(), Style.DASHBOARD_DATA_FONT));

    // Workarround for avoid resizing
    Image tendencyResize = getTendencyImage(project.getMeasure(MetricKeys.VIOLATIONS).getQualitativeTendency(),
            project.getMeasure(MetricKeys.VIOLATIONS).getQuantitativeTendency());
    tendencyResize.scaleAbsolute(Style.TENDENCY_ICONS_HEIGHT, Style.TENDENCY_ICONS_HEIGHT);
    PdfPCell tendencyCell = new PdfPCell(tendencyResize);
    tendencyCell.setBorder(0);
    violationsTendency.addCell(tendencyCell);

    violations.addCell(violationsTendency);

    codingRulesViolationsTable.setSpacingBefore(10);
    codingRulesViolationsTable.addCell(rulesCompliance);
    codingRulesViolationsTable.addCell(violations);
    codingRulesViolationsTable.addCell("");
    codingRulesViolationsTable.setSpacingAfter(20);

    section.add(Chunk.NEWLINE);
    section.add(staticAnalysis);
    section.add(staticAnalysisTable);
    section.add(dynamicAnalysis);
    section.add(dynamicAnalysisTable);
    section.add(codingRulesViolations);
    section.add(codingRulesViolationsTable);
}