/** * Install all the necessary formatters, aligners, etc for key-value rendering of Maps. */ public static TableBuilder configureKeyValueRendering(TableBuilder builder, String delimiter) { return builder.on(CellMatchers.ofType(Map.class)) .addFormatter(new MapFormatter(delimiter)) .addAligner(new KeyValueHorizontalAligner(delimiter.trim())) .addSizer(new KeyValueSizeConstraints(delimiter)) .addWrapper(new KeyValueTextWrapper(delimiter)).and(); } }
/** * Set a border around each and every cell of the table. */ public TableBuilder addFullBorder(BorderStyle style) { this.addBorder(0, 0, model.getRowCount(), model.getColumnCount(), FULL, style); return this; }
/** * Customize the given TableBuilder with almost same way than * {@link #applyStyle(TableBuilder)} but do not use any header styling. * * @param builder the table builder to use * @return the configured table builder */ public static TableBuilder applyStyleNoHeader(TableBuilder builder) { builder.addOutlineBorder(BorderStyle.fancy_double) .paintBorder(BorderStyle.air, BorderSpecification.INNER_VERTICAL).fromTopLeft().toBottomRight() .paintBorder(BorderStyle.fancy_light, BorderSpecification.INNER_VERTICAL).fromTopLeft() .toBottomRight(); return Tables.configureKeyValueRendering(builder, " = "); } }
public TableBuilder toBottomRight() { return toRowColumn(model.getRowCount(), model.getColumnCount()); } }
/** * Set a border on the outline of the whole table, as well as around the first row. */ public TableBuilder addHeaderBorder(BorderStyle style) { this.addBorder(0, 0, 1, model.getColumnCount(), OUTLINE, style); return addOutlineBorder(style); }
public Table build() { return TableBuilder.this.build(); } }
@Override public int getRowCount() { return TableModel.this.getColumnCount(); }
@Override public int getColumnCount() { return TableModel.this.getRowCount(); }
/** * Does this specification result in the need to paint an horizontal bar at row,column? */ /*default*/ char horizontals(int row, int column) { boolean result = (match & TOP) == TOP && row == row1; result |= (match & INNER_HORIZONTAL) == INNER_HORIZONTAL && row > row1 && row < row2; result |= (match & BOTTOM) == BOTTOM && row == row2; result &= column >= column1; result &= column < column2; return result ? style.horizontalGlyph() : BorderStyle.NONE; }
@Override public Extent width(String[] raw, int previous, int tableWidth) { return new Extent(width, width); } }
/** * Does this specification result in the need to paint a vertical bar at row,column? */ /*default*/ char verticals(int row, int column) { boolean result = (match & LEFT) == LEFT && column == column1; result |= (match & INNER_VERTICAL) == INNER_VERTICAL && column > column1 && column < column2; result |= (match & RIGHT) == RIGHT && column == column2; result &= row >= row1; result &= row < row2; return result ? style.verticalGlyph() : BorderStyle.NONE; }
public Borders() { verticals = new char[rows][columns + 1]; horizontals = new char[rows + 1][columns]; corners = new char[rows + 1][columns + 1]; vFillers = new boolean[columns + 1]; hFillers = new boolean[rows + 1]; init(); }
private static void registerMixedWithAirCombinations(char vertical, char horizontal) { registerCorner(vertical, vertical, ' ', NONE, vertical); registerCorner(vertical, vertical, NONE, ' ', vertical); registerCorner(vertical, vertical, ' ', ' ', vertical); registerCorner(' ', NONE, horizontal, horizontal, horizontal); registerCorner(NONE, ' ', horizontal, horizontal, horizontal); registerCorner(' ', ' ', horizontal, horizontal, horizontal); }
@Override public Object getValue(int row, int column) { return TableModel.this.getValue(column, row); } };
public BorderStub paintBorder(BorderStyle style, int match) { return new BorderStub(style, match); }
public TopLeft fromRowColumn(int row, int column) { return new TopLeft(row, column); }
/** * Set a border on the outline of the whole table, around the first row and draw vertical lines * around each column. */ public TableBuilder addHeaderAndVerticalsBorders(BorderStyle style) { this.addBorder(0, 0, 1, model.getColumnCount(), OUTLINE, style); this.addBorder(0, 0, model.getRowCount(), model.getColumnCount(), OUTLINE | INNER_VERTICAL, style); return this; }
/** * Set a border on the outline of the whole table. */ public TableBuilder addOutlineBorder(BorderStyle style) { this.addBorder(0, 0, model.getRowCount(), model.getColumnCount(), OUTLINE, style); return this; }
/** * Set a border on the inner verticals and horizontals of the table, but not on the outline. */ public TableBuilder addInnerBorder(BorderStyle style) { this.addBorder(0, 0, model.getRowCount(), model.getColumnCount(), INNER, style); return this; }