Package jexer

Class TTableWidget

  • All Implemented Interfaces:
    java.lang.Comparable<TWidget>

    public class TTableWidget
    extends TWidget
    TTableWidget is used to display and edit regular two-dimensional tables of cells. This class was inspired by a TTable implementation originally developed by David "Niki" ROULET [niki@nikiroo.be], made available under MIT at https://github.com/nikiroo/jexer/tree/ttable_pull.
    • Constructor Detail

      • TTableWidget

        public TTableWidget​(TWidget parent,
                            int x,
                            int y,
                            int width,
                            int height,
                            int gridColumns,
                            int gridRows)
        Public constructor.
        Parameters:
        parent - parent widget
        x - column relative to parent
        y - row relative to parent
        width - width of widget
        height - height of widget
        gridColumns - number of columns in grid
        gridRows - number of rows in grid
      • TTableWidget

        public TTableWidget​(TWidget parent,
                            int x,
                            int y,
                            int width,
                            int height)
        Public constructor.
        Parameters:
        parent - parent widget
        x - column relative to parent
        y - row relative to parent
        width - width of widget
        height - height of widget
    • Method Detail

      • onMouseDown

        public void onMouseDown​(TMouseEvent mouse)
        Handle mouse press events.
        Overrides:
        onMouseDown in class TWidget
        Parameters:
        mouse - mouse button press event
      • onKeypress

        public void onKeypress​(TKeypressEvent keypress)
        Handle keystrokes.
        Overrides:
        onKeypress in class TWidget
        Parameters:
        keypress - keystroke event
      • onResize

        public void onResize​(TResizeEvent event)
        Handle widget resize events.
        Overrides:
        onResize in class TWidget
        Parameters:
        event - resize event
      • draw

        public void draw()
        Draw the table row/column labels, and borders.
        Overrides:
        draw in class TWidget
      • getSelectedCell

        public TTableWidget.Cell getSelectedCell()
        Get the currently-selected cell.
        Returns:
        the selected cell
      • getSelectedColumn

        public TTableWidget.Column getSelectedColumn()
        Get the currently-selected column.
        Returns:
        the selected column
      • getSelectedRow

        public TTableWidget.Row getSelectedRow()
        Get the currently-selected row.
        Returns:
        the selected row
      • getSelectedColumnNumber

        public int getSelectedColumnNumber()
        Get the currently-selected column number. 0 is the left-most column.
        Returns:
        the selected column number
      • setSelectedColumnNumber

        public void setSelectedColumnNumber​(int column)
        Set the currently-selected column number. 0 is the left-most column.
        Parameters:
        column - the column number to select
      • getSelectedRowNumber

        public int getSelectedRowNumber()
        Get the currently-selected row number. 0 is the top-most row.
        Returns:
        the selected row number
      • setSelectedRowNumber

        public void setSelectedRowNumber​(int row)
        Set the currently-selected row number. 0 is the left-most column.
        Parameters:
        row - the row number to select
      • getHighlightRow

        public boolean getHighlightRow()
        Get the highlight row flag.
        Returns:
        true if the selected row is highlighted
      • setHighlightRow

        public void setHighlightRow​(boolean highlightRow)
        Set the highlight row flag.
        Parameters:
        highlightRow - if true, the selected row will be highlighted
      • getHighlightColumn

        public boolean getHighlightColumn()
        Get the highlight column flag.
        Returns:
        true if the selected column is highlighted
      • setHighlightColumn

        public void setHighlightColumn​(boolean highlightColumn)
        Set the highlight column flag.
        Parameters:
        highlightColumn - if true, the selected column will be highlighted
      • getShowRowLabels

        public boolean getShowRowLabels()
        Get the show row labels flag.
        Returns:
        true if row labels are shown
      • setShowRowLabels

        public void setShowRowLabels​(boolean showRowLabels)
        Set the show row labels flag.
        Parameters:
        showRowLabels - if true, the row labels will be shown
      • getShowColumnLabels

        public boolean getShowColumnLabels()
        Get the show column labels flag.
        Returns:
        true if column labels are shown
      • setShowColumnLabels

        public void setShowColumnLabels​(boolean showColumnLabels)
        Set the show column labels flag.
        Parameters:
        showColumnLabels - if true, the column labels will be shown
      • getColumnCount

        public int getColumnCount()
        Get the number of columns.
        Returns:
        the number of columns
      • getRowCount

        public int getRowCount()
        Get the number of rows.
        Returns:
        the number of rows
      • loadCsvFile

        public void loadCsvFile​(java.io.File csvFile)
                         throws java.io.IOException
        Load contents from file in CSV format.
        Parameters:
        csvFile - a File referencing the CSV data
        Throws:
        java.io.IOException - if a java.io operation throws
      • saveToCsvFilename

        public void saveToCsvFilename​(java.lang.String filename)
                               throws java.io.IOException
        Save contents to file in CSV format.
        Parameters:
        filename - file to save to
        Throws:
        java.io.IOException - if a java.io operation throws
      • saveToTextFilename

        public void saveToTextFilename​(java.lang.String filename)
                                throws java.io.IOException
        Save contents to file in text format with lines.
        Parameters:
        filename - file to save to
        Throws:
        java.io.IOException - if a java.io operation throws
      • setSelectedCell

        public void setSelectedCell​(int column,
                                    int row)
        Set the selected cell location.
        Parameters:
        column - the selected cell location column
        row - the selected cell location row
      • getCell

        public TTableWidget.Cell getCell​(int column,
                                         int row)
        Get a particular cell.
        Parameters:
        column - the cell column
        row - the cell row
        Returns:
        the cell
      • getCellText

        public java.lang.String getCellText​(int column,
                                            int row)
        Get the text of a particular cell.
        Parameters:
        column - the cell column
        row - the cell row
        Returns:
        the text in the cell
      • setCellText

        public void setCellText​(int column,
                                int row,
                                java.lang.String text)
        Set the text of a particular cell.
        Parameters:
        column - the cell column
        row - the cell row
        text - the text to put into the cell
      • setCellEnterAction

        public void setCellEnterAction​(int column,
                                       int row,
                                       TAction action)
        Set the action to perform when the user presses enter on a particular cell.
        Parameters:
        column - the cell column
        row - the cell row
        action - the action to perform when the user presses enter on the cell
      • setCellUpdateAction

        public void setCellUpdateAction​(int column,
                                        int row,
                                        TAction action)
        Set the action to perform when the user updates a particular cell.
        Parameters:
        column - the cell column
        row - the cell row
        action - the action to perform when the user updates the cell
      • getColumnWidth

        public int getColumnWidth​(int column)
        Get the width of a column.
        Parameters:
        column - the column number
        Returns:
        the width of the column
      • setColumnWidth

        public void setColumnWidth​(int column,
                                   int width)
        Set the width of a column.
        Parameters:
        column - the column number
        width - the new width of the column
      • getColumnLabel

        public java.lang.String getColumnLabel​(int column)
        Get the label of a column.
        Parameters:
        column - the column number
        Returns:
        the label of the column
      • setColumnLabel

        public void setColumnLabel​(int column,
                                   java.lang.String label)
        Set the label of a column.
        Parameters:
        column - the column number
        label - the new label of the column
      • getRowLabel

        public java.lang.String getRowLabel​(int row)
        Get the label of a row.
        Parameters:
        row - the row number
        Returns:
        the label of the row
      • setRowLabel

        public void setRowLabel​(int row,
                                java.lang.String label)
        Set the label of a row.
        Parameters:
        row - the row number
        label - the new label of the row
      • insertRowAbove

        public void insertRowAbove​(int row)
        Insert one row above a particular row.
        Parameters:
        row - the row number
      • insertRowBelow

        public void insertRowBelow​(int row)
        Insert one row below a particular row.
        Parameters:
        row - the row number
      • deleteRow

        public void deleteRow​(int row)
        Delete a particular row.
        Parameters:
        row - the row number
      • insertColumnLeft

        public void insertColumnLeft​(int column)
        Insert one column to the left of a particular column.
        Parameters:
        column - the column number
      • insertColumnRight

        public void insertColumnRight​(int column)
        Insert one column to the right of a particular column.
        Parameters:
        column - the column number
      • deleteColumn

        public void deleteColumn​(int column)
        Delete a particular column.
        Parameters:
        column - the column number
      • deleteCellShiftLeft

        public void deleteCellShiftLeft()
        Delete the selected cell, shifting cells over to the left.
      • deleteCellShiftUp

        public void deleteCellShiftUp()
        Delete the selected cell, shifting cells from below up.
      • setCellReadOnly

        public void setCellReadOnly​(int column,
                                    int row,
                                    boolean readOnly)
        Set a particular cell read-only (non-editable) or not.
        Parameters:
        column - the cell column
        row - the cell row
        readOnly - if true, the cell will be non-editable
      • setRowReadOnly

        public void setRowReadOnly​(int row,
                                   boolean readOnly)
        Set an entire row of cells read-only (non-editable) or not.
        Parameters:
        row - the row number
        readOnly - if true, the cells will be non-editable
      • setColumnReadOnly

        public void setColumnReadOnly​(int column,
                                      boolean readOnly)
        Set an entire column of cells read-only (non-editable) or not.
        Parameters:
        column - the column number
        readOnly - if true, the cells will be non-editable
      • setBorderAllNone

        public void setBorderAllNone()
        Set all borders across the entire table to Border.NONE.
      • setBorderAllSingle

        public void setBorderAllSingle()
        Set all borders across the entire table to Border.SINGLE.
      • setBorderCellNone

        public void setBorderCellNone()
        Set all borders around the selected cell to Border.NONE.
      • setBorderCellSingle

        public void setBorderCellSingle()
        Set all borders around the selected cell to Border.SINGLE.
      • setBorderColumnRightSingle

        public void setBorderColumnRightSingle()
        Set the column border to the right of the selected cell to Border.SINGLE.
      • setBorderColumnLeftSingle

        public void setBorderColumnLeftSingle()
        Set the column border to the right of the selected cell to Border.SINGLE.
      • setBorderRowAboveSingle

        public void setBorderRowAboveSingle()
        Set the row border above the selected cell to Border.SINGLE.
      • setBorderRowBelowSingle

        public void setBorderRowBelowSingle()
        Set the row border below the selected cell to Border.SINGLE.
      • setBorderRowBelowDouble

        public void setBorderRowBelowDouble()
        Set the row border below the selected cell to Border.DOUBLE.
      • setBorderRowBelowThick

        public void setBorderRowBelowThick()
        Set the row border below the selected cell to Border.THICK.