KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > console > table > Utils


1 package org.sapia.console.table;
2
3
4 /**
5  * @author Yanick Duchesne
6  * 2002-03-05
7  *
8  */

9 class Utils {
10   static void formatLine(Line line, int cellWidth) {
11     if (line._content.length() > cellWidth) {
12       StringBuffer JavaDoc split = new StringBuffer JavaDoc();
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 JavaDoc(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 JavaDoc content, int cellWidth) {
26     for (int i = content.length(); i < cellWidth; i++) {
27       content.append(' ');
28     }
29   }
30
31   private static StringBuffer JavaDoc lTrim(StringBuffer JavaDoc content) {
32     StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
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 JavaDoc[] args) {
47     Table t = new Table(System.out, 1, 80);
48     t.drawLine('=');
49
50     // Table t = new Table(System.out, 2, 5);
51
// Row r = t.newRow();
52
// Cell c;
53
// r.getCellAt(0).append("Hello World Maximum ouch");
54
// c = r.getCellAt(1);
55
// t.getTableMetaData().getColumnMetaDataAt(1).setWidth(10);
56
// c.append("The food is in the barn");
57
//
58
// r.flush();
59
//
60
// t.drawLine('=');
61
//
62
// r.flush();
63
// Line line = new Line();
64
// line._content.append("Hello World Maximum ouch");
65
// formatLine(line, 5);
66
// line.addEmptyLines(3, 5, 1);
67
// System.out.println(line.render(5, 1));
68
// System.out.println("" + line.getLineCount());
69
}
70 }
71
Popular Tags