1 package org.sapia.console.table; 2 3 4 9 class Utils { 10 static void formatLine(Line line, int cellWidth) { 11 if (line._content.length() > cellWidth) { 12 StringBuffer split = new StringBuffer (); 13 split.append(line._content.substring(cellWidth)); 14 line._content.delete(cellWidth, line._content.length()); 15 16 Line newLine = new Line(); 17 newLine._content = new StringBuffer (split.toString().trim()); 18 line._next = newLine; 19 formatLine(newLine, cellWidth); 20 } else { 21 appendSpaces(line._content, cellWidth); 22 } 23 } 24 25 private static void appendSpaces(StringBuffer content, int cellWidth) { 26 for (int i = content.length(); i < cellWidth; i++) { 27 content.append(' '); 28 } 29 } 30 31 private static StringBuffer lTrim(StringBuffer content) { 32 StringBuffer buf = new StringBuffer (); 33 int i = 0; 34 35 while ((content.charAt(i) == ' ') && (i < content.length())) { 36 i++; 37 } 38 39 if (i < content.length()) { 40 buf.append(content.substring(i)); 41 } 42 43 return buf; 44 } 45 46 public static void main(String [] args) { 47 Table t = new Table(System.out, 1, 80); 48 t.drawLine('='); 49 50 } 70 } 71 | Popular Tags |