Class PLTable
- java.lang.Object
-
- com.helger.pdflayout.base.AbstractPLObject<IMPLTYPE>
-
- com.helger.pdflayout.base.AbstractPLRenderableObject<PLTable>
-
- com.helger.pdflayout.element.table.PLTable
-
- All Implemented Interfaces:
com.helger.commons.id.IHasID<String>,com.helger.commons.traits.IGenericImplTrait<PLTable>,IPLHasMargin<PLTable>,IPLHasOutline,IPLObject<PLTable>,IPLRenderableObject<PLTable>,IPLSplittableObject<PLTable,PLTable>,IPLVisitable
public class PLTable extends AbstractPLRenderableObject<PLTable> implements IPLSplittableObject<PLTable,PLTable>, IPLHasMargin<PLTable>
A special table with a repeating header- Author:
- Philip Helger
-
-
Field Summary
-
Fields inherited from interface com.helger.pdflayout.base.IPLHasMargin
DEFAULT_MARGIN
-
Fields inherited from interface com.helger.pdflayout.base.IPLSplittableObject
DEFAULT_VERT_SPLITTABLE
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description PLTableRowaddAndReturnRow(PLTableCell... aCells)PLTableRowaddAndReturnRow(Iterable<? extends PLTableCell> aCells)Add a new table row with auto height.PLTableRowaddAndReturnRow(Iterable<? extends PLTableCell> aCells, HeightSpec aHeight)Add a new table row.PLTableaddRow()Deprecated.PLTableaddRow(PLTableCell... aCells)Add a new table row with auto height.PLTableaddRow(PLTableRow aRow)PLTableaddRow(PLTableRow aRow, HeightSpec aHeight)PLTableaddRow(Iterable<? extends PLTableCell> aCells)Add a new table row with auto height.PLTableaddRow(Iterable<? extends PLTableCell> aCells, HeightSpec aHeight)Add a new table row.static PLTablecreateWithEvenlySizedColumns(int nColumnCount)Create a new table with evenly sized columns.static PLTablecreateWithPercentage(float... aPercentages)Create a new table with the specified percentages.voidforEachCell(Consumer<? super PLTableCell> aConsumer)voidforEachRow(int nStartRowIncl, int nEndRowIncl, Consumer<? super PLTableRow> aConsumer)voidforEachRow(int nStartRowIncl, int nEndRowIncl, ObjIntConsumer<? super PLTableRow> aConsumer)voidforEachRow(Consumer<? super PLTableRow> aConsumer)voidforEachRowByIndex(ObjIntConsumer<? super PLTableRow> aConsumer)com.helger.commons.collection.impl.ICommonsList<WidthSpec>getAllWidths()PLTableCellgetCellAtIndex(int nRowIndex, int nColIndex)intgetColumnCount()intgetHeaderRowCount()MarginSpecgetMargin()PLTableRowgetRowAtIndex(int nIndex)intgetRowCount()PLTableinternalCreateNewVertSplitObject(PLTable aBase)Create a new object of the same type as this object.booleanisVertSplittable()protected voidonAfterSetID()Callback invoked after an ID change.protected voidonMarkAsNotPrepared()PL objects need to overwrite this method to reset their preparation state.protected SizeSpeconPrepare(PreparationContext aCtx)The abstract method that must be implemented by all subclasses.protected voidonRender(PageRenderContext aCtx)Abstract method to be implemented by subclasses.PLTablesetBasicDataFrom(PLTable aSource)For copying stuff internally.PLTablesetHeaderRowCount(int nHeaderRowCount)PLTablesetMargin(MarginSpec aMargin)Set the margin values.PLTablesetVertSplittable(boolean bVertSplittable)Change the vertical splitability of this object.PLSplitResultsplitElementVert(float fAvailableWidth, float fAvailableHeight)Split this element vertically into sub-elements according to the available height.StringtoString()com.helger.commons.state.EChangevisit(IPLVisitor aVisitor)Visit this object and all descendants-
Methods inherited from class com.helger.pdflayout.base.AbstractPLRenderableObject
getPrepareAvailableSize, getPreparedSize, getRenderSize, getRenderSize, internalCheckAlreadyPrepared, internalCheckNotPrepared, internalMarkAsNotPrepared, internalMarkAsNotPreparedDontPropagate, internalMarkAsPrepared, isPrepared, onRenderSizeChange, prepare, render
-
Methods inherited from class com.helger.pdflayout.base.AbstractPLObject
getDebugID, getID, setID
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.pdflayout.base.IPLHasMargin
addMarginBottom, addMarginLeft, addMarginRight, addMarginTop, addMarginX, addMarginY, getMarginBottom, getMarginLeft, getMarginRight, getMarginTop, getMarginXSum, getMarginYSum, getOutlineBottom, getOutlineLeft, getOutlineRight, getOutlineTop, getOutlineXSum, getOutlineYSum, setMargin, setMargin, setMargin, setMarginBottom, setMarginLeft, setMarginRight, setMarginTop, setMarginX, setMarginY
-
Methods inherited from interface com.helger.pdflayout.base.IPLObject
getAsSplittable, getDebugID, hasID
-
Methods inherited from interface com.helger.pdflayout.base.IPLRenderableObject
beforeRender, getPreparedHeight, getPreparedWidth, getRenderHeight, getRenderWidth
-
-
-
-
Constructor Detail
-
PLTable
@Deprecated @DevelopersNote("This ctor is only present to indicate if the varargs ctor would be used without parameters") public PLTable()
Deprecated.Don't use that constructor. UsePLTable(Iterable)orPLTable(WidthSpec...)!!!
-
PLTable
public PLTable(@Nonnull @Nonempty WidthSpec... aWidths)
- Parameters:
aWidths- Must all be of the same type! "auto" width is not allowed - only "star" may be used.
-
-
Method Detail
-
onAfterSetID
@OverridingMethodsMustInvokeSuper protected void onAfterSetID()
Description copied from class:AbstractPLObjectCallback invoked after an ID change. Overwrite this method to do local actions (if needed)- Overrides:
onAfterSetIDin classAbstractPLObject<PLTable>
-
setBasicDataFrom
@Nonnull @OverridingMethodsMustInvokeSuper public PLTable setBasicDataFrom(@Nonnull PLTable aSource)
Description copied from interface:IPLObjectFor copying stuff internally. Must always call super method- Specified by:
setBasicDataFromin interfaceIPLObject<PLTable>- Overrides:
setBasicDataFromin classAbstractPLRenderableObject<PLTable>- Parameters:
aSource- Source object to copy from. May not benull.- Returns:
- this for chaining
-
getMargin
@Nonnull public final MarginSpec getMargin()
- Specified by:
getMarginin interfaceIPLHasMargin<PLTable>- Returns:
- The current margin. Never
null.
-
setMargin
@Nonnull public final PLTable setMargin(@Nonnull MarginSpec aMargin)
Description copied from interface:IPLHasMarginSet the margin values.- Specified by:
setMarginin interfaceIPLHasMargin<PLTable>- Parameters:
aMargin- Margin to use. May not benull.- Returns:
- this
-
getAllWidths
@Nonnull @Nonempty @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<WidthSpec> getAllWidths()
- Returns:
- A copy of the list with all widths as specified in the constructor.
Neither
nullnor empty.
-
getColumnCount
@Nonnegative public int getColumnCount()
- Returns:
- The number of columns in the table. Always ≥ 0.
-
setHeaderRowCount
@Nonnull public PLTable setHeaderRowCount(@Nonnegative int nHeaderRowCount)
-
getHeaderRowCount
@Nonnegative public int getHeaderRowCount()
-
addAndReturnRow
@Nonnull public PLTableRow addAndReturnRow(@Nonnull PLTableCell... aCells)
-
addAndReturnRow
@Nonnull public PLTableRow addAndReturnRow(@Nonnull Iterable<? extends PLTableCell> aCells)
Add a new table row with auto height. All contained elements are added with the specified width in the constructor.nullelements are represented as empty cells.- Parameters:
aCells- The cells to add. May not benull.- Returns:
- the added table row and never
null.
-
addAndReturnRow
@Nonnull public PLTableRow addAndReturnRow(@Nonnull Iterable<? extends PLTableCell> aCells, @Nonnull HeightSpec aHeight)
Add a new table row. All contained elements are added with the specified width in the constructor.nullelements are represented as empty cells.- Parameters:
aCells- The cells to add. May not benullbut may containnullvalues.aHeight- Row height to be used. May not benull.- Returns:
- the added table row and never
null.
-
addRow
@Nonnull public PLTable addRow(@Nonnull PLTableRow aRow)
-
addRow
@Nonnull public PLTable addRow(@Nonnull PLTableRow aRow, @Nonnull HeightSpec aHeight)
-
addRow
@Nonnull @Deprecated public PLTable addRow()
Deprecated.Don't call this.- Returns:
- this for chaining
-
addRow
@Nonnull public PLTable addRow(@Nonnull PLTableCell... aCells)
Add a new table row with auto height. All contained elements are added with the specified width in the constructor.nullelements are represented as empty cells.- Parameters:
aCells- The cells to add. May not benull.- Returns:
- this
-
addRow
@Nonnull public PLTable addRow(@Nonnull Iterable<? extends PLTableCell> aCells)
Add a new table row with auto height. All contained elements are added with the specified width in the constructor.nullelements are represented as empty cells.- Parameters:
aCells- The cells to add. May not benull.- Returns:
- this
-
addRow
@Nonnull public PLTable addRow(@Nonnull Iterable<? extends PLTableCell> aCells, @Nonnull HeightSpec aHeight)
Add a new table row. All contained elements are added with the specified width in the constructor.nullelements are represented as empty cells.- Parameters:
aCells- The cells to add. May not benull.aHeight- Row height to be used.- Returns:
- this
-
forEachRow
public void forEachRow(@Nonnull Consumer<? super PLTableRow> aConsumer)
-
forEachRowByIndex
public void forEachRowByIndex(@Nonnull ObjIntConsumer<? super PLTableRow> aConsumer)
-
forEachRow
public void forEachRow(int nStartRowIncl, int nEndRowIncl, @Nonnull Consumer<? super PLTableRow> aConsumer)
-
forEachRow
public void forEachRow(int nStartRowIncl, int nEndRowIncl, @Nonnull ObjIntConsumer<? super PLTableRow> aConsumer)
-
getRowCount
@Nonnegative public int getRowCount()
-
forEachCell
public void forEachCell(@Nonnull Consumer<? super PLTableCell> aConsumer)
-
getRowAtIndex
@Nullable public PLTableRow getRowAtIndex(@Nonnegative int nIndex)
-
getCellAtIndex
@Nullable public PLTableCell getCellAtIndex(@Nonnegative int nRowIndex, @Nonnegative int nColIndex)
-
visit
@Nonnull public com.helger.commons.state.EChange visit(@Nonnull IPLVisitor aVisitor) throws IOException
Description copied from interface:IPLVisitableVisit this object and all descendants- Specified by:
visitin interfaceIPLVisitable- Overrides:
visitin classAbstractPLRenderableObject<PLTable>- Parameters:
aVisitor- The visitor to use. May not benull.- Returns:
EChange.CHANGEDif something changed internally.- Throws:
IOException- on PDFBox error
-
onPrepare
@OverridingMethodsMustInvokeSuper protected SizeSpec onPrepare(@Nonnull PreparationContext aCtx)
Description copied from class:AbstractPLRenderableObjectThe abstract method that must be implemented by all subclasses. It is ensured that this method is called only once per instance!- Specified by:
onPreparein classAbstractPLRenderableObject<PLTable>- Parameters:
aCtx- Preparation context. Nevernull.- Returns:
- The size of the rendered element without padding, border and
margin. May not be
null.
-
onMarkAsNotPrepared
protected void onMarkAsNotPrepared()
Description copied from class:AbstractPLRenderableObjectPL objects need to overwrite this method to reset their preparation state. They also need to propagate this to their children!- Specified by:
onMarkAsNotPreparedin classAbstractPLRenderableObject<PLTable>
-
isVertSplittable
public final boolean isVertSplittable()
- Specified by:
isVertSplittablein interfaceIPLObject<PLTable>- Specified by:
isVertSplittablein interfaceIPLSplittableObject<PLTable,PLTable>- Returns:
trueif this element is vertically splittable,falseotherwise. The default isIPLSplittableObject.DEFAULT_VERT_SPLITTABLE.
-
setVertSplittable
@Nonnull public final PLTable setVertSplittable(boolean bVertSplittable)
Description copied from interface:IPLSplittableObjectChange the vertical splitability of this object.- Specified by:
setVertSplittablein interfaceIPLSplittableObject<PLTable,PLTable>- Parameters:
bVertSplittable-trueif this element is splittable,falseotherwise.- Returns:
- this for chaining
-
internalCreateNewVertSplitObject
@Nonnull public PLTable internalCreateNewVertSplitObject(@Nonnull PLTable aBase)
Description copied from interface:IPLSplittableObjectCreate a new object of the same type as this object.- Specified by:
internalCreateNewVertSplitObjectin interfaceIPLSplittableObject<PLTable,PLTable>- Parameters:
aBase- The source object to copy data from.- Returns:
- Never
null.
-
splitElementVert
@Nullable public PLSplitResult splitElementVert(float fAvailableWidth, float fAvailableHeight)
Description copied from interface:IPLSplittableObjectSplit this element vertically into sub-elements according to the available height. Splitting is always done after preparation and must return prepared objects!- Specified by:
splitElementVertin interfaceIPLSplittableObject<PLTable,PLTable>- Parameters:
fAvailableWidth- The available width without outline of the element.fAvailableHeight- The available height without outline of this element. Must be ≥ 0.- Returns:
nullif splitting makes no sense.
-
onRender
protected void onRender(@Nonnull PageRenderContext aCtx) throws IOException
Description copied from class:AbstractPLRenderableObjectAbstract method to be implemented by subclasses.- Specified by:
onRenderin classAbstractPLRenderableObject<PLTable>- Parameters:
aCtx- Rendering context. Nevernull.- Throws:
IOException- In case of a PDFBox error
-
toString
public String toString()
- Overrides:
toStringin classAbstractPLRenderableObject<PLTable>
-
createWithPercentage
@Nonnull @ReturnsMutableCopy public static PLTable createWithPercentage(@Nonnull @Nonempty float... aPercentages)
Create a new table with the specified percentages.- Parameters:
aPercentages- The array to use. The sum of all percentages should be ≤ 100. May neither benullnor empty.- Returns:
- The created
PLTableand nevernull.
-
createWithEvenlySizedColumns
@Nonnull @ReturnsMutableCopy public static PLTable createWithEvenlySizedColumns(@Nonnegative int nColumnCount)
Create a new table with evenly sized columns.- Parameters:
nColumnCount- The number of columns to use. Must be > 0.- Returns:
- The created
PLTableand nevernull.
-
-