Example usage for com.lowagie.text Element ALIGN_MIDDLE

List of usage examples for com.lowagie.text Element ALIGN_MIDDLE

Introduction

In this page you can find the example usage for com.lowagie.text Element ALIGN_MIDDLE.

Prototype

int ALIGN_MIDDLE

To view the source code for com.lowagie.text Element ALIGN_MIDDLE.

Click Source Link

Document

A possible value for vertical alignment.

Usage

From source file:ro.nextreports.engine.exporter.RtfExporter.java

License:Apache License

private void setCellStyle(Font fnt, Map<String, Object> style, RtfCell cell) {
    if (style != null) {
        updateFont(fnt, style);//w ww .j  a v  a2 s. c o  m
        if (style.containsKey(StyleFormatConstants.BACKGROUND_COLOR)) {
            Color val = (Color) style.get(StyleFormatConstants.BACKGROUND_COLOR);
            cell.setBackgroundColor(val);
        }
        if (style.containsKey(StyleFormatConstants.HORIZONTAL_ALIGN_KEY)) {
            if (StyleFormatConstants.HORIZONTAL_ALIGN_LEFT
                    .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) {
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            }
            if (StyleFormatConstants.HORIZONTAL_ALIGN_RIGHT
                    .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) {
                cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            }
            if (StyleFormatConstants.HORIZONTAL_ALIGN_CENTER
                    .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) {
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            }
        }

        if (style.containsKey(StyleFormatConstants.VERTICAL_ALIGN_KEY)) {
            if (StyleFormatConstants.VERTICAL_ALIGN_TOP
                    .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) {
                cell.setVerticalAlignment(Element.ALIGN_TOP);
            }
            if (StyleFormatConstants.VERTICAL_ALIGN_MIDDLE
                    .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) {
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            }
            if (StyleFormatConstants.VERTICAL_ALIGN_BOTTOM
                    .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) {
                cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
            }
        }
        // if (style.containsKey(StyleFormatConstants.PADDING_LEFT)) {
        // Float val = (Float) style.get(StyleFormatConstants.PADDING_LEFT);
        // cell.setPaddingLeft(val);
        // }
        // if (style.containsKey(StyleFormatConstants.PADDING_RIGHT)) {
        // Float val = (Float)
        // style.get(StyleFormatConstants.PADDING_RIGHT);
        // cell.setPaddingRight(val);
        // }
        // if (style.containsKey(StyleFormatConstants.PADDING_TOP)) {
        // Float val = (Float) style.get(StyleFormatConstants.PADDING_TOP);
        // cell.setPaddingTop(val);
        // }
        // if (style.containsKey(StyleFormatConstants.PADDING_BOTTOM)) {
        // Float val = (Float)
        // style.get(StyleFormatConstants.PADDING_BOTTOM);
        // cell.setPaddingBottom(val);
        // }
        cell.setBorderWidth(0);

        Float val = Float.valueOf(1);
        RtfBorderGroup bg = new RtfBorderGroup();
        if (style.containsKey(StyleFormatConstants.BORDER_LEFT)) {
            val = (Float) style.get(StyleFormatConstants.BORDER_LEFT);
            Color color = (Color) style.get(StyleFormatConstants.BORDER_LEFT_COLOR);
            bg.addBorder(Rectangle.LEFT, RtfBorder.BORDER_SINGLE, val, color);
        }
        if (style.containsKey(StyleFormatConstants.BORDER_RIGHT)) {
            val = (Float) style.get(StyleFormatConstants.BORDER_RIGHT);
            Color color = (Color) style.get(StyleFormatConstants.BORDER_RIGHT_COLOR);
            bg.addBorder(Rectangle.RIGHT, RtfBorder.BORDER_SINGLE, val, color);
        }
        if (style.containsKey(StyleFormatConstants.BORDER_TOP)) {
            val = (Float) style.get(StyleFormatConstants.BORDER_TOP);
            Color color = (Color) style.get(StyleFormatConstants.BORDER_TOP_COLOR);
            bg.addBorder(Rectangle.TOP, RtfBorder.BORDER_SINGLE, val, color);
        }
        if (style.containsKey(StyleFormatConstants.BORDER_BOTTOM)) {
            val = (Float) style.get(StyleFormatConstants.BORDER_BOTTOM);
            Color color = (Color) style.get(StyleFormatConstants.BORDER_BOTTOM_COLOR);
            bg.addBorder(Rectangle.BOTTOM, RtfBorder.BORDER_SINGLE, val, color);
        }
        cell.setBorders(bg);

        // cell.setNoWrap(true);
        // if (bandElement != null) {
        // if (bandElement.isWrapText()) {
        // cell.setNoWrap(false);
        // }
        // }
    }
}

From source file:s2s.report.MiddleTable.java

License:GNU General Public License

public MiddleTable(int iColumns, boolean bNoWidth) throws BadElementException {
    super(iColumns);
    REPORT_SETTINGS = new ZREPORT_SETTINGS();
    this.setPadding(2);
    if (!bNoWidth) {
        this.setWidth(100);
    }//from  w  w  w.  j a v a2s  .c  o m
    this.setBorder(Rectangle.NO_BORDER);
    this.setDefaultVerticalAlignment(Element.ALIGN_MIDDLE);
    this.setDeafaultOffset();
}

From source file:s2s.report.MiddleTable.java

License:GNU General Public License

public void toMiddle() {
    this.setDefaultVerticalAlignment(Element.ALIGN_MIDDLE);
}

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

License:Open Source License

/**
 * Builds the report row headers./*from w ww . j  ava  2 s .c  o m*/
 */
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   ww  w  . j a  v a2 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("&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();
}

From source file:test.itext.html.AimsPdf.java

License:Open Source License

public static void addTitle(Document doc, String text)
        throws IOException, BadElementException, DocumentException {
    float[] widths = { 62f, 164f, 62f };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage(100);//from  w w  w  . j av  a2 s.co m
    table.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.setSpacingAfter(10);

    Image image = Image.getInstance("app_title.gif");
    image.scalePercent(70);
    PdfPCell cell = new PdfPCell(image);
    cell.setPadding(10);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    Paragraph title = new Paragraph(text, FontFactory.getFont("arial", 12, Font.BOLD));
    cell = new PdfPCell(title);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    image = Image.getInstance("title_shot.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(10);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    doc.add(table);

    table = new PdfPTable(1);
    table.setWidthPercentage(100);
    cell = new PdfPCell();
    cell.setBackgroundColor(Color.BLACK);
    cell.setFixedHeight(1);
    table.addCell(cell);

    doc.add(table);
}

From source file:test.itext.html.AimsPdf.java

License:Open Source License

public static void addScreenShorts(Document doc, String text)
        throws BadElementException, IOException, DocumentException {

    Paragraph heading = new Paragraph("Screenshots",
            FontFactory.getFont("arial", 10, Font.UNDERLINE | Font.BOLDITALIC));
    heading.setSpacingAfter(12f);/*ww  w  .  j  a v a 2  s  .c o m*/
    doc.add(heading);

    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(80);
    table.setHorizontalAlignment(Element.ALIGN_CENTER);

    Image image = Image.getInstance("screen_shoot1.gif");
    image.scalePercent(70);
    PdfPCell cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot2.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot3.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot4.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot5.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot6.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    //      doc.add(new Paragraph("\n"));
    doc.add(table);
}

From source file:uk.ac.bbsrc.tgac.miso.core.data.decorator.itext.ITextProjectDecorator.java

License:Open Source License

public void buildReport() throws DocumentException {
    report = new Document();
    PdfWriter writer = PdfWriter.getInstance(report, stream);
    report.open();/* ww  w  .j a v  a  2 s .  c  om*/
    report.add(new Paragraph("Project Summary"));
    PdfContentByte cb = writer.getDirectContent();
    cb.setLineWidth(2.0f); // Make a bit thicker than 1.0 default
    cb.setGrayStroke(0.9f); // 1 = black, 0 = white
    float x = 72f;
    float y = 200f;
    cb.moveTo(x, y);
    cb.lineTo(x + 72f * 6, y);
    cb.stroke();

    report.add(new Paragraph(project.getAlias()));
    report.add(new Paragraph(project.getDescription()));

    PdfPTable t = new PdfPTable(1);
    t.setHorizontalAlignment(Element.ALIGN_CENTER);
    t.setWidthPercentage(100f); // this would be the 100 from setHorizontalLine
    t.setSpacingAfter(5f);
    t.setSpacingBefore(0f);
    t.getDefaultCell().setUseVariableBorders(true);
    t.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    t.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    t.getDefaultCell().setBorder(Rectangle.BOTTOM); // This generates the line
    t.getDefaultCell().setBorderWidth(1f); // this would be the 1 from setHorizontalLine
    t.getDefaultCell().setPadding(0);
    t.addCell("");
    report.add(t);

    x = 72f;
    y = 100f;
    cb.moveTo(x, y);
    cb.lineTo(x + 72f * 6, y);
    cb.stroke();

    if (project.getSamples().size() > 0) {
        report.add(new Paragraph("Samples"));
        for (Sample sample : project.getSamples()) {
            Paragraph sPara = new Paragraph(sample.getAlias(), FontFactory.getFont("Helvetica", 12, Font.BOLD));
            sPara.setIndentationLeft(20);
            report.add(sPara);
            report.add(new Paragraph(sample.getDescription()));
        }
    }

    report.close();
}