@Override public String[] align(String[] text, int cellWidth, int cellHeight) { String[] result = new String[cellHeight]; int alignOffset = 0; for (String line : text) { alignOffset = Math.max(alignOffset, line.trim().indexOf(delimiter)); } int i = 0; for (String line : text) { String trimmed = line.trim(); int offset = trimmed.indexOf(delimiter); if (offset >= 0) { // It is possible that aligning would trigger overflow // Make sure not to int offsetToUse = Math.min(alignOffset - offset, cellWidth - trimmed.length()); result[i++] = pad(offsetToUse, cellWidth - trimmed.length() - offsetToUse, trimmed); } else { result[i++] = pad(0, cellWidth - line.length(), line); } } return result; }
/** * 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(); } }
.addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); List<String> excludes = securityInfo.isAuthenticated() ? Arrays.asList("roles", "class") builder.on(CellMatchers.ofType(SecurityInfo.class)) .addFormatter(new DataFlowTables.BeanWrapperFormatter(": ", null, excludes)) .addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); builder.on(CellMatchers.ofType(List.class)) .addFormatter(new DataFlowTables.BeanWrapperFormatter(": ", null, Arrays.asList("class", "platformSpecificInfo"))) .addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); rowsWithThinSeparators.forEach(row -> builder.paintBorder(BorderStyle.fancy_light_quadruple_dash, BorderSpecification.TOP)
.addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); List<String> excludes = securityInfo.isAuthenticated() ? Arrays.asList("roles", "class") builder.on(CellMatchers.ofType(SecurityInfo.class)) .addFormatter(new DataFlowTables.BeanWrapperFormatter(": ", null, excludes)) .addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); builder.on(CellMatchers.ofType(List.class)) .addFormatter(new DataFlowTables.BeanWrapperFormatter(": ", null, Arrays.asList("class", "platformSpecificInfo"))) .addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); rowsWithThinSeparators.forEach(row -> builder.paintBorder(BorderStyle.fancy_light_quadruple_dash, BorderSpecification.TOP)