com.lowagie.text.Row Java Examples

The following examples show how to use com.lowagie.text.Row. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RtfRow.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Imports a Row and copies all settings
 * 
 * @param row The Row to import
 */
private void importRow(Row row) {
    this.cells = new ArrayList();
    this.width = this.document.getDocumentHeader().getPageSetting().getPageWidth() - this.document.getDocumentHeader().getPageSetting().getMarginLeft() - this.document.getDocumentHeader().getPageSetting().getMarginRight();
    this.width = (int) (this.width * this.parentTable.getTableWidthPercent() / 100);
    
    int cellRight = 0;
    int cellWidth = 0;
    for(int i = 0; i < row.getColumns(); i++) {
        cellWidth = (int) (this.width * this.parentTable.getProportionalWidths()[i] / 100);
        cellRight = cellRight + cellWidth;
        
        Cell cell = (Cell) row.getCell(i);
        RtfCell rtfCell = new RtfCell(this.document, this, cell);
        rtfCell.setCellRight(cellRight);
        rtfCell.setCellWidth(cellWidth);
        this.cells.add(rtfCell);
    }
}
 
Example #2
Source File: PatchRtfRow.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Imports a Row and copies all settings
 *
 * @param row
 *          The Row to import
 */
private void importRow( Row row ) {
  this.cells = new ArrayList<PatchRtfCell>();
  this.width =
      this.document.getDocumentHeader().getPageSetting().getPageWidth()
          - this.document.getDocumentHeader().getPageSetting().getMarginLeft()
          - this.document.getDocumentHeader().getPageSetting().getMarginRight();
  this.width = (int) ( this.width * this.parentTable.getTableWidthPercent() / 100 );

  int cellRight = 0;
  int cellWidth = 0;
  for ( int i = 0; i < row.getColumns(); i++ ) {
    cellWidth = (int) ( this.width * this.parentTable.getProportionalWidths()[i] / 100 );
    cellRight = cellRight + cellWidth;

    Cell cell = (Cell) row.getCell( i );
    PatchRtfCell rtfCell = new PatchRtfCell( this.document, this, cell );
    rtfCell.setCellRight( cellRight );
    rtfCell.setCellWidth( cellWidth );
    this.cells.add( rtfCell );
  }
}
 
Example #3
Source File: PatchRtfTableTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testImportTableRemovesUnusedRow() throws BadElementException {
  Table table = Mockito.mock( Table.class );
  Row row = Mockito.mock( Row.class );
  RtfDocument rtfDocument = new RtfDocument();
  List<Row> rows = new ArrayList<>( 5 );
  for ( int i = 0; i < 5; i++ ) {
    rows.add( row );
  }
  Iterator<Row> iterator = rows.iterator();

  Mockito.when( table.iterator() ).thenReturn( iterator );

  new PatchRtfTable( rtfDocument, table );
  Assert.assertFalse( iterator.hasNext() );
  Assert.assertEquals( 0, rows.size() );
}
 
Example #4
Source File: RtfTable.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Imports the rows and settings from the Table into this
 * RtfTable.
 * 
 * @param table The source Table
 */
private void importTable(Table table) {
    this.rows = new ArrayList();
    this.tableWidthPercent = table.getWidth();
    this.proportionalWidths = table.getProportionalWidths();
    this.cellPadding = (float) (table.getPadding() * TWIPS_FACTOR);
    this.cellSpacing = (float) (table.getSpacing() * TWIPS_FACTOR);
    this.borders = new RtfBorderGroup(this.document, RtfBorder.ROW_BORDER, table.getBorder(), table.getBorderWidth(), table.getBorderColor());
    this.alignment = table.getAlignment();
    
    int i = 0;
    Iterator rowIterator = table.iterator();
    while(rowIterator.hasNext()) {
        this.rows.add(new RtfRow(this.document, this, (Row) rowIterator.next(), i));
        i++;
    }
    for(i = 0; i < this.rows.size(); i++) {
        ((RtfRow) this.rows.get(i)).handleCellSpanning();
        ((RtfRow) this.rows.get(i)).cleanRow();
    }
    this.headerRows = table.getLastHeaderRow();
    this.cellsFitToPage = table.isCellsFitPage();
    this.tableFitToPage = table.isTableFitsPage();
    if(!Float.isNaN(table.getOffset())) {
        this.offset = (int) (table.getOffset() * 2);
    }
}
 
Example #5
Source File: PatchRtfTable.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Imports the rows and settings from the Table into this PatchRtfTable.
 *
 * @param table
 *          The source Table
 */
private void importTable( Table table ) {
  this.rows = new ArrayList<PatchRtfRow>();
  this.tableWidthPercent = table.getWidth();
  this.proportionalWidths = table.getProportionalWidths();
  this.cellPadding = (float) ( table.getPadding() * TWIPS_FACTOR );
  this.cellSpacing = (float) ( table.getSpacing() * TWIPS_FACTOR );
  this.borders =
      new PatchRtfBorderGroup( this.document, PatchRtfBorder.ROW_BORDER, table.getBorder(), table.getBorderWidth(),
          table.getBorderColor() );
  this.alignment = table.getAlignment();

  int i = 0;
  Iterator rowIterator = table.iterator();
  while ( rowIterator.hasNext() ) {
    this.rows.add( new PatchRtfRow( this.document, this, (Row) rowIterator.next(), i ) );
    // avoid out of memory exception
    rowIterator.remove();
    i++;
  }
  for ( i = 0; i < this.rows.size(); i++ ) {
    this.rows.get( i ).handleCellSpanning();
    this.rows.get( i ).cleanRow();
  }
  this.headerRows = table.getLastHeaderRow();
  this.cellsFitToPage = table.isCellsFitPage();
  this.tableFitToPage = table.isTableFitsPage();
  if ( !Float.isNaN( table.getOffset() ) ) {
    this.offset = (int) ( table.getOffset() * 2 );
  }
}
 
Example #6
Source File: RtfRow.java    From itext2 with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * Constructs a RtfRow for a Row.
 * 
 * @param doc The RtfDocument this RtfRow belongs to
 * @param rtfTable The RtfTable this RtfRow belongs to
 * @param row The Row this RtfRow is based on
 * @param rowNumber The number of this row
 */
protected RtfRow(RtfDocument doc, RtfTable rtfTable, Row row, int rowNumber) {
    super(doc);
    this.parentTable = rtfTable;
    this.rowNumber = rowNumber;
    importRow(row);
}
 
Example #7
Source File: PatchRtfRow.java    From pentaho-reporting with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Constructs a PatchRtfRow for a Row.
 *
 * @param doc
 *          The RtfDocument this PatchRtfRow belongs to
 * @param PatchRtfTable
 *          The PatchRtfTable this PatchRtfRow belongs to
 * @param row
 *          The Row this PatchRtfRow is based on
 * @param rowNumber
 *          The number of this row
 */
protected PatchRtfRow( RtfDocument doc, PatchRtfTable PatchRtfTable, Row row, int rowNumber ) {
  super( doc );
  this.parentTable = PatchRtfTable;
  this.rowNumber = rowNumber;
  importRow( row );
}