Example usage for com.lowagie.text Table addCell

List of usage examples for com.lowagie.text Table addCell

Introduction

In this page you can find the example usage for com.lowagie.text Table addCell.

Prototype

public void addCell(String content, Point location) throws BadElementException 

Source Link

Document

Adds a Cell to the Table.

Usage

From source file:opisiame.controller.gestion_resultat.Choix_exportController.java

public void fill_data_pdf(Table table) throws BadElementException {
    if (onglet_actif.equals("questions")) {
        for (int i = 0; i < reponse_questions.size(); i++) {
            table.addCell(reponse_questions.get(i).getQuestion(), new Point(i + 1, 0));
            table.addCell(reponse_questions.get(i).getStr_pourcentage_rep_a(), new Point(i + 1, 1));
            table.addCell(reponse_questions.get(i).getStr_pourcentage_rep_b(), new Point(i + 1, 2));
            table.addCell(reponse_questions.get(i).getStr_pourcentage_rep_c(), new Point(i + 1, 3));
            table.addCell(reponse_questions.get(i).getStr_pourcentage_rep_d(), new Point(i + 1, 4));
            table.addCell(reponse_questions.get(i).getStr_pourcentage(), new Point(i + 1, 5));
        }//  w ww  .  j a  v a 2s  .co m
    } else if (onglet_actif.equals("eleves")) {
        for (int i = 0; i < resultats_eleves.size(); i++) {
            table.addCell(resultats_eleves.get(i).getNom_eleve(), new Point(i + 1, 0));
            table.addCell(resultats_eleves.get(i).getPrenom_eleve(), new Point(i + 1, 1));
            table.addCell(resultats_eleves.get(i).getNum_eleve().toString(), new Point(i + 1, 2));
            table.addCell(resultats_eleves.get(i).getNote_eleve().toString(), new Point(i + 1, 3));
            table.addCell(resultats_eleves.get(i).getPourcent_eleve().toString(), new Point(i + 1, 4));
        }
    } else if (onglet_actif.equals("eleves_pas_num")) {
        for (int i = 0; i < resultats_eleves.size(); i++) {
            table.addCell(resultats_eleves.get(i).getNom_eleve(), new Point(i + 1, 0));
            table.addCell(resultats_eleves.get(i).getPrenom_eleve(), new Point(i + 1, 1));
            table.addCell(resultats_eleves.get(i).getNote_eleve().toString(), new Point(i + 1, 2));
            table.addCell(resultats_eleves.get(i).getPourcent_eleve().toString(), new Point(i + 1, 3));
        }
    }

}

From source file:se.idega.idegaweb.commune.school.report.business.ReportPDFWriter.java

License:Open Source License

/**
 * Builds the report column headers./*from  w w  w.  j a v  a  2  s  .  c  o  m*/
 */
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  w  w .jav a2s .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./*w  ww.jav  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();
}