Module com.googlecode.lanterna
Class DefaultTableRenderer<V>
- java.lang.Object
-
- com.googlecode.lanterna.gui2.table.DefaultTableRenderer<V>
-
- Type Parameters:
V
- Type of data stored in each table cell
- All Implemented Interfaces:
ComponentRenderer<Table<V>>
,InteractableRenderer<Table<V>>
,TableRenderer<V>
public class DefaultTableRenderer<V> extends java.lang.Object implements TableRenderer<V>
Default implementation ofTableRenderer
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
allowPartialColumn
private TerminalSize
cachedSize
private TableCellBorderStyle
cellHorizontalBorderStyle
private TableCellBorderStyle
cellVerticalBorderStyle
private java.util.Set<java.lang.Integer>
expandableColumns
private TableCellBorderStyle
headerHorizontalBorderStyle
private int
headerSizeInRows
private TableCellBorderStyle
headerVerticalBorderStyle
private ScrollBar
horizontalScrollBar
private java.util.List<java.lang.Integer>
preferredColumnSizes
private java.util.List<java.lang.Integer>
preferredRowSizes
private boolean
scrollBarsHidden
private ScrollBar
verticalScrollBar
private int
viewLeftColumn
private int
viewTopRow
private int
visibleRowsOnLastDraw
-
Constructor Summary
Constructors Constructor Description DefaultTableRenderer()
Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private int
calculateVisibleColumns(TerminalSize area, int viewLeftColumn, int preferredVisibleColumns)
private int
calculateVisibleRows(TerminalSize area, int viewTopRow, int preferredVisibleRows)
void
drawComponent(TextGUIGraphics graphics, Table<V> table)
Using the supplied graphics object, draws the component passed in.private void
drawHeader(TextGUIGraphics graphics, Table<V> table, java.util.List<java.lang.Integer> columnSizes)
private void
drawRows(TextGUIGraphics graphics, Table<V> table, java.util.List<java.lang.Integer> columnSizes, int visibleRows, int visibleColumns, int renderColumns, boolean needVerticalScrollBar, boolean needHorizontalScrollBar)
private java.util.List<java.lang.Integer>
fitColumnsInAvailableSpace(Table<V> table, TerminalSize area, int visibleColumns)
boolean
getAllowPartialColumn()
TerminalPosition
getCursorLocation(Table<V> component)
private char
getHorizontalCharacter(TableCellBorderStyle style)
private char
getJunctionCharacter(TableCellBorderStyle mainStyle, TableCellBorderStyle styleAbove, TableCellBorderStyle styleBelow)
TerminalSize
getPreferredSize(Table<V> table)
Given the supplied component, how large does this renderer want the component to be? Notice that this is the responsibility of the renderer and not the component itself, since the component has no idea what its visual representation looks like.private char
getVerticalCharacter(TableCellBorderStyle style)
int
getViewLeftColumn()
Returns the index of the first visible column with the renderers current stateint
getViewTopRow()
Returns the index of the first visible row with the renderers current stateint
getVisibleRowsOnLastDraw()
Returns the number of rows that could be drawn on the last draw operation.private boolean
isHorizontallySpaced()
boolean
isScrollBarsHidden()
void
setAllowPartialColumn(boolean allowPartialColumn)
void
setCellHorizontalBorderStyle(TableCellBorderStyle cellHorizontalBorderStyle)
Sets the style to be used when horizontally separating table cells from each other.void
setCellVerticalBorderStyle(TableCellBorderStyle cellVerticalBorderStyle)
Sets the style to be used when vertically separating table cells from each other.void
setExpandableColumns(java.util.Collection<java.lang.Integer> expandableColumns)
Sets the list of columns (by index, where 0 is the first column) that can be expanded, should the drawable area be larger than the table is requesting.void
setHeaderHorizontalBorderStyle(TableCellBorderStyle headerHorizontalBorderStyle)
Sets the style to be used when separating the table header labels from each other.void
setHeaderVerticalBorderStyle(TableCellBorderStyle headerVerticalBorderStyle)
Sets the style to be used when separating the table header row from the actual "data" cells below.void
setScrollBarsHidden(boolean scrollBarsHidden)
void
setViewLeftColumn(int viewLeftColumn)
Modifies which column is the first visible, this may be overwritten depending on the circumstances when drawing the table.void
setViewTopRow(int viewTopRow)
Modifies which row is the first visible, this may be overwritten depending on the circumstances when drawing the table.
-
-
-
Field Detail
-
verticalScrollBar
private final ScrollBar verticalScrollBar
-
horizontalScrollBar
private final ScrollBar horizontalScrollBar
-
headerVerticalBorderStyle
private TableCellBorderStyle headerVerticalBorderStyle
-
headerHorizontalBorderStyle
private TableCellBorderStyle headerHorizontalBorderStyle
-
cellVerticalBorderStyle
private TableCellBorderStyle cellVerticalBorderStyle
-
cellHorizontalBorderStyle
private TableCellBorderStyle cellHorizontalBorderStyle
-
viewTopRow
private int viewTopRow
-
viewLeftColumn
private int viewLeftColumn
-
visibleRowsOnLastDraw
private int visibleRowsOnLastDraw
-
cachedSize
private TerminalSize cachedSize
-
preferredColumnSizes
private final java.util.List<java.lang.Integer> preferredColumnSizes
-
preferredRowSizes
private final java.util.List<java.lang.Integer> preferredRowSizes
-
expandableColumns
private final java.util.Set<java.lang.Integer> expandableColumns
-
headerSizeInRows
private int headerSizeInRows
-
allowPartialColumn
private boolean allowPartialColumn
-
scrollBarsHidden
private boolean scrollBarsHidden
-
-
Method Detail
-
setHeaderVerticalBorderStyle
public void setHeaderVerticalBorderStyle(TableCellBorderStyle headerVerticalBorderStyle)
Sets the style to be used when separating the table header row from the actual "data" cells below. This will cause a new line to be added under the header labels, unless set toTableCellBorderStyle.None
.- Parameters:
headerVerticalBorderStyle
- Style to use to separate Table header from body
-
setHeaderHorizontalBorderStyle
public void setHeaderHorizontalBorderStyle(TableCellBorderStyle headerHorizontalBorderStyle)
Sets the style to be used when separating the table header labels from each other. This will cause a new column to be added in between each label, unless set toTableCellBorderStyle.None
.- Parameters:
headerHorizontalBorderStyle
- Style to use when separating header columns horizontally
-
setCellVerticalBorderStyle
public void setCellVerticalBorderStyle(TableCellBorderStyle cellVerticalBorderStyle)
Sets the style to be used when vertically separating table cells from each other. This will cause a new line to be added between every row, unless set toTableCellBorderStyle.None
.- Parameters:
cellVerticalBorderStyle
- Style to use to separate table cells vertically
-
setCellHorizontalBorderStyle
public void setCellHorizontalBorderStyle(TableCellBorderStyle cellHorizontalBorderStyle)
Sets the style to be used when horizontally separating table cells from each other. This will cause a new column to be added between every row, unless set toTableCellBorderStyle.None
.- Parameters:
cellHorizontalBorderStyle
- Style to use to separate table cells horizontally
-
setExpandableColumns
public void setExpandableColumns(java.util.Collection<java.lang.Integer> expandableColumns)
Sets the list of columns (by index, where 0 is the first column) that can be expanded, should the drawable area be larger than the table is requesting.- Parameters:
expandableColumns
- Collection of indexes for expandable columns
-
isScrollBarsHidden
public boolean isScrollBarsHidden()
- Specified by:
isScrollBarsHidden
in interfaceTableRenderer<V>
-
setScrollBarsHidden
public void setScrollBarsHidden(boolean scrollBarsHidden)
- Specified by:
setScrollBarsHidden
in interfaceTableRenderer<V>
-
isHorizontallySpaced
private boolean isHorizontallySpaced()
-
getVisibleRowsOnLastDraw
public int getVisibleRowsOnLastDraw()
Returns the number of rows that could be drawn on the last draw operation. If the table doesn't have any visible row count set throughTable.setVisibleRows(int)
, this is the only way to find out exactly how large the table ended up. But even if you did set the number of visible rows explicitly, due to terminal size constraints the actually drawn size might have been different.- Specified by:
getVisibleRowsOnLastDraw
in interfaceTableRenderer<V>
- Returns:
- Number of rows that could be drawn on the last UI update call, will also return 0 if the table has not yet been drawn out
-
getViewTopRow
public int getViewTopRow()
Description copied from interface:TableRenderer
Returns the index of the first visible row with the renderers current state- Specified by:
getViewTopRow
in interfaceTableRenderer<V>
- Returns:
- Index of the first visible row of the table
-
setViewTopRow
public void setViewTopRow(int viewTopRow)
Description copied from interface:TableRenderer
Modifies which row is the first visible, this may be overwritten depending on the circumstances when drawing the table.- Specified by:
setViewTopRow
in interfaceTableRenderer<V>
- Parameters:
viewTopRow
- First row to be displayed when drawing the table
-
getViewLeftColumn
public int getViewLeftColumn()
Description copied from interface:TableRenderer
Returns the index of the first visible column with the renderers current state- Specified by:
getViewLeftColumn
in interfaceTableRenderer<V>
- Returns:
- Index of the first visible column of the table
-
setViewLeftColumn
public void setViewLeftColumn(int viewLeftColumn)
Description copied from interface:TableRenderer
Modifies which column is the first visible, this may be overwritten depending on the circumstances when drawing the table.- Specified by:
setViewLeftColumn
in interfaceTableRenderer<V>
- Parameters:
viewLeftColumn
- First column to be displayed when drawing the table
-
setAllowPartialColumn
public void setAllowPartialColumn(boolean allowPartialColumn)
- Specified by:
setAllowPartialColumn
in interfaceTableRenderer<V>
- Parameters:
allowPartialColumn
- when not all columns fit on the screen, whether to render part of a column, or skip rendering that column entirely
-
getAllowPartialColumn
public boolean getAllowPartialColumn()
- Specified by:
getAllowPartialColumn
in interfaceTableRenderer<V>
- See Also:
TableRenderer.setAllowPartialColumn(boolean)
-
getPreferredSize
public TerminalSize getPreferredSize(Table<V> table)
Description copied from interface:ComponentRenderer
Given the supplied component, how large does this renderer want the component to be? Notice that this is the responsibility of the renderer and not the component itself, since the component has no idea what its visual representation looks like.- Specified by:
getPreferredSize
in interfaceComponentRenderer<V>
- Specified by:
getPreferredSize
in interfaceTableRenderer<V>
- Parameters:
table
- Component to calculate the preferred size of- Returns:
- The size this renderer would like the component to take up
-
getCursorLocation
public TerminalPosition getCursorLocation(Table<V> component)
- Specified by:
getCursorLocation
in interfaceInteractableRenderer<V>
-
drawComponent
public void drawComponent(TextGUIGraphics graphics, Table<V> table)
Description copied from interface:ComponentRenderer
Using the supplied graphics object, draws the component passed in.- Specified by:
drawComponent
in interfaceComponentRenderer<V>
- Specified by:
drawComponent
in interfaceTableRenderer<V>
- Parameters:
graphics
- Graphics object to use for drawingtable
- Component to draw
-
calculateVisibleRows
private int calculateVisibleRows(TerminalSize area, int viewTopRow, int preferredVisibleRows)
-
calculateVisibleColumns
private int calculateVisibleColumns(TerminalSize area, int viewLeftColumn, int preferredVisibleColumns)
-
fitColumnsInAvailableSpace
private java.util.List<java.lang.Integer> fitColumnsInAvailableSpace(Table<V> table, TerminalSize area, int visibleColumns)
-
drawHeader
private void drawHeader(TextGUIGraphics graphics, Table<V> table, java.util.List<java.lang.Integer> columnSizes)
-
drawRows
private void drawRows(TextGUIGraphics graphics, Table<V> table, java.util.List<java.lang.Integer> columnSizes, int visibleRows, int visibleColumns, int renderColumns, boolean needVerticalScrollBar, boolean needHorizontalScrollBar)
-
getHorizontalCharacter
private char getHorizontalCharacter(TableCellBorderStyle style)
-
getVerticalCharacter
private char getVerticalCharacter(TableCellBorderStyle style)
-
getJunctionCharacter
private char getJunctionCharacter(TableCellBorderStyle mainStyle, TableCellBorderStyle styleAbove, TableCellBorderStyle styleBelow)
-
-