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.PdfThreadInformationsReport.java

License:Apache License

void writeIntro(JavaInformations javaInformations) throws DocumentException {
    final Font boldFont = PdfFonts.BOLD.getFont();
    final Font normalFont = PdfFonts.NORMAL.getFont();
    addToDocument(new Phrase(getFormattedString("Threads_sur", javaInformations.getHost()) + ": ", boldFont));
    addToDocument(new Phrase(
            getFormattedString("thread_count", javaInformations.getThreadCount(),
                    javaInformations.getPeakThreadCount(), javaInformations.getTotalStartedThreadCount()),
            normalFont));//from w w  w . java2s  .  c  o  m
}

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

License:Apache License

void writeDeadlocks() throws DocumentException {
    final List<ThreadInformations> deadlockedThreads = new ArrayList<ThreadInformations>();
    for (final ThreadInformations thread : threadInformationsList) {
        if (thread.isDeadlocked()) {
            deadlockedThreads.add(thread);
        }//w w w  .  j a  va 2  s  .co  m
    }
    if (!deadlockedThreads.isEmpty()) {
        final StringBuilder sb = new StringBuilder();
        sb.append('\n');
        sb.append(getString("Threads_deadlocks"));
        String separator = " ";
        for (final ThreadInformations thread : deadlockedThreads) {
            sb.append(separator);
            sb.append(thread.getName());
            separator = ", ";
        }
        sb.append('\n');
        addToDocument(new Phrase(sb.toString(), PdfFonts.SEVERE_CELL.getFont()));
    }
}

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

License:Apache License

private void writeThreadInformations(ThreadInformations threadInformations)
        throws DocumentException, IOException {
    final PdfPCell defaultCell = getDefaultCell();
    defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    addCell(threadInformations.getName());
    defaultCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    if (threadInformations.isDaemon()) {
        addCell(getString("oui"));
    } else {/*w ww .j  av a2 s .c o m*/
        addCell(getString("non"));
    }
    defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    addCell(integerFormat.format(threadInformations.getPriority()));
    defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    final PdfPCell cell = new PdfPCell();
    final Paragraph paragraph = new Paragraph(getDefaultCell().getLeading() + cellFont.getSize());
    paragraph.add(new Chunk(
            getImage("bullets/" + HtmlThreadInformationsReport.getStateIcon(threadInformations)), 0, -1));
    paragraph.add(new Phrase(String.valueOf(threadInformations.getState()), cellFont));
    cell.addElement(paragraph);
    addCell(cell);
    if (stackTraceEnabled) {
        addCell(threadInformations.getExecutedMethod());
    }
    if (cpuTimeEnabled) {
        defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        addCell(integerFormat.format(threadInformations.getCpuTimeMillis()));
        addCell(integerFormat.format(threadInformations.getUserTimeMillis()));
    }
}

From source file:net.bull.javamelody.PdfCoreReport.java

License:Apache License

private void writeThreads(boolean includeDetails) throws DocumentException, IOException {
    String eol = "";
    for (final JavaInformations javaInformations : javaInformationsList) {
        addToDocument(new Phrase(eol + getFormattedString("Threads_sur", javaInformations.getHost()) + ": ",
                boldFont));//  w  w  w  .java2  s . c  om
        addToDocument(new Phrase(
                getFormattedString("thread_count", javaInformations.getThreadCount(),
                        javaInformations.getPeakThreadCount(), javaInformations.getTotalStartedThreadCount()),
                normalFont));

        final PdfThreadInformationsReport pdfThreadInformationsReport = new PdfThreadInformationsReport(
                javaInformations.getThreadInformationsList(), javaInformations.isStackTraceEnabled(),
                pdfDocumentFactory, getDocument());
        pdfThreadInformationsReport.writeDeadlocks();

        if (includeDetails) {
            pdfThreadInformationsReport.toPdf();
        }
        eol = "\n";
    }
}

From source file:net.bull.javamelody.PdfCounterReport.java

License:Apache License

private void writeRequest(CounterRequest request) throws BadElementException, IOException {
    getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    final String name = request.getName();
    if (name.length() > 1000) {
        // si la requte fait plus de 1000 caractres, on la coupe pour y voir quelque chose
        addCell(name.substring(0, 1000) + "...");
    } else {/*from w w w. j a va  2 s.c  o m*/
        addCell(name);
    }
    if (includeGraph) {
        writeRequestGraph(request);
    }
    getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
    final CounterRequest globalRequest = counterRequestAggregation.getGlobalRequest();
    if (counterRequestAggregation.isTimesDisplayed()) {
        addPercentageCell(request.getDurationsSum(), globalRequest.getDurationsSum());
        addCell(integerFormat.format(request.getHits()));
        final int mean = request.getMean();
        addCell(new Phrase(integerFormat.format(mean), getSlaFont(mean)));
        addCell(integerFormat.format(request.getMaximum()));
        addCell(integerFormat.format(request.getStandardDeviation()));
    } else {
        addCell(integerFormat.format(request.getHits()));
    }
    if (counterRequestAggregation.isCpuTimesDisplayed()) {
        addPercentageCell(request.getCpuTimeSum(), globalRequest.getCpuTimeSum());
        final int cpuTimeMean = request.getCpuTimeMean();
        addCell(new Phrase(integerFormat.format(cpuTimeMean), getSlaFont(cpuTimeMean)));
    }
    if (!isErrorAndNotJobCounter()) {
        addCell(systemErrorFormat.format(request.getSystemErrorPercentage()));
    }
    if (counterRequestAggregation.isResponseSizeDisplayed()) {
        addCell(integerFormat.format(request.getResponseSizeMean() / 1024));
    }
    if (counterRequestAggregation.isChildHitsDisplayed()) {
        addCell(integerFormat.format(request.getChildHitsMean()));
        addCell(integerFormat.format(request.getChildDurationsMean()));
    }
}

From source file:net.bull.javamelody.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 .jav  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()));
    }
}

From source file:net.bull.javamelody.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.  ja va  2s.  com
        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);
    if (javaInformations.isDependenciesEnabled()) {
        addCell(getString("Dependencies") + ':');
        addCell(getFormattedString("nb_dependencies", javaInformations.getDependenciesList().size()) + " ;\n"
                + javaInformations.getDependencies());
    }
    addCell("");
    addCell("");
}

From source file:net.bull.javamelody.PdfOtherReport.java

License:Apache License

void writeAllCurrentRequestsAsPart(Map<JavaInformations, List<CounterRequestContext>> currentRequests,
        Collector collector, List<Counter> counters, long timeOfSnapshot) throws IOException {
    try {// w  ww  .ja v a2s . c om
        document.open();

        // on remplace les parentCounters
        final List<CounterRequestContext> allCurrentRequests = new ArrayList<CounterRequestContext>();
        for (final List<CounterRequestContext> rootCurrentContexts : currentRequests.values()) {
            allCurrentRequests.addAll(rootCurrentContexts);
        }
        CounterRequestContext.replaceParentCounters(allCurrentRequests, counters);
        final List<PdfCounterReport> pdfCounterReports = new ArrayList<PdfCounterReport>();
        // ce range n'a pas d'importance pour ce pdf
        final Range range = Period.TOUT.getRange();
        for (final Counter counter : counters) {
            final PdfCounterReport pdfCounterReport = new PdfCounterReport(collector, counter, range, false,
                    document);
            pdfCounterReports.add(pdfCounterReport);
        }
        final Font normalFont = PdfFonts.NORMAL.getFont();
        for (final Map.Entry<JavaInformations, List<CounterRequestContext>> entry : currentRequests
                .entrySet()) {
            final JavaInformations javaInformations = entry.getKey();
            final List<CounterRequestContext> rootCurrentContexts = entry.getValue();
            addParagraph(getString("Requetes_en_cours"), "hourglass.png");
            if (rootCurrentContexts.isEmpty()) {
                addToDocument(new Phrase(getString("Aucune_requete_en_cours"), normalFont));
            } else {
                final PdfCounterRequestContextReport pdfCounterRequestContextReport = new PdfCounterRequestContextReport(
                        rootCurrentContexts, pdfCounterReports, javaInformations.getThreadInformationsList(),
                        javaInformations.isStackTraceEnabled(), pdfDocumentFactory, document);
                pdfCounterRequestContextReport.setTimeOfSnapshot(timeOfSnapshot);
                pdfCounterRequestContextReport.writeContextDetails();
            }
        }
    } catch (final DocumentException e) {
        throw createIOException(e);
    }
    document.close();
}

From source file:net.bull.javamelody.PdfRequestAndGraphDetailReport.java

License:Apache License

@Override
void toPdf() throws DocumentException, IOException {
    if (request != null) {
        writeHeader();//from ww  w.  j  av a 2s . c  o  m

        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.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 w w w .ja v a2s.  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);
    if (displayUser) {
        defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
        final String remoteUser = session.getRemoteUser();
        if (remoteUser == null) {
            addCell("");
        } else {
            addCell(remoteUser);
        }
    }
}