- java.lang.Object
-
- com.itextpdf.text.Rectangle
-
- com.itextpdf.text.Cell
-
- All Implemented Interfaces:
Element,TextElementArray
public class Cell extends Rectangle implements TextElementArray
ACellis aRectanglecontaining otherElements.A
Cellmust be added to aTable. TheTablewill place theCellin aRow.Example:
Table table = new Table(3); table.setBorderWidth(1); table.setBorderColor(new Color(0, 0, 255)); table.setCellpadding(5); table.setCellspacing(5); Cell cell = new Cell("header"); cell.setHeader(true); cell.setColspan(3); table.addCell(cell); cell = new Cell("example cell with colspan 1 and rowspan 2"); cell.setRowspan(2); cell.setBorderColor(new Color(255, 0, 0)); table.addCell(cell); table.addCell("1.1"); table.addCell("2.1"); table.addCell("1.2"); table.addCell("2.2");
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.ArrayListarrayListTheArrayListofElements that are part of the content of the Cell.protected intcolspanThe colspan of the cell.protected booleangroupChangeDoes thisCellforce a group change?protected booleanheaderIs thisCella header?protected inthorizontalAlignmentThe horizontal alignment of the cell content.protected intmaxLinesMaximum number of lines allowed in the cell.protected booleanpercentageprotected introwspanThe rowspan of the cell.protected booleanuseAscenderIndicates that the largest ascender height should be used to determine the height of the first line.protected booleanuseBorderPaddingAdjusts the cell contents to compensate for border widths.protected booleanuseDescenderIndicates that the largest descender height should be added to the height of the last line (so characters like y don't dip into the border).protected intverticalAlignmentThe vertical alignment of the cell content.protected floatwidthThe width of the cell as a String.-
Fields inherited from class com.itextpdf.text.Rectangle
backgroundColor, border, borderColor, borderColorBottom, borderColorLeft, borderColorRight, borderColorTop, borderWidth, borderWidthBottom, borderWidthLeft, borderWidthRight, borderWidthTop, BOTTOM, BOX, LEFT, llx, lly, NO_BORDER, RIGHT, rotation, TOP, UNDEFINED, urx, ury, useVariableBorders
-
Fields inherited from interface com.itextpdf.text.Element
ALIGN_BASELINE, ALIGN_BOTTOM, ALIGN_CENTER, ALIGN_JUSTIFIED, ALIGN_JUSTIFIED_ALL, ALIGN_LEFT, ALIGN_MIDDLE, ALIGN_RIGHT, ALIGN_TOP, ALIGN_UNDEFINED, ANCHOR, ANNOTATION, AUTHOR, CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFBLOCK, CCITT_ENDOFLINE, CCITTG3_1D, CCITTG3_2D, CCITTG4, CELL, CHAPTER, CHUNK, CREATIONDATE, CREATOR, HEADER, IMGRAW, IMGTEMPLATE, JBIG2, JPEG, JPEG2000, KEYWORDS, LIST, LISTITEM, MARKED, MULTI_COLUMN_TEXT, PARAGRAPH, PHRASE, PRODUCER, PTABLE, RECTANGLE, ROW, SECTION, SUBJECT, TABLE, TITLE, YMARK
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(java.lang.Object o)Add anObjectto this cell.voidaddElement(Element element)Adds an element to thisCell.floatbottom(int margin)This method throws anUnsupportedOperationException.voidclear()Clears all theElements of thisCell.PdfPCellcreatePdfPCell()Creates a PdfPCell based on this Cell object.floatgetBottom()This method throws anUnsupportedOperationException.java.util.ArrayListgetChunks()Gets all the chunks in this element.intgetColspan()Gets the colspan.java.util.IteratorgetElements()Gets an iterator ofElements.booleangetGroupChange()Does thisCellforce a group change?intgetHorizontalAlignment()Gets the horizontal alignment.floatgetLeading()Gets the leading.floatgetLeft()This method throws anUnsupportedOperationException.intgetMaxLines()Getter for maxLinesfloatgetRight()This method throws anUnsupportedOperationException.intgetRowspan()Gets the rowspan.java.lang.StringgetShowTruncation()Getter for showTruncationfloatgetTop()This method throws anUnsupportedOperationException.intgetVerticalAlignment()Gets the vertical alignment.floatgetWidth()Gets the width.java.lang.StringgetWidthAsString()Gets the width as a String.booleanisEmpty()Checks if theCellis empty.booleanisHeader()Is thisCella header?booleanisTable()Checks if thisCellis a placeholder for a (nested) table.booleanisUseAscender()Gets the value of useAscenderbooleanisUseBorderPadding()Gets the value of useBorderPadding.booleanisUseDescender()gets the value of useDescenderfloatleft(int margin)This method throws anUnsupportedOperationException.booleanprocess(ElementListener listener)Processes the element by adding it (or the different parts) to anElementListener.floatright(int margin)This method throws anUnsupportedOperationException.voidsetBottom(int value)This method throws anUnsupportedOperationException.voidsetColspan(int value)Sets the colspan.voidsetGroupChange(boolean value)Sets group change.voidsetHeader(boolean value)Sets header.voidsetHorizontalAlignment(int value)Sets the horizontal alignment.voidsetHorizontalAlignment(java.lang.String alignment)Sets the alignment of this cell.voidsetLeading(float value)Sets the leading.voidsetLeft(int value)This method throws anUnsupportedOperationException.voidsetMaxLines(int value)Setter for maxLinesvoidsetRight(int value)This method throws anUnsupportedOperationException.voidsetRowspan(int value)Sets the rowspan.voidsetShowTruncation(java.lang.String value)Setter for showTruncationvoidsetTop(int value)This method throws anUnsupportedOperationException.voidsetUseAscender(boolean use)Sets the value of useAscender.voidsetUseBorderPadding(boolean use)Sets the value of useBorderPadding.voidsetUseDescender(boolean use)Sets the value of useDescender.voidsetVerticalAlignment(int value)Sets the vertical alignment.voidsetVerticalAlignment(java.lang.String alignment)Sets the alignment of this paragraph.voidsetWidth(float value)Sets the width.voidsetWidth(java.lang.String value)Sets the width.intsize()Gets the number ofElements in the Cell.floattop(int margin)This method throws anUnsupportedOperationException.inttype()Gets the type of the text element.-
Methods inherited from class com.itextpdf.text.Rectangle
cloneNonPositionParameters, disableBorderSide, enableBorderSide, getBackgroundColor, getBorder, getBorderColor, getBorderColorBottom, getBorderColorLeft, getBorderColorRight, getBorderColorTop, getBorderWidth, getBorderWidthBottom, getBorderWidthLeft, getBorderWidthRight, getBorderWidthTop, getBottom, getGrayFill, getHeight, getLeft, getRight, getRotation, getTop, hasBorder, hasBorders, isContent, isNestable, isUseVariableBorders, normalize, rectangle, rotate, setBackgroundColor, setBorder, setBorderColor, setBorderColorBottom, setBorderColorLeft, setBorderColorRight, setBorderColorTop, setBorderWidth, setBorderWidthBottom, setBorderWidthLeft, setBorderWidthRight, setBorderWidthTop, setBottom, setGrayFill, setLeft, setRight, setTop, setUseVariableBorders, softCloneNonPositionParameters, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.itextpdf.text.Element
isContent, isNestable, toString
-
-
-
-
Field Detail
-
arrayList
protected java.util.ArrayList arrayList
TheArrayListofElements that are part of the content of the Cell.
-
horizontalAlignment
protected int horizontalAlignment
The horizontal alignment of the cell content.
-
verticalAlignment
protected int verticalAlignment
The vertical alignment of the cell content.
-
width
protected float width
The width of the cell as a String. It can be an absolute value "100" or a percentage "20%".
-
percentage
protected boolean percentage
-
colspan
protected int colspan
The colspan of the cell.
-
rowspan
protected int rowspan
The rowspan of the cell.
-
header
protected boolean header
Is thisCella header?
-
maxLines
protected int maxLines
Maximum number of lines allowed in the cell. The default value of this property is not to limit the maximum number of lines (contributed by dperezcar@fcc.es)
-
useAscender
protected boolean useAscender
Indicates that the largest ascender height should be used to determine the height of the first line. Note that this only has an effect when rendered to PDF. Setting this to true can help with vertical alignment problems.
-
useDescender
protected boolean useDescender
Indicates that the largest descender height should be added to the height of the last line (so characters like y don't dip into the border). Note that this only has an effect when rendered to PDF.
-
useBorderPadding
protected boolean useBorderPadding
Adjusts the cell contents to compensate for border widths. Note that this only has an effect when rendered to PDF.
-
groupChange
protected boolean groupChange
Does thisCellforce a group change?
-
-
Constructor Detail
-
Cell
public Cell()
Constructs an emptyCell.
-
Cell
public Cell(boolean dummy)
Constructs an emptyCell(for internal use only).- Parameters:
dummy- a dummy value
-
Cell
public Cell(java.lang.String content)
Constructs aCellwith a certain content.The
Stringwill be converted into aParagraph.- Parameters:
content- aString
-
Cell
public Cell(Element element) throws BadElementException
Constructs aCellwith a certainElement.if the element is a
ListItem,RoworCell, an exception will be thrown.- Parameters:
element- the element- Throws:
BadElementException- when the creator was called with aListItem,RoworCell
-
-
Method Detail
-
process
public boolean process(ElementListener listener)
Processes the element by adding it (or the different parts) to anElementListener.
-
type
public int type()
Gets the type of the text element.
-
getChunks
public java.util.ArrayList getChunks()
Gets all the chunks in this element.
-
getHorizontalAlignment
public int getHorizontalAlignment()
Gets the horizontal alignment.- Returns:
- a value
-
setHorizontalAlignment
public void setHorizontalAlignment(int value)
Sets the horizontal alignment.- Parameters:
value- the new value
-
setHorizontalAlignment
public void setHorizontalAlignment(java.lang.String alignment)
Sets the alignment of this cell. This methods allows you to set the alignment as a String.- Parameters:
alignment- the new alignment as aString
-
getVerticalAlignment
public int getVerticalAlignment()
Gets the vertical alignment.- Returns:
- a value
-
setVerticalAlignment
public void setVerticalAlignment(int value)
Sets the vertical alignment.- Parameters:
value- the new value
-
setVerticalAlignment
public void setVerticalAlignment(java.lang.String alignment)
Sets the alignment of this paragraph.- Parameters:
alignment- the new alignment as aString
-
setWidth
public void setWidth(float value)
Sets the width.- Parameters:
value- the new value
-
setWidth
public void setWidth(java.lang.String value)
Sets the width. It can be an absolute value "100" or a percentage "20%"- Parameters:
value- the new value
-
getWidth
public float getWidth()
Gets the width.
-
getWidthAsString
public java.lang.String getWidthAsString()
Gets the width as a String.- Returns:
- a value
-
setColspan
public void setColspan(int value)
Sets the colspan.- Parameters:
value- the new value
-
getColspan
public int getColspan()
Gets the colspan.- Returns:
- a value
-
setRowspan
public void setRowspan(int value)
Sets the rowspan.- Parameters:
value- the new value
-
getRowspan
public int getRowspan()
Gets the rowspan.- Returns:
- a value
-
setLeading
public void setLeading(float value)
Sets the leading.- Parameters:
value- the new value
-
getLeading
public float getLeading()
Gets the leading.- Returns:
- a value
-
setHeader
public void setHeader(boolean value)
Sets header.- Parameters:
value- the new value
-
isHeader
public boolean isHeader()
Is thisCella header?- Returns:
- a value
-
setMaxLines
public void setMaxLines(int value)
Setter for maxLines- Parameters:
value- the maximum number of lines
-
getMaxLines
public int getMaxLines()
Getter for maxLines- Returns:
- the maxLines value
-
setShowTruncation
public void setShowTruncation(java.lang.String value)
Setter for showTruncation- Parameters:
value- Can be null for avoiding marking the truncation.
-
getShowTruncation
public java.lang.String getShowTruncation()
Getter for showTruncation- Returns:
- the showTruncation value
-
setUseAscender
public void setUseAscender(boolean use)
Sets the value of useAscender.- Parameters:
use- use ascender height if true
-
isUseAscender
public boolean isUseAscender()
Gets the value of useAscender- Returns:
- useAscender
-
setUseDescender
public void setUseDescender(boolean use)
Sets the value of useDescender.- Parameters:
use- use descender height if true
-
isUseDescender
public boolean isUseDescender()
gets the value of useDescender- Returns:
- useDescender
-
setUseBorderPadding
public void setUseBorderPadding(boolean use)
Sets the value of useBorderPadding.- Parameters:
use- adjust layout for borders if true
-
isUseBorderPadding
public boolean isUseBorderPadding()
Gets the value of useBorderPadding.- Returns:
- useBorderPadding
-
getGroupChange
public boolean getGroupChange()
Does thisCellforce a group change?- Returns:
- a value
-
setGroupChange
public void setGroupChange(boolean value)
Sets group change.- Parameters:
value- the new value
-
size
public int size()
Gets the number ofElements in the Cell.- Returns:
- a
size.
-
getElements
public java.util.Iterator getElements()
Gets an iterator ofElements.- Returns:
- an
Iterator.
-
clear
public void clear()
Clears all theElements of thisCell.
-
isEmpty
public boolean isEmpty()
Checks if theCellis empty.- Returns:
falseif there are non-emptyElements in theCell.
-
isTable
public boolean isTable()
Checks if thisCellis a placeholder for a (nested) table.- Returns:
- true if the only element in this cell is a table
-
addElement
public void addElement(Element element) throws BadElementException
Adds an element to thisCell.Remark: you can't add
ListItems,Rows,Cells,JPEGs,GIFs orPNGs to aCell.- Parameters:
element- TheElementto add- Throws:
BadElementException- if the method was called with aListItem,RoworCell
-
add
public boolean add(java.lang.Object o)
Add anObjectto this cell.- Specified by:
addin interfaceTextElementArray- Parameters:
o- the object to add- Returns:
- always
true
-
createPdfPCell
public PdfPCell createPdfPCell() throws BadElementException
Creates a PdfPCell based on this Cell object.- Returns:
- a PdfPCell
- Throws:
BadElementException
-
getTop
public float getTop()
This method throws anUnsupportedOperationException.
-
getBottom
public float getBottom()
This method throws anUnsupportedOperationException.
-
getLeft
public float getLeft()
This method throws anUnsupportedOperationException.
-
getRight
public float getRight()
This method throws anUnsupportedOperationException.
-
top
public float top(int margin)
This method throws anUnsupportedOperationException.- Parameters:
margin-- Returns:
- NA
-
bottom
public float bottom(int margin)
This method throws anUnsupportedOperationException.- Parameters:
margin-- Returns:
- NA
-
left
public float left(int margin)
This method throws anUnsupportedOperationException.- Parameters:
margin-- Returns:
- NA
-
right
public float right(int margin)
This method throws anUnsupportedOperationException.- Parameters:
margin- NA- Returns:
- NA
-
setTop
public void setTop(int value)
This method throws anUnsupportedOperationException.- Parameters:
value- NA
-
setBottom
public void setBottom(int value)
This method throws anUnsupportedOperationException.- Parameters:
value- NA
-
setLeft
public void setLeft(int value)
This method throws anUnsupportedOperationException.- Parameters:
value- NA
-
setRight
public void setRight(int value)
This method throws anUnsupportedOperationException.- Parameters:
value- NA
-
-