List of usage examples for com.lowagie.text Paragraph add
public boolean add(Object o)
Object
to the Paragraph
. 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();// w ww. j a v a 2s .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 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 www.j a v a2s . 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); }
From source file:net.bull.javamelody.internal.web.pdf.PdfRequestAndGraphDetailReport.java
License:Apache License
private void writeSqlRequestExplainPlan() throws DocumentException { try {//ww w.j ava 2s . co m 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.PdfSessionInformationsReport.java
License:Apache License
@Override void toPdf() throws IOException, DocumentException { if (sessionsInformations.isEmpty()) { addToDocument(new Phrase(getString("Aucune_session"), cellFont)); return;/*from w w w.jav a 2 s . c o m*/ } 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.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 {/*from w w w . ja v a 2 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 writeGraphs(Collection<JRobin> jrobins, Map<String, byte[]> mySmallGraphs) throws IOException, DocumentException { if (collector.isStopped()) { // pas de graphs, ils seraient en erreur sans timer // mais un message d'avertissement la place final String message = getString("collect_server_misusage"); final Paragraph jrobinParagraph = new Paragraph(message, PdfFonts.BOLD.getFont()); jrobinParagraph.setAlignment(Element.ALIGN_CENTER); addToDocument(jrobinParagraph);/*from w w w . ja v a 2s . com*/ return; } final Paragraph jrobinParagraph = new Paragraph("", FontFactory.getFont(FontFactory.HELVETICA, 9f, Font.NORMAL)); jrobinParagraph.setAlignment(Element.ALIGN_CENTER); jrobinParagraph.add(new Phrase("\n\n\n\n")); int i = 0; if (mySmallGraphs != null) { // si les graphiques ont t prinitialiss (en Swing) alors on les utilise for (final byte[] imageData : mySmallGraphs.values()) { if (i % 3 == 0 && i != 0) { // un retour aprs httpSessions et avant activeThreads pour l'alignement jrobinParagraph.add(new Phrase("\n\n\n\n\n")); } final Image image = Image.getInstance(imageData); image.scalePercent(50); jrobinParagraph.add(new Phrase(new Chunk(image, 0, 0))); jrobinParagraph.add(new Phrase(" ")); i++; } } else { if (jrobins.isEmpty()) { return; } for (final JRobin jrobin : jrobins) { if (i % 3 == 0 && i != 0) { // un retour aprs httpSessions et avant activeThreads pour l'alignement jrobinParagraph.add(new Phrase("\n\n\n\n\n")); } final Image image = Image.getInstance(jrobin.graph(range, SMALL_GRAPH_WIDTH, SMALL_GRAPH_HEIGHT)); image.scalePercent(50); jrobinParagraph.add(new Phrase(new Chunk(image, 0, 0))); jrobinParagraph.add(new Phrase(" ")); i++; } } jrobinParagraph.add(new Phrase("\n")); addToDocument(jrobinParagraph); }
From source file:net.bull.javamelody.PdfRequestAndGraphDetailReport.java
License:Apache License
@Override void toPdf() throws DocumentException, IOException { if (request != null) { writeHeader();/* w ww. ja va 2 s . 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.swing.print.MRtfWriter.java
License:Apache License
/** * We create a writer that listens to the document and directs a RTF-stream to out * * @param table//from w ww . j a v a 2s. co m * MBasicTable * @param document * Document * @param out * OutputStream * @return DocWriter */ @Override protected DocWriter createWriter(final MBasicTable table, final Document document, final OutputStream out) { final RtfWriter2 writer = RtfWriter2.getInstance(document, out); // title final String title = buildTitle(table); if (title != null) { final HeaderFooter header = new RtfHeaderFooter(new Paragraph(title)); header.setAlignment(Element.ALIGN_LEFT); header.setBorder(Rectangle.NO_BORDER); document.setHeader(header); document.addTitle(title); } // advanced page numbers : x/y final Paragraph footerParagraph = new Paragraph(); final Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL); footerParagraph.add(new RtfPageNumber(font)); footerParagraph.add(new Phrase(" / ", font)); footerParagraph.add(new RtfTotalPageNumber(font)); footerParagraph.setAlignment(Element.ALIGN_CENTER); final HeaderFooter footer = new RtfHeaderFooter(footerParagraph); footer.setBorder(Rectangle.TOP); document.setFooter(footer); return writer; }
From source file:net.nosleep.superanalyzer.Share.java
License:Open Source License
public static void saveAnalysisPdf(JFrame window, Analysis analysis, JProgressBar progressBar) { File pdfFile = askForFile(window, "pdf"); if (pdfFile == null) return;/*from ww w .j ava2 s . co m*/ Misc.printMemoryInfo("pdfstart"); DateFormat dateFormat = new SimpleDateFormat().getDateInstance(DateFormat.SHORT); String infoString = Misc.getString("CREATED_ON") + " " + dateFormat.format(Calendar.getInstance().getTime()); int viewCount = 15; int viewsDone = 0; progressBar.setMinimum(0); progressBar.setMaximum(viewCount); Dimension d = new Dimension(500, 400); try { String tmpPath = System.getProperty("java.io.tmpdir") + "/image.png"; // create the pdf document object Document document = new Document(); // create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.getInstance(document, new FileOutputStream(pdfFile)); // we open the document document.open(); Font titleFont = FontFactory.getFont(FontFactory.HELVETICA, 18, Font.NORMAL, new Color(0x00, 0x00, 0x00)); Paragraph p = new Paragraph(Misc.getString("MY_MUSIC_COLLECTION"), titleFont); p.setSpacingAfter(4); document.add(p); Font subtitleFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, new Color(0x88, 0x88, 0x88)); p = new Paragraph("The Super Analyzer by Nosleep Software", subtitleFont); p.setSpacingAfter(-2); document.add(p); p = new Paragraph(infoString, subtitleFont); p.setSpacingAfter(30); document.add(p); PdfPTable table = new PdfPTable(2); table.getDefaultCell().setBorder(PdfPCell.NO_BORDER); table.setTotalWidth(500f); table.setLockedWidth(true); Font statNameFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, new Color(0x66, 0x66, 0x66)); Font statValueFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, new Color(0x00, 0x00, 0x00)); Vector<StringTriple> statPairs = SummaryView.createStatPairs(analysis); Paragraph statParagraph = new Paragraph(); Font summaryTitleFont = FontFactory.getFont(FontFactory.HELVETICA, 11, Font.BOLD, new Color(0x00, 0x00, 0x00)); Paragraph titleParagraph = new Paragraph(Misc.getString("SUMMARY"), summaryTitleFont); statParagraph.add(titleParagraph); Paragraph spaceParagraph = new Paragraph("", statNameFont); statParagraph.add(spaceParagraph); for (int i = 0; i < statPairs.size(); i++) { Paragraph statLine = new Paragraph(); StringTriple triple = statPairs.elementAt(i); Phrase namePhrase = new Phrase(triple.Name + ": ", statNameFont); Phrase valuePhrase = new Phrase(triple.Value, statValueFont); statLine.add(namePhrase); statLine.add(valuePhrase); statParagraph.add(statLine); } table.addCell(statParagraph); viewsDone++; progressBar.setValue(viewsDone); GenreView genreView = new GenreView(analysis); genreView.saveImage(new File(tmpPath), d); genreView = null; Image img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); LikesView likesView = new LikesView(analysis); likesView.saveImage(new File(tmpPath), d); likesView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); YearView yearView = new YearView(analysis); yearView.saveImage(new File(tmpPath), d); yearView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); RatingView ratingView = new RatingView(analysis); ratingView.saveImage(new File(tmpPath), d); ratingView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); TimeView timeView = new TimeView(analysis); timeView.saveImage(new File(tmpPath), d); timeView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); QualityView qualityView = new QualityView(analysis); qualityView.saveImage(new File(tmpPath), d); qualityView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); PlayCountView playCountView = new PlayCountView(analysis); playCountView.saveImage(new File(tmpPath), d); playCountView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); MostPlayedAAView mostPlayedAAView = new MostPlayedAAView(analysis); mostPlayedAAView.saveImage(new File(tmpPath), d); img = Image.getInstance(tmpPath); table.addCell(img); mostPlayedAAView.saveImageExtra(new File(tmpPath), d); img = Image.getInstance(tmpPath); table.addCell(img); mostPlayedAAView = null; viewsDone++; progressBar.setValue(viewsDone); MostPlayedDGView mostPlayedDGView = new MostPlayedDGView(analysis); mostPlayedDGView.saveImage(new File(tmpPath), d); img = Image.getInstance(tmpPath); table.addCell(img); mostPlayedDGView.saveImageExtra(new File(tmpPath), d); img = Image.getInstance(tmpPath); table.addCell(img); mostPlayedDGView = null; viewsDone++; progressBar.setValue(viewsDone); EncodingKindView encodingKindView = new EncodingKindView(analysis); encodingKindView.saveImage(new File(tmpPath), d); encodingKindView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); GrowthView growthView = new GrowthView(analysis); growthView.saveImage(new File(tmpPath), d); growthView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); WordView wordView = new WordView(analysis); wordView.saveImage(new File(tmpPath), d); wordView = null; img = Image.getInstance(tmpPath); table.addCell(img); table.addCell(""); viewsDone++; progressBar.setValue(viewsDone); Misc.printMemoryInfo("pdfend"); document.add(table); // step 5: we close the document document.close(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } }
From source file:net.nosleep.superanalyzer.Share.java
License:Open Source License
public static void saveListOfAlbumsAsPdf(JFrame window, Analysis analysis, JProgressBar progressBar) { File file = askForFile(window, "pdf"); if (file == null) return;// w w w. j av a 2s. c o m Hashtable albums = analysis.getHash(Analysis.KIND_ALBUM); DecimalFormat timeFormat = new DecimalFormat("0.0"); StringPair list[] = new StringPair[albums.size()]; Enumeration keys = albums.keys(); Integer index = 0; String regex = Album.SeparatorRegEx; while (keys.hasMoreElements()) { String albumartist = (String) keys.nextElement(); String[] parts = albumartist.split(regex); StringPair pair = new StringPair(parts[1], parts[0]); list[index] = pair; index++; } Arrays.sort(list, new StringPairComparator()); int done = 0; progressBar.setMinimum(0); progressBar.setMaximum(list.length); String infoString = NumberFormat.getInstance().format(list.length) + " "; if (list.length == 1) infoString += Misc.getString("ALBUM") + ", "; else infoString += Misc.getString("ALBUMS") + ", "; DateFormat dateFormat = new SimpleDateFormat().getDateInstance(DateFormat.SHORT); infoString += "created on " + dateFormat.format(Calendar.getInstance().getTime()); try { String tmpPath = System.getProperty("java.io.tmpdir") + "/image.png"; // create the pdf document object Document document = new Document(); // create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.getInstance(document, new FileOutputStream(file)); // we open the document document.open(); Font titleFont = FontFactory.getFont(FontFactory.HELVETICA, 18, Font.NORMAL, new Color(0x00, 0x00, 0x00)); Paragraph p = new Paragraph(Misc.getString("MY_ALBUMS"), titleFont); p.setSpacingAfter(4); document.add(p); Font subtitleFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, new Color(0x88, 0x88, 0x88)); p = new Paragraph("The Super Analyzer by Nosleep Software", subtitleFont); p.setSpacingAfter(-2); document.add(p); p = new Paragraph(infoString, subtitleFont); p.setSpacingAfter(30); document.add(p); FontSelector albumSelector = new FontSelector(); Color albumColor = new Color(0x55, 0x55, 0x55); albumSelector.addFont(FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, albumColor)); Font albumAsianFont = FontFactory.getFont("MSung-Light", "UniCNS-UCS2-H", BaseFont.NOT_EMBEDDED); albumAsianFont.setSize(8); albumAsianFont.setColor(albumColor); albumSelector.addFont(albumAsianFont); FontSelector artistSelector = new FontSelector(); Color artistColor = new Color(0x77, 0x77, 0x77); artistSelector.addFont(FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, artistColor)); Font artistAsianFont = FontFactory.getFont("MSung-Light", "UniCNS-UCS2-H", BaseFont.NOT_EMBEDDED); artistAsianFont.setSize(8); artistAsianFont.setColor(artistColor); artistSelector.addFont(artistAsianFont); for (index = 0; index < list.length; index++) { p = new Paragraph(); p.setLeading(9); // separate the string into the album and artist parts Phrase phrase = albumSelector.process(list[index].Value); p.add(phrase); phrase = artistSelector.process(" " + Misc.getString("BY") + " " + list[index].Name); p.add(phrase); document.add(p); done++; progressBar.setValue(done); } // step 5: we close the document document.close(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } }