List of usage examples for com.lowagie.text Cell setVerticalAlignment
public void setVerticalAlignment(String alignment)
From source file:se.idega.idegaweb.commune.school.report.business.ReportPDFWriter.java
License:Open Source License
/** * Builds the report column headers.// w ww. j av a 2 s . c om */ protected void buildColumnHeaders(Table table) throws BadElementException { Header[] headers = this._reportModel.getColumnHeaders(); com.lowagie.text.Cell cell = new com.lowagie.text.Cell(); cell.setRowspan(2); table.addCell(cell, new Point(0, 0)); int column = 1; for (int i = 0; i < headers.length; i++) { Header header = headers[i]; Header[] children = header.getChildren(); if (children == null) { String s = null; if (header.getHeaderType() == Header.HEADERTYPE_COLUMN_NONLOCALIZED_HEADER) { s = header.getLocalizationKey(); } else { s = localize(header.getLocalizationKey(), header.getLocalizationKey()); } cell = new com.lowagie.text.Cell(new Phrase(s, this._normalFont)); cell.setRowspan(2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); table.addCell(cell, new Point(0, column)); setColSize(s, column, true); column++; } else { String s = null; if (header.getHeaderType() == Header.HEADERTYPE_COLUMN_NONLOCALIZED_HEADER) { s = header.getLocalizationKey(); } else { s = localize(header.getLocalizationKey(), header.getLocalizationKey()); } cell = new com.lowagie.text.Cell(new Phrase(s, this._normalFont)); cell.setColspan(children.length); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell, new Point(0, column)); if (children.length == 1) { setColSize(s, column, false); } for (int j = 0; j < children.length; j++) { Header child = children[j]; s = null; if (child.getHeaderType() == Header.HEADERTYPE_COLUMN_NONLOCALIZED_HEADER) { s = child.getLocalizationKey(); } else { s = localize(child.getLocalizationKey(), child.getLocalizationKey()); } cell = new com.lowagie.text.Cell(new Phrase(s, this._normalFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setNoWrap(true); table.addCell(cell, new Point(1, column + j)); setColSize(s, column + j, false); } column += children.length; } } }
From source file:se.idega.idegaweb.commune.school.report.business.ReportPDFWriter.java
License:Open Source License
/** * Builds the report row headers.//from w ww. jav a 2s.c om */ protected void buildRowHeaders(Table table) throws BadElementException { Header[] headers = this._reportModel.getRowHeaders(); int row = 2; String s = null; com.lowagie.text.Cell cell = null; for (int i = 0; i < headers.length; i++) { Header header = headers[i]; Header[] children = header.getChildren(); if (children == null) { int headerType = header.getHeaderType(); if (headerType == Header.HEADERTYPE_ROW_SPACER) { s = " "; } else if (headerType == Header.HEADERTYPE_ROW_NONLOCALIZED_HEADER || header.getHeaderType() == Header.HEADERTYPE_ROW_NONLOCALIZED_NORMAL) { s = header.getLocalizationKey(); } else { s = localize(header.getLocalizationKey(), header.getLocalizationKey()); } cell = new com.lowagie.text.Cell(new Phrase(s, this._boldFont)); if (headerType == Header.HEADERTYPE_ROW_LABEL || headerType == Header.HEADERTYPE_ROW_SPACER) { cell.setColspan(this._reportModel.getColumnSize() + 1); } cell.setNoWrap(true); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); if (headerType == Header.HEADERTYPE_ROW_LABEL) { cell.setBackgroundColor(new java.awt.Color(0xe0, 0xe0, 0xe0)); } table.addCell(cell, new Point(row, 0)); setColSize(s, 0, false); row++; } else { if (header.getHeaderType() == Header.HEADERTYPE_ROW_NONLOCALIZED_HEADER || header.getHeaderType() == Header.HEADERTYPE_ROW_NONLOCALIZED_NORMAL) { s = header.getLocalizationKey(); } else { s = localize(header.getLocalizationKey(), header.getLocalizationKey()); } cell = new com.lowagie.text.Cell(new Phrase(s, this._normalFont)); cell.setColspan(this._reportModel.getColumnSize() + 1); cell.setLeading(16); table.addCell(cell, new Point(row, 0)); row++; for (int j = 0; j < children.length; j++) { Header child = children[j]; int headerType = child.getHeaderType(); if (headerType == Header.HEADERTYPE_ROW_SPACER) { s = " "; } else if (headerType == Header.HEADERTYPE_ROW_NONLOCALIZED_HEADER || headerType == Header.HEADERTYPE_ROW_NONLOCALIZED_NORMAL) { s = child.getLocalizationKey(); } else { s = localize(child.getLocalizationKey(), child.getLocalizationKey()); } cell = new com.lowagie.text.Cell(new Phrase(s, this._boldFont)); if (headerType == Header.HEADERTYPE_ROW_LABEL || headerType == Header.HEADERTYPE_ROW_SPACER) { cell.setColspan(this._reportModel.getColumnSize() + 1); } cell.setNoWrap(true); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); if (headerType == Header.HEADERTYPE_ROW_LABEL) { cell.setBackgroundColor(new java.awt.Color(0xe0, 0xe0, 0xe0)); } table.addCell(cell, row, 0); setColSize(s, 0, false); row++; } } } }
From source file:se.idega.idegaweb.commune.school.report.business.ReportPDFWriter.java
License:Open Source License
/** * Builds the report cells./*from w w w . j a v a 2 s . c o m*/ */ protected void buildReportCells(Table table) throws BadElementException { int cellRow = 0; int tableRow = 2; Header[] rowHeaders = this._reportModel.getRowHeaders(); NumberFormat formatter = NumberFormat.getNumberInstance(); formatter.setMaximumFractionDigits(1); for (int i = 0; i < rowHeaders.length; i++) { int rowCount = 0; Header header = rowHeaders[i]; Header[] children = header.getChildren(); boolean hasChildren = false; if (children != null) { hasChildren = true; tableRow++; rowCount = children.length; } else { int headerType = header.getHeaderType(); if (headerType == Header.HEADERTYPE_ROW_LABEL || headerType == Header.HEADERTYPE_ROW_SPACER) { rowCount = 0; tableRow++; } else { rowCount = 1; } } for (int j = 0; j < rowCount; j++) { if (hasChildren) { Header child = children[j]; int headerType = child.getHeaderType(); if (headerType == Header.HEADERTYPE_ROW_LABEL || headerType == Header.HEADERTYPE_ROW_SPACER) { tableRow++; continue; } } for (int cellColumn = 0; cellColumn < this._reportModel.getColumnSize(); cellColumn++) { Cell cell = this._reportModel.getCell(cellRow, cellColumn); int align = Element.ALIGN_RIGHT; Font font = this._normalFont; String s = null; switch (cell.getCellType()) { case Cell.CELLTYPE_PERCENT: s = formatter.format(cell.getFloatValue()); break; case Cell.CELLTYPE_ROW_HEADER: s = cell.getStringValue(); if (s.equals(" ")) { s = " "; } font = this._boldFont; align = Element.ALIGN_LEFT; break; case Cell.CELLTYPE_SUM: s = formatNumber(cell.getValue()); font = this._boldFont; break; case Cell.CELLTYPE_TOTAL: s = formatNumber(cell.getValue()); font = this._boldFont; break; default: s = formatNumber(cell.getValue()); break; } int tableColumn = cellColumn + 1; com.lowagie.text.Cell pdfCell = new com.lowagie.text.Cell(new Phrase(s, font)); pdfCell.setHorizontalAlignment(align); pdfCell.setNoWrap(true); pdfCell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(pdfCell, new Point(tableRow, tableColumn)); setColSize(s, tableColumn, false); } cellRow++; tableRow++; } } this._reportModel.close(); }