List of usage examples for com.itextpdf.text Phrase Phrase
private Phrase(final boolean dummy)
From source file:drugsupplychain.neu.css.gui.common.distributor.GenerateBillPDF.java
/** * create table/*from w w w .j a va2 s.c o m*/ * @param subCatPart * @throws BadElementException */ private static int createTable(Section subCatPart, Order order) throws BadElementException { PdfPTable table = new PdfPTable(3); PdfPCell c1 = new PdfPCell(new Phrase("Order Item ID")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Quantity")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Value")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); int totalPrice = 0; for (OrderItem orderItem : order.getOrderItemList()) { table.addCell(orderItem.getProduct().getBarcode()); table.addCell(String.valueOf(orderItem.getQuantity())); table.addCell(String.valueOf(orderItem.getQuantity() * orderItem.getProduct().getPrice())); totalPrice = totalPrice + (orderItem.getQuantity() * orderItem.getProduct().getPrice()); } subCatPart.add(table); return totalPrice; }
From source file:edu.bedelias.utils.ReportsService.java
private static void addStudentGrid(java.util.List<Student> students, Document document) throws DocumentException { Paragraph results = new Paragraph(); // Add a table PdfPTable table = new PdfPTable(3); PdfPCell c1 = new PdfPCell(new Phrase("CI Estudiante")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);/*from ww w .j a va 2s. c o m*/ c1 = new PdfPCell(new Phrase("Nombre Completo")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Resultado")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (Student s : students) { table.addCell(s.getCedula()); table.addCell(s.getName()); table.addCell(""); } results.add(table); // Now add all this to the document document.add(results); }
From source file:edu.esprit.pi.gui.internalframes.PDFwithItextInternalFrame.java
public void createTable(Section subCatPart) throws BadElementException { PdfPTable table = new PdfPTable(3); PdfPCell c1 = new PdfPCell(new Phrase("Client")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);//from ww w . ja va2 s.c o m c1 = new PdfPCell(new Phrase("Article")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Quantit")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); // Rcupration de la liste des articles. java.util.List<Article> listArticles = new ArticleDAO().findAll(); // remplissare des cellules de la liste for (Article article : listArticles) { table.addCell("" + article.getClient().getNom()); table.addCell("" + article.getStock().getLibelle()); table.addCell("" + article.getQuantite()); } subCatPart.add(table); }
From source file:Ekon.zamestnanecToPDF.java
private static void createTable(Section subCatPart) throws BadElementException { PdfPTable table = new PdfPTable(3); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("Mesic")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);//from w ww . j ava2 s . co m c1 = new PdfPCell(new Phrase("Pocet odpracovanych hodin hodin")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); subCatPart.add(table); }
From source file:EplanPrinter.PDFPrint.java
License:Open Source License
public String insertStamp(String loc, float x, float y, int width, int height, int set, String date, int pageNum, int masterHeight, int masterWidth, String projNo) throws BadElementException, MalformedURLException, IOException, DocumentException { Image image = Image.getInstance(loc); float[] scalar = scale(x, y, width, height, masterHeight, masterWidth, pageNum); float[] trans = translate(x, y, r[pageNum - 1].getHeight(), r[pageNum - 1].getWidth(), masterHeight, masterWidth, pageNum);// w ww. jav a 2s .co m float[] f = commentTrans(x, y, masterHeight, masterWidth, pageNum); float shift = 0; /* Addition. ftorres - 7/22/2015 - Added to account for rotated pages * with the origin (0,0) not set to the bottom-left of the page. [1400] */ trans = translateRotation(trans[0], trans[1], pageNum); if (set == 1) { float m = image.getPlainHeight(); float pageChunk = r[pageNum - 1].getHeight() / 10; shift = r[pageNum - 1].getHeight() / 100; scalar[1] = (int) (pageChunk); scalar[0] = (int) (image.getPlainWidth() * pageChunk) / image.getPlainHeight(); trans[0] = (int) (0 + (pageChunk * widthScalar)); trans[1] = (int) (r[pageNum - 1].getHeight() - (pageChunk * heightScalar) - (shift * (heightScalar + 2))); heightScalar = heightScalar + 1; if (heightScalar == 8) { heightScalar = 0; widthScalar = widthScalar + 2; } } if (set == 1) { image.setAbsolutePosition(trans[0] + shift, trans[1] - scalar[1]); image.scaleAbsoluteHeight(scalar[1]); image.scaleAbsoluteWidth(scalar[0]); image.setRotationDegrees(rot); } else { //swap stamp dimensions for rotated drawings if (rot > 0) { image.setAbsolutePosition(trans[0] - 2 * scalar[1], trans[1] - 2 * scalar[0]); } else { image.setAbsolutePosition(trans[0], trans[1] - 2 * scalar[1]); } image.scaleAbsoluteHeight(scalar[1] * 2); image.scaleAbsoluteWidth(scalar[0] * 2); image.setRotationDegrees(rot); } PdfContentByte fg = pds.getOverContent(pageNum); fg.addImage(image); //Added by tmittelstadt on 09/21/2012 for ticket #698 //draws a box around the date fg.setColorFill(BaseColor.WHITE); fg.setLineWidth(0f); //dmoody removed box. ticket 900 /*fg.moveTo(trans[0], trans[1] - scalar[1] * 2); fg.lineTo(trans[0], trans[1] - scalar[1] * 2 - 10); fg.lineTo(trans[0] + scalar[0] * 2, trans[1] - scalar[1] * 2 - 10); fg.lineTo(trans[0] + scalar[0] * 2, trans[1] - scalar[1] * 2); fg.lineTo(trans[0], trans[1] - scalar[1] * 2);*/ fg.closePathFillStroke(); fg.fill(); //adds the date the stamp was added to the document to the pdf Phrase p = new Phrase(date); p.getFont().setColor(BaseColor.BLACK); //Modification zreeve 10/11/2012. set font size to 11. p.getFont().setSize(9f); //p.getChunks().get(0).setAnnotation(PdfAnnotation.createText(pds.getWriter(), new Rectangle(trans[0],trans[1], trans[0]+5f, trans[1]+5f), id, comment, true, id)); ColumnText.showTextAligned(fg, Element.ALIGN_CENTER, p, (float) (trans[0]), (float) (trans[1] - scalar[1] * 2 - 12), 0); Phrase pn = new Phrase("#[" + projNo + "]"); pn.getFont().setColor(BaseColor.BLACK); pn.getFont().setSize(10f); pn.getFont().setStyle("bold"); ColumnText.showTextAligned(fg, Element.ALIGN_CENTER, pn, (float) (trans[0]), (float) (trans[1] - scalar[1] * 2 - 22), 0); return ""; }
From source file:EplanPrinter.PDFPrint.java
License:Open Source License
public String insertComment(String sx, String sy, String id, String deptValue, String userInit, String comment, int pageNum, int masterHeight, int masterWidth, int pinned, int customFontSize) throws DocumentException, IOException { float ratio = getRatio(masterHeight, masterWidth, pageNum); float x = Float.parseFloat(sx); float y = Float.parseFloat(sy); float[] f = commentTrans(x, y, masterHeight, masterWidth, pageNum); PdfGState gs1 = new PdfGState(); gs1.setFillOpacity(1);/*from www . ja v a 2 s . co m*/ if (customFontSize > 0) fontSize = customFontSize; PdfContentByte fg = pds.getOverContent(pageNum); fg.setGState(gs1); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); float[] trans = translate(x, y, r[pageNum - 1].getHeight(), r[pageNum - 1].getWidth(), masterHeight, masterWidth, pageNum); // comment tag image (width=35pts, height=8pts) float[] scalar = scale(trans[0], trans[1], 35, 8, masterHeight, masterWidth, pageNum); /* Addition. ftorres - 7/21/2015 - Added to account for rotated pages * with the origin (0,0) not set to the bottom-left of the page. [1400] */ float coords[] = translateRotation(trans[0], trans[1], pageNum); coords = checkBounds(coords[0], coords[1], pageNum); /* Addition. ftorres - 10/20/2015 - If the comment was pinned in EPC, then * render the comment inside a comment box. */ if (pinned == 1) { insertPinnedComment(coords[0], coords[1], id + " - " + deptValue + " (" + userInit + ")", comment, pageNum, masterHeight, masterWidth); // Add the pinned comment text to page annotation -Jon Changkachith 11/24/2015 Rectangle rect = new Rectangle(0, 0, 0, 0); PdfAnnotation annotation = PdfAnnotation.createText(pds.getWriter(), rect, id + " - " + deptValue + " (" + userInit + ")", cleanupComment(comment), true, id); pds.addAnnotation(annotation, pds.getWriter().getCurrentPageNumber()); } else { Image image = Image.getInstance(commentIMGPath); image.setAbsolutePosition(coords[0] + (scalar[0] * (id.length() / 5f)), coords[1]); /* * Commented out by Jon Changkachith 12/09/2015 because it was throwing * DocumentException with the message "The image must have absolute positioning." image.scaleAbsoluteHeight(1); image.scaleAbsoluteWidth(1); */ image.scalePercent(ratio); //Added to fix DocumentException "The image must have absolute positioning." Jon Changkachith 12/09/2015 image.setAnnotation(new Annotation(id + " - " + deptValue + " (" + userInit + ")", cleanupComment(comment), 0, 0, 0, 0)); fg.addImage(image); } fg.setLineWidth(.5f * ratio); fg.setColorStroke(new BaseColor(Color.decode("0x6E2405").getRGB())); fg.setColorFill(new BaseColor(Color.decode("0x6E2405").getRGB())); float tHeight = scalar[1]; float tWidth = 0; if (id.length() > 3) { tWidth = (scalar[0] * (id.length() / 5f)); } else { tWidth = (scalar[0]); } fg.moveTo(coords[0], coords[1]); fg.lineTo(coords[0] + (10f * ratio), coords[1] - (tHeight / 2)); fg.lineTo(coords[0] + tWidth, coords[1] - (tHeight / 2)); fg.lineTo(coords[0] + tWidth, coords[1] + (tHeight / 2)); fg.lineTo(coords[0] + (10f * ratio), coords[1] + (tHeight / 2)); fg.lineTo(coords[0], coords[1]); fg.closePathFillStroke(); fg.fill(); // Comment number that goes on the comment tag image Phrase p = new Phrase(id); p.getFont().setColor(BaseColor.WHITE); p.getFont().setSize(8f * ratio); //comment number font size = 8f //p.getChunks().get(0).setAnnotation(PdfAnnotation.createText(pds.getWriter(), new Rectangle(trans[0],trans[1], trans[0]+5f, trans[1]+5f), id, comment, true, id)); float fs[] = translateRotation(f[0], f[1], pageNum); fs = checkBounds(fs[0], fs[1], pageNum); ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, p, (float) (fs[0] + (9 * ratio)), (float) (fs[1] - (3 * ratio)), 0); return ""; }
From source file:es.clinica.veterinaria.albaranes.AlbaranPdf.java
public PdfPTable createTable() throws DocumentException { // a table with three columns int iva = 0, iva2 = 0; DecimalFormat df = new DecimalFormat("0.00"); PdfPTable table = new PdfPTable(5); table.setTotalWidth(new float[] { 55, 150, 200, 70, 70 }); table.setLockedWidth(true);//from w w w .j a v a 2 s . c o m // the cell object // we add a cell with colspan 3 PdfPCell cell = new PdfPCell(new Phrase("CANT.")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingTop(5); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("CONCEPTO")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingTop(5); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("DESCRIPCIN")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingTop(5); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("PRECIO")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingTop(5); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("IMPORTE")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingTop(5); cell.setPaddingBottom(5); table.addCell(cell); HashSet<VentaLinea> listVenta = getVenta().getVenta_lineas(); for (VentaLinea vlinea : listVenta) { if (vlinea.getTipo() == 1) { if (vlinea.getProducto().getIva() != null) { iva2 = vlinea.getProducto().getIva().getValor(); // System.out.println("IVA: " +iva2); } } else if (vlinea.getTipo() == 2) { if (vlinea.getServicio().getIva() != null) { iva2 = vlinea.getServicio().getIva().getValor(); // System.out.println("IVA: " +iva2); } } //Para hacer el calculo nos vamos a quedar con el IVA mayor if (iva < iva2) { iva = iva2; } cell = new PdfPCell(new Phrase(vlinea.getCantidad() + "", small)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPaddingBottom(5); table.addCell(cell); table.addCell(new PdfPCell(new Phrase(vlinea.getNombre(), small))); String descripcion = vlinea.getDescripcion(); if (descripcion == null || "null".equals(descripcion)) { table.addCell(new PdfPCell(new Phrase(" ", small))); // System.out.println("null:" + descripcion); } else { table.addCell(new PdfPCell(new Phrase(descripcion, small))); // System.out.println("!null:" + descripcion); } cell = new PdfPCell(new Phrase(df.format(vlinea.getPvp()) + " ", small)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase(df.format(vlinea.getPreciototalNoIVA()) + " ", small)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setPaddingBottom(5); table.addCell(cell); } cell = new PdfPCell(new Phrase(" ")); cell.setColspan(1); cell.setBorderWidthBottom(0); cell.setBorderWidthLeft(0); cell.setBorder(0); cell.setBorderColorLeft(BaseColor.WHITE); cell.setBorderColorBottom(BaseColor.WHITE); cell.setPaddingBottom(5); table.addCell(cell); table.addCell(cell); table.addCell(cell); cell = new PdfPCell(new Phrase("SUMA")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase(df.format(venta.getCostesinIva()) + " ")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setPaddingBottom(5); table.addCell(cell); /* IVA */ cell = new PdfPCell(new Phrase(" ")); cell.setColspan(1); cell.setBorderWidthBottom(0); cell.setBorderWidthLeft(0); cell.setBorder(0); cell.setBorderColorLeft(BaseColor.WHITE); cell.setBorderColorBottom(BaseColor.WHITE); cell.setPaddingBottom(5); table.addCell(cell); table.addCell(cell); table.addCell(cell); // float costetotal = (float) (venta.getCoste() * (1+(iva*0.01))); cell = new PdfPCell(new Phrase("IVA " + iva + "%")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase(df.format(venta.getIvas()) + " ")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setPaddingBottom(5); table.addCell(cell); /* COSTE TOTAL */ cell = new PdfPCell(new Phrase(" ")); cell.setColspan(1); cell.setBorderWidthBottom(0); cell.setBorderWidthLeft(0); cell.setBorder(0); cell.setBorderColorLeft(BaseColor.WHITE); cell.setBorderColorBottom(BaseColor.WHITE); cell.setPaddingBottom(5); table.addCell(cell); table.addCell(cell); table.addCell(cell); cell = new PdfPCell(new Phrase("TOTAL")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase(df.format(venta.getCoste()) + " ")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setPaddingBottom(5); table.addCell(cell); return table; }
From source file:es.clinica.veterinaria.facturas.FacturaPdf.java
public PdfPTable createTable() throws DocumentException { // a table with three columns int iva = 0, iva2 = 0; DecimalFormat df = new DecimalFormat("0.00"); PdfPTable table = new PdfPTable(6); table.setTotalWidth(new float[] { 50, 65, 150, 150, 65, 70 }); table.setLockedWidth(true);/*from w w w . j ava2 s .co m*/ // the cell object // we add a cell with colspan 3 PdfPCell cell = new PdfPCell(new Phrase("CANT.")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingTop(5); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("FECHA")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingTop(5); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("CONCEPTO")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingTop(5); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("DESCRIPCIN")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingTop(5); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("PRECIO")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingTop(5); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("IMPORTE")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingTop(5); cell.setPaddingBottom(5); table.addCell(cell); HashSet<Venta> ventas = this.getFactura().getVentas(); for (Venta venta : ventas) { HashSet<VentaLinea> listVenta = venta.getVenta_lineas(); for (VentaLinea vlinea : listVenta) { if (vlinea.getTipo() == 1) { if (vlinea.getProducto().getIva() != null) { iva2 = vlinea.getProducto().getIva().getValor(); // System.out.println("IVA: " +iva2); } } else if (vlinea.getTipo() == 2) { if (vlinea.getServicio().getIva() != null) { iva2 = vlinea.getServicio().getIva().getValor(); // System.out.println("IVA: " +iva2); } } //Para hacer el calculo nos vamos a quedar con el IVA mayor if (iva < iva2) { iva = iva2; } cell = new PdfPCell(new Phrase(vlinea.getCantidad() + "", small)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell( new Phrase(new SimpleDateFormat("dd-MM-yyyy").format(vlinea.getFecha()), small)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPaddingBottom(5); table.addCell(cell); if (vlinea.getTipo() == 2) { //Servicio table.addCell(new PdfPCell(new Phrase(vlinea.getNombre(), small))); String descripcion = vlinea.getDescripcion(); if (descripcion == null || "null".equals(descripcion)) { table.addCell(new PdfPCell(new Phrase(" ", small))); // System.out.println("null:" + descripcion); } else { table.addCell(new PdfPCell(new Phrase(descripcion, small))); // System.out.println("!null:" + descripcion); } } else if (vlinea.getTipo() == 1) { //Producto //Si el producto es Tratamiento if (vlinea.getProducto().getFamilia().isTratamiento()) { table.addCell(new PdfPCell(new Phrase("Tratamiento", small))); table.addCell(new PdfPCell(new Phrase("", small))); } else { table.addCell(new PdfPCell(new Phrase(vlinea.getNombre(), small))); String descripcion = vlinea.getDescripcion(); if (descripcion == null || "null".equals(descripcion)) { table.addCell(new PdfPCell(new Phrase(" ", small))); // System.out.println("null:" + descripcion); } else { table.addCell(new PdfPCell(new Phrase(descripcion, small))); // System.out.println("!null:" + descripcion); } } } cell = new PdfPCell(new Phrase(df.format(vlinea.getPvp()) + " ", small)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase(df.format(vlinea.getPreciototalNoIVA()) + " ", small)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setPaddingBottom(5); table.addCell(cell); } } cell = new PdfPCell(new Phrase(" ")); cell.setColspan(1); cell.setBorderWidthBottom(0); cell.setBorderWidthLeft(0); cell.setBorder(0); cell.setBorderColorLeft(BaseColor.WHITE); cell.setBorderColorBottom(BaseColor.WHITE); cell.setPaddingBottom(5); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); cell = new PdfPCell(new Phrase("SUMA")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase(df.format(factura.getCoste()) + " ", smallBold)); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setPaddingBottom(5); table.addCell(cell); /* IVA */ cell = new PdfPCell(new Phrase(" ")); cell.setColspan(1); cell.setBorderWidthBottom(0); cell.setBorderWidthLeft(0); cell.setBorder(0); cell.setBorderColorLeft(BaseColor.WHITE); cell.setBorderColorBottom(BaseColor.WHITE); cell.setPaddingBottom(5); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); float costetotal = (float) (factura.getCostetotal()); cell = new PdfPCell(new Phrase("IVA " + iva + "%")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase(df.format(factura.getIvas()) + " ", smallBold)); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setPaddingBottom(5); table.addCell(cell); /* COSTE TOTAL */ cell = new PdfPCell(new Phrase(" ")); cell.setColspan(1); cell.setBorderWidthBottom(0); cell.setBorderWidthLeft(0); cell.setBorder(0); cell.setBorderColorLeft(BaseColor.WHITE); cell.setBorderColorBottom(BaseColor.WHITE); cell.setPaddingBottom(5); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); cell = new PdfPCell(new Phrase("TOTAL")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase(df.format(costetotal) + " ", smallBold)); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setPaddingBottom(5); table.addCell(cell); return table; }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java
License:Open Source License
private void buildSectionGoalDelegations(Section section) { String sectionIntro = "Stakeholders interact with others to achieve some of their goals by means of goal delegations. Goal delegations are graphically represented as a relation that starts from a delegator actor to a delegatee actor (following the direction of the arrow), having a rounded corner rectangle representing the goal being delegated. Security needs are graphically specified as labels that appear below the delegated goal " + socialDiagRef() + "."; section.add(createParagraph(sectionIntro)); List<Actor> selActor = getGoalDelegationsActors(); List<Paragraph> phrases = new ArrayList<Paragraph>(); for (Actor a : selActor) { for (Delegation d : a.getOutgoingDelegations()) { Paragraph par = createParagraph("%b" + a.getName() + "% delegates goal %i" + d.getSourceGoal().getName() + "% to %b" + d.getTarget().getName() + "%."); List<String> secNeeds = buildDelegationSecNeedList(d); if (secNeeds.size() > 0) { par.add(new Phrase(" The following security needs apply to this delegation:")); par.add(Chunk.NEWLINE);/*from w w w .ja v a2 s . c o m*/ par.add(new Phrase(separateListOfString(secNeeds) + ".")); } phrases.add(par); } /* * StringBuilder sbInc = new StringBuilder(); sbInc.append("%b" + * a.getName() + "% is delegated by "); * * int incCount = 0; for (Delegation d : a.getIncomingDelegations()) * { if (incCount > 0) sbInc.append(", and is delegated by "); * sbInc.append("%i" + d.getSource().getName() + "% goal %i" + * d.getSourceGoal().getName() + "%"); List<String> secNeed1 = * buildSecNeedString(d, false, 'i'); List<String> secNeed2 = * buildSecNeedString(d, true, 'i'); * * if (secNeed2.size() > 0) { switch (secNeed2.size()) { case 1: * sbInc.append(" and is required to comply with the " + * separateListOfString(secNeed2) + " security need"); break; * default: sbInc.append(" and is required to comply with the " + * separateListOfString(secNeed2) + " security needs"); break; } } * if (secNeed1.size() > 0) { switch (secNeed1.size()) { case 1: * sbInc.append(" and requires it to comply with the " + * separateListOfString(secNeed1) + " security need"); break; * default: sbInc.append(" and requires it to comply with the " + * separateListOfString(secNeed1) + " security needs"); break; } * * } List<String> parmSecNeed = buildParamterizedSecNeedString(d, * 'i'); if (parmSecNeed.size() > 0) { * sbInc.append(" and is required for a level of " + * separateListOfString(parmSecNeed)); } if (secNeed1.size() == 0 && * secNeed2.size() == 0 && parmSecNeed.size() == 0) { * sbInc.append(": no security need is speccified"); } incCount++; } * * * StringBuilder sbOut = new StringBuilder(); int outCount = 0; for * (Delegation d : a.getOutgoingDelegations()) { if (outCount > 0) * sbOut.append(", and delegates to "); sbOut.append("%i" + * d.getTarget().getName() + "% goal %i" + * d.getSourceGoal().getName() + "%"); List<String> secNeed1 = * buildSecNeedString(d, true, 'i'); List<String> secNeed2 = * buildSecNeedString(d, false, 'i'); * * if (secNeed1.size() > 0) { switch (secNeed1.size()) { case 1: * sbOut.append(" and requires it to comply with the " + * separateListOfString(secNeed1) + " security need"); break; * default: sbOut.append(" and requires it to comply with the " + * separateListOfString(secNeed1) + " security needs"); break; } } * if (secNeed2.size() > 0) { switch (secNeed2.size()) { case 1: * sbOut.append(" and is required to comply with the " + * separateListOfString(secNeed2) + " security need"); break; * default: sbOut.append(" and is required to comply with the " + * separateListOfString(secNeed2) + " security needs"); break; } } * List<String> parmSecNeed = buildParamterizedSecNeedString(d, * 'i'); if (parmSecNeed.size() > 0) { * sbOut.append(" and requires a level of " + * separateListOfString(parmSecNeed)); } if (secNeed1.size() == 0 && * secNeed2.size() == 0 && parmSecNeed.size() == 0) { * sbOut.append(": no security need is speccified"); } * * outCount++; } * * StringBuilder sb = new StringBuilder(); if (incCount > 0) { if * (outCount > 0) { sb.append(sbInc.toString() + * " while it delegates to " + sbOut.toString() + "."); } else { * sb.append(sbInc.toString() + "."); } } else { if (outCount > 0) { * sb.append("%b" + a.getName() + "% delegates to " + * sbOut.toString() + "."); } } if (sb.length() > 0) { * phrases.add(createParagraph(sb.toString())); } */ } if (phrases.size() != 0) { sectionIntro = "The following description enlists all the delegations from one role/agent to the others. When applicable, security needs expressed over the delegations are enumerated."; section.add(createParagraph(sectionIntro)); String t = "In the " + getProjectName() + " project" + socialDiagRef() + ", we have the following goal delegations:"; section.add(createParagraph(t)); section.add(listParagraphs(phrases)); section.add(createParagraph(ftc.getTable(FigureConstant.DELEGATION_TABLE) + " summarises %igoal delegations%, together with the eventual %isecurity needs%, and the possible %ipreconditions% and %ipostconditions%, which determine when the delegation can take place, and the expected outcome of the delegation, respectively.")); List<String[]> headers = new ArrayList<String[]>(); headers.add(new String[] { "Delegator" }); headers.add(new String[] { "Goal" }); headers.add(new String[] { "Delegatee" }); headers.add(new String[] { "Security", "Needs" }); headers.add(new String[] { "Delegation", "Description" }); headers.add(new String[] { "Pre-", "conditions" }); headers.add(new String[] { "Post-", "conditions" }); PdfPTable table = createTable(headers); for (Actor a : selActor) { if (a.getOutgoingDelegations().size() > 0) { PdfPCell cell = getContentCell(); cell.setPhrase(new Phrase(a.getName(), TABLE_CONTENT)); cell.setRowspan(a.getOutgoingDelegations().size()); table.addCell(cell); for (Delegation d : a.getOutgoingDelegations()) { table.addCell(getContentCell(d.getSourceGoal().getName())); table.addCell(getContentCell(d.getTarget().getName())); List<String> sn = buildDelegationSecNeedList(d); Phrase p = null; for (int i = 0; i < sn.size(); i++) { if (i == 0) p = new Phrase(sn.get(i), TABLE_CONTENT_SMALL); else { p.add(Chunk.NEWLINE); p.add(new Phrase(sn.get(i), TABLE_CONTENT_SMALL)); } } PdfPCell c = getContentCell(); c.addElement(p); table.addCell(c); table.addCell(getContentCell(d.getDescription())); table.addCell(getContentCell(d.getPreConditions())); table.addCell(getContentCell(d.getPostConditions())); } } } addTableCaption(table, ftc.getTable(FigureConstant.DELEGATION_TABLE) + " - Goal Delegations and Security Needs"); section.add(table); table.setComplete(true); } else { section.add(createParagraph("In the " + getProjectName() + " project there are no goal delegations taking place for the given agents/roles.")); } section.setComplete(true); }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java
License:Open Source License
private void buildSectionDocumentProvisions(Section section) { String sectionIntro = "Stakeholders exchange information by means of documents with other stakeholders. The following description enlists all the provisions from one role/agent representing the stakeholder, to other roles/agents. %iDocument provision% is represented as an arrow from the provider to the providee, with a rectangle representing the document. The security needs expressed over the provisions are described, if applicable. Security needs are specified with the help of labels that appear below the document."; section.add(createParagraph(sectionIntro)); List<Actor> selActor = getDocumentProvisionsActors(); List<Paragraph> phrases = new ArrayList<Paragraph>(); for (Actor a : selActor) { for (Provision p : a.getOutgoingProvisions()) { Paragraph par = createParagraph("%b" + a.getName() + "% provides document %i" + p.getSourceResource().getName() + "% to %b" + p.getTarget().getName() + "%."); List<String> secNeeds = buildProvisionSecNeedList(p); if (secNeeds.size() > 0) { par.add(new Phrase(" The following security needs apply to this provision:")); par.add(Chunk.NEWLINE);//from w ww. ja va 2 s.co m par.add(new Phrase(separateListOfString(secNeeds) + ".")); } phrases.add(par); } } /* * for (Actor a : selActor) { StringBuilder sbInc = new StringBuilder(); * sbInc.append("%b" + a.getName() + "% is provided by "); int incCount * = 0; for (Provision p : a.getIncomingProvisions()) { if (incCount > * 0) sbInc.append(", and is provided by "); sbInc.append("%i" + * p.getSource().getName() + "% document %i" + * p.getSourceResource().getName() + "%"); if (p.isIntegrity()) { * sbInc.append(" and requires %b" + p.getSource().getName() + * "% to ensure %iintegrity of transmission% over the provision of this document" * ); } * * incCount++; } * * StringBuilder sbOut = new StringBuilder(); int outCount = 0; for * (Provision p : a.getOutgoingProvisions()) { if (outCount > 0) * sbOut.append(", and it provides to "); sbOut.append("%i" + * p.getTarget().getName() + "% document %i" + * p.getSourceResource().getName() + "%"); if (p.isIntegrity()) { * sbInc.append(" and requires %iAvailability% level of " + * p.getAvailabilityValue() + "%"); } outCount++; } * * StringBuilder sb = new StringBuilder(); if (incCount > 0) { if * (outCount > 0) { sb.append(sbInc.toString() + * " while it provides to " + sbOut.toString() + "."); } else { * sb.append(sbInc.toString() + "."); } } else { if (outCount > 0) { * sb.append("%b" + a.getName() + "% provides to " + sbOut.toString() + * "."); } } * * if (sb.length() > 0) { phrases.add(createParagraph(sb.toString())); } * } */ if (phrases.size() != 0) { String s = "In the " + getProjectName() + " project " + socialDiagRef() + ", we have the following %idocument provisions%:"; section.add(createParagraph(s)); section.add(listParagraphs(phrases)); section.add(createParagraph(ftc.getTable(FigureConstant.PROVISION_TABLE) + " summarises the %idocument provisions% for the " + getProjectName() + " project.")); List<String[]> headers = new ArrayList<String[]>(); headers.add(new String[] { "Providor" }); headers.add(new String[] { "Document" }); headers.add(new String[] { "Providee" }); headers.add(new String[] { "Security", "Needs" }); headers.add(new String[] { "Provision", "Descr." }); PdfPTable table = createTable(headers); for (Actor a : selActor) { if (a.getOutgoingProvisions().size() > 0) { PdfPCell cell = getContentCell(); cell.setPhrase(new Phrase(a.getName(), TABLE_CONTENT)); cell.setRowspan(a.getOutgoingProvisions().size()); table.addCell(cell); for (Provision p : a.getOutgoingProvisions()) { table.addCell(getContentCell(p.getSourceResource().getName())); table.addCell(getContentCell(p.getTarget().getName())); List<String> sn = buildProvisionSecNeedList(p); Phrase pr = null; for (int i = 0; i < sn.size(); i++) { if (i == 0) pr = new Phrase(sn.get(i), TABLE_CONTENT_SMALL); else { pr.add(Chunk.NEWLINE); pr.add(new Phrase(sn.get(i), TABLE_CONTENT_SMALL)); } } PdfPCell c = getContentCell(); c.addElement(pr); table.addCell(c); table.addCell(getContentCell(p.getDescription())); } } } addTableCaption(table, ftc.getTable(FigureConstant.PROVISION_TABLE) + " - Document Provisions"); section.add(table); table.setComplete(true); } else { section.add(createParagraph("In the " + getProjectName() + " project there are no document provisions taking place for the given agents/roles.")); } section.setComplete(true); }