示例#1
0
  /**
   * Gives you the possibility to add columns.
   *
   * @param aColumns the number of columns to add
   */
  public void addColumns(int aColumns) {
    ArrayList newRows = new ArrayList(rows.size());

    int newColumns = columns + aColumns;
    Row row;
    for (int i = 0; i < rows.size(); i++) {
      row = new Row(newColumns);
      for (int j = 0; j < columns; j++) {
        row.setElement(((Row) rows.get(i)).getCell(j), j);
      }
      for (int j = columns; j < newColumns && i < curPosition.x; j++) {
        row.setElement(null, j);
      }
      newRows.add(row);
    }
    // applied 1 column-fix; last column needs to have a width of 0
    float[] newWidths = new float[newColumns];
    System.arraycopy(widths, 0, newWidths, 0, columns);
    for (int j = columns; j < newColumns; j++) {
      newWidths[j] = 0;
    }
    columns = newColumns;
    widths = newWidths;
    rows = newRows;
  }
示例#2
0
 /**
  * Create a PdfPTable based on this Table object.
  *
  * @return a PdfPTable object
  * @throws BadElementException
  */
 public PdfPTable createPdfPTable() throws BadElementException {
   if (!convert2pdfptable) {
     throw new BadElementException(
         MessageLocalization.getComposedMessage("no.error.just.an.old.style.table"));
   }
   setAutoFillEmptyCells(true);
   complete();
   PdfPTable pdfptable = new PdfPTable(widths);
   pdfptable.setComplete(complete);
   if (isNotAddedYet()) pdfptable.setSkipFirstHeader(true);
   SimpleTable t_evt = new SimpleTable();
   t_evt.cloneNonPositionParameters(this);
   t_evt.setCellspacing(cellspacing);
   pdfptable.setTableEvent(t_evt);
   pdfptable.setHeaderRows(lastHeaderRow + 1);
   pdfptable.setSplitLate(cellsFitPage);
   pdfptable.setKeepTogether(tableFitsPage);
   if (!Float.isNaN(offset)) {
     pdfptable.setSpacingBefore(offset);
   }
   pdfptable.setHorizontalAlignment(alignment);
   if (locked) {
     pdfptable.setTotalWidth(width);
     pdfptable.setLockedWidth(true);
   } else {
     pdfptable.setWidthPercentage(width);
   }
   Row row;
   for (Iterator iterator = iterator(); iterator.hasNext(); ) {
     row = (Row) iterator.next();
     Element cell;
     PdfPCell pcell;
     for (int i = 0; i < row.getColumns(); i++) {
       if ((cell = (Element) row.getCell(i)) != null) {
         if (cell instanceof Table) {
           pcell = new PdfPCell(((Table) cell).createPdfPTable());
         } else if (cell instanceof Cell) {
           pcell = ((Cell) cell).createPdfPCell();
           pcell.setPadding(cellpadding + cellspacing / 2f);
           SimpleCell c_evt = new SimpleCell(SimpleCell.CELL);
           c_evt.cloneNonPositionParameters((Cell) cell);
           c_evt.setSpacing(cellspacing * 2f);
           pcell.setCellEvent(c_evt);
         } else {
           pcell = new PdfPCell();
         }
         pdfptable.addCell(pcell);
       }
     }
   }
   return pdfptable;
 }
示例#3
0
 /**
  * Deletes a column in this table.
  *
  * @param column the number of the column that has to be deleted
  * @throws BadElementException
  */
 public void deleteColumn(int column) throws BadElementException {
   float newWidths[] = new float[--columns];
   System.arraycopy(widths, 0, newWidths, 0, column);
   System.arraycopy(widths, column + 1, newWidths, column, columns - column);
   setWidths(newWidths);
   System.arraycopy(widths, 0, newWidths, 0, columns);
   widths = newWidths;
   Row row;
   int size = rows.size();
   for (int i = 0; i < size; i++) {
     row = (Row) rows.get(i);
     row.deleteColumn(column);
     rows.set(i, row);
   }
   if (column == columns) {
     curPosition.setLocation(curPosition.x + 1, 0);
   }
 }
示例#4
0
  /**
   * Inserts a Cell in a cell-array and reserves cells defined by row-/colspan.
   *
   * @param someRows some rows
   * @param aCell the cell that has to be inserted
   * @param aPosition the position where the cell has to be placed
   */
  private void placeCell(ArrayList someRows, Cell aCell, Point aPosition) {
    int i;
    Row row = null;
    int rowCount = aPosition.x + aCell.getRowspan() - someRows.size();
    assumeTableDefaults(aCell);
    if ((aPosition.x + aCell.getRowspan()) > someRows.size()) {
      for (i = 0; i < rowCount; i++) {
        row = new Row(columns);
        someRows.add(row);
      }
    }

    // reserve cell in rows below
    for (i = aPosition.x + 1; i < (aPosition.x + aCell.getRowspan()); i++) {
      if (!((Row) someRows.get(i)).reserve(aPosition.y, aCell.getColspan())) {

        // should be impossible to come here :-)
        throw new RuntimeException(
            MessageLocalization.getComposedMessage("addcell.error.in.reserve"));
      }
    }
    row = (Row) someRows.get(aPosition.x);
    row.addElement(aCell, aPosition.y);
  }