Example usage for com.lowagie.text Chunk Chunk

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

Introduction

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

Prototype

public Chunk(DrawInterface separator, float tabPosition, boolean newline) 

Source Link

Document

Creates a tab Chunk.

Usage

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

License:Apache License

Element createParagraphElement(String paragraphTitle, String iconName) throws DocumentException, IOException {
    final Paragraph paragraph = new Paragraph("", paragraphTitleFont);
    paragraph.setSpacingBefore(5);/*  w w  w  .  j  ava2s. com*/
    paragraph.setSpacingAfter(5);
    if (iconName != null) {
        paragraph.add(new Chunk(getParagraphImage(iconName), 0, -5));
    }
    final Phrase element = new Phrase(' ' + paragraphTitle, paragraphTitleFont);
    element.setLeading(12);
    paragraph.add(element);
    // chapter pour avoir la liste des signets
    final ChapterAutoNumber chapter = new ChapterAutoNumber(paragraph);
    // sans numro de chapitre
    chapter.setNumberDepth(0);
    chapter.setBookmarkOpen(false);
    chapter.setTriggerNewPage(false);
    return chapter;
}

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

License:Apache License

private void writeSummary(JavaInformations javaInformations) throws BadElementException, IOException {
    addCell(getString("Host") + ':');
    currentTable.addCell(new Phrase(javaInformations.getHost(), boldCellFont));
    addCell(getString("memoire_utilisee") + ':');
    final MemoryInformations memoryInformations = javaInformations.getMemoryInformations();
    final long usedMemory = memoryInformations.getUsedMemory();
    final long maxMemory = memoryInformations.getMaxMemory();
    final Phrase memoryPhrase = new Phrase(
            integerFormat.format(usedMemory / 1024 / 1024) + ' ' + getString("Mo") + DIVIDE
                    + integerFormat.format(maxMemory / 1024 / 1024) + ' ' + getString("Mo") + BAR_SEPARATOR,
            cellFont);/*from w ww . j a v  a 2s.  c o  m*/
    final Image memoryImage = Image
            .getInstance(Bar.toBarWithAlert(memoryInformations.getUsedMemoryPercentage()), null);
    memoryImage.scalePercent(50);
    memoryPhrase.add(new Chunk(memoryImage, 0, 0));
    currentTable.addCell(memoryPhrase);
    if (javaInformations.getSessionCount() >= 0) {
        addCell(getString("nb_sessions_http") + ':');
        addCell(integerFormat.format(javaInformations.getSessionCount()));
    }
    addCell(getString("nb_threads_actifs") + "\n(" + getString("Requetes_http_en_cours") + "):");
    addCell(integerFormat.format(javaInformations.getActiveThreadCount()));
    if (!noDatabase) {
        addCell(getString("nb_connexions_actives") + ':');
        addCell(integerFormat.format(javaInformations.getActiveConnectionCount()));
        addCell(getString("nb_connexions_utilisees") + "\n(" + getString("ouvertes") + "):");
        final int usedConnectionCount = javaInformations.getUsedConnectionCount();
        final int maxConnectionCount = javaInformations.getMaxConnectionCount();
        if (maxConnectionCount <= 0) {
            addCell(integerFormat.format(usedConnectionCount));
        } else {
            final Phrase usedConnectionCountPhrase = new Phrase(integerFormat.format(usedConnectionCount)
                    + DIVIDE + integerFormat.format(maxConnectionCount) + BAR_SEPARATOR, cellFont);
            final Image usedConnectionCountImage = Image
                    .getInstance(Bar.toBarWithAlert(javaInformations.getUsedConnectionPercentage()), null);
            usedConnectionCountImage.scalePercent(50);
            usedConnectionCountPhrase.add(new Chunk(usedConnectionCountImage, 0, 0));
            currentTable.addCell(usedConnectionCountPhrase);
        }
    }
    if (javaInformations.getSystemLoadAverage() >= 0) {
        addCell(getString("Charge_systeme") + ':');
        addCell(decimalFormat.format(javaInformations.getSystemLoadAverage()));
    }
    if (javaInformations.getSystemCpuLoad() >= 0) {
        addCell(getString("systemCpuLoad") + ':');
        final Phrase systemCpuLoadPhrase = new Phrase(
                decimalFormat.format(javaInformations.getSystemCpuLoad()) + BAR_SEPARATOR, cellFont);
        final Image systemCpuLoadImage = Image
                .getInstance(Bar.toBarWithAlert(javaInformations.getSystemCpuLoad()), null);
        systemCpuLoadImage.scalePercent(50);
        systemCpuLoadPhrase.add(new Chunk(systemCpuLoadImage, 0, 0));
        currentTable.addCell(systemCpuLoadPhrase);
    }
}

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

License:Apache License

private void writeDetails(JavaInformations javaInformations) throws BadElementException, IOException {
    addCell(getString("OS") + ':');
    final Phrase osPhrase = new Phrase("", cellFont);
    final String osIconName = HtmlJavaInformationsReport.getOSIconName(javaInformations.getOS());
    final String separator = "   ";
    if (osIconName != null) {
        final Image osImage = PdfDocumentFactory.getImage("servers/" + osIconName);
        osImage.scalePercent(40);/*from  w ww .  jav a  2 s. co m*/
        osPhrase.add(new Chunk(osImage, 0, 0));
        osPhrase.add(separator);
    }
    osPhrase.add(javaInformations.getOS() + " (" + javaInformations.getAvailableProcessors() + ' '
            + getString("coeurs") + ')');
    currentTable.addCell(osPhrase);
    addCell(getString("Java") + ':');
    addCell(javaInformations.getJavaVersion());
    addCell(getString("JVM") + ':');
    final Phrase jvmVersionPhrase = new Phrase(javaInformations.getJvmVersion(), cellFont);
    if (javaInformations.getJvmVersion().contains("Client")) {
        jvmVersionPhrase.add(separator);
        final Image alertImage = PdfDocumentFactory.getImage("alert.png");
        alertImage.scalePercent(50);
        jvmVersionPhrase.add(new Chunk(alertImage, 0, -2));
    }
    currentTable.addCell(jvmVersionPhrase);
    addCell(getString("PID") + ':');
    addCell(javaInformations.getPID());
    if (javaInformations.getUnixOpenFileDescriptorCount() >= 0) {
        writeFileDescriptorCounts(javaInformations);
    }
    final String serverInfo = javaInformations.getServerInfo();
    if (serverInfo != null) {
        writeServerInfo(serverInfo);
        addCell(getString("Contexte_webapp") + ':');
        addCell(javaInformations.getContextPath());
    }
    addCell(getString("Demarrage") + ':');
    addCell(I18N.createDateAndTimeFormat().format(javaInformations.getStartDate()));
    addCell(getString("Arguments_JVM") + ':');
    addCell(javaInformations.getJvmArguments());
    if (javaInformations.getSessionCount() >= 0) {
        addCell(getString("httpSessionsMeanAge") + ':');
        addCell(integerFormat.format(javaInformations.getSessionMeanAgeInMinutes()));
    }
    writeTomcatInformations(javaInformations.getTomcatInformationsList());
    addCell(getString("Gestion_memoire") + ':');
    writeMemoryInformations(javaInformations.getMemoryInformations());
    if (javaInformations.getFreeDiskSpaceInTemp() >= 0) {
        // on considre que l'espace libre sur le disque dur est celui sur la partition du rpertoire temporaire
        addCell(getString("Free_disk_space") + ':');
        addCell(integerFormat.format(javaInformations.getFreeDiskSpaceInTemp() / 1024 / 1024) + ' '
                + getString("Mo"));
    }
    writeDatabaseVersionAndDataSourceDetails(javaInformations);
    addCell("");
    addCell("");
}

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

License:Apache License

private void writeServerInfo(String serverInfo) throws BadElementException, IOException {
    addCell(getString("Serveur") + ':');
    final Phrase serverInfoPhrase = new Phrase("", cellFont);
    final String applicationServerIconName = HtmlJavaInformationsReport
            .getApplicationServerIconName(serverInfo);
    if (applicationServerIconName != null) {
        final Image applicationServerImage = PdfDocumentFactory
                .getImage("servers/" + applicationServerIconName);
        applicationServerImage.scalePercent(40);
        serverInfoPhrase.add(new Chunk(applicationServerImage, 0, 0));
        serverInfoPhrase.add("   ");
    }/*from  ww w . j  a v a 2  s.  c  o  m*/
    serverInfoPhrase.add(serverInfo);
    currentTable.addCell(serverInfoPhrase);
}

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

License:Apache License

private void writeFileDescriptorCounts(JavaInformations javaInformations)
        throws BadElementException, IOException {
    final long unixOpenFileDescriptorCount = javaInformations.getUnixOpenFileDescriptorCount();
    final long unixMaxFileDescriptorCount = javaInformations.getUnixMaxFileDescriptorCount();
    addCell(getString("nb_fichiers") + ':');
    final Phrase fileDescriptorCountPhrase = new Phrase(integerFormat.format(unixOpenFileDescriptorCount)
            + DIVIDE + integerFormat.format(unixMaxFileDescriptorCount) + BAR_SEPARATOR, cellFont);
    final Image fileDescriptorCountImage = Image
            .getInstance(Bar.toBarWithAlert(javaInformations.getUnixOpenFileDescriptorPercentage()), null);
    fileDescriptorCountImage.scalePercent(50);
    fileDescriptorCountPhrase.add(new Chunk(fileDescriptorCountImage, 0, 0));
    currentTable.addCell(fileDescriptorCountPhrase);
}

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

License:Apache License

private void writeTomcatInformations(List<TomcatInformations> tomcatInformationsList)
        throws BadElementException, IOException {
    for (final TomcatInformations tomcatInformations : tomcatInformationsList) {
        if (tomcatInformations.getRequestCount() <= 0) {
            continue;
        }//  ww w  . j a  v a  2s .  c om
        addCell("Tomcat " + tomcatInformations.getName() + ':');
        // rq: on n'affiche pas pour l'instant getCurrentThreadCount
        final int currentThreadsBusy = tomcatInformations.getCurrentThreadsBusy();
        final String equal = " = ";
        final Phrase phrase = new Phrase(
                getString("busyThreads") + equal + integerFormat.format(currentThreadsBusy) + DIVIDE
                        + integerFormat.format(tomcatInformations.getMaxThreads()) + BAR_SEPARATOR,
                cellFont);
        final Image threadsImage = Image.getInstance(
                Bar.toBarWithAlert(100d * currentThreadsBusy / tomcatInformations.getMaxThreads()), null);
        threadsImage.scalePercent(50);
        phrase.add(new Chunk(threadsImage, 0, 0));

        phrase.add(new Chunk('\n' + getString("bytesReceived") + equal
                + integerFormat.format(tomcatInformations.getBytesReceived()) + '\n' + getString("bytesSent")
                + equal + integerFormat.format(tomcatInformations.getBytesSent()) + '\n'
                + getString("requestCount") + equal + integerFormat.format(tomcatInformations.getRequestCount())
                + '\n' + getString("errorCount") + equal
                + integerFormat.format(tomcatInformations.getErrorCount()) + '\n' + getString("processingTime")
                + equal + integerFormat.format(tomcatInformations.getProcessingTime()) + '\n'
                + getString("maxProcessingTime") + equal
                + integerFormat.format(tomcatInformations.getMaxTime())));
        currentTable.addCell(phrase);
    }
}

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

License:Apache License

private void writeMemoryInformations(MemoryInformations memoryInformations)
        throws BadElementException, IOException {
    addCell(memoryInformations.getMemoryDetails().replace(" Mo", ' ' + getString("Mo")));
    final long usedPermGen = memoryInformations.getUsedPermGen();
    if (usedPermGen > 0) {
        // perm gen est  0 sous jrockit
        final long maxPermGen = memoryInformations.getMaxPermGen();
        addCell(getString("Memoire_Perm_Gen") + ':');
        if (maxPermGen > 0) {
            final Phrase permGenPhrase = new Phrase(integerFormat.format(usedPermGen / 1024 / 1024) + ' '
                    + getString("Mo") + DIVIDE + integerFormat.format(maxPermGen / 1024 / 1024) + ' '
                    + getString("Mo") + BAR_SEPARATOR, cellFont);
            final Image permGenImage = Image
                    .getInstance(Bar.toBarWithAlert(memoryInformations.getUsedPermGenPercentage()), null);
            permGenImage.scalePercent(50);
            permGenPhrase.add(new Chunk(permGenImage, 0, 0));
            currentTable.addCell(permGenPhrase);
        } else {/*from   w  w  w . ja va  2  s .com*/
            addCell(integerFormat.format(usedPermGen / 1024 / 1024) + ' ' + getString("Mo"));
        }
    }
}

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

License:Apache License

private void writeJndiBinding(JndiBinding jndiBinding) throws BadElementException, IOException {
    final PdfPCell defaultCell = getDefaultCell();
    defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    final String name = jndiBinding.getName();
    final String className = jndiBinding.getClassName();
    final String contextPath = jndiBinding.getContextPath();
    final String value = jndiBinding.getValue();
    if (contextPath != null) {
        final Image image = getFolderImage();
        final Phrase phrase = new Phrase("", cellFont);
        phrase.add(new Chunk(image, 0, 0));
        phrase.add(" ");
        phrase.add(name);//from  w  ww  . j av  a2  s .com
        addCell(phrase);
    } else {
        addCell(name);
    }
    addCell(className != null ? className : "");
    addCell(value != null ? value : "");
}

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

License:Apache License

private void writeJobTimes(JobInformations jobInformations, CounterRequest counterRequest)
        throws BadElementException, IOException {
    final long elapsedTime = jobInformations.getElapsedTime();
    if (elapsedTime >= 0) {
        final Phrase elapsedTimePhrase = new Phrase(durationFormat.format(elapsedTime), cellFont);
        final Image memoryImage = Image.getInstance(Bar.toBar(100d * elapsedTime / counterRequest.getMean()),
                null);//w  w w.  j  ava2s.c  o m
        memoryImage.scalePercent(47);
        elapsedTimePhrase.add("\n");
        elapsedTimePhrase.add(new Chunk(memoryImage, 0, 0));
        addCell(elapsedTimePhrase);
    } else {
        addCell("");
    }
    if (jobInformations.getPreviousFireTime() != null) {
        addCell(fireTimeFormat.format(jobInformations.getPreviousFireTime()));
    } else {
        addCell("");
    }
    if (jobInformations.getNextFireTime() != null) {
        addCell(fireTimeFormat.format(jobInformations.getNextFireTime()));
    } else {
        addCell("");
    }
    // on n'affiche pas la priode si >= 1 jour car ce formateur ne saurait pas l'afficher
    if (jobInformations.getRepeatInterval() > 0 && jobInformations.getRepeatInterval() < ONE_DAY_MILLIS) {
        addCell(durationFormat.format(new Date(jobInformations.getRepeatInterval())));
    } else if (jobInformations.getCronExpression() != null) {
        addCell(jobInformations.getCronExpression());
    } else {
        addCell("");
    }
}

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 a 2s.  co m*/
    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);
}