Example usage for com.lowagie.text Chunk NEWLINE

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

Introduction

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

Prototype

Chunk NEWLINE

To view the source code for com.lowagie.text Chunk NEWLINE.

Click Source Link

Document

This is a Chunk containing a newline.

Usage

From source file:com.nokia.s60tools.swmtanalyser.wizards.ReportCreationJob.java

License:Open Source License

private void addGeneralDetails(Document document) throws DocumentException {
    //Report Title
    Paragraph title = new Paragraph("MemSpy - System Wide Memory Tracking - Analysis Report", fontHeader);
    title.setAlignment(Element.ALIGN_CENTER);
    document.add(title);//from w  w w .j  a  v  a2  s  .co  m
    document.add(Chunk.NEWLINE);

    //Introduction title
    Paragraph hdng = new Paragraph("Introduction of Memspy (S60) and SWMT Analyser", fontHeading1);
    document.add(hdng);

    //About the MemSpy S60 Application
    Paragraph intro_memspy = new Paragraph(
            "The MemSpy S60 application tracks various subsystems that directly or indirectly contribute to overall system memory usage and provides information about the changes in these subsystems at specified time intervals.",
            fontNormal);
    document.add(intro_memspy);
    document.add(Chunk.NEWLINE);
    //About the SWMT Analyser
    Paragraph intro_swmt = new Paragraph(
            "A System Wide Memory Tracker log file contains information about system wide memory status changes over time. SWMT Analyser is a Carbide.c++ Extension for analyzing System Wide Memory Tracking logs produced by the MemSpy S60 application and imported to PC with the MemSpy Carbide.c++ Extension.",
            fontNormal);
    document.add(intro_swmt);
    document.add(Chunk.NEWLINE);

    //Properties heading
    Paragraph props_title = new Paragraph("Properties", fontHeading1);
    document.add(props_title);
    Chunk no_of_cycles = new Chunk("No of cycles   :   ", fontHeading2);
    document.add(no_of_cycles);
    Chunk cycles = new Chunk(ov.noOfcycles + "", fontNormal);
    document.add(cycles);
    document.add(Chunk.NEWLINE);

    Chunk time_period = new Chunk("Time period   :   ", fontHeading2);
    document.add(time_period);
    Chunk period = new Chunk(ov.fromTime + " to " + ov.toTime, fontNormal);
    document.add(period);
    document.add(Chunk.NEWLINE);

    Chunk duration = new Chunk("Time duration   :   ", fontHeading2);
    document.add(duration);
    Chunk dur = new Chunk(ov.durationString, fontNormal);
    document.add(dur);
    document.add(Chunk.NEWLINE);

    document.add(Chunk.NEWLINE);
    Paragraph rom_title = new Paragraph("ROM Details", fontHeading1);
    document.add(rom_title);
    Chunk rom_checksum = new Chunk("ROM Checksum   :   ", fontHeading2);
    document.add(rom_checksum);
    Chunk checksum = new Chunk(this.rom_checkSum_string, fontNormal);
    document.add(checksum);
    document.add(Chunk.NEWLINE);

    Chunk rom_version = new Chunk("ROM Version   :   ", fontHeading2);
    document.add(rom_version);
    Chunk version = new Chunk(this.rom_version_string, fontNormal);
    document.add(version);
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
}

From source file:com.nokia.s60tools.swmtanalyser.wizards.ReportCreationJob.java

License:Open Source License

private void addSelectedIssuesReport(Document document) throws DocumentException, BadElementException {
    Paragraph selected_title = new Paragraph("Selected issues", fontHeading1);
    selected_title.setSpacingAfter(SPACING_AFTER_HEADER_TEXT);
    document.add(selected_title);//from w ww .  j a  va2  s.  c o  m

    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            table = getTableForTheSelectedIssues(all_tree_items);
        }
    });
    document.add(table);

    document.add(Chunk.NEWLINE);

    Paragraph graph_title = new Paragraph("Graph for the selected issues", fontHeading1);
    //Using chapter, so title stays together with image 
    Chapter chapter = new Chapter(graph_title, 0);
    //Chapter with out number, when depth is 0
    chapter.setNumberDepth(0);

    com.lowagie.text.Image img = null;
    try {
        img = com.lowagie.text.Image
                .getInstance(SwmtAnalyserPlugin.getPluginInstallPath() + "\\swmt_graph.bmp");
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    img.scalePercent(50f);
    img.setBorder(Rectangle.BOX);
    img.setBorderWidth(1f);
    img.setBorderColor(new GrayColor(0.5f));
    //Adding image to chapter
    chapter.add(img);
    //Adding chapter to document
    document.add(chapter);

}

From source file:com.nokia.s60tools.swmtanalyser.wizards.ReportCreationJob.java

License:Open Source License

private void addOverviewReport(Document document) throws DocumentException {
    Paragraph res_title = new Paragraph("Overview Of Analysis Results", fontHeading1);
    res_title.setSpacingAfter(SPACING_AFTER_HEADER_TEXT);
    document.add(res_title);//from  w w  w  .j  av a2 s  . co  m

    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            table = getTableForOverallIssues(all_tree_items);
        }
    });
    document.add(table);
    document.add(Chunk.NEWLINE);

    res_title = new Paragraph("Details", fontHeading1);
    document.add(res_title);

    res_title = new Paragraph("Critical Severity Issues", fontHeading2);
    res_title.setSpacingAfter(SPACING_AFTER_HEADER_TEXT);

    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            table = getTableForIssues(all_tree_items, AnalyserConstants.Priority.CRITICAL);
            ;
        }
    });
    if (table != null) {
        document.add(res_title);
        document.add(table);
        document.add(Chunk.NEWLINE);
    }

    res_title = new Paragraph("High Severity Issues", fontHeading2);
    res_title.setSpacingAfter(SPACING_AFTER_HEADER_TEXT);

    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            table = getTableForIssues(all_tree_items, AnalyserConstants.Priority.HIGH);
        }
    });
    if (table != null) {
        document.add(res_title);
        document.add(table);
        document.add(Chunk.NEWLINE);
    }

    res_title = new Paragraph("Normal Severity Issues", fontHeading2);
    res_title.setSpacingAfter(SPACING_AFTER_HEADER_TEXT);

    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            table = getTableForIssues(all_tree_items, AnalyserConstants.Priority.NORMAL);
        }
    });
    if (table != null) {
        document.add(res_title);
        document.add(table);
    }
}

From source file:com.opst.adminBean.java

public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
    Document pdf = (Document) document;
    pdf.open();//from  w w w.  ja v  a 2 s . c  o  m
    pdf.setPageSize(PageSize.A4);
    String string = "CTP Leaderboard - " + adminBean.firstandlast + " Week: " + adminBean.week;
    Chunk ch = new Chunk();
    pdf.add(new Chunk(string));
    pdf.add(Chunk.NEWLINE);
    pdf.add(Chunk.NEWLINE);
    pdf.add(new Chunk(" "));

}

From source file:com.orange.atk.compModel.PDFGenerator.java

License:Apache License

/**
 * @see com.orange.atk.results.logger.documentGenerator.DocumentGenerator#dumpInStream(boolean, interpreter.logger.DocumentLogger)
 *///from w  w  w  . ja  v  a2  s  . com

public void dumpInStream(boolean isParseErrorHappened, /*DocumentLogger dl,*/ org.w3c.dom.Document xmlDoc,
        Model model3) {
    long endTime = new Date().getTime();
    // step 1: creation of a document-object
    Document document = new Document();
    PdfWriter writer = null;

    // step 2:
    // we create a writer that listens to the document
    // and directs a PDF-stream to the outputStream
    try {
        writer = PdfWriter.getInstance(document, outputStream);
    } catch (DocumentException e1) {
        e1.printStackTrace();
        return;
    }
    writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
    // step 3: we open the document
    document.open();
    document.addTitle("REPORT");
    document.addCreationDate();

    HeaderFooter headerPage = new HeaderFooter(new Phrase("ScreenShot report"), false);
    HeaderFooter footerPage = new HeaderFooter(new Phrase(" - "), new Phrase(" - "));
    headerPage.setAlignment(Element.ALIGN_CENTER);
    footerPage.setAlignment(Element.ALIGN_CENTER);
    document.setHeader(headerPage);
    document.setFooter(footerPage);

    // Chapter 1 : Summary
    // Section 1 : Informations

    Chunk c = new Chunk("Summary");
    c.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f);
    c.setFont(FONT_PAR_TITLE);

    Paragraph title1 = new Paragraph(c);
    title1.setAlignment("CENTER");
    title1.setLeading(20);
    Chapter chapter1 = new Chapter(title1, 1);
    chapter1.setNumberDepth(0);

    Paragraph title11 = new Paragraph("Informations");
    Section section1 = chapter1.addSection(title11);
    Paragraph pSum = new Paragraph();
    pSum.add("Author : " + author);
    pSum.add(Chunk.NEWLINE);
    pSum.add("Group : " + group);
    pSum.add(Chunk.NEWLINE);
    pSum.add("Script : " + script);
    pSum.add(Chunk.NEWLINE);
    pSum.add("Reference directory: " + model3.getRefDirectory());
    pSum.add(Chunk.NEWLINE);
    pSum.add("Test directory: " + model3.getTestDirectory());
    pSum.add(Chunk.NEWLINE);
    SimpleDateFormat formatter = new SimpleDateFormat("MMMMM dd, yyyy - hh:mm aaa");
    String dateString = formatter.format(endTime);
    pSum.add("Date : " + dateString);
    pSum.add(Chunk.NEWLINE);
    pSum.add(Chunk.NEWLINE);
    if (model3.getNbFail() > 0) {
        pSum.add(model3.getNbFail() + "/" + model3.getNbImages() + " images didn't succeed the test.");
    } else {
        pSum.add("All images (" + model3.getNbImages() + ") have succeed this comparaison.");
    }
    pSum.add(Chunk.NEWLINE);
    pSum.setIndentationLeft(20);
    section1.add(pSum);
    section1.add(new Paragraph(Chunk.NEXTPAGE));

    try {
        document.add(chapter1);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.newPage();

    if (isParseErrorHappened) {
        document.close();
        return;
    }

    // Add generated pictures
    Chunk c3 = new Chunk("ScreenShots");
    c3.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f);
    c3.setFont(FONT_PAR_TITLE);
    Paragraph p3 = new Paragraph(c3);
    p3.setAlignment("CENTER");
    p3.setLeading(20);
    Chapter chapter3 = new Chapter(p3, 1);
    chapter3.setNumberDepth(0);

    NodeList imgs = xmlDoc.getElementsByTagName("img");
    for (int i = 0; i < imgs.getLength(); i++) {
        org.w3c.dom.Element eImg = (org.w3c.dom.Element) imgs.item(i);
        if (eImg.getElementsByTagName("Pass").item(0).getTextContent().equals(Model.FAIL)) {

            org.w3c.dom.Element eRef = (org.w3c.dom.Element) eImg.getElementsByTagName("Ref").item(0);
            org.w3c.dom.Element eTest = (org.w3c.dom.Element) eImg.getElementsByTagName("Test").item(0);
            Paragraph pScreen = new Paragraph(eTest.getAttributes().getNamedItem("name").getNodeValue() + " "
                    + eImg.getElementsByTagName("Pass").item(0).getTextContent());
            Section section31 = chapter3.addSection(pScreen);
            PdfPTable scTable = null;
            scTable = new PdfPTable(2);
            scTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
            scTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
            scTable.getDefaultCell().setPadding(5);
            if (new File(eRef.getTextContent()).exists()) {
                Image refImg;
                try {
                    refImg = Image.getInstance(eRef.getTextContent());
                    refImg.scaleToFit(310, 260);
                    refImg.setAlignment(Element.ALIGN_BASELINE);
                    scTable.addCell(refImg);
                } catch (BadElementException e) {
                    e.printStackTrace();
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (DOMException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
            if (new File(eTest.getTextContent()).exists()) {
                Image testImg;
                try {
                    BufferedImage bi = ImageIO.read(new File(eTest.getTextContent()));
                    Graphics2D g2d = (Graphics2D) bi.getGraphics();
                    g2d.setStroke(new BasicStroke(1.5f));
                    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f));

                    Boolean2D dif = model3.getCouplesComparaison().get(i).getDifWithMask();
                    //               if (squarable){
                    g2d.setColor(Color.red);
                    int w = bi.getWidth();
                    int h = bi.getHeight();
                    //TODO: Gurvan, Maybe we need to have the list of masks in the report?
                    Mask mask = model3.getCouplesComparaison().get(i).getMaskSum();
                    //g2d.drawRect(0, 0, mask.getWidth()*2*sampleWidth, mask.getHeight()*2*sampleHeight);
                    for (int x = 0; x < mask.getWidth(); x++) {

                        for (int y = 0; y < mask.getHeight(); y++) {

                            if (mask.getCell(x, y)) {
                                g2d.setColor(Color.blue);
                                ////Logger.getLogger(this.getClass() ).debug("grise");
                                g2d.fillRect(x * 2 * Mask.getCELL_HALF_SIZE(), y * 2 * Mask.getCELL_HALF_SIZE(),
                                        2 * Mask.getCELL_HALF_SIZE(), 2 * Mask.getCELL_HALF_SIZE());
                            }

                            if (!dif.get(x, y)) {
                                g2d.setColor(Color.green);
                                g2d.fillRect(x * 2 * Mask.getCELL_HALF_SIZE(), y * 2 * Mask.getCELL_HALF_SIZE(),
                                        2 * Mask.getCELL_HALF_SIZE(), 2 * Mask.getCELL_HALF_SIZE());
                            }
                        }
                    }
                    testImg = Image.getInstance(bi, null);
                    testImg.scaleToFit(310, 260);
                    testImg.setAlignment(Element.ALIGN_BASELINE);
                    scTable.addCell(testImg);
                    section31.add(Chunk.NEWLINE);
                    section31.add(scTable);
                } catch (BadElementException e) {
                    e.printStackTrace();
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (DOMException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
            section31.add(new Paragraph("Reference screenshot description : "
                    + eImg.getElementsByTagName("RefDescription").item(0).getTextContent()));
            section31.add(Chunk.NEWLINE);

            section31
                    .add(new Paragraph("Mask : " + eImg.getElementsByTagName("Mask").item(0).getTextContent()));
            section31.add(Chunk.NEWLINE);

            section31.add(new Paragraph(
                    "Comment : " + eImg.getElementsByTagName("Comment").item(0).getTextContent()));
            section31.add(new Paragraph(Chunk.NEXTPAGE));

        }
    }
    try {
        document.add(chapter3);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.newPage();

    // step 5: we close the document
    document.close();
}

From source file:com.orange.atk.results.logger.documentGenerator.PDFGenerator.java

License:Apache License

/**
 * @see com.orange.atk.results.logger.documentGenerator.DocumentGenerator#dumpInStream(boolean,
 *      com.orange.atk.results.logger.log.DocumentLogger)
 *//*from www.ja v a 2  s.  c  o  m*/
public void dumpInStream(boolean isParseErrorHappened, DocumentLogger dl) {
    long endTime = new Date().getTime();
    // step 1: creation of a document-object
    Document document = new Document();
    PdfWriter writer = null;
    // step 2:
    // we create a writer that listens to the document
    // and directs a PDF-stream to the outputStream
    try {
        writer = PdfWriter.getInstance(document, outputStream);
    } catch (DocumentException e1) {
        e1.printStackTrace();
        return;
    }
    writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
    // step 3: we open the document
    document.open();
    // step 4: we add a paragraph to the document
    List<Message> msgLogged = dl.getMsgsLogged();
    Paragraph pLoggedMsg = new Paragraph();
    // logged messages
    for (int i = 0; i < msgLogged.size(); i++) {
        Message msg = msgLogged.get(i);
        SimpleDateFormat formatter = new SimpleDateFormat("H:mm:ssSSS");
        String dateString = formatter.format(msg.getTimestamp());
        switch (msg.getType()) {
        case Message.INFO_MSG:
            pLoggedMsg.add("[" + dateString + "] " + msg.getMessage());
            break;
        case Message.WARN_MSG:
            pLoggedMsg.add("[" + dateString + "] WARN : " + msg.getMessage() + " at line : " + msg.getLine());
            break;
        case Message.ERROR_MSG:
            pLoggedMsg.add("[" + dateString + "] ERROR : " + msg.getMessage() + " at line : " + msg.getLine());
            break;
        default:
            break;

        }
        pLoggedMsg.add(Chunk.NEWLINE);
    }

    Paragraph pLastLogguedLines = new Paragraph();
    int startIndex = msgLogged.size() > 5 ? msgLogged.size() - 5 : 0;
    for (int i = startIndex; i < msgLogged.size(); i++) {
        Message m = msgLogged.get(i);
        switch (m.getType()) {
        case Message.INFO_MSG:
            pLastLogguedLines.add("INFO : " + m.getMessage());
            break;
        case Message.WARN_MSG:
            pLastLogguedLines.add("WARN : " + m.getMessage());
            break;
        case Message.ERROR_MSG:
            pLastLogguedLines.add("ERROR : " + m.getMessage());
            break;
        default:
            break;

        }
        pLastLogguedLines.add(Chunk.NEWLINE);
    }
    // l.setIndentationLeft(40);
    // Min/Max/Ave values
    /*
     * PdfPTable table = new PdfPTable(4); table.addCell("");
     * table.addCell("Min"); table.addCell("Max"); table.addCell("Avg");
     * 
     * 
     * table.addCell("Battery in  %"); table.addCell(String.valueOf(dl
     * .getMinValueFromList(dl.getplt("BATTERY"))));
     * table.addCell(String.valueOf(dl
     * .getMaxValueFromList(dl.getplt("BATTERY"))));
     * table.addCell(String.valueOf(dl
     * .getAveValueFromList(dl.getplt("BATTERY"))));
     * table.addCell("Storage in bytes"); table.addCell(String.valueOf(dl
     * .getMinValueFromList(dl.getplt("Storage"))));
     * table.addCell(String.valueOf(dl
     * .getMaxValueFromList(dl.getplt("Storage"))));
     * table.addCell(String.valueOf(dl
     * .getAveValueFromList(dl.getplt("Storage"))));
     */
    document.addTitle("REPORT");
    document.addCreationDate();

    HeaderFooter headerPage = new HeaderFooter(new Phrase("Execution report"), false);
    HeaderFooter footerPage = new HeaderFooter(new Phrase(" - "), new Phrase(" - "));
    headerPage.setAlignment(Element.ALIGN_CENTER);
    footerPage.setAlignment(Element.ALIGN_CENTER);
    document.setHeader(headerPage);
    document.setFooter(footerPage);

    // Chapter 1 : Summary
    // Section 1 : Informations

    Chunk c = new Chunk("Summary");
    c.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f);
    c.setFont(FONT_PAR_TITLE);

    Paragraph title1 = new Paragraph(c);
    title1.setAlignment("CENTER");
    title1.setLeading(20);
    Chapter chapter1 = new Chapter(title1, 1);
    chapter1.setNumberDepth(0);

    Paragraph title11 = new Paragraph("Informations");
    Section section1 = chapter1.addSection(title11);
    Paragraph pSum = new Paragraph();
    pSum.add("Author : " + author);
    pSum.add(Chunk.NEWLINE);
    pSum.add("Group : " + group);
    pSum.add(Chunk.NEWLINE);
    pSum.add("Script : " + script);
    pSum.add(Chunk.NEWLINE);
    SimpleDateFormat formatter = new SimpleDateFormat("MMM d, yyyy - hh:mm aaa");
    String dateString = formatter.format(endTime);
    pSum.add("Date : " + dateString);
    pSum.add(Chunk.NEWLINE);
    pSum.setIndentationLeft(20);
    section1.add(pSum);
    section1.add(new Paragraph(Chunk.NEXTPAGE));

    Chunk c11 = new Chunk("Executive summary");
    c11.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f);
    c11.setFont(FONT_PAR_TITLE);
    Paragraph title12 = new Paragraph(c11);
    Section section12 = chapter1.addSection(title12);
    Paragraph pExecSum = new Paragraph();
    // pExecSum.add("Value : ");
    // pExecSum.add(Chunk.NEWLINE);
    // pExecSum.add(table);
    pExecSum.add(Chunk.NEWLINE);
    pExecSum.add("Last logged lines : ");
    pExecSum.add(Chunk.NEWLINE);
    pExecSum.add(pLastLogguedLines);
    pExecSum.add(Chunk.NEWLINE);
    pExecSum.setIndentationLeft(20);

    section12.add(pExecSum);

    try {
        document.add(chapter1);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.newPage();

    // Chapter 2 : Log information
    Chunk c2 = new Chunk("Log information");
    c2.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f);
    c2.setFont(FONT_PAR_TITLE);
    Paragraph title2 = new Paragraph(c2);
    title2.setAlignment("CENTER");
    title2.setLeading(20);
    Chapter chapter2 = new Chapter(title2, 1);
    chapter2.setNumberDepth(0);

    Section section2 = chapter2.addSection("Log");
    // Add log information
    section2.add(pLoggedMsg);
    section2.add(Chunk.NEWLINE);

    // section2.add(table);
    try {
        document.add(chapter2);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.newPage();

    if (isParseErrorHappened) {
        document.close();
        return;
    }

    // Add generated pictures
    Chunk c3 = new Chunk("Graphics");
    c3.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f);
    c3.setFont(FONT_PAR_TITLE);
    Paragraph p3 = new Paragraph(c3);
    p3.setAlignment("CENTER");
    p3.setLeading(20);
    Chapter chapter3 = new Chapter(p3, 1);
    chapter3.setNumberDepth(0);

    // add current graph
    Map<String, PlotList> mapint = dl.getMapint();
    Set<String> cles = mapint.keySet();
    Iterator<String> it = cles.iterator();
    while (it.hasNext()) {
        String cle = (String) it.next();
        Paragraph pCPUimg = new Paragraph(cle);
        Section section31 = chapter3.addSection(pCPUimg);
        if (new File(dl.getPNGpath(cle)).exists()) {
            Image jpg1 = null;
            try {
                jpg1 = Image.getInstance(dl.getPNGpath(cle));
            } catch (BadElementException e) {
                e.printStackTrace();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

            if (jpg1 == null) {
                Logger.getLogger(this.getClass()).warn("Error when Creating image jpg1 is null");
                return;
            }
            // jpg1.setRotationDegrees(270);
            jpg1.scalePercent(75);
            jpg1.setAlignment(Element.ALIGN_CENTER);
            section31.add(jpg1);
            PlotList plotlist = mapint.get(cle);
            DecimalFormat df = new DecimalFormat("#,###.##");

            if (plotlist.getType() == PlotList.TYPE_SUM) {
                section31.add(new Paragraph("Total : " + df.format(plotlist.getTotal() / plotlist.getScale())
                        + " " + plotlist.getunit()));
            } else { // PlotList.TYPE_AVG
                section31.add(new Paragraph("Average : "
                        + df.format(plotlist.getAverage() / plotlist.getScale()) + " " + plotlist.getunit()));
            }

        }
        section31.add(new Paragraph(Chunk.NEXTPAGE));
    }

    /*
     * // Section 3.1 : CPU data Paragraph pCPUimg = new
     * Paragraph("CPU data"); Section section31 =
     * chapter3.addSection(pCPUimg); if (new
     * File(dl.getPNGpath("CPU")).exists()) { Image jpg1 = null; try { jpg1
     * = Image.getInstance(dl.getPNGpath("CPU")); } catch
     * (BadElementException e) { e.printStackTrace(); } catch
     * (MalformedURLException e) { e.printStackTrace(); } catch (IOException
     * e) { e.printStackTrace(); } //jpg1.setRotationDegrees(270);
     * jpg1.scalePercent(75); jpg1.setAlignment(Element.ALIGN_CENTER);
     * section31.add(jpg1); } section31.add(new Paragraph(Chunk.NEXTPAGE));
     * 
     * // Section 3.2 : BAT data Paragraph pBATimg = new
     * Paragraph("Battery data"); Section section32 =
     * chapter3.addSection(pBATimg); if (new
     * File(dl.getPNGpath("BATTERY")).exists()) { Image jpg2 = null; try {
     * jpg2 = Image.getInstance(dl.getPNGpath("BATTERY")); } catch
     * (BadElementException e) { e.printStackTrace(); } catch
     * (MalformedURLException e) { e.printStackTrace(); } catch (IOException
     * e) { e.printStackTrace(); } //jpg2.setRotationDegrees(270);
     * jpg2.scalePercent(75); jpg2.setAlignment(Element.ALIGN_CENTER);
     * section32.add(jpg2); } section32.add(new Paragraph(Chunk.NEXTPAGE));
     * 
     * // Section 3.3 : MEM data Paragraph pMEMimg = new
     * Paragraph("Memory data"); Section section33 =
     * chapter3.addSection(pMEMimg); if (new
     * File(dl.getPNGpath("MEMORY")).exists()) {
     * 
     * Image jpg3 = null; try { jpg3 =
     * Image.getInstance(dl.getPNGpath("MEMORY")); } catch
     * (BadElementException e) { e.printStackTrace(); } catch
     * (MalformedURLException e) { e.printStackTrace(); } catch (IOException
     * e) { e.printStackTrace(); } //jpg3.setRotationDegrees(270);
     * jpg3.scalePercent(75); jpg3.setAlignment(Element.ALIGN_CENTER);
     * section33.add(jpg3); } section33.add(new Paragraph(Chunk.NEXTPAGE));
     * 
     * // Section 3.4 : STO data Paragraph pSTOimg = new
     * Paragraph("Storage data"); Section section34 =
     * chapter3.addSection(pSTOimg); if (new
     * File(dl.getPNGpath("Storage")).exists()) {
     * 
     * Image jpg4 = null; try { jpg4 =
     * Image.getInstance(dl.getPNGpath("Storage")); } catch
     * (BadElementException e) { e.printStackTrace(); } catch
     * (MalformedURLException e) { e.printStackTrace(); } catch (IOException
     * e) { e.printStackTrace(); } //jpg4.setRotationDegrees(270);
     * jpg4.scalePercent(75); jpg4.setAlignment(Element.ALIGN_CENTER);
     * section34.add(jpg4); }
     * 
     * 
     * // Section 3.5 : Network connection //Paragraph pNetworkimg = new
     * Paragraph("Network QoS data"); //Section section35 =
     * chapter3.addSection(pNetworkimg); // if (new
     * File(dl.getNetworkPNGfile()).exists()) {
     * 
     * // Image jpg5 = null; // try { // jpg5 =
     * Image.getInstance(dl.getNetworkPNGfile()); // } catch
     * (BadElementException e) { // e.printStackTrace(); // } catch
     * (MalformedURLException e) { // e.printStackTrace(); // } catch
     * (IOException e) { // e.printStackTrace(); // }
     * //jpg4.setRotationDegrees(270); // jpg5.scalePercent(75); //
     * jpg5.setAlignment(Element.ALIGN_CENTER); // section35.add(jpg5); //}
     */
    try {
        document.add(chapter3);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.newPage();

    // if (isTableEnabled) {
    // // Add tables filled with measurement
    // // Chapter 4 : Measurement tables
    // Chunk c4 = new Chunk("Statistics tables");
    // c4.setBackground(new Color(0xFF, 0x66, 0x00), 200, 3f, 200f, 3f);
    // c4.setFont(FontFactory.getFont(BaseFont.HELVETICA,
    // BaseFont.WINANSI, BaseFont.NOT_EMBEDDED, 16));
    // Paragraph title4 = new Paragraph(c4);
    // title4.setAlignment("CENTER");
    // title4.setLeading(20);
    // Chapter chapter4 = new Chapter(title4, 1);
    // chapter4.setNumberDepth(0);
    //
    // // Section 4.1 : Battery value
    // Paragraph titleSection41 = new Paragraph("Battery value");
    // Section section41 = chapter4.addSection(titleSection41);
    // Paragraph pBatList = new Paragraph();
    // pBatList.add(Chunk.NEWLINE);
    // pBatList.add(createPDFTableFromList(dl
    // .getList(DocumentLogger.BATTERY), "Battery"));
    // pBatList.setAlignment("CENTER");
    // section41.add(pBatList);
    //
    // // Section 4.2 : CPU value
    // Paragraph titleSection42 = new Paragraph("CPU value");
    // Section section42 = chapter4.addSection(titleSection42);
    // Paragraph pCPUList = new Paragraph();
    // pCPUList.add(Chunk.NEWLINE);
    // pCPUList.add(createPDFTableFromList(dl.getList(DocumentLogger.CPU),
    // "CPU"));
    // pCPUList.setAlignment("CENTER");
    // section42.add(pCPUList);
    //
    // // Section 4.3 : Memory value
    // Paragraph titleSection43 = new Paragraph("Memory value");
    // Section section43 = chapter4.addSection(titleSection43);
    // Paragraph pMemList = new Paragraph();
    // pMemList.add(Chunk.NEWLINE);
    // pMemList.add(createPDFTableFromList(dl
    // .getList(DocumentLogger.MEMORY), "Memory"));
    // pMemList.setAlignment("CENTER");
    // section43.add(pMemList);
    //
    // // Section 4.4 : Storage value
    // Paragraph titleSection44 = new Paragraph("Storage value");
    // Section section44 = chapter4.addSection(titleSection44);
    // Paragraph pStoList = new Paragraph();
    // pStoList.add(Chunk.NEWLINE);
    // pStoList.add(createPDFTableFromList(dl
    // .getList(DocumentLogger.STORAGE), "Storage"));
    // pStoList.setAlignment("CENTER");
    // section44.add(pStoList);
    //
    // try {
    // document.add(chapter4);
    // } catch (DocumentException e) {
    // e.printStackTrace();
    // }
    // }

    // step 5: we close the document
    document.close();
    createHTMLFile(dl);
}

From source file:com.orange.atk.results.logger.documentGenerator.PDFGenerator.java

License:Apache License

public void dumpInStreamactionlogger(boolean isParseErrorHappened, ActionsLogger actionlog, DocumentLogger dl) {
    long endTime = new Date().getTime();
    // step 1: creation of a document-object
    Document document = new Document();
    PdfWriter writer = null;//from   w w  w .  ja  v  a 2  s . c o  m
    Vector VectAction = actionlog.getActions();
    // step 2:
    // we create a writer that listens to the document
    // and directs a PDF-stream to the outputStream
    try {
        writer = PdfWriter.getInstance(document, outputStream);
    } catch (DocumentException e1) {
        e1.printStackTrace();
        return;
    }
    writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
    // step 3: we open the document
    document.open();
    // step 4: we add a paragraph to the document
    Paragraph pLoggedMsg = new Paragraph();
    // logged messages

    for (int i = 0; i < VectAction.size(); i++) {
        Action action = (Action) VectAction.get(i);
        SimpleDateFormat formatter = new SimpleDateFormat("H:mm:ssSSS");
        SimpleDateFormat spf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss SSS");
        String dateString = spf.format(action.getStartTime());
        pLoggedMsg.add("[" + dateString + "]  : " + action.getActionName());

        pLoggedMsg.add(Chunk.NEWLINE);

    }

    Paragraph pLastLogguedLines = new Paragraph();
    int startIndex = VectAction.size() > 5 ? VectAction.size() - 5 : 0;
    for (int i = startIndex; i < VectAction.size(); i++) {
        Action action = (Action) VectAction.get(i);
        // SimpleDateFormat formatter = new SimpleDateFormat("H:mm:ssSSS");
        SimpleDateFormat spf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss SSS");
        String dateString = spf.format(action.getStartTime());
        pLastLogguedLines.add("[" + dateString + "]  : " + action.getActionName());

        pLastLogguedLines.add(Chunk.NEWLINE);

    }

    document.addTitle("REPORT");
    document.addCreationDate();

    HeaderFooter headerPage = new HeaderFooter(new Phrase("Execution report"), false);
    HeaderFooter footerPage = new HeaderFooter(new Phrase(" - "), new Phrase(" - "));
    headerPage.setAlignment(Element.ALIGN_CENTER);
    footerPage.setAlignment(Element.ALIGN_CENTER);
    document.setHeader(headerPage);
    document.setFooter(footerPage);

    // Chapter 1 : Summary
    // Section 1 : Informations

    Chunk c = new Chunk("Summary");
    c.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f);
    c.setFont(FONT_PAR_TITLE);

    Paragraph title1 = new Paragraph(c);
    title1.setAlignment("CENTER");
    title1.setLeading(20);
    Chapter chapter1 = new Chapter(title1, 1);
    chapter1.setNumberDepth(0);

    Paragraph title11 = new Paragraph("Informations");
    Section section1 = chapter1.addSection(title11);
    Paragraph pSum = new Paragraph();
    pSum.add("Author : " + author);
    pSum.add(Chunk.NEWLINE);
    pSum.add("Group : " + group);
    pSum.add(Chunk.NEWLINE);
    pSum.add("Script : " + script);
    pSum.add(Chunk.NEWLINE);
    SimpleDateFormat formatter = new SimpleDateFormat("MMM d, yyyy - hh:mm aaa");
    String dateString = formatter.format(endTime);
    pSum.add("Date : " + dateString);
    pSum.add(Chunk.NEWLINE);
    pSum.setIndentationLeft(20);
    section1.add(pSum);
    section1.add(new Paragraph(Chunk.NEXTPAGE));

    Chunk c11 = new Chunk("Executive summary");
    c11.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f);
    c11.setFont(FONT_PAR_TITLE);
    Paragraph title12 = new Paragraph(c11);
    Section section12 = chapter1.addSection(title12);
    Paragraph pExecSum = new Paragraph();
    // pExecSum.add("Value : ");
    // pExecSum.add(Chunk.NEWLINE);
    // pExecSum.add(table);
    pExecSum.add(Chunk.NEWLINE);
    pExecSum.add("Last logged lines : ");
    pExecSum.add(Chunk.NEWLINE);
    pExecSum.add(pLastLogguedLines);
    pExecSum.add(Chunk.NEWLINE);
    pExecSum.setIndentationLeft(20);

    section12.add(pExecSum);

    try {
        document.add(chapter1);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.newPage();

    // Chapter 2 : Log information
    Chunk c2 = new Chunk("Log information");
    c2.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f);
    c2.setFont(FONT_PAR_TITLE);
    Paragraph title2 = new Paragraph(c2);
    title2.setAlignment("CENTER");
    title2.setLeading(20);
    Chapter chapter2 = new Chapter(title2, 1);
    chapter2.setNumberDepth(0);

    Section section2 = chapter2.addSection("Log");
    // Add log information
    section2.add(pLoggedMsg);
    section2.add(Chunk.NEWLINE);

    // section2.add(table);
    try {
        document.add(chapter2);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.newPage();

    if (isParseErrorHappened) {
        document.close();
        return;
    }

    // Add generated pictures
    Chunk c3 = new Chunk("Graphics");
    c3.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f);
    c3.setFont(FONT_PAR_TITLE);
    Paragraph p3 = new Paragraph(c3);
    p3.setAlignment("CENTER");
    p3.setLeading(20);
    Chapter chapter3 = new Chapter(p3, 1);
    chapter3.setNumberDepth(0);

    // add current graph
    Map<String, PlotList> mapint = dl.getMapint();
    Set<String> cles = mapint.keySet();
    Iterator<String> it = cles.iterator();
    while (it.hasNext()) {
        String cle = (String) it.next();
        Paragraph pCPUimg = new Paragraph(cle);
        Section section31 = chapter3.addSection(pCPUimg);
        if (new File(dl.getPNGpath(cle)).exists()) {
            Image jpg1 = null;
            try {
                jpg1 = Image.getInstance(dl.getPNGpath(cle));
            } catch (BadElementException e) {
                e.printStackTrace();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (jpg1 == null) {
                Logger.getLogger(this.getClass()).warn("Error when Creating image jpg1 is null");
                return;
            }
            // jpg1.setRotationDegrees(270);
            jpg1.scalePercent(75);
            jpg1.setAlignment(Element.ALIGN_CENTER);
            section31.add(jpg1);
        }
        section31.add(new Paragraph(Chunk.NEXTPAGE));
    }

    try {
        document.add(chapter3);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.newPage();

    document.close();
    createHTMLFileactionlog(actionlog, dl);
}

From source file:com.qcadoo.mes.costCalculation.print.CostCalculationPdfService.java

License:Open Source License

@Override
protected void buildPdfContent(final Document document, final Entity entity, final Locale locale)
        throws DocumentException {
    String documentTitle = translationService.translate("costCalculation.costCalculationDetails.report.title",
            locale);/*  www  .  j ava2 s.com*/
    String documentAuthor = translationService.translate("qcadooReport.commons.generatedBy.label", locale);

    pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, new Date());

    DataDefinition dataDefCostCalculation = dataDefinitionService
            .get(CostCalculationConstants.PLUGIN_IDENTIFIER, CostCalculationConstants.MODEL_COST_CALCULATION);
    Entity costCalculation = dataDefCostCalculation.find("where id = " + entity.getId().toString())
            .uniqueResult();

    PdfPTable leftPanelColumn = addLeftPanelToReport(costCalculation, locale);

    PdfPTable rightPanelColumn = addRightPanelToReport(costCalculation, locale);

    PdfPTable panelTable = pdfHelper.createPanelTable(2);

    panelTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);
    panelTable.addCell(leftPanelColumn);
    panelTable.addCell(rightPanelColumn);
    panelTable.setSpacingAfter(20);
    panelTable.setSpacingBefore(20);

    panelTable.setTableEvent(null);
    panelTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);

    document.add(panelTable);

    document.add(new Paragraph(
            translationService.translate("costCalculation.costCalculationDetails.report.paragraph", locale),
            FontUtils.getDejavuBold11Dark()));
    PdfPTable materialsTable = addMaterialsTable(costCalculation, locale);
    document.add(materialsTable);

    document.add(Chunk.NEWLINE);
    document.add(new Paragraph(
            translationService.translate("costCalculation.costCalculationDetails.report.paragraph2", locale),
            FontUtils.getDejavuBold11Dark()));

    CalculateOperationCostMode calculateOperationCostMode = CalculateOperationCostMode
            .parseString(costCalculation.getStringField(CostCalculationFields.CALCULATE_OPERATION_COSTS_MODE));

    if (CalculateOperationCostMode.HOURLY.equals(calculateOperationCostMode)) {
        document.add(addHourlyCostsTable(costCalculation, locale));
    } else if (CalculateOperationCostMode.PIECEWORK.equals(calculateOperationCostMode)) {
        document.add(addTableAboutPieceworkCost(costCalculation, locale));
    } else {
        throw new IllegalStateException("Unsupported CalculateOperationCostMode");
    }

    printMaterialAndOperationNorms(document, costCalculation, locale);
}

From source file:com.qcadoo.mes.costCalculation.print.CostCalculationPdfService.java

License:Open Source License

public void printMaterialAndOperationNorms(final Document document, final Entity costCalculation,
        final Locale locale) throws DocumentException {
    if (costCalculation.getBooleanField(CostCalculationFields.PRINT_COST_NORMS_OF_MATERIALS)) {
        document.add(Chunk.NEWLINE);
        document.add(new Paragraph(translationService
                .translate("costCalculation.costCalculationDetails.report.paragraph3", locale),
                FontUtils.getDejavuBold11Dark()));
        PdfPTable optionTable = addOptionTablePrintCostNormsOfMaterials(costCalculation, locale);
        document.add(optionTable);//from   w w  w.  ja va  2s .  co  m
    }

    if (costCalculation.getBooleanField(CostCalculationFields.PRINT_OPERATION_NORMS)) {
        CalculateOperationCostMode calculateOperationCostMode = CalculateOperationCostMode.parseString(
                costCalculation.getStringField(CostCalculationFields.CALCULATE_OPERATION_COSTS_MODE));

        if (CalculateOperationCostMode.PIECEWORK.equals(calculateOperationCostMode)) {
            document.add(Chunk.NEWLINE);
            document.add(
                    new Paragraph(
                            translationService.translate(
                                    "costCalculation.costCalculationDetails.report.paragraph4", locale),
                            FontUtils.getDejavuBold11Dark()));
            document.add(addOptionTablePrintOperationNormsPiecework(costCalculation, locale));
        } else if (CalculateOperationCostMode.HOURLY.equals(calculateOperationCostMode)) {
            document.add(Chunk.NEWLINE);
            document.add(
                    new Paragraph(
                            translationService.translate(
                                    "costCalculation.costCalculationDetails.report.paragraph5", locale),
                            FontUtils.getDejavuBold11Dark()));
            addOptionTablePrintOperationNormsHourly(document, costCalculation, locale);
        }
    }
}

From source file:com.qcadoo.mes.deliveries.print.DeliveryReportPdf.java

License:Open Source License

private void createProductsTable(final Document document, final Entity delivery, final Locale locale)
        throws DocumentException {
    List<Entity> columnsForDeliveries = deliveriesService.getColumnsForDeliveries();

    if (!columnsForDeliveries.isEmpty()) {
        List<DeliveryProduct> deliveryProducts = deliveryColumnFetcher.getDeliveryProducts(delivery);

        Map<DeliveryProduct, Map<String, String>> deliveryProductsColumnValues = deliveryColumnFetcher
                .getDeliveryProductsColumnValues(deliveryProducts);

        List<Entity> filteredColumnsForDeliveries = getDeliveryReportColumns(columnsForDeliveries,
                deliveryProducts, deliveryProductsColumnValues);

        if (!filteredColumnsForDeliveries.isEmpty()) {
            List<String> columnsName = Lists.newArrayList();

            for (Entity entity : filteredColumnsForDeliveries) {
                columnsName.add(entity.getStringField(ColumnForDeliveriesFields.IDENTIFIER));
            }//from w w  w  .  java 2s.  com

            Map<String, HeaderAlignment> alignments = prepareHeaderAlignment(filteredColumnsForDeliveries,
                    locale);
            PdfPTable productsTable = pdfHelper.createTableWithHeader(filteredColumnsForDeliveries.size(),
                    prepareProductsTableHeader(document, filteredColumnsForDeliveries, locale), false,
                    pdfHelper.getReportColumnWidths(REPORT_WIDTH, parameterService.getReportColumnWidths(),
                            columnsName),
                    alignments);

            for (DeliveryProduct deliveryProduct : deliveryProducts) {
                for (Entity columnForDeliveries : filteredColumnsForDeliveries) {
                    String identifier = columnForDeliveries
                            .getStringField(ColumnForDeliveriesFields.IDENTIFIER);
                    String alignment = columnForDeliveries.getStringField(ColumnForDeliveriesFields.ALIGNMENT);

                    String value = deliveryProductsColumnValues.get(deliveryProduct).get(identifier);

                    prepareProductColumnAlignment(productsTable.getDefaultCell(),
                            ColumnAlignment.parseString(alignment));

                    productsTable.addCell(new Phrase(value, FontUtils.getDejavuRegular7Dark()));
                }
            }

            addTotalRow(productsTable, locale, columnsName, delivery);

            document.add(productsTable);
            document.add(Chunk.NEWLINE);
        }
    }
}