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 classTTableWidget.BorderAvailable borders for cells.classTTableWidget.CellCell represents an editable cell in the table.classTTableWidget.ColumnColumn represents a column of cells.classTTableWidget.RowRow 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 voidclearAll()Reset all cells to blanks.voiddeleteCellShiftLeft()Delete the selected cell, shifting cells over to the left.voiddeleteCellShiftUp()Delete the selected cell, shifting cells from below up.voiddeleteColumn(int column)Delete a particular column.voiddeleteRow(int row)Delete a particular row.voiddraw()Draw the table row/column labels, and borders.TTableWidget.CellgetCell(int column, int row)Get a particular cell.java.lang.StringgetCellText(int column, int row)Get the text of a particular cell.intgetColumnCount()Get the number of columns.java.lang.StringgetColumnLabel(int column)Get the label of a column.intgetColumnWidth(int column)Get the width of a column.booleangetHighlightColumn()Get the highlight column flag.booleangetHighlightRow()Get the highlight row flag.intgetRowCount()Get the number of rows.java.lang.StringgetRowLabel(int row)Get the label of a row.intgetRowLabelWidth()Get the width of the column used to show the row labels.TTableWidget.CellgetSelectedCell()Get the currently-selected cell.TTableWidget.ColumngetSelectedColumn()Get the currently-selected column.intgetSelectedColumnNumber()Get the currently-selected column number.TTableWidget.RowgetSelectedRow()Get the currently-selected row.intgetSelectedRowNumber()Get the currently-selected row number.booleangetShowColumnLabels()Get the show column labels flag.booleangetShowRowLabels()Get the show row labels flag.voidinsertColumnLeft(int column)Insert one column to the left of a particular column.voidinsertColumnRight(int column)Insert one column to the right of a particular column.voidinsertRowAbove(int row)Insert one row above a particular row.voidinsertRowBelow(int row)Insert one row below a particular row.voidloadCsvFile(java.io.File csvFile)Load contents from file in CSV format.voidonKeypress(TKeypressEvent keypress)Handle keystrokes.voidonMouseDown(TMouseEvent mouse)Handle mouse press events.voidonResize(TResizeEvent event)Handle widget resize events.voidsaveToCsvFilename(java.lang.String filename)Save contents to file in CSV format.voidsaveToTextFilename(java.lang.String filename)Save contents to file in text format with lines.voidsetBorderAllNone()Set all borders across the entire table to Border.NONE.voidsetBorderAllSingle()Set all borders across the entire table to Border.SINGLE.voidsetBorderCellNone()Set all borders around the selected cell to Border.NONE.voidsetBorderCellSingle()Set all borders around the selected cell to Border.SINGLE.voidsetBorderColumnLeftSingle()Set the column border to the right of the selected cell to Border.SINGLE.voidsetBorderColumnRightSingle()Set the column border to the right of the selected cell to Border.SINGLE.voidsetBorderRowAboveSingle()Set the row border above the selected cell to Border.SINGLE.voidsetBorderRowBelowDouble()Set the row border below the selected cell to Border.DOUBLE.voidsetBorderRowBelowSingle()Set the row border below the selected cell to Border.SINGLE.voidsetBorderRowBelowThick()Set the row border below the selected cell to Border.THICK.voidsetCellEnterAction(int column, int row, TAction action)Set the action to perform when the user presses enter on a particular cell.voidsetCellReadOnly(int column, int row, boolean readOnly)Set a particular cell read-only (non-editable) or not.voidsetCellText(int column, int row, java.lang.String text)Set the text of a particular cell.voidsetCellUpdateAction(int column, int row, TAction action)Set the action to perform when the user updates a particular cell.voidsetColumnLabel(int column, java.lang.String label)Set the label of a column.voidsetColumnReadOnly(int column, boolean readOnly)Set an entire column of cells read-only (non-editable) or not.voidsetColumnWidth(int column, int width)Set the width of a column.voidsetColumnWidthAuto(int column, int maxWidth)Automatically set the width of a column to either the minimum required to display the data, or the maximum supplied width, whichever is smaller.voidsetGridSize(int gridColumns, int gridRows)Set the size of the table grid.voidsetHighlightColumn(boolean highlightColumn)Set the highlight column flag.voidsetHighlightRow(boolean highlightRow)Set the highlight row flag.voidsetRowLabel(int row, java.lang.String label)Set the label of a row.voidsetRowLabelWidth(int rowLabelWidth)Set the width of the column used to show the row labels.voidsetRowLabelWidthAuto(int maxWidth)Automatically set the width of the column used to show the row labels to either the minimum required to display the data, or the maximum supplied width, whichever is smaller.voidsetRowReadOnly(int row, boolean readOnly)Set an entire row of cells read-only (non-editable) or not.voidsetSelectedCell(int column, int row)Set the selected cell location.voidsetSelectedColumnNumber(int column)Set the currently-selected column number.voidsetSelectedRowNumber(int row)Set the currently-selected row number.voidsetShowColumnLabels(boolean showColumnLabels)Set the show column labels flag.voidsetShowRowLabels(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, 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, getLocale, getMouseStyle, getParent, getScreen, getTheme, getWidgetUnderMouse, getWidth, getWindow, getX, getY, handleEvent, hasChild, hLineXY, 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, setLocale, setMouseStyle, setParent, setupForTWindow, setVisible, setWidth, setWindow, setX, setY, splitHorizontal, splitVertical, switchWidget, toPrettyString, toPrettyString, toString, vLineXY, 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:
onMouseDownin classTWidget- Parameters:
mouse- mouse button press event
-
onKeypress
public void onKeypress(TKeypressEvent keypress)
Handle keystrokes.- Overrides:
onKeypressin 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.
-
setGridSize
public void setGridSize(int gridColumns, int gridRows)Set the size of the table grid. All cells are reset to blank.- Parameters:
gridColumns- number of columns in gridgridRows- number of rows in grid
-
clearAll
public void clearAll()
Reset all cells to blanks.
-
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
-
getRowLabelWidth
public int getRowLabelWidth()
Get the width of the column used to show the row labels.- Returns:
- the row label width
-
setRowLabelWidth
public void setRowLabelWidth(int rowLabelWidth)
Set the width of the column used to show the row labels.- Parameters:
rowLabelWidth- the new row label width
-
setRowLabelWidthAuto
public void setRowLabelWidthAuto(int maxWidth)
Automatically set the width of the column used to show the row labels to either the minimum required to display the data, or the maximum supplied width, whichever is smaller.- Parameters:
maxWidth- the maximum width to size to
-
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.IOExceptionLoad 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.IOExceptionSave 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.IOExceptionSave 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
-
setColumnWidthAuto
public void setColumnWidthAuto(int column, int maxWidth)Automatically set the width of a column to either the minimum required to display the data, or the maximum supplied width, whichever is smaller.- Parameters:
column- the column numbermaxWidth- the maximum width to size to
-
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.
-
-