Example usage for com.lowagie.text Cell setHorizontalAlignment

List of usage examples for com.lowagie.text Cell setHorizontalAlignment

Introduction

In this page you can find the example usage for com.lowagie.text Cell setHorizontalAlignment.

Prototype

public void setHorizontalAlignment(String alignment) 

Source Link

Document

Sets the alignment of this cell.

Usage

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 av  a  2s .co 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("&nbsp;")) {
                        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();
}