List of usage examples for com.lowagie.text.pdf PdfPCell setBorder
public void setBorder(int border)
From source file:org.revager.export.InvitationPDFExporter.java
License:Open Source License
/** * Write the aspects.//from w w w . j ava 2s .c o m * * @throws ExportException * If an error occurs while writing the aspects */ private void writeAspects() throws ExportException { /* * If the role of the attendee is not reviewer show all aspects */ List<Aspect> aspects = null; if (attendee.getRole() == Role.REVIEWER) { aspects = attMgmt.getAspects(attendee); } else { aspects = aspMgmt.getAspects(); } if (aspects.size() == 0) { return; } try { Font descriptionFont = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font directiveFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font categoryFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font reviewerFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 9); /* * Build base table for all attendees */ PdfPTable tableAspects = new PdfPTable(1); tableAspects.setWidthPercentage(100); tableAspects.setSplitRows(false); tableAspects.getDefaultCell().setBorderWidth(0); tableAspects.getDefaultCell().setPadding(0); boolean grayBackground = true; for (Aspect asp : aspects) { /* * Build table for one aspect */ PdfPTable tableAspect = new PdfPTable(new float[] { 0.70f, 0.30f }); tableAspect.setWidthPercentage(100); tableAspect.getDefaultCell().setBorderWidth(0); tableAspect.getDefaultCell().setPadding(0); PdfPCell cellAspect = new PdfPCell(); cellAspect.setPadding(0); cellAspect.setBorder(0); Phrase phraseStrut = new Phrase(" "); phraseStrut.setLeading(leading * 0.4f); /* * directive and description of the aspect */ PdfPCell cell = new PdfPCell(); cell.setBorderWidth(0); cell.setPadding(padding * 0.4f); cell.setPaddingBottom(padding * 1.5f); cell.addElement(new Phrase(asp.getDirective(), directiveFont)); cell.addElement(phraseStrut); cell.addElement(new Phrase(asp.getDescription(), descriptionFont)); /* * the reviewers of this aspect (moderator only) */ if (attendee.getRole() == Role.MODERATOR) { cell.addElement(phraseStrut); cell.addElement(phraseStrut); String separator = ""; Phrase phraseReviewers = new Phrase(); phraseReviewers.setLeading(leading); phraseReviewers.setFont(reviewerFont); for (Attendee att : attMgmt.getAttendees()) { if (attMgmt.hasAspect(asp, att)) { phraseReviewers.add(new Chunk(separator + att.getName(), reviewerFont)); separator = " "; } } cell.addElement(phraseReviewers); } tableAspect.addCell(cell); /* * category of the aspect */ cell = new PdfPCell(new Phrase(asp.getCategory(), categoryFont)); cell.setBorderWidth(0); cell.setPadding(padding * 0.4f); cell.setPaddingTop(padding * 1.1f); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableAspect.addCell(cell); cellAspect.addElement(tableAspect); cellAspect.setPadding(0); cellAspect.setPaddingLeft(padding); cellAspect.setPaddingRight(padding); if (grayBackground == true) { grayBackground = false; cellAspect.setBackgroundColor(cellBackground); } else { grayBackground = true; } /* * Add aspect to the list */ tableAspects.addCell(cellAspect); } PdfPCell cellBottomLine = new PdfPCell(); cellBottomLine.setPadding(0); cellBottomLine.setBorderWidth(0); cellBottomLine.setBorderWidthBottom(1); cellBottomLine.setBorderColor(cellBackground); tableAspects.addCell(cellBottomLine); /* * Add the attendee base table to the document */ pdfDoc.add(tableAspects); } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExportException(translate("Cannot put aspects into the PDF document.")); } }
From source file:org.revager.export.ProtocolPDFExporter.java
License:Open Source License
/** * Write the title page of the protocol. * //from ww w . j a v a 2 s . c o 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.")); } }
From source file:org.revager.export.ProtocolPDFExporter.java
License:Open Source License
/** * Writes the given attendees to the protocol. * /* w w w .ja v a 2 s . co m*/ * @param protocol * the protocol * @param showAttendeesAspects * true, if the aspects of the reviewers should be part of the * protocol * @param showAttendeesPrepTime * true, if the preparation time of the reviewers should be part * of the protocol * @param showSignatureFields * ture, if the signature fields should be part of the protocol * * @throws ExportException * If an error occurs while writing the attendees to the * protocol */ protected void writeAttendees(Protocol protocol, boolean showAttendeesAspects, boolean showAttendeesPrepTime, boolean showSignatureFields) throws ExportException { List<Attendee> atts; if (protocol != null) { atts = protMgmt.getAttendees(protocol); } else { atts = Application.getInstance().getAttendeeMgmt().getAttendees(); } /* * Sort the attendees by their role into different lists */ List<Attendee> reviewers = new ArrayList<Attendee>(); List<Attendee> moderators = new ArrayList<Attendee>(); List<Attendee> scribes = new ArrayList<Attendee>(); List<Attendee> authors = new ArrayList<Attendee>(); List<Attendee> customers = new ArrayList<Attendee>(); List<Attendee> others = new ArrayList<Attendee>(); for (Attendee att : atts) { switch (att.getRole()) { case AUTHOR: authors.add(att); break; case CUSTOMER: customers.add(att); break; case MODERATOR: moderators.add(att); break; case REVIEWER: reviewers.add(att); break; case SCRIBE: scribes.add(att); break; default: others.add(att); break; } } List<List<Attendee>> attendees = new ArrayList<List<Attendee>>(); attendees.add(moderators); attendees.add(scribes); attendees.add(authors); attendees.add(customers); attendees.add(reviewers); attendees.add(others); /* * Write attendees */ try { Font contactFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font nameFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font roleFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font aspectsFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 8); Font aspectsTitleFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 8); /* * Build base table for all attendees */ PdfPTable tableAttendees = new PdfPTable(1); tableAttendees.setWidthPercentage(100); tableAttendees.setSplitRows(false); tableAttendees.getDefaultCell().setBorderWidth(0); tableAttendees.getDefaultCell().setPadding(0); boolean grayBackground = true; for (List<Attendee> attList : attendees) { for (Attendee att : attList) { /* * Build table for one attendee */ PdfPTable tableAttendee = new PdfPTable(new float[] { 0.80f, 0.20f }); tableAttendee.setWidthPercentage(100); tableAttendee.getDefaultCell().setBorderWidth(0); tableAttendee.getDefaultCell().setPadding(0); PdfPCell cellAttendee = new PdfPCell(); cellAttendee.setPadding(0); cellAttendee.setBorder(0); /* * Name of the attendee */ PdfPCell cell = new PdfPCell(); cell.setBorderWidth(0); cell.setPadding(padding * 0.4f); cell.setPaddingBottom(padding * 1.5f); cell.addElement(new Phrase(att.getName(), nameFont)); cell.addElement(new Phrase(att.getContact(), contactFont)); Phrase phraseStrut = new Phrase(" "); phraseStrut.setLeading(leading * 0.6f); /* * Aspects of this attendee */ if (!attMgmt.getAspects(att).isEmpty() && showAttendeesAspects) { String separator = ""; cell.addElement(phraseStrut); cell.addElement(new Phrase(translate("Assigned aspects:") + " ", aspectsTitleFont)); Phrase phraseAspects = new Phrase(); phraseAspects.setLeading(leading); phraseAspects.setFont(aspectsFont); for (Aspect asp : attMgmt.getAspects(att)) { phraseAspects.add(new Chunk( separator + asp.getDirective() + " (" + asp.getCategory() + ")", aspectsFont)); separator = " "; } cell.addElement(phraseAspects); } /* * Preparation time of the attendee */ Duration prepTime; if (protocol != null) { prepTime = protMgmt.getAttendeePrepTime(att, protocol); } else { prepTime = null; } if (prepTime != null && showAttendeesPrepTime) { cell.addElement(phraseStrut); cell.addElement(new Phrase(translate("Preparation time:") + " ", aspectsTitleFont)); Phrase phrasePrepTime = new Phrase(); phrasePrepTime.setLeading(leading); phrasePrepTime.setFont(aspectsFont); String prep = ""; String separator = ""; if (prepTime.getDays() > 0) { prep = prep + prepTime.getDays() + " " + translate("Day(s)"); separator = ", "; } if (prepTime.getHours() > 0) { prep = prep + separator + prepTime.getHours() + " " + translate("Hour(s)"); separator = ", "; } if (prepTime.getMinutes() >= 0) { prep = prep + separator + prepTime.getMinutes() + " " + translate("Minute(s)"); separator = ", "; } phrasePrepTime.add(new Chunk(prep, aspectsFont)); cell.addElement(phrasePrepTime); } /* * Signature field for the attendee */ if (showSignatureFields) { cell.addElement(phraseStrut); cell.addElement(phraseStrut); cell.addElement(phraseStrut); cell.addElement(phraseStrut); cell.addElement(new Phrase("________________________________________", aspectsFont)); cell.addElement( new Phrase(translate("Date, Signature") + " (" + att.getName() + ")", aspectsFont)); } tableAttendee.addCell(cell); /* * role of the attendee */ cell = new PdfPCell(new Phrase(translate(att.getRole().toString()), roleFont)); cell.setBorderWidth(0); cell.setPadding(padding * 0.4f); cell.setPaddingTop(padding * 1.1f); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableAttendee.addCell(cell); cellAttendee.addElement(tableAttendee); cellAttendee.setPadding(0); cellAttendee.setPaddingLeft(padding); cellAttendee.setPaddingRight(padding); if (grayBackground == true) { grayBackground = false; cellAttendee.setBackgroundColor(cellBackground); } else { grayBackground = true; } /* * Add attendee to the list */ tableAttendees.addCell(cellAttendee); } } PdfPCell cellBottomLine = new PdfPCell(); cellBottomLine.setPadding(0); cellBottomLine.setBorderWidth(0); cellBottomLine.setBorderWidthBottom(1); cellBottomLine.setBorderColor(cellBackground); tableAttendees.addCell(cellBottomLine); /* * Add the attendee base table to the document */ pdfDoc.add(tableAttendees); } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExportException(translate("Cannot put attendees into the PDF document.")); } }
From source file:org.sakaiproject.tool.assessment.pdf.itext.HTMLWorker.java
License:Mozilla Public License
public void startElement(String tag, HashMap h) { if (!tagsSupported.containsKey(tag)) return;/*from w w w . j a va 2s.c o m*/ try { style.applyStyle(tag, h); String follow = (String) FactoryProperties.followTags.get(tag); if (follow != null) { HashMap prop = new HashMap(); prop.put(follow, null); cprops.addToChain(follow, prop); return; } FactoryProperties.insertStyle(h); if (tag.equals("a")) { cprops.addToChain(tag, h); if (currentParagraph == null) currentParagraph = new Paragraph(); stack.push(currentParagraph); currentParagraph = new Paragraph(); return; } if (tag.equals("br")) { if (currentParagraph == null) currentParagraph = new Paragraph(); currentParagraph.add(factoryProperties.createChunk("\n", cprops)); return; } if (tag.equals("hr")) { PdfPTable hr = new PdfPTable(1); hr.setHorizontalAlignment(Element.ALIGN_CENTER); hr.setWidthPercentage(100f); hr.setSpacingAfter(0f); hr.setSpacingBefore(0f); PdfPCell cell = new PdfPCell(); cell.setUseVariableBorders(true); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(PdfPCell.BOTTOM); cell.setBorderWidth(1f); cell.setPadding(0); cell.addElement(factoryProperties.createChunk("\n", cprops)); hr.addCell(cell); // paragraphs can't have tables? really? without it hr's may be rendered a bit early.. //if (currentParagraph != null) // currentParagraph.add(hr); //else document.add(hr); return; } if (tag.equals("font") || tag.equals("span")) { cprops.addToChain(tag, h); return; } if (tag.equals("img")) { String src = (String) h.get("src"); if (src == null) return; cprops.addToChain(tag, h); Image img = null; if (interfaceProps != null) { HashMap images = (HashMap) interfaceProps.get("img_static"); if (images != null) { Image tim = (Image) images.get(src); if (tim != null) img = Image.getInstance(tim); } else { if (!src.startsWith("http")) { // relative src references only String baseurl = (String) interfaceProps.get("img_baseurl"); if (baseurl != null) { src = baseurl + src; img = Image.getInstance(src); } } } } if (img == null) { if (!src.startsWith("http")) { String path = cprops.getProperty("image_path"); if (path == null) path = ""; src = new File(path, src).getPath(); img = Image.getInstance(src); } else { byte[] buffer; String srcResource = src.substring(src.indexOf("/content", 0)).replaceAll("/content", ""); buffer = getImageStream(URLDecoder.decode(srcResource)); img = Image.getInstance(buffer); } } String align = (String) h.get("align"); String width = (String) h.get("width"); String height = (String) h.get("height"); String border = (String) h.get("border"); String hspace = (String) h.get("hspace"); String vspace = (String) h.get("vspace"); String before = cprops.getProperty("before"); String after = cprops.getProperty("after"); float wp = 0.0f; float lp = 0.0f; if (maxWidth > 0 && ((width != null && Integer.parseInt(width) > maxWidth) || (width == null && (int) img.getWidth() > maxWidth))) { wp = lengthParse(String.valueOf(maxWidth), (int) img.getWidth()); lp = wp; } else { wp = lengthParse(width, (int) img.getWidth()); lp = lengthParse(height, (int) img.getHeight()); } if (wp > 0 && lp > 0) img.scalePercent(wp, lp); else if (wp > 0) img.scalePercent(wp); else if (lp > 0) img.scalePercent(lp); img.setWidthPercentage(0); // border if (border != null && !"".equals(border)) { try { img.setBorderWidth(Integer.parseInt(border)); img.setBorder(Image.BOX); } catch (Exception e) { e.printStackTrace(); } } // horizonatal space if (hspace != null && !"".equals(hspace)) { try { img.setSpacingAfter(Float.parseFloat(hspace)); img.setSpacingBefore(Float.parseFloat(hspace)); } catch (Exception e) { e.printStackTrace(); } } // horizontal alignment if (align != null && (align.equalsIgnoreCase("left") || align.equalsIgnoreCase("right"))) { endElement("p"); int ralign = Image.LEFT; if (align.equalsIgnoreCase("right")) ralign = Image.RIGHT; img.setAlignment(ralign | Image.TEXTWRAP); Img i = null; boolean skip = false; if (interfaceProps != null) { i = (Img) interfaceProps.get("img_interface"); if (i != null) skip = i.process(img, h, cprops, document); } if (!skip) document.add(img); cprops.removeChain(tag); } // vertical alignment (or none) else { img.setAlignment(Image.TEXTWRAP); float bottom = 0.0f; float top = img.getTop(); float prevHeight = 0.0f; float prevRise = 0.0f; if (currentParagraph != null) { ArrayList chunks = currentParagraph.getChunks(); Chunk sibling = null; for (int k = chunks.size() - 1; k >= 0; k--) { if (chunks.get(k) != null) sibling = (Chunk) chunks.get(k); } if (sibling != null) { if (sibling.hasAttributes()) prevRise = sibling.getTextRise(); prevHeight = 0.0f; if (sibling.getFont() != null) { prevHeight = sibling.getFont().getCalculatedSize(); } } } if ("absMiddle".equalsIgnoreCase(align)) { if (prevHeight > 0) bottom += (img.getScaledHeight() / 2.0f) - (prevHeight / 2.0f); else if (img.getScaledHeight() > 0) bottom += img.getScaledHeight() / 2.0f; } else if ("middle".equalsIgnoreCase(align)) { if (img.getScaledHeight() > 0) bottom += (img.getScaledHeight() / 2.0f); } else if ("bottom".equalsIgnoreCase(align) || "baseline".equalsIgnoreCase(align) || "absbottom".equalsIgnoreCase(align)) { //baseline and absbottom should have some slight tweeking from bottom, but not sure what?? } else if ("top".equalsIgnoreCase(align)) { bottom += img.getScaledHeight() - prevHeight; } else if ("texttop".equalsIgnoreCase(align)) { bottom += img.getScaledHeight() - (prevHeight - prevRise); } cprops.removeChain(tag); if (currentParagraph == null) { currentParagraph = FactoryProperties.createParagraph(cprops); bottom = 0f; } else if (currentParagraph.isEmpty()) { bottom = 0f; } currentParagraph.setLeading(2f + bottom, 1.00f); currentParagraph.add(new Chunk(img, 0, 0 - bottom)); } return; } if (tag.equals("blockquote")) { cprops.addToChain(tag, h); inBLOCK = true; if (currentParagraph != null) endElement("p"); currentParagraph = FactoryProperties.createParagraph(cprops); currentParagraph.add(factoryProperties.createChunk("\n", cprops)); return; } endElement("p"); if (tag.equals("h1") || tag.equals("h2") || tag.equals("h3") || tag.equals("h4") || tag.equals("h5") || tag.equals("h6")) { if (!h.containsKey("size")) { int v = 8 - Integer.parseInt(tag.substring(1)); h.put("size", Integer.toString(v)); } cprops.addToChain(tag, h); return; } if (tag.equals("ul")) { if (pendingLI) endElement("li"); skipText = true; cprops.addToChain(tag, h); com.lowagie.text.List list = new com.lowagie.text.List(false, 10); list.setListSymbol("\u2022"); stack.push(list); return; } if (tag.equals("ol")) { if (pendingLI) endElement("li"); skipText = true; cprops.addToChain(tag, h); com.lowagie.text.List list = new com.lowagie.text.List(true, 10); stack.push(list); return; } if (tag.equals("li")) { if (pendingLI) endElement("li"); skipText = false; pendingLI = true; cprops.addToChain(tag, h); stack.push(FactoryProperties.createListItem(cprops)); return; } if (tag.equals("div") || tag.equals("body")) { cprops.addToChain(tag, h); return; } if (tag.equals("pre")) { if (!h.containsKey("face")) { h.put("face", "Courier"); } cprops.addToChain(tag, h); isPRE = true; return; } if (tag.equals("p")) { cprops.addToChain(tag, h); currentParagraph = FactoryProperties.createParagraph(cprops); if (inBLOCK) { currentParagraph.setIndentationLeft(currentParagraph.getIndentationLeft() + 40.0F); } return; } if (tag.equals("tr")) { if (pendingTR) endElement("tr"); skipText = true; pendingTR = true; cprops.addToChain("tr", h); return; } if (tag.equals("td") || tag.equals("th")) { if (pendingTD) endElement(tag); skipText = false; pendingTD = true; cprops.addToChain("td", h); stack.push(new IncCell(tag, cprops)); return; } if (tag.equals("table")) { cprops.addToChain("table", h); IncTable table = new IncTable(h); stack.push(table); tableState.push(new boolean[] { pendingTR, pendingTD }); pendingTR = pendingTD = false; skipText = true; return; } } catch (Exception e) { e.printStackTrace(); //throw new ExceptionConverter(e); } }
From source file:org.sonar.report.pdf.ExecutivePDFReporter.java
License:Open Source License
protected void printDashboard(Project project, Section section) throws DocumentException { // Static Analysis Paragraph staticAnalysis = new Paragraph(getTextProperty("general.static_analysis"), Style.UNDERLINED_FONT); PdfPTable staticAnalysisTable = new PdfPTable(3); staticAnalysisTable.getDefaultCell().setBorderColor(Color.WHITE); PdfPTable linesOfCode = new PdfPTable(1); Style.noBorderTable(linesOfCode); linesOfCode.addCell(new Phrase(getTextProperty("general.lines_of_code"), Style.DASHBOARD_TITLE_FONT)); PdfPTable linesOfCodeTendency = new PdfPTable(2); Style.noBorderTable(linesOfCodeTendency); linesOfCodeTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT); linesOfCodeTendency.addCell(//from w w w . j a va2 s .c om new Phrase(project.getMeasure(MetricKeys.NCLOC).getFormatValue(), Style.DASHBOARD_DATA_FONT)); linesOfCodeTendency.addCell(getTendencyImage(project.getMeasure(MetricKeys.NCLOC).getQualitativeTendency(), project.getMeasure(MetricKeys.NCLOC).getQuantitativeTendency())); linesOfCode.addCell(linesOfCodeTendency); linesOfCode.addCell(new Phrase(project.getMeasure(MetricKeys.PACKAGES).getFormatValue() + " packages", Style.DASHBOARD_DATA_FONT_2)); linesOfCode.addCell(new Phrase(project.getMeasure(MetricKeys.CLASSES).getFormatValue() + " classes", Style.DASHBOARD_DATA_FONT_2)); linesOfCode.addCell(new Phrase(project.getMeasure(MetricKeys.FUNCTIONS).getFormatValue() + " methods", Style.DASHBOARD_DATA_FONT_2)); linesOfCode.addCell(new Phrase( project.getMeasure(MetricKeys.DUPLICATED_LINES_DENSITY).getFormatValue() + " duplicated lines", Style.DASHBOARD_DATA_FONT_2)); PdfPTable comments = new PdfPTable(1); Style.noBorderTable(comments); comments.addCell(new Phrase(getTextProperty("general.comments"), Style.DASHBOARD_TITLE_FONT)); PdfPTable commentsTendency = new PdfPTable(2); commentsTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT); Style.noBorderTable(commentsTendency); commentsTendency.addCell(new Phrase(project.getMeasure(MetricKeys.COMMENT_LINES_DENSITY).getFormatValue(), Style.DASHBOARD_DATA_FONT)); commentsTendency.addCell( getTendencyImage(project.getMeasure(MetricKeys.COMMENT_LINES_DENSITY).getQualitativeTendency(), project.getMeasure(MetricKeys.COMMENT_LINES_DENSITY).getQuantitativeTendency())); comments.addCell(commentsTendency); comments.addCell( new Phrase(project.getMeasure(MetricKeys.COMMENT_LINES).getFormatValue() + " comment lines", Style.DASHBOARD_DATA_FONT_2)); PdfPTable complexity = new PdfPTable(1); Style.noBorderTable(complexity); complexity.addCell(new Phrase(getTextProperty("general.complexity"), Style.DASHBOARD_TITLE_FONT)); PdfPTable complexityTendency = new PdfPTable(2); complexityTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT); Style.noBorderTable(complexityTendency); complexityTendency.addCell(new Phrase(project.getMeasure(MetricKeys.FUNCTION_COMPLEXITY).getFormatValue(), Style.DASHBOARD_DATA_FONT)); complexityTendency.addCell( getTendencyImage(project.getMeasure(MetricKeys.FUNCTION_COMPLEXITY).getQualitativeTendency(), project.getMeasure(MetricKeys.FUNCTION_COMPLEXITY).getQuantitativeTendency())); complexity.addCell(complexityTendency); complexity.addCell(new Phrase(project.getMeasure(MetricKeys.CLASS_COMPLEXITY).getFormatValue() + " /class", Style.DASHBOARD_DATA_FONT_2)); complexity .addCell(new Phrase(project.getMeasure(MetricKeys.COMPLEXITY).getFormatValue() + " decision points", Style.DASHBOARD_DATA_FONT_2)); staticAnalysisTable.setSpacingBefore(10); staticAnalysisTable.addCell(linesOfCode); staticAnalysisTable.addCell(comments); staticAnalysisTable.addCell(complexity); staticAnalysisTable.setSpacingAfter(20); // Dynamic Analysis Paragraph dynamicAnalysis = new Paragraph(getTextProperty("general.dynamic_analysis"), Style.UNDERLINED_FONT); PdfPTable dynamicAnalysisTable = new PdfPTable(3); Style.noBorderTable(dynamicAnalysisTable); PdfPTable codeCoverage = new PdfPTable(1); Style.noBorderTable(codeCoverage); codeCoverage.addCell(new Phrase(getTextProperty("general.code_coverage"), Style.DASHBOARD_TITLE_FONT)); PdfPTable codeCoverageTendency = new PdfPTable(2); Style.noBorderTable(codeCoverageTendency); codeCoverageTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT); codeCoverageTendency.addCell(new Phrase( project.getMeasure(MetricKeys.COVERAGE).getFormatValue() + " coverage", Style.DASHBOARD_DATA_FONT)); codeCoverageTendency .addCell(getTendencyImage(project.getMeasure(MetricKeys.COVERAGE).getQualitativeTendency(), project.getMeasure(MetricKeys.COVERAGE).getQuantitativeTendency())); codeCoverage.addCell(codeCoverageTendency); codeCoverage.addCell(new Phrase(project.getMeasure(MetricKeys.TESTS).getFormatValue() + " tests", Style.DASHBOARD_DATA_FONT_2)); PdfPTable testSuccess = new PdfPTable(1); Style.noBorderTable(testSuccess); testSuccess.addCell(new Phrase(getTextProperty("general.test_success"), Style.DASHBOARD_TITLE_FONT)); PdfPTable testSuccessTendency = new PdfPTable(2); Style.noBorderTable(testSuccessTendency); testSuccessTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT); testSuccessTendency.addCell(new Phrase(project.getMeasure(MetricKeys.TEST_SUCCESS_DENSITY).getFormatValue(), Style.DASHBOARD_DATA_FONT)); testSuccessTendency.addCell( getTendencyImage(project.getMeasure(MetricKeys.TEST_SUCCESS_DENSITY).getQualitativeTendency(), project.getMeasure(MetricKeys.TEST_SUCCESS_DENSITY).getQuantitativeTendency())); testSuccess.addCell(testSuccessTendency); testSuccess.addCell(new Phrase(project.getMeasure(MetricKeys.TEST_FAILURES).getFormatValue() + " failures", Style.DASHBOARD_DATA_FONT_2)); testSuccess.addCell(new Phrase(project.getMeasure(MetricKeys.TEST_ERRORS).getFormatValue() + " errors", Style.DASHBOARD_DATA_FONT_2)); dynamicAnalysisTable.setSpacingBefore(10); dynamicAnalysisTable.addCell(codeCoverage); dynamicAnalysisTable.addCell(testSuccess); dynamicAnalysisTable.addCell(""); dynamicAnalysisTable.setSpacingAfter(20); Paragraph codingRulesViolations = new Paragraph(getTextProperty("general.coding_rules_violations"), Style.UNDERLINED_FONT); PdfPTable codingRulesViolationsTable = new PdfPTable(3); Style.noBorderTable(codingRulesViolationsTable); PdfPTable rulesCompliance = new PdfPTable(1); Style.noBorderTable(rulesCompliance); rulesCompliance .addCell(new Phrase(getTextProperty("general.rules_compliance"), Style.DASHBOARD_TITLE_FONT)); PdfPTable rulesComplianceTendency = new PdfPTable(2); Style.noBorderTable(rulesComplianceTendency); rulesComplianceTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT); rulesComplianceTendency.addCell(new Phrase( project.getMeasure(MetricKeys.VIOLATIONS_DENSITY).getFormatValue(), Style.DASHBOARD_DATA_FONT)); // Workarround for avoid resizing Image tendencyRulesResize = getTendencyImage( project.getMeasure(MetricKeys.VIOLATIONS_DENSITY).getQualitativeTendency(), project.getMeasure(MetricKeys.VIOLATIONS_DENSITY).getQuantitativeTendency()); tendencyRulesResize.scaleAbsolute(Style.TENDENCY_ICONS_HEIGHT, Style.TENDENCY_ICONS_HEIGHT); PdfPCell tendencyRulesCell = new PdfPCell(tendencyRulesResize); tendencyRulesCell.setBorder(0); rulesComplianceTendency.addCell(tendencyRulesCell); rulesCompliance.addCell(rulesComplianceTendency); PdfPTable violations = new PdfPTable(1); Style.noBorderTable(violations); violations.addCell(new Phrase(getTextProperty("general.violations"), Style.DASHBOARD_TITLE_FONT)); PdfPTable violationsTendency = new PdfPTable(2); Style.noBorderTable(violationsTendency); violationsTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT); violationsTendency.addCell( new Phrase(project.getMeasure(MetricKeys.VIOLATIONS).getFormatValue(), Style.DASHBOARD_DATA_FONT)); // Workarround for avoid resizing Image tendencyResize = getTendencyImage(project.getMeasure(MetricKeys.VIOLATIONS).getQualitativeTendency(), project.getMeasure(MetricKeys.VIOLATIONS).getQuantitativeTendency()); tendencyResize.scaleAbsolute(Style.TENDENCY_ICONS_HEIGHT, Style.TENDENCY_ICONS_HEIGHT); PdfPCell tendencyCell = new PdfPCell(tendencyResize); tendencyCell.setBorder(0); violationsTendency.addCell(tendencyCell); violations.addCell(violationsTendency); codingRulesViolationsTable.setSpacingBefore(10); codingRulesViolationsTable.addCell(rulesCompliance); codingRulesViolationsTable.addCell(violations); codingRulesViolationsTable.addCell(""); codingRulesViolationsTable.setSpacingAfter(20); section.add(Chunk.NEWLINE); section.add(staticAnalysis); section.add(staticAnalysisTable); section.add(dynamicAnalysis); section.add(dynamicAnalysisTable); section.add(codingRulesViolations); section.add(codingRulesViolationsTable); }
From source file:org.tellervo.desktop.print.BasicBoxLabel.java
License:Open Source License
/** * Get PdfPTable containing the samples per object * /* w ww. ja v a2 s . c o m*/ * @return PdfPTable * @throws DocumentException */ private void addTable(WSIBox b) throws DocumentException { float[] widths = { 0.15f, 0.75f, 0.2f }; PdfPTable tbl = new PdfPTable(widths); PdfPCell headerCell = new PdfPCell(); tbl.setWidthPercentage(100f); // Write header cells of table headerCell.setBorderWidthBottom(headerLineWidth); headerCell.setBorderWidthTop(headerLineWidth); headerCell.setBorderWidthLeft(0); headerCell.setBorderWidthRight(0); headerCell.setPhrase(new Phrase("Object", tableHeaderFontLarge)); headerCell.setHorizontalAlignment(Element.ALIGN_LEFT); tbl.addCell(headerCell); headerCell.setPhrase(new Phrase("Elements", tableHeaderFontLarge)); headerCell.setHorizontalAlignment(Element.ALIGN_LEFT); tbl.addCell(headerCell); headerCell.setPhrase(new Phrase("# Samples", tableHeaderFontLarge)); headerCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tbl.addCell(headerCell); // Find all objects associated with samples in this box SearchParameters objparam = new SearchParameters(SearchReturnObject.OBJECT); objparam.addSearchConstraint(SearchParameterName.SAMPLEBOXID, SearchOperator.EQUALS, b.getIdentifier().getValue().toString()); EntitySearchResource<TridasObject> objresource = new EntitySearchResource<TridasObject>(objparam); objresource.setProperty(TellervoResourceProperties.ENTITY_REQUEST_FORMAT, TellervoRequestFormat.COMPREHENSIVE); TellervoResourceAccessDialog dialog = new TellervoResourceAccessDialog(objresource); objresource.query(); dialog.setVisible(true); if (!dialog.isSuccessful()) { System.out.println("oopsey doopsey. Error getting objects"); return; } List<TridasObject> obj = objresource.getAssociatedResult(); // Check that there are not too many objects to fit on box label if (obj.size() > 10) { System.out.println("Warning this label has " + Integer.toString(obj.size()) + " objects associated with it so is unlikely to fit and may take some time to produce!"); } if (obj.size() < 4) { // Not many objects so add some space to the table for prettiness sake headerCell.setBorder(0); headerCell.setPhrase(new Phrase(" ")); tbl.addCell(headerCell); tbl.addCell(headerCell); tbl.addCell(headerCell); } // Sort objects into alphabetically order based on labcode TridasComparator sorter = new TridasComparator(); Collections.sort(obj, sorter); Integer sampleCountInBox = 0; // Loop through objects List<TridasObject> objdone = new ArrayList<TridasObject>(); // Array of top level objects that have already been dealt with mainobjloop: for (TridasObject myobj : obj) { // Need to check if this object has already been done as there will be duplicate top level objects if there are samples // from more than one subobject in the box if (objdone.size() > 0) { try { for (TridasObject tlo : objdone) { TridasObjectEx tloex = (TridasObjectEx) tlo; TridasObjectEx myobjex = (TridasObjectEx) myobj; if (tloex.getLabCode().compareTo(myobjex.getLabCode()) == 0) { // Object already been done so skip to next continue mainobjloop; } else { // Object has not been done so add to the done list and keep going objdone.add(myobj); } } } catch (Exception e) { } } else { objdone.add(myobj); } // Add object code to first column PdfPCell dataCell = new PdfPCell(); dataCell.setBorderWidthBottom(0); dataCell.setBorderWidthTop(0); dataCell.setBorderWidthLeft(0); dataCell.setBorderWidthRight(0); dataCell.setHorizontalAlignment(Element.ALIGN_LEFT); String objCode = null; if (myobj instanceof TridasObjectEx) objCode = ((TridasObjectEx) myobj).getLabCode(); dataCell.setPhrase(new Phrase(objCode, bodyFontLarge)); tbl.addCell(dataCell); // Search for elements associated with this object System.out.println("Starting search for elements associated with " + myobj.getTitle().toString()); SearchParameters sp = new SearchParameters(SearchReturnObject.ELEMENT); sp.addSearchConstraint(SearchParameterName.SAMPLEBOXID, SearchOperator.EQUALS, b.getIdentifier().getValue()); sp.addSearchConstraint(SearchParameterName.ANYPARENTOBJECTID, SearchOperator.EQUALS, myobj.getIdentifier().getValue()); EntitySearchResource<TridasElement> resource = new EntitySearchResource<TridasElement>(sp); resource.setProperty(TellervoResourceProperties.ENTITY_REQUEST_FORMAT, TellervoRequestFormat.SUMMARY); TellervoResourceAccessDialog dialog2 = new TellervoResourceAccessDialog(resource); resource.query(); dialog2.setVisible(true); if (!dialog2.isSuccessful()) { System.out.println("oopsey doopsey. Error getting elements"); return; } //XMLDebugView.showDialog(); List<TridasElement> elements = resource.getAssociatedResult(); TridasComparator numSorter = new TridasComparator(TridasComparator.Type.TITLES, TridasComparator.NullBehavior.NULLS_LAST, TridasComparator.CompareBehavior.AS_NUMBERS_THEN_STRINGS); Collections.sort(elements, numSorter); // Loop through elements Integer smpCnt = 0; ArrayList<String> numlist = new ArrayList<String>(); for (TridasElement myelem : elements) { // Add element title to string if (myelem.getTitle() != null) { String mytitle = myelem.getTitle(); numlist.add(mytitle); } // Grab associated samples and add count to running total List<TridasSample> samples = myelem.getSamples(); smpCnt += samples.size(); } // Add element names to second column dataCell.setPhrase(new Phrase(hyphenSummarize(numlist), bodyFontLarge)); tbl.addCell(dataCell); // Add sample count to third column dataCell.setPhrase(new Phrase(smpCnt.toString(), bodyFontLarge)); dataCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tbl.addCell(dataCell); sampleCountInBox += smpCnt; } if (obj.size() < 4) { // Not many objects so add some space to the table for prettiness sake headerCell.setBorder(0); headerCell.setPhrase(new Phrase(" ")); tbl.addCell(headerCell); tbl.addCell(headerCell); tbl.addCell(headerCell); } headerCell.setBorderWidthBottom(headerLineWidth); headerCell.setBorderWidthTop(headerLineWidth); headerCell.setBorderWidthLeft(0); headerCell.setBorderWidthRight(0); headerCell.setPhrase(new Phrase(" ", bodyFontLarge)); tbl.addCell(headerCell); headerCell.setPhrase(new Phrase("Grand Total", tableHeaderFontLarge)); headerCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tbl.addCell(headerCell); headerCell.setPhrase(new Phrase(sampleCountInBox.toString(), bodyFontLarge)); tbl.addCell(headerCell); // Add table to document document.add(tbl); }
From source file:org.tellervo.desktop.print.CompleteBoxLabel.java
License:Open Source License
/** * Get PdfPTable containing the samples per object * //from ww w .jav a 2 s . c om * @return PdfPTable * @throws DocumentException */ private void addTable(WSIBox b) throws DocumentException { float[] widths = { 0.15f, 0.75f, 0.2f }; PdfPTable tbl = new PdfPTable(widths); PdfPCell headerCell = new PdfPCell(); tbl.setWidthPercentage(100f); // Write header cells of table headerCell.setBorderWidthBottom(headerLineWidth); headerCell.setBorderWidthTop(headerLineWidth); headerCell.setBorderWidthLeft(0); headerCell.setBorderWidthRight(0); headerCell.setPhrase(new Phrase("Object", tableHeaderFontLarge)); headerCell.setHorizontalAlignment(Element.ALIGN_LEFT); tbl.addCell(headerCell); headerCell.setPhrase(new Phrase("Elements", tableHeaderFontLarge)); headerCell.setHorizontalAlignment(Element.ALIGN_LEFT); tbl.addCell(headerCell); headerCell.setPhrase(new Phrase("# Samples", tableHeaderFontLarge)); headerCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tbl.addCell(headerCell); // Find all objects associated with samples in this box SearchParameters objparam = new SearchParameters(SearchReturnObject.OBJECT); objparam.addSearchConstraint(SearchParameterName.SAMPLEBOXID, SearchOperator.EQUALS, b.getIdentifier().getValue().toString()); EntitySearchResource<TridasObject> objresource = new EntitySearchResource<TridasObject>(objparam); objresource.setProperty(TellervoResourceProperties.ENTITY_REQUEST_FORMAT, TellervoRequestFormat.COMPREHENSIVE); TellervoResourceAccessDialog dialog = new TellervoResourceAccessDialog(objresource); objresource.query(); dialog.setVisible(true); if (!dialog.isSuccessful()) { System.out.println("oopsey doopsey. Error getting objects"); return; } List<TridasObject> obj = objresource.getAssociatedResult(); // Check that there are not too many objects to fit on box label if (obj.size() > 10) { System.out.println("Warning this label has " + Integer.toString(obj.size()) + " objects associated with it so is unlikely to fit and may take some time to produce!"); } if (obj.size() < 4) { // Not many objects so add some space to the table for prettiness sake headerCell.setBorder(0); headerCell.setPhrase(new Phrase(" ")); tbl.addCell(headerCell); tbl.addCell(headerCell); tbl.addCell(headerCell); } // Sort objects into alphabetically order based on labcode TridasComparator sorter = new TridasComparator(); Collections.sort(obj, sorter); Integer sampleCountInBox = 0; // Loop through objects List<TridasObject> objlist = new ArrayList<TridasObject>(); // Array of top level objects that have already been dealt with for (TridasObject myobj : obj) { objlist.add(myobj); if (myobj.isSetObjects()) { for (TridasObject obj2 : myobj.getObjects()) { objlist.add(obj2); } } } Collections.sort(objlist, sorter); mainobjloop: for (TridasObject myobj : objlist) { // Need to check if this object has already been done as there will be duplicate top level objects if there are samples // from more than one subobject in the box /*if(objdone.size()>0) { try{for(TridasObject tlo : objdone){ TridasObjectEx tloex = (TridasObjectEx) tlo; TridasObjectEx myobjex = (TridasObjectEx) myobj; //if (tloex.getLabCode().compareTo(myobjex.getLabCode())==0){ // Object already been done so skip to next // continue mainobjloop; //} //else { // Object has not been done so add to the done list and keep going objdone.add(myobj); //} }} catch (Exception e){} } else { objdone.add(myobj); }*/ // Add object code to first column PdfPCell dataCell = new PdfPCell(); dataCell.setBorderWidthBottom(0); dataCell.setBorderWidthTop(0); dataCell.setBorderWidthLeft(0); dataCell.setBorderWidthRight(0); dataCell.setHorizontalAlignment(Element.ALIGN_LEFT); String objCode = null; if (myobj instanceof TridasObjectEx) objCode = ((TridasObjectEx) myobj).getMultiLevelLabCode(); // Search for elements associated with this object System.out.println("Starting search for elements associated with " + myobj.getTitle().toString()); SearchParameters sp = new SearchParameters(SearchReturnObject.ELEMENT); sp.addSearchConstraint(SearchParameterName.SAMPLEBOXID, SearchOperator.EQUALS, b.getIdentifier().getValue()); sp.addSearchConstraint(SearchParameterName.OBJECTID, SearchOperator.EQUALS, myobj.getIdentifier().getValue()); EntitySearchResource<TridasElement> resource = new EntitySearchResource<TridasElement>(sp); resource.setProperty(TellervoResourceProperties.ENTITY_REQUEST_FORMAT, TellervoRequestFormat.SUMMARY); TellervoResourceAccessDialog dialog2 = new TellervoResourceAccessDialog(resource); resource.query(); dialog2.setVisible(true); if (!dialog2.isSuccessful()) { System.out.println("oopsey doopsey. Error getting elements"); return; } //XMLDebugView.showDialog(); List<TridasElement> elements = resource.getAssociatedResult(); if (elements == null || elements.size() == 0) continue; dataCell.setPhrase(new Phrase(objCode, bodyFontLarge)); tbl.addCell(dataCell); TridasComparator numSorter = new TridasComparator(TridasComparator.Type.TITLES, TridasComparator.NullBehavior.NULLS_LAST, TridasComparator.CompareBehavior.AS_NUMBERS_THEN_STRINGS); Collections.sort(elements, numSorter); // Loop through elements Integer smpCnt = 0; ArrayList<String> numlist = new ArrayList<String>(); for (TridasElement myelem : elements) { // Add element title to string if (myelem.getTitle() != null) { String mytitle = myelem.getTitle(); numlist.add(mytitle); } // Grab associated samples and add count to running total List<TridasSample> samples = myelem.getSamples(); smpCnt += samples.size(); } // Add element names to second column dataCell.setPhrase(new Phrase(hyphenSummarize(numlist), bodyFontLarge)); tbl.addCell(dataCell); // Add sample count to third column dataCell.setPhrase(new Phrase(smpCnt.toString(), bodyFontLarge)); dataCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tbl.addCell(dataCell); sampleCountInBox += smpCnt; } if (obj.size() < 4) { // Not many objects so add some space to the table for prettiness sake headerCell.setBorder(0); headerCell.setPhrase(new Phrase(" ")); tbl.addCell(headerCell); tbl.addCell(headerCell); tbl.addCell(headerCell); } headerCell.setBorderWidthBottom(headerLineWidth); headerCell.setBorderWidthTop(headerLineWidth); headerCell.setBorderWidthLeft(0); headerCell.setBorderWidthRight(0); headerCell.setPhrase(new Phrase(" ", bodyFontLarge)); tbl.addCell(headerCell); headerCell.setPhrase(new Phrase("Grand Total", tableHeaderFontLarge)); headerCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tbl.addCell(headerCell); headerCell.setPhrase(new Phrase(sampleCountInBox.toString(), bodyFontLarge)); tbl.addCell(headerCell); // Add table to document document.add(tbl); }
From source file:org.tellervo.desktop.print.SeriesReport.java
License:Open Source License
private void getTableKey() throws DocumentException, IOException, IOException { PdfPTable mainTable = new PdfPTable(12); float[] widths = { 0.1f, 0.1f, 0.8f, 0.1f, 0.1f, 0.8f, 0.1f, 0.1f, 0.8f, 0.1f, 0.1f, 0.8f }; mainTable.setWidths(widths);//from ww w . jav a2 s . c om mainTable.setWidthPercentage(100); PdfPTable userRemarksTable = new PdfPTable(2); float[] widths2 = { 0.083f, 0.92f }; userRemarksTable.setWidths(widths2); userRemarksTable.setWidthPercentage(100); Boolean userRemarkUsed = false; DecadalModel model; model = new UnitAwareDecadalModel(s); int rows = model.getRowCount(); List<TridasRemark> masterList = null; // Loop through rows for (int row = 0; row < rows; row++) { // Loop through columns for (int col = 0; col < 11; col++) { org.tellervo.desktop.Year year = model.getYear(row, col); List<TridasRemark> remarksList = null; remarksList = s.getRemarksForYear(year); // If masterlist is still null initialize it with this remarks list if (remarksList.size() > 0 && masterList == null) masterList = remarksList; for (TridasRemark remark : remarksList) { if (!masterList.contains(remark)) masterList.add(remark); } } } for (TridasRemark remark : masterList) { PdfPCell iconCell = new PdfPCell(); PdfPCell equalsCell = new PdfPCell(); PdfPCell descriptionCell = new PdfPCell(); iconCell.setBorder(0); equalsCell.setBorder(0); descriptionCell.setBorder(0); iconCell.setVerticalAlignment(Element.ALIGN_TOP); equalsCell.setVerticalAlignment(Element.ALIGN_TOP); descriptionCell.setVerticalAlignment(Element.ALIGN_TOP); Image icon = null; String remarkStr = null; // Get actual icon (either tridas or tellervo) if (remark.isSetNormalTridas()) { remarkStr = remark.getNormalTridas().toString().toLowerCase(); remarkStr = remarkStr.replace("_", " "); icon = getTridasIcon(remark.getNormalTridas()); if (icon == null) icon = Builder.getITextImageMissingIcon(); } else if (TELLERVO.equals(remark.getNormalStd())) { remarkStr = remark.getNormal(); icon = getCorinaIcon(remark.getNormal()); if (icon == null) icon = Builder.getITextImageMissingIcon(); } else { if (!userRemarkUsed) { remarkStr = "User Remark (See Below)"; icon = Builder.getITextImageIcon("user.png"); userRemarkUsed = true; } else { // User remark and we already have a key for this so continue continue; } } iconCell.addElement(icon); equalsCell.addElement(new Phrase("=", tableBodyFont)); descriptionCell.addElement(new Phrase(WordUtils.capitalize(remarkStr), tableBodyFont)); mainTable.addCell(iconCell); mainTable.addCell(equalsCell); mainTable.addCell(descriptionCell); } // Pad out empty cells PdfPCell blankCell = new PdfPCell(); blankCell.addElement(new Phrase("")); blankCell.setBorder(0); for (int i = 0; i < 12; i++) { mainTable.addCell(blankCell); } document.add(mainTable); if (userRemarkUsed) { PdfPCell yearCell = new PdfPCell(); yearCell.setBorder(0); yearCell.setHorizontalAlignment(Element.ALIGN_RIGHT); yearCell.addElement(new Phrase("Year", tableHeaderFont)); userRemarksTable.addCell(yearCell); PdfPCell remarkCell = new PdfPCell(); remarkCell.setBorder(0); remarkCell.addElement(new Phrase("User ring remarks", tableHeaderFont)); userRemarksTable.addCell(remarkCell); for (int row = 0; row < rows; row++) { // Loop through columns for (int col = 0; col < 11; col++) { org.tellervo.desktop.Year year = model.getYear(row, col); List<TridasRemark> remarksList = null; remarksList = s.getRemarksForYear(year); for (TridasRemark remark : remarksList) { if (remark.isSetNormalTridas() || remark.isSetNormalStd()) continue; yearCell = new PdfPCell(); yearCell.setBorder(0); yearCell.setHorizontalAlignment(Element.ALIGN_RIGHT); yearCell.addElement(new Phrase(year.toString(), tableHeaderFont)); userRemarksTable.addCell(yearCell); remarkCell = new PdfPCell(); remarkCell.setBorder(0); remarkCell.addElement(new Phrase(remark.getValue(), tableBodyFont)); userRemarksTable.addCell(remarkCell); } } } document.add(userRemarksTable); } }
From source file:org.tellervo.desktop.util.labels.PDFLabelMaker.java
License:Open Source License
public void addCell(PdfPCell cell) { cell.setBorder(borderwidth); cell.setNoWrap(false);//from ww w. ja v a 2 s. c om cell.setFixedHeight(margins.getLabelHeight()); //cell.setHorizontalAlignment(Element.ALIGN_CENTER); //cell.setVerticalAlignment(Element.ALIGN_TOP); if (curX != 0) { PdfPCell gapcell = new PdfPCell(); gapcell.setBorder(borderwidth); table.addCell(gapcell); } curX++; table.addCell(cell); if (curX == nAcross) //table.completeRow(); curX = 0; }
From source file:org.unitime.timetable.export.PDFPrinter.java
License:Open Source License
@Override public void printHeader(String... fields) { iTable = new PdfPTable(fields.length - iHiddenColumns.size()); iMaxWidth = new float[fields.length]; iTable.setHeaderRows(1);/*www .j av a 2 s .c o m*/ iTable.setWidthPercentage(100); for (int idx = 0; idx < fields.length; idx++) { if (iHiddenColumns.contains(idx)) continue; String f = fields[idx]; PdfPCell cell = new PdfPCell(); cell.setBorder(Rectangle.BOTTOM); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_LEFT); Font font = PdfFont.getFont(true); cell.addElement(new Chunk(f, font)); iTable.addCell(cell); float width = 0; if (f.indexOf('\n') >= 0) { for (StringTokenizer s = new StringTokenizer(f, "\n"); s.hasMoreTokens();) width = Math.max(width, font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize())); } else width = Math.max(width, font.getBaseFont().getWidthPoint(f, font.getSize())); iMaxWidth[idx] = width; } }