Class InfoTable


  • public class InfoTable
    extends java.lang.Object
    Used to package and unpackage tabular information to aid with debugging. If you wish to add a new kind of table data that can be viewed with debuggers that support this feature, you must implement a TableGenerator and register it with Tables.
    Since:
    3.0
    Author:
    Chris Jennings
    See Also:
    TableGenerator, Tables
    • Constructor Summary

      Constructors 
      Constructor Description
      InfoTable()
      Creates a new, empty table.
      InfoTable​(java.lang.String[] serializedTable)
      Creates a new table by deserializing a previously serialized table.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.lang.String... row)
      Adds a new row of data to the table.
      static InfoTable errorTable​(java.lang.String message, java.lang.Throwable t)
      Creates a dummy table that is filled in with an error message.
      static java.lang.String escape​(java.lang.String s)
      Escapes the content of a cell string into the format used for serialization.
      java.lang.String get​(int row, int col)
      Returns the table cell for the requested row and column.
      java.lang.String[] getColumns()
      Returns an array of the column names for this table.
      void install​(javax.swing.JTable t)
      Install this table's data in a JTable, replacing the existing table model.
      void section​(java.lang.String name)
      Inserts a new section into the table data.
      void serialize​(java.lang.StringBuilder b)
      Serializes this table's content by writing a string into a StringBuilder.
      void setColumns​(java.lang.String... cols)
      Sets the column names used by this table.
      static java.lang.String unescape​(java.lang.String s)
      Unescapes a previously escaped string from the format used for serialization.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • InfoTable

        public InfoTable()
        Creates a new, empty table.
      • InfoTable

        public InfoTable​(java.lang.String[] serializedTable)
        Creates a new table by deserializing a previously serialized table.
        Parameters:
        serializedTable - a serialized table, presented as one line per array entry
    • Method Detail

      • setColumns

        public void setColumns​(java.lang.String... cols)
        Sets the column names used by this table. The columns can only be set once.
        Parameters:
        cols - an array of column names
        Throws:
        java.lang.NullPointerException - if cols is null
        java.lang.IllegalArgumentException - if the columns
      • getColumns

        public java.lang.String[] getColumns()
        Returns an array of the column names for this table.
        Returns:
        the columns previously set on this table
      • section

        public void section​(java.lang.String name)
        Inserts a new section into the table data. A section is a row with only one column.
        Parameters:
        name - the name of the section
        Throws:
        java.lang.IllegalStateException - if the columns have not been set
      • add

        public void add​(java.lang.String... row)
        Adds a new row of data to the table. One string is passed per column; if the number of strings passed in is less than the number of columns, additional empty columns will be appended to fill out the row. If too many strings are passed in, the superfluous strings are ignored.
        Parameters:
        row - the strings that make up the cells in the this row
        Throws:
        java.lang.IllegalStateException - if the columns have not been set
      • get

        public java.lang.String get​(int row,
                                    int col)
        Returns the table cell for the requested row and column.
        Parameters:
        row - the index of the cell's row
        col - the index of the cell's column
        Returns:
        the cell data at the requested row and column
        Throws:
        java.lang.IndexOutOfBoundsException - if the row or column is outside of the table
      • serialize

        public void serialize​(java.lang.StringBuilder b)
        Serializes this table's content by writing a string into a StringBuilder. This prepares the table for transport to a debugging client running in a separate process.
        Parameters:
        b - the string builder to append the table to
      • install

        public void install​(javax.swing.JTable t)
        Install this table's data in a JTable, replacing the existing table model.
        Parameters:
        t - the table component to use to display the data
      • escape

        public static java.lang.String escape​(java.lang.String s)
        Escapes the content of a cell string into the format used for serialization. You do not typically call this directly; the table implementation handles escaping and unescaping transparently.
        Parameters:
        s - the string to escape
        Returns:
        an escaped string that is ready to serialize
      • unescape

        public static java.lang.String unescape​(java.lang.String s)
        Unescapes a previously escaped string from the format used for serialization. You do not typically call this directly; the table implementation handles escaping and unescaping transparently.
        Parameters:
        s - the string to unescape
        Returns:
        an unescaped string
      • errorTable

        public static InfoTable errorTable​(java.lang.String message,
                                           java.lang.Throwable t)
        Creates a dummy table that is filled in with an error message. This can be used to generate a stand-in table when table generation fails.
        Parameters:
        message - an optional message
        t - an optional exception
        Returns:
        a table that describes the error