Method from com.lowagie.text.Table Detail: |
public void addCell(Cell cell) {
try {
addCell(cell, curPosition);
}
catch(BadElementException bee) {
// don't add the cell
}
}
Adds a Cell to the Table . |
public void addCell(Phrase content) throws BadElementException {
addCell(content, curPosition);
}
|
public void addCell(String content) throws BadElementException {
addCell(new Phrase(content), curPosition);
}
|
public void addCell(Cell aCell,
Point aLocation) throws BadElementException {
if (aCell == null) throw new NullPointerException("addCell - cell has null-value");
if (aLocation == null) throw new NullPointerException("addCell - point has null-value");
if (aCell.isTable()) insertTable((Table)aCell.getElements().next(), aLocation);
if (aLocation.x < 0) throw new BadElementException("row coordinate of location must be >= 0");
if ((aLocation.y < = 0) && (aLocation.y > columns)) throw new BadElementException("column coordinate of location must be >= 0 and < nr of columns");
if (!isValidLocation(aCell, aLocation)) throw new BadElementException("Adding a cell at the location (" + aLocation.x + "," + aLocation.y + ") with a colspan of " + aCell.getColspan() + " and a rowspan of " + aCell.getRowspan() + " is illegal (beyond boundaries/overlapping).");
if (aCell.getBorder() == UNDEFINED) aCell.setBorder(defaultCell.getBorder());
aCell.fill();
placeCell(rows, aCell, aLocation);
setCurrentLocationToNextValidPosition(aLocation);
}
Adds a Cell to the Table at a certain location. |
public void addCell(Phrase content,
Point location) throws BadElementException {
Cell cell = new Cell(content);
cell.setBorder(defaultCell.getBorder());
cell.setBorderWidth(defaultCell.getBorderWidth());
cell.setBorderColor(defaultCell.getBorderColor());
cell.setBackgroundColor(defaultCell.getBackgroundColor());
cell.setHorizontalAlignment(defaultCell.getHorizontalAlignment());
cell.setVerticalAlignment(defaultCell.getVerticalAlignment());
cell.setColspan(defaultCell.getColspan());
cell.setRowspan(defaultCell.getRowspan());
addCell(cell, location);
}
Adds a Cell to the Table .
This is a shortcut for addCell(Cell cell, Point location) .
The Phrase will be converted to a Cell . |
public void addCell(String content,
Point location) throws BadElementException {
addCell(new Phrase(content), location);
}
Adds a Cell to the Table .
This is a shortcut for addCell(Cell cell, Point location) .
The String will be converted to a Cell . |
public void addCell(Cell aCell,
int row,
int column) throws BadElementException {
addCell(aCell, new Point(row,column));
}
Adds a Cell to the Table at a certain row and column. |
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;
}
Gives you the possibility to add columns. |
public void complete() {
if (mTableInserted) {
mergeInsertedTables(); // integrate tables in the table
mTableInserted = false;
}
if (autoFillEmptyCells) {
fillEmptyMatrixCells();
}
}
Will fill empty cells with valid blank Cell s |
public PdfPTable createPdfPTable() throws BadElementException {
if (!convert2pdfptable) {
throw new BadElementException("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;
}
Create a PdfPTable based on this Table object. |
public void deleteAllRows() {
rows.clear();
rows.add(new Row(columns));
curPosition.setLocation(0, 0);
lastHeaderRow = -1;
}
Deletes all rows in this table.
(contributed by dperezcar@fcc.es) |
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);
}
}
Deletes a column in this table. |
public boolean deleteLastRow() {
return deleteRow(rows.size() - 1);
}
Deletes the last row in this table. |
public boolean deleteRow(int row) {
if (row < 0 || row >= rows.size()) {
return false;
}
rows.remove(row);
curPosition.setLocation(curPosition.x-1, curPosition.y);
return true;
}
|
public int endHeaders() {
lastHeaderRow = curPosition.x - 1;
return lastHeaderRow;
}
Marks the last row of the table headers. |
public void flushContent() {
this.setNotAddedYet(false);
ArrayList headerrows = new ArrayList();
for (int i = 0; i < getLastHeaderRow() + 1; i++) {
headerrows.add(rows.get(i));
}
rows = headerrows;
}
|
public int getAlignment() {
return alignment;
}
Gets the horizontal alignment. |
public ArrayList getChunks() {
return new ArrayList();
}
Gets all the chunks in this element. |
public int getColumns() {
return columns;
}
Gets the number of columns. |
public Cell getDefaultCell() {
return defaultCell;
}
Gets the default layout of the Table. |
public Cell getDefaultLayout() {
return getDefaultCell();
} Deprecated! As - of iText 2.0.7, replaced by #getDefaultCell() ,
scheduled for removal at 2.2.0
Gets the default layout of the Table. |
public Dimension getDimension() {
return new Dimension(columns, size());
}
Gets the dimension of this table |
public Object getElement(int row,
int column) {
return ((Row) rows.get(row)).getCell(column);
}
returns the element at the position row, column
(Cast to Cell or Table) |
public int getLastHeaderRow() {
return this.lastHeaderRow;
}
Gets the last number of the rows that contain headers. |
public float getOffset() {
return offset;
}
Gets the offset of this table. |
public float getPadding() {
return cellpadding;
}
|
public float[] getProportionalWidths() {
return widths;
}
Gets the proportional widths of the columns in this Table . |
public float getSpacing() {
return cellspacing;
}
|
public float getWidth() {
return width;
}
Gets the table width (a percentage). |
public float[] getWidths(float left,
float totalWidth) {
// for x columns, there are x+1 borders
float[] w = new float[columns + 1];
float wPercentage;
if (locked) {
wPercentage = 100 * width / totalWidth;
}
else {
wPercentage = width;
}
// the border at the left is calculated
switch(alignment) {
case Element.ALIGN_LEFT:
w[0] = left;
break;
case Element.ALIGN_RIGHT:
w[0] = left + (totalWidth * (100 - wPercentage)) / 100;
break;
case Element.ALIGN_CENTER:
default:
w[0] = left + (totalWidth * (100 - wPercentage)) / 200;
}
// the total available width is changed
totalWidth = (totalWidth * wPercentage) / 100;
// the inner borders are calculated
for (int i = 1; i < columns; i++) {
w[i] = w[i - 1] + (widths[i - 1] * totalWidth / 100);
}
// the border at the right is calculated
w[columns] = w[0] + totalWidth;
return w;
}
Gets an array with the positions of the borders between every column.
This method translates the widths expressed in percentages into the
x-coordinate of the borders of the columns on a real document. |
public void insertTable(Table aTable) {
if (aTable == null) throw new NullPointerException("insertTable - table has null-value");
insertTable(aTable, curPosition);
}
To put a table within the existing table at the current position
generateTable will of course re-arrange the widths of the columns. |
public void insertTable(Table aTable,
Point aLocation) {
if (aTable == null) throw new NullPointerException("insertTable - table has null-value");
if (aLocation == null) throw new NullPointerException("insertTable - point has null-value");
mTableInserted = true;
aTable.complete();
if (aLocation.y > columns) {
throw new IllegalArgumentException("insertTable -- wrong columnposition("+ aLocation.y + ") of location; max =" + columns);
}
int rowCount = aLocation.x + 1 - rows.size();
int i = 0;
if ( rowCount > 0 ) { //create new rows ?
for (; i < rowCount; i++) {
rows.add(new Row(columns));
}
}
((Row) rows.get(aLocation.x)).setElement(aTable,aLocation.y);
setCurrentLocationToNextValidPosition(aLocation);
}
To put a table within the existing table at the given position
generateTable will of course re-arrange the widths of the columns. |
public void insertTable(Table aTable,
int row,
int column) {
if (aTable == null) throw new NullPointerException("insertTable - table has null-value");
insertTable(aTable, new Point(row, column));
}
To put a table within the existing table at the given position
generateTable will of course re-arrange the widths of the columns. |
public boolean isCellsFitPage() {
return cellsFitPage;
}
Checks if the cells of this Table have to fit a page. |
public boolean isComplete() {
return complete;
}
|
public boolean isConvert2pdfptable() {
return convert2pdfptable;
}
Method to check if the Table should be converted to a PdfPTable or not. |
public boolean isLocked() {
return locked;
}
|
public boolean isNestable() {
return true;
}
|
public boolean isNotAddedYet() {
return notAddedYet;
}
Indicates if this is the first time the section is added. |
public boolean isTableFitsPage() {
return tableFitsPage;
}
Checks if this Table has to fit a page. |
public Iterator iterator() {
return rows.iterator();
}
Gets an Iterator of all the Row s. |
public boolean process(ElementListener listener) {
try {
return listener.add(this);
}
catch(DocumentException de) {
return false;
}
}
Processes the element by adding it (or the different parts) to an
ElementListener . |
public void setAlignment(int value) {
alignment = value;
}
Sets the horizontal alignment. |
public void setAlignment(String alignment) {
if (ElementTags.ALIGN_LEFT.equalsIgnoreCase(alignment)) {
this.alignment = Element.ALIGN_LEFT;
return;
}
if (ElementTags.RIGHT.equalsIgnoreCase(alignment)) {
this.alignment = Element.ALIGN_RIGHT;
return;
}
this.alignment = Element.ALIGN_CENTER;
}
Sets the alignment of this paragraph. |
public void setAutoFillEmptyCells(boolean aDoAutoFill) {
autoFillEmptyCells = aDoAutoFill;
}
Enables/disables automatic insertion of empty cells before table is rendered. (default = false)
As some people may want to create a table, fill only a couple of the cells and don't bother with
investigating which empty ones need to be added, this default behavior may be very welcome.
Disabling is recommended to increase speed. (empty cells should be added through extra code then) |
public void setCellsFitPage(boolean fitPage) {
this.cellsFitPage = fitPage;
}
Allows you to control when a page break occurs.
When a cell doesn't fit a page, it is split in two parts.
If you want to avoid this, you should set the cellsFitPage value to true. |
public void setComplete(boolean complete) {
this.complete = complete;
}
|
public void setConvert2pdfptable(boolean convert2pdfptable) {
this.convert2pdfptable = convert2pdfptable;
}
If set to true, iText will try to convert the Table to a PdfPTable. |
public void setDefaultCell(Cell value) {
defaultCell = value;
}
Sets the default layout of the Table to
the provided Cell |
public void setDefaultLayout(Cell value) {
defaultCell = value;
} Deprecated! As - of iText 2.0.7, replaced by #setDefaultCell(Cell) ,
scheduled for removal at 2.2.0
Sets the default layout of the Table to
the provided Cell |
public void setLastHeaderRow(int value) {
lastHeaderRow = value;
}
Sets the horizontal alignment. |
public void setLocked(boolean locked) {
this.locked = locked;
}
|
public void setNotAddedYet(boolean notAddedYet) {
this.notAddedYet = notAddedYet;
}
Sets the indication if the section was already added to
the document. |
public void setOffset(float offset) {
this.offset = offset;
}
Sets the offset of this table.
Normally a newline is added before you add a Table object.
This newline uses the current leading.
If you want to control the space between the table and the previous
element yourself, you have to set the offset of this table. |
public void setPadding(float value) {
cellpadding = value;
}
|
public void setSpacing(float value) {
cellspacing = value;
}
|
public void setTableFitsPage(boolean fitPage) {
this.tableFitsPage = fitPage;
if (fitPage) setCellsFitPage(true);
}
Allows you to control when a page break occurs.
When a table doesn't fit a page, it is split in two parts.
If you want to avoid this, you should set the tableFitsPage value to true. |
public void setWidth(float width) {
this.width = width;
}
Sets the width of this table (in percentage of the available space). |
public void setWidths(float[] widths) throws BadElementException {
if (widths.length != columns) {
throw new BadElementException("Wrong number of columns.");
}
// The sum of all values is 100%
float hundredPercent = 0;
for (int i = 0; i < columns; i++) {
hundredPercent += widths[i];
}
// The different percentages are calculated
float width;
this.widths[columns - 1] = 100;
for (int i = 0; i < columns - 1; i++) {
width = (100.0f * widths[i]) / hundredPercent;
this.widths[i] = width;
this.widths[columns - 1] -= width;
}
}
Sets the widths of the different columns (percentages).
You can give up relative values of borderwidths.
The sum of these values will be considered 100%.
The values will be recalculated as percentages of this sum.
example:
float[] widths = {2, 1, 1};
table.setWidths(widths)
The widths will be: a width of 50% for the first column,
25% for the second and third column. |
public void setWidths(int[] widths) throws DocumentException {
float tb[] = new float[widths.length];
for (int k = 0; k < widths.length; ++k)
tb[k] = widths[k];
setWidths(tb);
}
Sets the widths of the different columns (percentages).
You can give up relative values of borderwidths.
The sum of these values will be considered 100%.
The values will be recalculated as percentages of this sum. |
public int size() {
return rows.size();
}
Gets the number of rows in this Table . |
public int type() {
return Element.TABLE;
}
Gets the type of the text element. |