📄 table.java
字号:
*
* @param value the new value
*/
public void setAlignment(int value) {
alignment = value;
}
/**
* Sets the alignment of this paragraph.
*
* @param alignment the new alignment as a <CODE>String</CODE>
*/
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;
}
/**
* Gets the cellpadding.
*
* @return a value
*/
public float getPadding() {
return cellpadding;
}
/**
* Sets the cellpadding.
*
* @param value the new value
*/
public void setPadding(float value) {
cellpadding = value;
}
/**
* Gets the cellspacing.
*
* @return a value
*/
public float getSpacing() {
return cellspacing;
}
/**
* Sets the cellspacing.
*
* @param value the new value
*/
public void setSpacing(float value) {
cellspacing = value;
}
/**
* 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 behaviour may be very welcome.
* Disabling is recommended to increase speed. (empty cells should be added through extra code then)
*
* @param aDoAutoFill enable/disable autofill
*/
public void setAutoFillEmptyCells(boolean aDoAutoFill) {
autoFillEmptyCells = aDoAutoFill;
}
/**
* Gets the table width (a percentage).
*
* @return the table width
*/
public float getWidth() {
return width;
}
/**
* Sets the width of this table (in percentage of the available space).
*
* @param width the width
*/
public void setWidth(float width) {
this.width = width;
}
/**
* @return the locked
*/
public boolean isLocked() {
return locked;
}
/**
* @param locked the locked to set
*/
public void setLocked(boolean locked) {
this.locked = locked;
}
/**
* Gets the proportional widths of the columns in this <CODE>Table</CODE>.
*
* @return the proportional widths of the columns in this <CODE>Table</CODE>
*/
public float[] getProportionalWidths() {
return widths;
}
/**
* Sets the widths of the different columns (percentages).
* <P>
* 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.
* <P>
* example:
* <BLOCKQUOTE><PRE>
* float[] widths = {2, 1, 1};
* <STRONG>table.setWidths(widths)</STRONG>
* </PRE></BLOCKQUOTE>
* The widths will be: a width of 50% for the first column,
* 25% for the second and third column.
*
* @param widths an array with values
* @throws BadElementException
*/
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).
* <P>
* 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.
*
* @param widths an array with values
* @throws DocumentException
*/
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);
}
/**
* Checks if this <CODE>Table</CODE> has to fit a page.
*
* @return true if the table may not be split
*/
public boolean isTableFitsPage() {
return tableFitsPage;
}
/**
* Allows you to control when a page break occurs.
* <P>
* When a table doesn't fit a page, it is split in two parts.
* If you want to avoid this, you should set the <VAR>tableFitsPage</VAR> value to true.
*
* @param fitPage enter true if you don't want to split cells
*/
public void setTableFitsPage(boolean fitPage) {
this.tableFitsPage = fitPage;
if (fitPage) setCellsFitPage(true);
}
/**
* Checks if the cells of this <CODE>Table</CODE> have to fit a page.
*
* @return true if the cells may not be split
*/
public boolean isCellsFitPage() {
return cellsFitPage;
}
/**
* Allows you to control when a page break occurs.
* <P>
* When a cell doesn't fit a page, it is split in two parts.
* If you want to avoid this, you should set the <VAR>cellsFitPage</VAR> value to true.
*
* @param fitPage enter true if you don't want to split cells
*/
public void setCellsFitPage(boolean fitPage) {
this.cellsFitPage = fitPage;
}
/**
* 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.
*
* @param offset the space between this table and the previous object.
*/
public void setOffset(float offset) {
this.offset = offset;
}
/**
* Gets the offset of this table.
*
* @return the space between this table and the previous element.
*/
public float getOffset() {
return offset;
}
/**
* Method to check if the Table should be converted to a PdfPTable or not.
* @return false if the table should be handled the oldfashioned way.
*/
public boolean isConvert2pdfptable() {
return convert2pdfptable;
}
/**
* If set to true, iText will try to convert the Table to a PdfPTable.
* @param convert2pdfptable true if you want iText to try to convert the Table to a PdfPTable
*/
public void setConvert2pdfptable(boolean convert2pdfptable) {
this.convert2pdfptable = convert2pdfptable;
}
// methods to add content to the table
/**
* Adds a <CODE>Cell</CODE> to the <CODE>Table</CODE> at a certain row and column.
*
* @param aCell The <CODE>Cell</CODE> to add
* @param row The row where the <CODE>Cell</CODE> will be added
* @param column The column where the <CODE>Cell</CODE> will be added
* @throws BadElementException
*/
public void addCell(Cell aCell, int row, int column) throws BadElementException {
addCell(aCell, new Point(row,column));
}
/**
* Adds a <CODE>Cell</CODE> to the <CODE>Table</CODE> at a certain location.
*
* @param aCell The <CODE>Cell</CODE> to add
* @param aLocation The location where the <CODE>Cell</CODE> will be added
* @throws BadElementException
*/
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(defaultLayout.getBorder());
aCell.fill();
placeCell(rows, aCell, aLocation);
setCurrentLocationToNextValidPosition(aLocation);
}
/**
* Adds a <CODE>Cell</CODE> to the <CODE>Table</CODE>.
*
* @param cell a <CODE>Cell</CODE>
*/
public void addCell(Cell cell) {
try {
addCell(cell, curPosition);
}
catch(BadElementException bee) {
// don't add the cell
}
}
/**
* Adds a <CODE>Cell</CODE> to the <CODE>Table</CODE>.
* <P>
* This is a shortcut for <CODE>addCell(Cell cell)</CODE>.
* The <CODE>Phrase</CODE> will be converted to a <CODE>Cell</CODE>.
*
* @param content a <CODE>Phrase</CODE>
* @throws BadElementException this should never happen
*/
public void addCell(Phrase content) throws BadElementException {
addCell(content, curPosition);
}
/**
* Adds a <CODE>Cell</CODE> to the <CODE>Table</CODE>.
* <P>
* This is a shortcut for <CODE>addCell(Cell cell, Point location)</CODE>.
* The <CODE>Phrase</CODE> will be converted to a <CODE>Cell</CODE>.
*
* @param content a <CODE>Phrase</CODE>
* @param location a <CODE>Point</CODE>
* @throws BadElementException this should never happen
*/
public void addCell(Phrase content, Point location) throws BadElementException {
Cell cell = new Cell(content);
cell.setBorder(defaultLayout.getBorder());
cell.setBorderWidth(defaultLayout.getBorderWidth());
cell.setBorderColor(defaultLayout.getBorderColor());
cell.setBackgroundColor(defaultLayout.getBackgroundColor());
cell.setHorizontalAlignment(defaultLayout.getHorizontalAlignment());
cell.setVerticalAlignment(defaultLayout.getVerticalAlignment());
cell.setColspan(defaultLayout.getColspan());
cell.setRowspan(defaultLayout.getRowspan());
addCell(cell, location);
}
/**
* Adds a <CODE>Cell</CODE> to the <CODE>Table</CODE>.
* <P>
* This is a shortcut for <CODE>addCell(Cell cell)</CODE>.
* The <CODE>String</CODE> will be converted to a <CODE>Cell</CODE>.
*
* @param content a <CODE>String</CODE>
* @throws BadElementException this should never happen
*/
public void addCell(String content) throws BadElementException {
addCell(new Phrase(content), curPosition);
}
/**
* Adds a <CODE>Cell</CODE> to the <CODE>Table</CODE>.
* <P>
* This is a shortcut for <CODE>addCell(Cell cell, Point location)</CODE>.
* The <CODE>String</CODE> will be converted to a <CODE>Cell</CODE>.
*
* @param content a <CODE>String</CODE>
* @param location a <CODE>Point</CODE>
* @throws BadElementException this should never happen
*/
public void addCell(String content, Point location) throws BadElementException {
addCell(new Phrase(content), location);
}
/**
* To put a table within the existing table at the current position
* generateTable will of course re-arrange the widths of the columns.
*
* @param aTable the table you want to insert
*/
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 given position
* generateTable will of course re-arrange the widths of the columns.
*
* @param aTable The <CODE>Table</CODE> to add
* @param row The row where the <CODE>Cell</CODE> will be added
* @param column The column where the <CODE>Cell</CODE> will be added
*/
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.
*
* @param aTable the table you want to insert
* @param aLocation a <CODE>Point</CODE>
*/
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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -