java.lang.Object
io.github.chkrishnatej.rp3200.Columns

public final class Columns extends Object
A column layout for table-like rows such as Item | Qty | Amount.

Written as a compact spec string, one entry per column, separated by commas:

Column spec syntax
EntryMeaning
1010 characters wide, left aligned
10r10 characters wide, right aligned (use for numbers)
10c10 characters wide, centred
* / *r / *ctakes the remaining width; several * columns share it equally

Columns are separated by one space (withGap(int) changes that). Text that does not fit is word-wrapped inside its own column. Widths are in normal-size characters; the whole row must fit the profile's PrinterProfile.charsPerLine() (48 on 80 mm, 32 on 58 mm).


 // 80 mm: name gets 48 - 4 - 9 - 10 - 3 gaps = 22 characters
 Columns items = Columns.parse("*,4r,9r,10r");
 builder.row(items, "Item", "Qty", "Rate", "Amount");
 

Immutable and thread-safe: parse once and reuse. In templates the same spec is written as [cols *,4r,9r,10r].

  • Method Details

    • parse

      public static Columns parse(String spec)
      Parses a column spec such as "*,4r,10r". Spaces around entries are ignored.
      Parameters:
      spec - comma-separated column entries, see the class description
      Returns:
      the layout
      Throws:
      IllegalArgumentException - if the spec is empty or an entry is malformed
    • withGap

      public Columns withGap(int spaces)
      Returns a copy with a different number of spaces between columns (default 1).
      Parameters:
      spaces - spaces between neighbouring columns, 0 or more
      Returns:
      the new layout
      Throws:
      IllegalArgumentException - if spaces is negative
    • size

      public int size()
      Returns the number of columns.
      Returns:
      the column count