Example usage for com.lowagie.text Phrase Phrase

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

Introduction

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

Prototype

public Phrase(float leading, String string) 

Source Link

Document

Constructs a Phrase with a certain leading and a certain String.

Usage

From source file:net.bull.javamelody.internal.web.pdf.PdfRequestAndGraphDetailReport.java

License:Apache License

@Override
void toPdf() throws DocumentException, IOException {
    if (request != null) {
        if (request.getRumData() != null && request.getRumData().getHits() != 0) {
            writeRequestRumData();/*from w w w.ja  v a2s .c om*/
        }

        writeHeader();

        writeRequests();

        addTableToDocument();

        if (JdbcWrapper.SINGLETON.getSqlCounter().isRequestIdFromThisCounter(request.getId())
                && !request.getName().toLowerCase(Locale.ENGLISH).startsWith("alter ")) {
            // inutile d'essayer d'avoir le plan d'excution des requtes sql
            // telles que "alter session set ..." (cf issue 152)
            writeSqlRequestExplainPlan();
        }
    }

    if (isGraphDisplayed()) {
        writeGraph();
    }

    if (request != null && request.getStackTrace() != null) {
        final Paragraph paragraph = new Paragraph("\n", cellFont);
        paragraph.setIndentationLeft(20);
        paragraph.setIndentationRight(20);
        paragraph.add(new Phrase("Stack-trace\n", boldFont));
        paragraph.add(new Phrase(request.getStackTrace().replace("\t", "        "), cellFont));
        addToDocument(paragraph);
    }
}

From source file:net.bull.javamelody.internal.web.pdf.PdfRequestAndGraphDetailReport.java

License:Apache License

private void writeRequestRumData() throws DocumentException {
    final CounterRequestRumData rumData = request.getRumData();
    final DecimalFormat percentFormat = I18N.createPercentFormat();
    final int networkTimeMean = rumData.getNetworkTimeMean();
    final int serverMean = request.getMean();
    final int domProcessingMean = rumData.getDomProcessingMean();
    final int pageRenderingMean = rumData.getPageRenderingMean();
    final int totalTime = networkTimeMean + serverMean + domProcessingMean + pageRenderingMean;
    final double networkPercent = 100d * networkTimeMean / totalTime;
    final double serverPercent = 100d * serverMean / totalTime;
    final double domProcessingPercent = 100d * domProcessingMean / totalTime;
    final double pageRenderingPercent = 100d * pageRenderingMean / totalTime;

    final PdfPTable table = new PdfPTable(2);
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    table.setWidthPercentage(25);/*from   w  ww  .j  a  v  a 2 s.  c  o  m*/
    table.getDefaultCell().setBorderWidth(0);
    table.addCell(new Phrase(I18N.getString("Network"), cellFont));
    table.addCell(new Phrase(
            integerFormat.format(networkTimeMean) + " ms (" + percentFormat.format(networkPercent) + "%)",
            cellFont));
    table.addCell(new Phrase(I18N.getString("Server"), cellFont));
    table.addCell(new Phrase(
            integerFormat.format(serverMean) + " ms (" + percentFormat.format(serverPercent) + "%)", cellFont));
    table.addCell(new Phrase(I18N.getString("DOM_processing"), cellFont));
    table.addCell(new Phrase(integerFormat.format(domProcessingMean) + " ms ("
            + percentFormat.format(domProcessingPercent) + "%)", cellFont));
    table.addCell(new Phrase(I18N.getString("Page_rendering"), cellFont));
    table.addCell(new Phrase(integerFormat.format(pageRenderingMean) + " ms ("
            + percentFormat.format(pageRenderingPercent) + "%)", cellFont));
    addToDocument(table);
    addToDocument(new Phrase("\n", cellFont));
}

From source file:net.bull.javamelody.internal.web.pdf.PdfRequestAndGraphDetailReport.java

License:Apache License

private void writeRequest(CounterRequest childRequest, float executionsByRequest, boolean allChildHitsDisplayed)
        throws IOException, DocumentException {
    final PdfPCell defaultCell = getDefaultCell();
    defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    final Paragraph paragraph = new Paragraph(defaultCell.getLeading() + cellFont.getSize());
    if (executionsByRequest != -1) {
        paragraph.setIndentationLeft(5);
    }//from  w  w  w . j  a  v  a2  s.c  om
    final Counter parentCounter = getCounterByRequestId(childRequest);
    if (parentCounter != null && parentCounter.getIconName() != null) {
        paragraph.add(new Chunk(getSmallImage(parentCounter.getIconName()), 0, -1));
    }
    paragraph.add(new Phrase(childRequest.getName(), cellFont));
    final PdfPCell requestCell = new PdfPCell();
    requestCell.addElement(paragraph);
    requestCell.setGrayFill(defaultCell.getGrayFill());
    requestCell.setPaddingTop(defaultCell.getPaddingTop());
    addCell(requestCell);

    defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    if (executionsByRequest != -1) {
        addCell(nbExecutionsFormat.format(executionsByRequest));
    } else {
        addCell("");
    }
    writeRequestValues(childRequest, allChildHitsDisplayed);
}

From source file:net.bull.javamelody.internal.web.pdf.PdfRequestAndGraphDetailReport.java

License:Apache License

private void writeGraph() throws IOException, DocumentException {
    final JRobin jrobin = collector.getJRobin(graphName);
    if (jrobin != null) {
        final byte[] img = jrobin.graph(range, 960, 400);
        final Image image = Image.getInstance(img);
        image.scalePercent(50);//from www . j  a  v  a 2  s . com

        final PdfPTable table = new PdfPTable(1);
        table.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(0);
        table.addCell("\n");
        table.addCell(image);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(new Phrase(getString("graph_units"), cellFont));
        addToDocument(table);
    } else {
        // just in case request is null and collector.getJRobin(graphName) is null, we must write something in the document
        addToDocument(new Phrase("\n", cellFont));
    }
}

From source file:net.bull.javamelody.internal.web.pdf.PdfRequestAndGraphDetailReport.java

License:Apache License

private void writeSqlRequestExplainPlan() throws DocumentException {
    try {/*w w w  .  j  a v  a2s. c om*/
        final String explainPlan;
        if (collectorServer == null) {
            explainPlan = DatabaseInformations.explainPlanFor(request.getName());
        } else {
            explainPlan = collectorServer.collectSqlRequestExplainPlan(collector.getApplication(),
                    request.getName());
        }
        if (explainPlan != null) {
            final Paragraph paragraph = new Paragraph("", cellFont);
            paragraph.add(new Phrase('\n' + getString("Plan_d_execution") + '\n', boldFont));
            paragraph.add(new Phrase(explainPlan, courierFont));
            addToDocument(paragraph);
        }
    } catch (final Exception e) {
        final Paragraph paragraph = new Paragraph("", cellFont);
        paragraph.add(new Phrase('\n' + getString("Plan_d_execution") + '\n', boldFont));
        paragraph.add(new Phrase(e.toString(), cellFont));
        addToDocument(paragraph);
    }
}

From source file:net.bull.javamelody.internal.web.pdf.PdfRuntimeDependenciesReport.java

License:Apache License

@Override
void toPdf() throws DocumentException {
    final Map<String, Map<String, Integer>> runtimeDependencies = getRuntimeDependencies();
    if (runtimeDependencies.isEmpty()) {
        addToDocument(new Phrase(getString("Aucune_dependance"), normalFont));
        return;//from  w w  w  .ja v a2  s  .c  om
    }
    addToDocument(new Phrase(getString("runtime_dependencies_desc"), normalFont));
    this.standardDeviation = getStandardDeviation(runtimeDependencies);
    this.calledBeans = getCalledBeans(runtimeDependencies);

    writeHeader();

    final List<String> callerBeans = new ArrayList<String>(runtimeDependencies.keySet());
    Collections.sort(callerBeans);
    final PdfPCell defaultCell = getDefaultCell();
    boolean odd = false;
    for (final String callerBean : callerBeans) {
        if (odd) {
            defaultCell.setGrayFill(0.97f);
        } else {
            defaultCell.setGrayFill(1);
        }
        odd = !odd; // NOPMD
        final Map<String, Integer> beanDependencies = runtimeDependencies.get(callerBean);
        writeBeanDependencies(callerBean, beanDependencies);
    }
    addToDocument(currentTable);
}

From source file:net.bull.javamelody.internal.web.pdf.PdfRuntimeDependenciesReport.java

License:Apache License

private void writeHeader() throws DocumentException {
    final List<String> headers = new ArrayList<String>();
    headers.add("Beans");
    headers.addAll(calledBeans);/*from w w w  .  j ava2 s  . c  o m*/
    final int[] relativeWidths = new int[headers.size()];
    Arrays.fill(relativeWidths, 0, headers.size(), 1);
    relativeWidths[0] = 4;

    final PdfPTable table = new PdfPTable(headers.size());
    table.setWidthPercentage(100);
    table.setWidths(relativeWidths);
    table.setHeaderRows(1);
    final PdfPCell defaultCell = table.getDefaultCell();
    defaultCell.setGrayFill(0.9f);
    defaultCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    defaultCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    defaultCell.setPaddingLeft(0);
    defaultCell.setPaddingRight(0);
    for (final String header : headers) {
        table.addCell(new Phrase(header, boldCellFont));
        // pas la premire entte de colonne
        defaultCell.setRotation(90);
    }
    defaultCell.setRotation(0);
    defaultCell.setPaddingLeft(2);
    defaultCell.setPaddingRight(2);
    currentTable = table;
}

From source file:net.bull.javamelody.internal.web.pdf.PdfRuntimeDependenciesReport.java

License:Apache License

private void addCell(String string, Font font) {
    currentTable.addCell(new Phrase(string, font));
}

From source file:net.bull.javamelody.internal.web.pdf.PdfSessionInformationsReport.java

License:Apache License

@Override
void toPdf() throws IOException, DocumentException {

    if (sessionsInformations.isEmpty()) {
        addToDocument(new Phrase(getString("Aucune_session"), cellFont));
        return;/*from ww  w  .  j a va  2s  . c om*/
    }

    writeHeader();
    writeSessions();

    long totalSerializedSize = 0;
    int nbSerializableSessions = 0;
    for (final SessionInformations sessionInformations : sessionsInformations) {
        final int size = sessionInformations.getSerializedSize();
        if (size >= 0) {
            totalSerializedSize += size;
            nbSerializableSessions++;
        }
    }
    final long meanSerializedSize;
    if (nbSerializableSessions > 0) {
        meanSerializedSize = totalSerializedSize / nbSerializableSessions;
    } else {
        meanSerializedSize = -1;
    }
    final Paragraph paragraph = new Paragraph("", cellFont);
    paragraph.add(getFormattedString("nb_sessions", sessionsInformations.size()) + "\n\n"
            + getFormattedString("taille_moyenne_sessions", meanSerializedSize));
    paragraph.setAlignment(Element.ALIGN_RIGHT);
    addToDocument(paragraph);
}

From source file:net.bull.javamelody.internal.web.pdf.PdfSessionInformationsReport.java

License:Apache License

private void writeSession(SessionInformations session) throws IOException, BadElementException {
    final PdfPCell defaultCell = getDefaultCell();
    defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    addCell(session.getId());/*from  ww w. j a  v  a 2  s  . co  m*/
    defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    addCell(durationFormat.format(session.getLastAccess()));
    addCell(durationFormat.format(session.getAge()));
    addCell(expiryFormat.format(session.getExpirationDate()));
    addCell(integerFormat.format(session.getAttributeCount()));
    defaultCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    if (session.isSerializable()) {
        addCell(getString("oui"));
    } else {
        final Phrase non = new Phrase(getString("non"), severeCellFont);
        addCell(non);
    }
    defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    addCell(integerFormat.format(session.getSerializedSize()));
    defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    final String remoteAddr = session.getRemoteAddr();
    if (remoteAddr == null) {
        addCell("");
    } else {
        addCell(remoteAddr);
    }
    defaultCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    writeCountry(session);
    writeBrowserAndOs(session);
    if (displayUser) {
        defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
        final String remoteUser = session.getRemoteUser();
        if (remoteUser == null) {
            addCell("");
        } else {
            addCell(remoteUser);
        }
    }
}