1 12 13 package org.displaytag.sample.decorators; 14 15 import com.lowagie.text.BadElementException; 16 import com.lowagie.text.Cell; 17 import com.lowagie.text.Chunk; 18 import com.lowagie.text.Element; 19 import com.lowagie.text.Font; 20 import com.lowagie.text.FontFactory; 21 import com.lowagie.text.Rectangle; 22 import com.lowagie.text.Table; 23 24 25 31 public class ItextTotalWrapper extends TotalWrapperTemplate 32 implements 33 org.displaytag.render.ItextTableWriter.ItextDecorator 34 { 35 36 39 private Table table; 40 41 44 private Font font; 45 46 51 public void setTable(Table table) 52 { 53 this.table = table; 54 } 55 56 61 public void setFont(Font font) 62 { 63 this.font = font; 64 } 65 66 69 public String startRow() 70 { 71 this.table.setDefaultCellBorder(Rectangle.BOTTOM); 72 return null; 73 } 74 75 80 protected void writeCityTotal(String city, double total) 81 { 82 this.writeTotal(city, total); 83 } 84 85 89 protected void writeGrandTotal(double total) 90 { 91 this.writeTotal("Grand", total); 92 } 93 94 99 private void writeTotal(String value, double total) 100 { 101 if (assertRequiredState()) 102 { 103 try 104 { 105 this.font = FontFactory.getFont(this.font.getFamilyname(), this.font.size(), Font.BOLD, this.font 106 .color()); 107 table.addCell(this.getCell("")); 108 table.addCell(this.getCell("")); 109 table.addCell(this.getCell("-------------")); 110 table.addCell(this.getCell("")); 111 table.addCell(this.getCell("")); 113 table.addCell(this.getCell(value + " Total:")); 114 table.addCell(this.getCell(total + "")); 115 table.addCell(this.getCell("")); 116 } 117 catch (BadElementException e) 118 { 119 } 120 } 121 } 122 123 129 private Cell getCell(String value) throws BadElementException 130 { 131 Cell cell = new Cell(new Chunk(value, this.font)); 132 cell.setLeading(8); 133 cell.setHorizontalAlignment(Element.ALIGN_LEFT); 134 return cell; 135 } 136 137 141 private boolean assertRequiredState() 142 { 143 return this.table != null && this.font != null; 144 } 145 } 146 | Popular Tags |