Class TextTablePrinter


  • public final class TextTablePrinter
    extends TablePrinter
    An interface for creating a text based table. Tables have configurable column widths, padding, and column separators.
    • Constructor Detail

      • TextTablePrinter

        public TextTablePrinter​(OutputStream stream)
        Creates a new text table printer for the specified output stream. The text table printer will have the following initial settings:
        • headings will be displayed
        • no separators between columns
        • columns are padded by one character
        Parameters:
        stream - The stream to output tables to.
      • TextTablePrinter

        public TextTablePrinter​(Writer writer)
        Creates a new text table printer for the specified writer. The text table printer will have the following initial settings:
        • headings will be displayed
        • no separators between columns
        • columns are padded by one character
        Parameters:
        writer - The writer to output tables to.
    • Method Detail

      • setColumnSeparator

        public void setColumnSeparator​(String columnSeparator)
        Sets the column separator which should be used to separate one column from the next (not including padding).
        Parameters:
        columnSeparator - The column separator.
      • setColumnWidth

        public void setColumnWidth​(int column,
                                   int width)
        Set the maximum width for a column. If a cell is too big to fit in its column then it will be wrapped.
        Parameters:
        column - The column to make fixed width (0 is the first column).
        width - The width of the column (this should not include column separators or padding), or 0 to indicate that this column should be expandable.
        Throws:
        IllegalArgumentException - If column is less than 0.
      • setDisplayHeadings

        public void setDisplayHeadings​(boolean displayHeadings)
        Specify whether the column headings should be displayed or not.
        Parameters:
        displayHeadings - true if column headings should be displayed.
      • setHeadingSeparator

        public void setHeadingSeparator​(char headingSeparator)
        Sets the heading separator which should be used to separate the table heading row from the rows beneath.
        Parameters:
        headingSeparator - The heading separator.
      • setHeadingSeparatorStartColumn

        public void setHeadingSeparatorStartColumn​(int startColumn)
        Sets the heading separator start column. The heading separator will only be display in the specified column and all subsequent columns. Usually this should be left at zero (the default) but sometimes it useful to indent the heading separate in order to provide additional emphasis (for example in menus).
        Parameters:
        startColumn - The heading separator start column.
      • setIndentWidth

        public void setIndentWidth​(int indentWidth)
        Sets the amount of characters that the table should be indented. By default the table is not indented.
        Parameters:
        indentWidth - The number of characters the table should be indented.
        Throws:
        IllegalArgumentException - If indentWidth is less than 0.
      • setPadding

        public void setPadding​(int padding)
        Sets the padding which will be used to separate a cell's contents from its adjacent column separators.
        Parameters:
        padding - The padding.
      • setTotalWidth

        public void setTotalWidth​(int totalWidth)
        Sets the total permitted width for the table which expandable columns can use up.
        Parameters:
        totalWidth - The total width.
      • getSerializer

        protected TableSerializer getSerializer()
        Description copied from class: TablePrinter
        Creates a new table serializer based on the configuration of this table printer.
        Specified by:
        getSerializer in class TablePrinter
        Returns:
        Returns a new table serializer based on the configuration of this table printer.