Class Table

java.lang.Object
com.codename1.wordprocessing.Table
All Implemented Interfaces:
Block

public final class Table extends Object implements Block

An immutable table: a rectangular grid of cells, each holding its own blocks (paragraphs, pictures and nested tables), with optional merged ranges.

The grid is always rectangular. A merged range keeps its covered cells in the grid; they are simply not shown, so inserting or deleting a row never has to reshape the grid.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    A rectangular range of cells shown as one, anchored at its top-left cell.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
    The number of leading rows repeated at the top of every page the table spans.
    final String
    The block id.
    The merged ranges, never overlapping.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Table(String id, List<List<List<Block>>> cells, List<Table.Merge> merges, int headerRows)
    Creates a table.
  • Method Summary

    Modifier and Type
    Method
    Description
    cell(int row, int column)
    The blocks of one cell.
    cellText(int row, int column)
    The text of one cell without formatting, paragraphs joined by newlines.
    int
    The number of columns.
    The preferred column widths in points, one per column, or an empty list when the columns share the width equally.
    boolean
    covered(int row, int column)
    Whether a cell is hidden inside a merge anchored elsewhere.
    deleteColumn(int at)
    A copy without one column.
    deleteRow(int at)
    A copy without one row.
    boolean
    Two tables are equal when their id, cells, merges, header rows and column widths are.
    int
    A hash consistent with equals.
    id()
    The block id.
    insertColumn(int at)
    A copy with a column of empty cells inserted.
    insertRow(int at)
    A copy with a row of empty cells inserted.
    static Table
    ofText(String id, String[][] values)
    Creates a table whose cells each hold one paragraph of plain text.
    int
    The number of rows.
    span(int row, int column)
    The merge anchored at a cell.
    withCell(int row, int column, List<Block> blocks)
    A copy with one cell's blocks replaced.
    withColumnWidths(float... points)
    A copy with preferred column widths.
    withHeaderRows(int value)
    A copy with a different number of header rows.
    A copy with different merges.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • id

      public final String id
      The block id.
    • headerRows

      public final int headerRows
      The number of leading rows repeated at the top of every page the table spans.
    • merges

      public final List<Table.Merge> merges
      The merged ranges, never overlapping.
  • Constructor Details

    • Table

      public Table(String id, List<List<List<Block>>> cells, List<Table.Merge> merges, int headerRows)

      Creates a table.

      Parameters
      • id: the block id

      • cells: the rows; every row must have the same number of cells and every cell is a list of blocks. The lists are copied.

      • merges: merged ranges, or null for none

      • headerRows: the number of header rows

  • Method Details

    • columnWidths

      public List<Float> columnWidths()

      The preferred column widths in points, one per column, or an empty list when the columns share the width equally. A table wider or narrower than the space it is laid out in keeps the proportions.

      Returns

      the widths, unmodifiable

    • withColumnWidths

      public Table withColumnWidths(float... points)

      A copy with preferred column widths.

      Parameters
      • points: one positive width per column, in points; null or empty for equal columns
      Returns

      the copy

    • id

      public String id()

      The block id.

      Returns

      the id

      Specified by:
      id in interface Block
    • rows

      public int rows()

      The number of rows.

      Returns

      the row count

    • columns

      public int columns()

      The number of columns.

      Returns

      the column count

    • cell

      public List<Block> cell(int row, int column)

      The blocks of one cell.

      Parameters
      • row: the row

      • column: the column

      Returns

      an unmodifiable list

    • cellText

      public String cellText(int row, int column)

      The text of one cell without formatting, paragraphs joined by newlines.

      Parameters
      • row: the row

      • column: the column

      Returns

      the characters

    • span

      public Table.Merge span(int row, int column)

      The merge anchored at a cell.

      Parameters
      • row: the row

      • column: the column

      Returns

      the merge, or null when none starts there

    • covered

      public boolean covered(int row, int column)

      Whether a cell is hidden inside a merge anchored elsewhere.

      Parameters
      • row: the row

      • column: the column

      Returns

      true when covered

    • withCell

      public Table withCell(int row, int column, List<Block> blocks)

      A copy with one cell's blocks replaced.

      Parameters
      • row: the row

      • column: the column

      • blocks: the new contents

      Returns

      the copy

    • withMerges

      public Table withMerges(List<Table.Merge> value)

      A copy with different merges.

      Parameters
      • value: the merges
      Returns

      the copy

    • withHeaderRows

      public Table withHeaderRows(int value)

      A copy with a different number of header rows.

      Parameters
      • value: the header row count
      Returns

      the copy

    • insertRow

      public Table insertRow(int at)

      A copy with a row of empty cells inserted. Merges below move down; a merge the new row passes through grows by one.

      Parameters
      • at: the new row's index, 0 to rows()
      Returns

      the copy

    • deleteRow

      public Table deleteRow(int at)

      A copy without one row. Merges shrink or disappear with it.

      Parameters
      • at: the row to delete
      Returns

      the copy

    • insertColumn

      public Table insertColumn(int at)

      A copy with a column of empty cells inserted.

      Parameters
      • at: the new column's index, 0 to columns()
      Returns

      the copy

    • deleteColumn

      public Table deleteColumn(int at)

      A copy without one column.

      Parameters
      • at: the column to delete
      Returns

      the copy

    • ofText

      public static Table ofText(String id, String[][] values)

      Creates a table whose cells each hold one paragraph of plain text. Paragraph ids are derived from the table id.

      Parameters
      • id: the table id

      • values: the cell texts, row by row; short rows are padded

      Returns

      the table

    • equals

      public boolean equals(Object o)

      Two tables are equal when their id, cells, merges, header rows and column widths are.

      Parameters
      • o: the other object
      Returns

      true when equal

      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()

      A hash consistent with equals.

      Returns

      the hash

      Overrides:
      hashCode in class Object