| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2007-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2015 ForgeRock AS. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package com.forgerock.opendj.cli; |
| | | |
| | |
| | | * Tables have configurable column widths, padding, and column separators. |
| | | */ |
| | | public final class TextTablePrinter extends TablePrinter { |
| | | |
| | | /** |
| | | * Table serializer implementation. |
| | | */ |
| | | /** Table serializer implementation. */ |
| | | private final class Serializer extends TableSerializer { |
| | | |
| | | /**The real column widths taking into account size constraints but |
| | | not including padding or separators.*/ |
| | | private final List<Integer> columnWidths = new ArrayList<>(); |
| | |
| | | this.indentPadding = builder.toString(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void addCell(String s) { |
| | | currentRow.add(s); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void addColumn(int width) { |
| | | columnWidths.add(width); |
| | | totalColumns++; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void addHeading(String s) { |
| | | if (displayHeadings) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void endHeader() { |
| | | if (displayHeadings) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void endRow() { |
| | | boolean isRemainingText; |
| | |
| | | endIndex = width; |
| | | head = contents.substring(0, endIndex); |
| | | tail = contents.substring(endIndex); |
| | | |
| | | } else { |
| | | head = contents.substring(0, endIndex); |
| | | tail = contents.substring(endIndex + 1); |
| | |
| | | |
| | | // Output the line. |
| | | writer.println(builder.toString()); |
| | | |
| | | } while (isRemainingText); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void endTable() { |
| | | writer.flush(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void startHeader() { |
| | | determineColumnWidths(); |
| | | currentRow.clear(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void startRow() { |
| | | currentRow.clear(); |
| | |
| | | /** The number of characters the table should be indented. */ |
| | | private int indentWidth; |
| | | |
| | | /** |
| | | * The character which should be used to separate the table |
| | | * heading row from the rows beneath. |
| | | */ |
| | | /** The character which should be used to separate the table heading row from the rows beneath. */ |
| | | private char headingSeparator = DEFAULT_HEADING_SEPARATOR; |
| | | |
| | | /** The column where the heading separator should begin. */ |
| | |
| | | */ |
| | | private int padding = DEFAULT_PADDING; |
| | | |
| | | /** |
| | | * Total permitted width for the table which expandable columns |
| | | * can use up. |
| | | */ |
| | | /** Total permitted width for the table which expandable columns can use up. */ |
| | | private int totalWidth = MAX_LINE_WIDTH; |
| | | |
| | | /** The output destination. */ |
| | |
| | | this.totalWidth = totalWidth; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | protected TableSerializer getSerializer() { |
| | | return new Serializer(); |