Package jexer
Class TTableWidget
- java.lang.Object
-
- jexer.TWidget
-
- jexer.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TTableWidget.Border
Available borders for cells.class
TTableWidget.Cell
Cell represents an editable cell in the table.class
TTableWidget.Column
Column represents a column of cells.class
TTableWidget.Row
Row represents a row of cells.
-
Constructor Summary
Constructors Constructor Description TTableWidget(TWidget parent, int x, int y, int width, int height)
Public constructor.TTableWidget(TWidget parent, int x, int y, int width, int height, int gridColumns, int gridRows)
Public constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
deleteCellShiftLeft()
Delete the selected cell, shifting cells over to the left.void
deleteCellShiftUp()
Delete the selected cell, shifting cells from below up.void
deleteColumn(int column)
Delete a particular column.void
deleteRow(int row)
Delete a particular row.void
draw()
Draw the table row/column labels, and borders.TTableWidget.Cell
getCell(int column, int row)
Get a particular cell.java.lang.String
getCellText(int column, int row)
Get the text of a particular cell.int
getColumnCount()
Get the number of columns.java.lang.String
getColumnLabel(int column)
Get the label of a column.int
getColumnWidth(int column)
Get the width of a column.boolean
getHighlightColumn()
Get the highlight column flag.boolean
getHighlightRow()
Get the highlight row flag.int
getRowCount()
Get the number of rows.java.lang.String
getRowLabel(int row)
Get the label of a row.TTableWidget.Cell
getSelectedCell()
Get the currently-selected cell.TTableWidget.Column
getSelectedColumn()
Get the currently-selected column.int
getSelectedColumnNumber()
Get the currently-selected column number.TTableWidget.Row
getSelectedRow()
Get the currently-selected row.int
getSelectedRowNumber()
Get the currently-selected row number.boolean
getShowColumnLabels()
Get the show column labels flag.boolean
getShowRowLabels()
Get the show row labels flag.void
insertColumnLeft(int column)
Insert one column to the left of a particular column.void
insertColumnRight(int column)
Insert one column to the right of a particular column.void
insertRowAbove(int row)
Insert one row above a particular row.void
insertRowBelow(int row)
Insert one row below a particular row.void
loadCsvFile(java.io.File csvFile)
Load contents from file in CSV format.void
onKeypress(TKeypressEvent keypress)
Handle keystrokes.void
onMouseDown(TMouseEvent mouse)
Handle mouse press events.void
onResize(TResizeEvent event)
Handle widget resize events.void
saveToCsvFilename(java.lang.String filename)
Save contents to file in CSV format.void
saveToTextFilename(java.lang.String filename)
Save contents to file in text format with lines.void
setBorderAllNone()
Set all borders across the entire table to Border.NONE.void
setBorderAllSingle()
Set all borders across the entire table to Border.SINGLE.void
setBorderCellNone()
Set all borders around the selected cell to Border.NONE.void
setBorderCellSingle()
Set all borders around the selected cell to Border.SINGLE.void
setBorderColumnLeftSingle()
Set the column border to the right of the selected cell to Border.SINGLE.void
setBorderColumnRightSingle()
Set the column border to the right of the selected cell to Border.SINGLE.void
setBorderRowAboveSingle()
Set the row border above the selected cell to Border.SINGLE.void
setBorderRowBelowDouble()
Set the row border below the selected cell to Border.DOUBLE.void
setBorderRowBelowSingle()
Set the row border below the selected cell to Border.SINGLE.void
setBorderRowBelowThick()
Set the row border below the selected cell to Border.THICK.void
setCellEnterAction(int column, int row, TAction action)
Set the action to perform when the user presses enter on a particular cell.void
setCellReadOnly(int column, int row, boolean readOnly)
Set a particular cell read-only (non-editable) or not.void
setCellText(int column, int row, java.lang.String text)
Set the text of a particular cell.void
setCellUpdateAction(int column, int row, TAction action)
Set the action to perform when the user updates a particular cell.void
setColumnLabel(int column, java.lang.String label)
Set the label of a column.void
setColumnReadOnly(int column, boolean readOnly)
Set an entire column of cells read-only (non-editable) or not.void
setColumnWidth(int column, int width)
Set the width of a column.void
setHighlightColumn(boolean highlightColumn)
Set the highlight column flag.void
setHighlightRow(boolean highlightRow)
Set the highlight row flag.void
setRowLabel(int row, java.lang.String label)
Set the label of a row.void
setRowReadOnly(int row, boolean readOnly)
Set an entire row of cells read-only (non-editable) or not.void
setSelectedCell(int column, int row)
Set the selected cell location.void
setSelectedColumnNumber(int column)
Set the currently-selected column number.void
setSelectedRowNumber(int row)
Set the currently-selected row number.void
setShowColumnLabels(boolean showColumnLabels)
Set the show column labels flag.void
setShowRowLabels(boolean showRowLabels)
Set the show row labels flag.-
Methods inherited from class jexer.TWidget
activate, activate, activate, activateAll, addButton, addCalendar, addCheckBox, addCheckBox, addComboBox, addDirectoryList, addDirectoryList, addDirectoryList, addDirectoryList, addEditor, addField, addField, addField, addField, addImage, addImage, addLabel, addLabel, addLabel, addLabel, addLabel, addLabel, addList, addList, addList, addList, addPanel, addPasswordField, addPasswordField, addPasswordField, addProgressBar, addRadioGroup, addRadioGroup, addSpinner, addSplitPane, addTable, addTable, addText, addText, addTreeViewWidget, addTreeViewWidget, close, compareTo, doRepaint, drawBox, drawBox, drawBoxShadow, drawChildren, fileOpenBox, fileOpenBox, fileOpenBox, fileOpenBox, fileSaveBox, getAbsoluteX, getAbsoluteY, getActiveChild, getApplication, getAttrXY, getChildren, getClipboard, getCursorAbsoluteX, getCursorAbsoluteY, getCursorX, getCursorY, getCustomMousePointer, getHeight, getLayoutManager, getMouseStyle, getParent, getScreen, getTheme, getWidgetUnderMouse, getWidth, getWindow, getX, getY, handleEvent, hasChild, hLineXY, inputBox, inputBox, inputBox, isAbsoluteActive, isActive, isCursorVisible, isDrawable, isEchoKeystrokes, isEnabled, isPixelMouse, isVisible, messageBox, messageBox, mouseWouldHit, onCommand, onIdle, onMenu, onMouseDoubleClick, onMouseMotion, onMouseUp, putAll, putAttrXY, putAttrXY, putCharXY, putCharXY, putCharXY, putStringXY, putStringXY, remove, remove, remove, remove, removeAll, resetTabOrder, setActive, setCursorVisible, setCursorX, setCursorY, setCustomMousePointer, setDimensions, setEchoKeystrokes, setEchoKeystrokes, setEnabled, setHeight, setLayoutManager, setMouseStyle, setParent, setupForTWindow, setVisible, setWidth, setWindow, setX, setY, splitHorizontal, splitVertical, switchWidget, toPrettyString, toPrettyString, toString, vLineXY
-
-
-
-
Constructor Detail
-
TTableWidget
public TTableWidget(TWidget parent, int x, int y, int width, int height, int gridColumns, int gridRows)
Public constructor.- Parameters:
parent
- parent widgetx
- column relative to parenty
- row relative to parentwidth
- width of widgetheight
- height of widgetgridColumns
- number of columns in gridgridRows
- number of rows in grid
-
TTableWidget
public TTableWidget(TWidget parent, int x, int y, int width, int height)
Public constructor.- Parameters:
parent
- parent widgetx
- column relative to parenty
- row relative to parentwidth
- width of widgetheight
- height of widget
-
-
Method Detail
-
onMouseDown
public void onMouseDown(TMouseEvent mouse)
Handle mouse press events.- Overrides:
onMouseDown
in classTWidget
- Parameters:
mouse
- mouse button press event
-
onKeypress
public void onKeypress(TKeypressEvent keypress)
Handle keystrokes.- Overrides:
onKeypress
in classTWidget
- Parameters:
keypress
- keystroke event
-
onResize
public void onResize(TResizeEvent event)
Handle widget resize events.
-
draw
public void draw()
Draw the table row/column labels, and borders.
-
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 columnrow
- the selected cell location row
-
getCell
public TTableWidget.Cell getCell(int column, int row)
Get a particular cell.- Parameters:
column
- the cell columnrow
- 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 columnrow
- 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 columnrow
- the cell rowtext
- 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 columnrow
- the cell rowaction
- 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 columnrow
- the cell rowaction
- 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 numberwidth
- 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 numberlabel
- 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 numberlabel
- 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 columnrow
- the cell rowreadOnly
- 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 numberreadOnly
- 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 numberreadOnly
- 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.
-
-