1 package com
.googlecode
.lanterna
.gui2
.table
;
3 import com
.googlecode
.lanterna
.TerminalTextUtils
;
4 import com
.googlecode
.lanterna
.TerminalSize
;
5 import com
.googlecode
.lanterna
.graphics
.ThemeDefinition
;
6 import com
.googlecode
.lanterna
.gui2
.TextGUIGraphics
;
9 * Default implementation of {@code TableCellRenderer}
10 * @param <V> Type of data stored in each table cell
13 public class DefaultTableCellRenderer
<V
> implements TableCellRenderer
<V
> {
15 public TerminalSize
getPreferredSize(Table
<V
> table
, V cell
, int columnIndex
, int rowIndex
) {
16 String
[] lines
= getContent(cell
);
18 for(String line
: lines
) {
19 int length
= TerminalTextUtils
.getColumnWidth(line
);
20 if(maxWidth
< length
) {
24 return new TerminalSize(maxWidth
, lines
.length
);
28 public void drawCell(Table
<V
> table
, V cell
, int columnIndex
, int rowIndex
, TextGUIGraphics textGUIGraphics
) {
29 ThemeDefinition themeDefinition
= textGUIGraphics
.getThemeDefinition(Table
.class);
30 if((table
.getSelectedColumn() == columnIndex
&& table
.getSelectedRow() == rowIndex
) ||
31 (table
.getSelectedRow() == rowIndex
&& !table
.isCellSelection())) {
32 if(table
.isFocused()) {
33 textGUIGraphics
.applyThemeStyle(themeDefinition
.getActive());
36 textGUIGraphics
.applyThemeStyle(themeDefinition
.getSelected());
38 textGUIGraphics
.fill(' '); //Make sure to fill the whole cell first
41 textGUIGraphics
.applyThemeStyle(themeDefinition
.getNormal());
43 String
[] lines
= getContent(cell
);
45 for(String line
: lines
) {
46 textGUIGraphics
.putString(0, rowCount
++, line
);
50 private String
[] getContent(V cell
) {
53 lines
= new String
[] { "" };
56 lines
= cell
.toString().split("\r?\n");