X-Git-Url: http://git.nikiroo.be/?p=jvcard.git;a=blobdiff_plain;f=src%2Fcom%2Fgooglecode%2Flanterna%2Fgui2%2Ftable%2FDefaultTableCellRenderer.java;fp=src%2Fcom%2Fgooglecode%2Flanterna%2Fgui2%2Ftable%2FDefaultTableCellRenderer.java;h=0000000000000000000000000000000000000000;hp=0b6e66951ba12bdfb07e128508d801f54be3f5d5;hb=f06c81000632cfb5f525ca458f719338f55f9f66;hpb=a73a906356c971b080c36368e71a15d87e8b8d31 diff --git a/src/com/googlecode/lanterna/gui2/table/DefaultTableCellRenderer.java b/src/com/googlecode/lanterna/gui2/table/DefaultTableCellRenderer.java deleted file mode 100644 index 0b6e669..0000000 --- a/src/com/googlecode/lanterna/gui2/table/DefaultTableCellRenderer.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.googlecode.lanterna.gui2.table; - -import com.googlecode.lanterna.TerminalTextUtils; -import com.googlecode.lanterna.TerminalSize; -import com.googlecode.lanterna.graphics.ThemeDefinition; -import com.googlecode.lanterna.gui2.TextGUIGraphics; - -/** - * Default implementation of {@code TableCellRenderer} - * @param Type of data stored in each table cell - * @author Martin - */ -public class DefaultTableCellRenderer implements TableCellRenderer { - @Override - public TerminalSize getPreferredSize(Table table, V cell, int columnIndex, int rowIndex) { - String[] lines = getContent(cell); - int maxWidth = 0; - for(String line: lines) { - int length = TerminalTextUtils.getColumnWidth(line); - if(maxWidth < length) { - maxWidth = length; - } - } - return new TerminalSize(maxWidth, lines.length); - } - - @Override - public void drawCell(Table table, V cell, int columnIndex, int rowIndex, TextGUIGraphics textGUIGraphics) { - ThemeDefinition themeDefinition = textGUIGraphics.getThemeDefinition(Table.class); - if((table.getSelectedColumn() == columnIndex && table.getSelectedRow() == rowIndex) || - (table.getSelectedRow() == rowIndex && !table.isCellSelection())) { - if(table.isFocused()) { - textGUIGraphics.applyThemeStyle(themeDefinition.getActive()); - } - else { - textGUIGraphics.applyThemeStyle(themeDefinition.getSelected()); - } - textGUIGraphics.fill(' '); //Make sure to fill the whole cell first - } - else { - textGUIGraphics.applyThemeStyle(themeDefinition.getNormal()); - } - String[] lines = getContent(cell); - int rowCount = 0; - for(String line: lines) { - textGUIGraphics.putString(0, rowCount++, line); - } - } - - private String[] getContent(V cell) { - String[] lines; - if(cell == null) { - lines = new String[] { "" }; - } - else { - lines = cell.toString().split("\r?\n"); - } - return lines; - } -}