List of usage examples for com.lowagie.text Anchor Anchor
public Anchor(Phrase phrase)
Anchor
with a certain Phrase
. From source file:org.eclipse.osee.ats.rest.internal.build.report.table.BuildTraceTable.java
License:Open Source License
private Anchor setHyperlink(String element, String link) { Anchor anchor = new Anchor(element); anchor.setReference(link); return anchor; }
From source file:org.eclipse.osee.ats.rest.internal.build.report.table.UrlListTable.java
License:Open Source License
public void addUrl(Pair<String, String>... urls) { List<Anchor> toAdd = new LinkedList<Anchor>(); for (Pair<String, String> url : urls) { Anchor anchor = new Anchor(url.getFirst()); anchor.setReference(url.getSecond()); // Save to a sorted set until complete then add to table in 'close()' toAdd.add(anchor);// ww w . j a v a 2 s. c o m } sortedList.add(toAdd); }
From source file:org.revager.export.ProtocolPDFExporter.java
License:Open Source License
/** * Write the title page of the protocol. * //w ww .j av a 2s. co m * @param meetings * the meetings * @param attachProdExtRefs * true, if the external reference of the product should be part * of the protocol * * @throws ExportException * If an error occurs while writing the title page */ protected void writeTitlePage(List<Meeting> meetings, boolean attachProdExtRefs) throws ExportException { try { Font plainFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font plainFontSmall = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 8); Font boldFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 11); Font italicFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font italicFontSmall = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 8); Font boldItalicFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 11); Font boldItalicFontSmall = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 8); Font protocolFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 20); Font reviewFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 15); Font meetingFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 13); /* * Title of the protocol */ PdfPTable tableTitlePage = new PdfPTable(new float[] { 0.6f, 0.4f }); tableTitlePage.setWidthPercentage(100); tableTitlePage.setSplitRows(false); tableTitlePage.getDefaultCell().setBorder(0); tableTitlePage.getDefaultCell().setPadding(0); String protocolTitle = translate("Findings List of the Review"); if (meetings.size() == 1) { protocolTitle = translate("Findings List of the Review Meeting"); } PdfPCell cellProtocol = new PdfPCell(new Phrase(protocolTitle, protocolFontTitle)); cellProtocol.setHorizontalAlignment(Element.ALIGN_CENTER); cellProtocol.setColspan(2); cellProtocol.setBorderWidth(0); cellProtocol.setPaddingTop(PDFTools.cmToPt(0.4f)); cellProtocol.setPaddingBottom(PDFTools.cmToPt(0.2f)); tableTitlePage.addCell(cellProtocol); /* * Name of the review */ PdfPCell cellRevName = new PdfPCell( new Phrase(Application.getInstance().getReviewMgmt().getReviewName(), reviewFontTitle)); cellRevName.setHorizontalAlignment(Element.ALIGN_CENTER); cellRevName.setColspan(2); cellRevName.setBorderWidth(0); cellRevName.setPaddingBottom(PDFTools.cmToPt(1.6f)); tableTitlePage.addCell(cellRevName); /* * Review meeting date and location */ if (meetings.size() == 1) { sdfDate.setTimeZone(meetings.get(0).getProtocol().getDate().getTimeZone()); sdfTime.setTimeZone(meetings.get(0).getProtocol().getDate().getTimeZone()); String meetingDate = sdfDate.format(meetings.get(0).getProtocol().getDate().getTime()); String meetingTime = sdfTime.format(meetings.get(0).getProtocol().getStart().getTime()) + " - " + sdfTime.format(meetings.get(0).getProtocol().getEnd().getTime()) + " [" + meetings.get(0).getProtocol().getEnd().getTimeZone().getDisplayName() + "]"; Phrase phraseMeeting = new Phrase(meetingDate + " (" + meetingTime + ")", meetingFontTitle); PdfPCell cellMeeting = new PdfPCell(phraseMeeting); cellMeeting.setColspan(2); cellMeeting.setHorizontalAlignment(Element.ALIGN_CENTER); cellMeeting.setPadding(0); cellMeeting.setBorderWidth(0); tableTitlePage.addCell(cellMeeting); String location = meetings.get(0).getProtocol().getLocation(); if (location.trim().equals("")) { location = "--"; } cellMeeting = new PdfPCell(new Phrase(translate("Location") + ": " + location, meetingFontTitle)); cellMeeting.setColspan(2); cellMeeting.setHorizontalAlignment(Element.ALIGN_CENTER); cellMeeting.setPadding(0); cellMeeting.setBorderWidth(0); cellMeeting.setPaddingTop(PDFTools.cmToPt(0.15f)); cellMeeting.setPaddingBottom(PDFTools.cmToPt(1.9f)); tableTitlePage.addCell(cellMeeting); } /* * Review description and comments */ PdfPCell cellRevDesc = new PdfPCell(new Phrase(translate("Review Description:"), boldItalicFont)); cellRevDesc.setBorderWidth(0); cellRevDesc.setPadding(padding); tableTitlePage.addCell(cellRevDesc); cellRevDesc = new PdfPCell(new Phrase(translate("Review Comments"), boldFont)); cellRevDesc.setBorderWidth(0); cellRevDesc.setPadding(padding); cellRevDesc.setBackgroundColor(cellBackground); tableTitlePage.addCell(cellRevDesc); String revDesc = Application.getInstance().getReviewMgmt().getReviewDescription(); if (revDesc.trim().equals("")) { revDesc = "--"; } Phrase phrDesc = new Phrase(revDesc, plainFont); phrDesc.setLeading(leading); cellRevDesc = new PdfPCell(); cellRevDesc.addElement(phrDesc); cellRevDesc.setBorderWidth(0); cellRevDesc.setPadding(padding); cellRevDesc.setPaddingBottom(padding * 1.8f); tableTitlePage.addCell(cellRevDesc); String revComm = Application.getInstance().getReviewMgmt().getReviewComments(); if (revComm.trim().equals("")) { revComm = "--"; } Phrase phrComm = new Phrase(revComm, italicFont); phrComm.setLeading(leading); cellRevDesc = new PdfPCell(); cellRevDesc.addElement(phrComm); cellRevDesc.setBorderWidth(0); cellRevDesc.setPadding(padding); cellRevDesc.setPaddingBottom(padding * 1.8f); cellRevDesc.setBackgroundColor(cellBackground); tableTitlePage.addCell(cellRevDesc); tableTitlePage.addCell(createVerticalStrut(PDFTools.cmToPt(1.0f), 2)); /* * Product title */ PdfPTable tableProduct = new PdfPTable(new float[] { 0.07f, 0.93f }); tableProduct.setWidthPercentage(100); tableProduct.setSplitRows(false); tableProduct.getDefaultCell().setBorderWidth(0); tableProduct.getDefaultCell().setPadding(0); PdfPCell cellProdTitle = new PdfPCell(new Phrase(translate("Reviewed Product:"), boldItalicFont)); cellProdTitle.setColspan(2); cellProdTitle.setPadding(padding); cellProdTitle.setBorder(0); tableProduct.addCell(cellProdTitle); /* * List point used for lists */ Phrase phraseListPoint = new Phrase("", boldFont); phraseListPoint.setLeading(leading); PdfPCell cellListPoint = new PdfPCell(); cellListPoint.addElement(phraseListPoint); cellListPoint.setBorderWidth(0); cellListPoint.setPadding(padding); cellListPoint.setPaddingLeft(padding * 2); cellListPoint.setPaddingBottom(0); /* * Write name and version of the reviewed product */ String prodName = Data.getInstance().getResiData().getReview().getProduct().getName(); if (prodName.trim().equals("")) { prodName = "--"; } Phrase phrName = new Phrase(translate("Product Name") + ": " + prodName, plainFont); phrName.setLeading(leading); PdfPCell cellName = new PdfPCell(); cellName.addElement(phrName); cellName.setBorderWidth(0); cellName.setPadding(padding); cellName.setPaddingBottom(0); tableProduct.addCell(cellListPoint); tableProduct.addCell(cellName); String prodVersion = Data.getInstance().getResiData().getReview().getProduct().getVersion(); if (prodVersion.trim().equals("")) { prodVersion = "--"; } Phrase phrVersion = new Phrase(translate("Product Version") + ": " + prodVersion, plainFont); phrVersion.setLeading(leading); PdfPCell cellVersion = new PdfPCell(); cellVersion.addElement(phrVersion); cellVersion.setBorderWidth(0); cellVersion.setPadding(padding); cellVersion.setPaddingBottom(0); tableProduct.addCell(cellListPoint); tableProduct.addCell(cellVersion); if (Application.getInstance().getReviewMgmt().getNumberOfProdRefs() > 0) { /* * Table of product references */ PdfPCell cellRefTitle = new PdfPCell(new Phrase(translate("Product References:"), boldItalicFont)); cellRefTitle.setBorderWidth(0); cellRefTitle.setPadding(padding); cellRefTitle.setPaddingTop(padding * 4); cellRefTitle.setColspan(2); tableProduct.addCell(cellRefTitle); /* * Textual references */ for (String ref : Application.getInstance().getReviewMgmt().getProductReferences()) { Phrase phraseRef = new Phrase(ref, plainFont); phraseRef.setLeading(leading); PdfPCell cellRef = new PdfPCell(); cellRef.addElement(phraseRef); cellRef.setBorderWidth(0); cellRef.setPadding(padding); cellRef.setPaddingBottom(0); tableProduct.addCell(cellListPoint); tableProduct.addCell(cellRef); } /* * External file references */ for (File ref : Application.getInstance().getReviewMgmt().getExtProdReferences()) { Phrase phraseRef = new Phrase(); phraseRef.add(new Chunk(ref.getName(), plainFont)); phraseRef.add(new Chunk(" (" + translate("File Attachment") + ")", italicFont)); phraseRef.setFont(plainFont); phraseRef.setLeading(leading); PdfPCell cellRef = new PdfPCell(); cellRef.addElement(phraseRef); cellRef.setBorderWidth(0); cellRef.setPadding(padding); cellRef.setPaddingBottom(0); tableProduct.addCell(cellListPoint); if (attachProdExtRefs) { cellRef.setCellEvent(new PDFCellEventExtRef(pdfWriter, ref)); } tableProduct.addCell(cellRef); } } /* * Add the product table to the base table */ PdfPCell cellProduct = new PdfPCell(tableProduct); cellProduct.setBorder(0); cellProduct.setPadding(0); tableTitlePage.addCell(cellProduct); /* * List the meetings of this review */ PdfPCell cellInfos = new PdfPCell(); cellInfos.setBorder(0); cellInfos.setPadding(0); /* * meeting list title or meeting info title */ PdfPTable tableInfos = new PdfPTable(new float[] { 0.09f, 0.91f }); tableInfos.setWidthPercentage(100); tableInfos.setSplitRows(false); tableInfos.getDefaultCell().setBorderWidth(0); tableInfos.getDefaultCell().setPadding(0); String title = translate("Meeting Information:"); if (meetings.size() > 1) { title = translate("Findings Lists of the Review Meetings:"); } PdfPCell cellInfosTitle = new PdfPCell(new Phrase(title, boldFont)); cellInfosTitle.setColspan(2); cellInfosTitle.setPadding(padding); cellInfosTitle.setBorder(0); tableInfos.addCell(cellInfosTitle); if (meetings.size() > 1) { /* * list the meetings of this review (for review protocols) */ for (Meeting m : meetings) { Protocol protocol = m.getProtocol(); if (protocol != null) { String meetingDate = sdfDate.format(protocol.getDate().getTime()); String meetingTime = sdfTime.format(protocol.getStart().getTime()) + " - " + sdfTime.format(protocol.getEnd().getTime()) + " [" + protocol.getEnd().getTimeZone().getDisplayName() + "]"; String protLoc = protocol.getLocation(); if (protLoc.trim().equals("")) { protLoc = "--"; } Phrase phraseMeet = new Phrase( translate("Date") + ": " + meetingDate + "\n" + translate("Time") + ": " + meetingTime + "\n" + translate("Location") + ": " + protLoc, italicFont); Paragraph paraMeet = new Paragraph(); paraMeet.setLeading(leading); Anchor anchor = new Anchor(phraseMeet); anchor.setReference("#" + Long.toString( protocol.getDate().getTimeInMillis() + protocol.getStart().getTimeInMillis())); paraMeet.add(anchor); PdfPCell cellMeet = new PdfPCell(); cellMeet.addElement(paraMeet); cellMeet.setBorderWidth(0); cellMeet.setPadding(padding); tableInfos.addCell(cellListPoint); tableInfos.addCell(cellMeet); } } } else { Protocol prot = meetings.get(0).getProtocol(); Duration meetDur = DatatypeFactory.newInstance() .newDuration(prot.getEnd().getTimeInMillis() - prot.getStart().getTimeInMillis()); Phrase phraseMeetInfo = new Phrase( translate("Duration of the meeting") + ":\n" + meetDur.getHours() + " " + translate("Hour(s)") + ", " + meetDur.getMinutes() + " " + translate("Minute(s)"), italicFont); phraseMeetInfo.setLeading(leading); PdfPCell cellMeetInfo = new PdfPCell(); cellMeetInfo.addElement(phraseMeetInfo); cellMeetInfo.setBorderWidth(0); cellMeetInfo.setPadding(padding); tableInfos.addCell(cellListPoint); tableInfos.addCell(cellMeetInfo); /* * meeting number of findings */ phraseMeetInfo = new Phrase(translate("Number of findings") + ": " + prot.getFindings().size(), italicFont); phraseMeetInfo.setLeading(leading); cellMeetInfo = new PdfPCell(); cellMeetInfo.addElement(phraseMeetInfo); cellMeetInfo.setBorderWidth(0); cellMeetInfo.setPadding(padding); tableInfos.addCell(cellListPoint); tableInfos.addCell(cellMeetInfo); /* * meeting number of attendees */ phraseMeetInfo = new Phrase( translate("Number of attendees") + ": " + protMgmt.getAttendees(prot).size(), italicFont); phraseMeetInfo.setLeading(leading); cellMeetInfo = new PdfPCell(); cellMeetInfo.addElement(phraseMeetInfo); cellMeetInfo.setBorderWidth(0); cellMeetInfo.setPadding(padding); tableInfos.addCell(cellListPoint); tableInfos.addCell(cellMeetInfo); } cellInfos.addElement(tableInfos); cellInfos.setBackgroundColor(cellBackground); cellInfos.setPaddingBottom(padding); tableTitlePage.addCell(cellInfos); /* * Insert vertical strut */ tableTitlePage.addCell(createVerticalStrut(PDFTools.cmToPt(1.0f), 2)); /* * Write general impression and recommendation */ PdfPTable tableRevInfo = new PdfPTable(new float[] { 0.5f, 0.5f }); tableRevInfo.setWidthPercentage(100); tableRevInfo.setSplitRows(false); tableRevInfo.getDefaultCell().setBorderWidth(0); tableRevInfo.getDefaultCell().setPadding(0); /* * Insert vertical strut */ tableRevInfo.addCell(createVerticalStrut(PDFTools.cmToPt(0.5f), 2)); PdfPCell cellImpr = new PdfPCell( new Phrase(translate("General impressions of the product:"), boldFont)); cellImpr.setBorderWidth(0); cellImpr.setPadding(padding); cellImpr.setBorderColor(verticalBorderColor); cellImpr.setBorderWidthLeft(verticalBorderWidth); tableRevInfo.addCell(cellImpr); PdfPCell cellReco = new PdfPCell( new Phrase(translate("Final recommendation for the product:"), boldFont)); cellReco.setBorderWidth(0); cellReco.setPadding(padding); cellReco.setBorderColor(verticalBorderColor); cellReco.setBorderWidthLeft(verticalBorderWidth); tableRevInfo.addCell(cellReco); String impression = Application.getInstance().getReviewMgmt().getImpression(); if (impression.trim().equals("")) { impression = "--"; } Phrase phrImpr = new Phrase(impression, italicFont); phrImpr.setLeading(leading); cellImpr = new PdfPCell(); cellImpr.addElement(phrImpr); cellImpr.setBorderWidth(0); cellImpr.setPadding(padding); cellImpr.setPaddingBottom(padding * 1.8f); cellImpr.setBorderColor(verticalBorderColor); cellImpr.setBorderWidthLeft(verticalBorderWidth); tableRevInfo.addCell(cellImpr); String recommendation = Application.getInstance().getReviewMgmt().getRecommendation(); if (recommendation.trim().equals("")) { recommendation = "--"; } Phrase phrReco = new Phrase(recommendation, italicFont); phrReco.setLeading(leading); cellReco = new PdfPCell(); cellReco.addElement(phrReco); cellReco.setBorderWidth(0); cellReco.setPadding(padding); cellReco.setPaddingBottom(padding * 1.8f); cellReco.setBorderColor(verticalBorderColor); cellReco.setBorderWidthLeft(verticalBorderWidth); tableRevInfo.addCell(cellReco); /* * Add vertical strut */ tableRevInfo.addCell(createVerticalStrut(PDFTools.cmToPt(0.8f), 2)); /* * Write possible severities for this review */ String severities = ""; String separator = ""; for (String sev : Application.getInstance().getSeverityMgmt().getSeverities()) { severities = severities + separator + sev; separator = "; "; } Phrase phrSeverities = new Phrase(); phrSeverities.add(new Chunk( translate("The severities of the findings in this review (descending order of importance):"), italicFontSmall)); phrSeverities.add(new Chunk(" " + severities, boldItalicFontSmall)); phrSeverities.setLeading(leading); PdfPCell cellSevs = new PdfPCell(); cellSevs.setColspan(2); cellSevs.addElement(phrSeverities); cellSevs.setBorderWidth(0); cellSevs.setPadding(padding); tableRevInfo.addCell(cellSevs); /* * Short review statistics */ if (meetings.size() > 1) { Phrase phrRevStat = new Phrase(MessageFormat.format(translate( "This review consists of {0} attendees, {1} findings, {2} meetings and {3} aspects."), Application.getInstance().getReviewMgmt().getNumberOfAttendees(), Application.getInstance().getReviewMgmt().getNumberOfFindings(), Application.getInstance().getReviewMgmt().getNumberOfMeetings(), Application.getInstance().getReviewMgmt().getNumberOfAspects()), italicFontSmall); phrRevStat.setLeading(leading); PdfPCell cellRevStat = new PdfPCell(); cellRevStat.setColspan(2); cellRevStat.setHorizontalAlignment(Element.ALIGN_CENTER); cellRevStat.addElement(phrRevStat); cellRevStat.setBorderWidth(0); cellRevStat.setPadding(padding); cellRevStat.setPaddingTop(0); tableRevInfo.addCell(cellRevStat); } /* * Write the date of creation */ String creationDate = sdfDate.format(new Date().getTime()); Phrase phrCreationDate = new Phrase( translate("This finding has been created with RevAger on") + " " + creationDate, plainFontSmall); phrCreationDate.setLeading(leading); PdfPCell cellCrDate = new PdfPCell(); cellCrDate.setColspan(2); cellCrDate.setHorizontalAlignment(Element.ALIGN_CENTER); cellCrDate.addElement(phrCreationDate); cellCrDate.setBorderWidth(0); cellCrDate.setPadding(0); cellCrDate.setPaddingLeft(padding); cellCrDate.setPaddingRight(padding); tableRevInfo.addCell(cellCrDate); /* * Add content to the base table */ PdfPCell cellRevInfo = new PdfPCell(); cellRevInfo.setColspan(2); cellRevInfo.setBorder(0); cellRevInfo.setPadding(0); cellRevInfo.addElement(tableRevInfo); tableTitlePage.addCell(cellRevInfo); pdfDoc.add(tableTitlePage); } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExportException(translate("Cannot generate front page of the PDF document.")); } }