/** * Returns the row width. * * @return int the width of the row */ private int getRowWidth() { int returnVal = 1; if (rows.size() < 1) { returnVal = 0; } for (int i = 0; i < rows.size(); i++) { if (rows.get(i) instanceof Row) { returnVal = ((Row)rows.get(i)).getRowWidth(); } } return returnVal; }
/** * Returns the row's total width. * * @return the width of the row. */ public int getRowWidth() { int overallWidth = 0; for (int i = 0; i < data.length; i++) { overallWidth += getTable().getColumnWidth(i); } return overallWidth; }
/** * Adds a string row. checks that the strings added do not contain newlines, * because if so, it has to split them in order to make them fit the row. * * @param data * the array of data. */ public void addRow(final String[] data) { if (anyStringContainsNewLine(data)) { final String[][] theMatrix = Util.createMatrix(data); for (int i = 0; i < theMatrix.length; i++) { addRow(theMatrix[i]); } } else { final Row myRow = new Row(this, data); rows.add(myRow); } }
/** * Constructor. * * @param myParent * table to be printed to * @param paramData * data to be plotted */ public Row(final NiceTable myParent, final String[] paramData) { super(myParent); data = new String[paramData.length]; System.arraycopy(paramData, 0, data, 0, paramData.length); for (int i = 0; i < data.length; i++) { getTable().updateColumnWidth(i, data[i].length()); data[i] = data[i].trim(); } }
/** * {@inheritDoc} */ @Override public String draw() { final String[] row = new String[data.length]; for (int i = 0; i < data.length; i++) { row[i] = Util.pad(data[i], ' ', getTable().getColumnWidth(i), getTable().getOrientation(i)); } return Util.combine(new String(new char[] { AbstractTabularComponent.BORDER }), SPACE, Util.implode(Util.combine(SPACE, new String(new char[] { AbstractTabularComponent.BORDER }), SPACE), row), SPACE, new String(new char[] { AbstractTabularComponent.BORDER }), NEWLINE); }