| Interface | Description |
|---|---|
| V2_TableRenderer |
Table renderer interface.
|
| V2_Width |
Calculator for the width of a table.
|
| Class | Description |
|---|---|
| ProcessedRow |
A row processed for rendering.
|
| RenderUtilities |
Utilities for manipulating tables and table rows.
|
| V2_AsciiTableRenderer |
Renders a table.
|
| WidthAbsoluteEven |
Defines the width of table columns using an absolute table width evenly distributed over all columns.
|
| WidthFixedColumns |
Defines the width of table columns using a fixed width for each column.
|
| WidthLongestLine |
Defines the width of table columns automatically based on the longest line in each column with optional minimum/maximum column width.
|
| WidthLongestWord |
Defines the width of table columns using the longest word per column without further restrictions.
|
| WidthLongestWordMaxCol |
Defines the width of table columns using the longest word per column but with a maximum column length.
|
| WidthLongestWordMinCol |
Defines the width of table columns using the longest word per column but with a minimum column length.
|
| WidthUtilities |
Utility methods for width calculation.
|
| Enum | Description |
|---|---|
| BorderPosition |
Position of a border element.
|
| BorderType |
Border type.
|
Most of the classes and enumerates here should be used automatically by a V2 ASCII table.
The main external class is the V2_TableRenderer, which is used to render a V2 ASCII table.
V2_TableRenderer interface provides the base line for realizing a table renderer.
It defines a number of methods to set the behavior of a renderer:
V2_TableRenderer.setPaddingChar(char),V2_TableRenderer.setWidth(de.vandermeer.asciitable.v2.render.V2_Width),V2_TableRenderer.setTheme(de.vandermeer.asciitable.v2.themes.V2_TableTheme).V2_AsciiTableRenderer implements a standard renderer.
It is using the theme V2_E_TableThemes.PLAIN_7BIT as default theme.
ProcessedRow
To enable multiple renderer objects processing the same table each renderer stores all information of the rendering process in a new table (list of rows).
This new table contains ProcessedRow objects that contain the render-generated information.
The original table is not changed (except for adjustment of top and bottom rule row types).
So each renderer creates its own view of the original table.
A processed row contains a link to the original row (for access to original content and configuration) plus the generated information for processed columns (wrapped lines, normalized, flipped content array) and border types.
BorderPosition as
BorderPosition.LEFT - a border on the left side of the row,BorderPosition.RIGHT - a border on the right side of the row,BorderPosition.MIDDLE - a border between left and right, in the middle.BorderType as
BorderType.UP - a border that goes up (linked to the previous row) only,BorderType.DOWN - a border that goes down (linked to the next row) only,BorderType.ALL - a border that goes up and down (linked to the previous and to the next row),BorderType.CONTENT - a border specific to a content row with special linkage to previous and next rows,BorderType.NONE - a border that goes neither up nor down nor is a content border, usually a blank character, used for column spanning.Combining border type and border position describes a complete border. With both characteristics, the renderer can pick the correct border character from a row or table theme. Once the type and the position of the row are determined, border character can be retrieved from table and row themes.
For instance, a border of type BorderPosition.MIDDLE and position BorderType.ALL
means to use getMidBorderAll() for a mid-rule row on a V2_RowTheme to get the right character.
For the row theme V2_E_RowThemes.UTF_DOUBLE_MID this character will be '╬'.
Similar, a border of type BorderPosition.RIGHT and position BorderType.UP
means to use getMidBorderAll() for a bottom-rule row.
For the row theme V2_E_RowThemes.UTF_DOUBLE_BOTTOM this character will be '╝'.
RenderUtilities implements a number of utility methods applicable to all (many) renderer implementations:
RenderUtilities.createContentArray(Object[], int[], int[]),RenderUtilities.getBorderTypes_BottomRule(ProcessedRow, de.vandermeer.asciitable.v2.row.V2_Row, int),RenderUtilities.getBorderTypes_ContentRow(String[], de.vandermeer.asciitable.v2.row.ContentRow, int),RenderUtilities.getBorderTypes_MidRule(ProcessedRow, ProcessedRow, de.vandermeer.asciitable.v2.row.V2_Row, int),RenderUtilities.getBorderTypes_TopRule(ProcessedRow, de.vandermeer.asciitable.v2.row.V2_Row, int),RenderUtilities.getChar(BorderPosition, BorderType, de.vandermeer.asciitable.v2.themes.V2_RowTheme).
The calculation of the overall table width and the width of individual columns is out-sourced into objects implementing the V2_Width interface.
This allows to define many different possible ways of calculating table/column width, and then hand it over to a renderer to build a rendered table.
V2_Width.getColumnWidths(de.vandermeer.asciitable.v2.V2_AsciiTable)WidthAbsoluteEven gets the width of the table and equally distributes the available space of the number of columns given by the renderer.
The distribution (characters per column) is the table width minus 1 (last border) minus number of columns (for all other borders).
The minimum (ideal) column width is the distribution divided by the number of columns.
Potential leftover is the distribution minus minimum column width multiplied by number of columns:
int distribute = this.width-1-this.colNumber;
int colmin = distribute/this.colNumber;
int leftover = distribute-colmin*this.colNumber;
The calculation of the column width then is to give each column the minimum width and for as long as there are leftover characters one additional character.
for(int i=0; i<this.colNumber; i++){
ret[i] = colmin;
if(leftover!=0){
ret[i] += 1;
leftover -= 1;
}
}
Here are a few examples of calculated column width for tables, all with a padding of 0:
7236,3524,23,2318,17,17,1714,14,14,13,1315,15,15,14,14WidthFixedColumns allows to add fixed column width, one by one.
The only calculation it does is adding the given width for the overall table width.
WidthLongestWord calculates the widths of columns taking the longest word (continuous characters between whitespaces) without further restrictions.
Padding is automatically added, so the padding adds to the column width.
The overall table width is then the sum of all calculated column width.
V2_AsciiTable at = new V2_AsciiTable(0);
at.addRow("first", "information");
at.addRow("second", "info");
Then we use this table to calculate the width using the longest word:
V2_Width width = new WidthLongestWord();
int[] = width.getColumnWidths(at);
The column width calculated are 6 for the first column (longest word: second) and 11 for the second column (longest word: information). If the table is created with the default padding of one, the values will change to 8 and 13.
The following example create a table with two rows and two columns each, and it applies different padding to individual columns.
V2_AsciiTable at = new V2_AsciiTable(0);
at.addRow("first", "information").setPadding(new int[]{2, 3});
at.addRow("second", "info").setPadding(new int[]{3, 4});
The calculated width for the columns are now as follows: 12 for the first column (longest word: second plus padding of 3 twice) and 17 for the second column (longest word: information plus padding of 3 twice).
WidthLongestWordMinCol calculates the widths of columns taking the longest word (continuous characters between whitespaces) but with a minimum column width.
Padding is automatically added, so the padding adds to the column width.
The overall table width is then the sum of all calculated column width.
V2_AsciiTable at = new V2_AsciiTable();
at.addRow("first", "information");
at.addRow("second", "info");
Then we use this table to calculate the width using the longest word and minimum column width of 11:
V2_Width width = new WidthLongestWordMinCol(11);
int[] = width.getColumnWidths(at);
The calculated width for the columns are now as follows: 11 for the first column (longest word: second plus padding of 1 twice = 8, but minimum column width is set to 11) and 13 for the second column (longest word: information plus padding of 1 twice).
We can also define the minimum column width per column. Here, a value of -1 indicates to simply use the longest word and values above 3 (the absolute minimum colmn width) will be taken as minimum width for a particular column:
V2_Width width = new WidthLongestWordMinCol(new int[]{-1,50});
int[] = width.getColumnWidths(at);
The calculated width for the columns are now as follows: 8 for the first column (longest word: second plus padding of 1 twice, no minimum width given) and 50 for the second column (longest word: information plus padding of 1 twice but minimum width set to 50).
WidthLongestWordMaxCol calculates the widths of columns taking the longest word (continuous characters between whitespaces) but with a maximum column width.
Padding is automatically added, so the padding adds to the column width.
The overall table width is then the sum of all calculated column width.
V2_AsciiTable at = new V2_AsciiTable();
at.addRow("first", "information");
at.addRow("second", "info");
Then we use this table to calculate the width using the longest word and maximum column width of 10:
V2_Width width = new WidthLongestWordMaxCol(10)
int[] = width.getColumnWidths(at);
The calculated width for the columns are now as follows: 8 for the first column (longest word: second plus padding of 1 twice = 8) and 10 for the second column (longest word: information plus padding of 1 twice = 11, but maximum width set to 10).
We can also define the maximum column width per column. Here, a value of -1 indicates to simply use the longest word and other values will be taken as maximum width for a particular column:
V2_Width width = new WidthLongestWordMaxCol(new int[]{5,-1});
int[] = width.getColumnWidths(at);
The calculated width for the columns are now as follows: 5 for the first column (longest word: second plus padding of 1 twice, but maximum set to 5) and 13 for the second column (longest word: information plus padding of 1 twice, no maximum given).
Copyright © 2010–2015. All rights reserved.