KickJava   Java API By Example, From Geeks To Geeks.

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


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

9 public class Cell {
10   private Row _row;
11   private int _index;
12   private Line _content = new Line();
13
14   /**
15    * Constructor for Column.
16    */

17   Cell(Row owner, int index) {
18     _row = owner;
19     _index = index;
20   }
21
22   Row getRow() {
23     return _row;
24   }
25
26   public int getIndex() {
27     return _index;
28   }
29
30   public int getWidth() {
31     return _row.getTable().getTableMetaData().getColumnMetaDataAt(_index)
32                .getWidth();
33   }
34
35   public Cell append(String JavaDoc content) {
36     _content.append(content);
37
38     return this;
39   }
40
41   int getHeight() {
42     return _content.getLineCount();
43   }
44
45   void format() {
46     ColumnMetaData meta = _row.getTable().getTableMetaData()
47                               .getColumnMetaDataAt(_index);
48     _content.format(meta.getWidth());
49   }
50
51   void pack(int height) {
52     ColumnMetaData meta = _row.getTable().getTableMetaData()
53                               .getColumnMetaDataAt(_index);
54     _content.addEmptyLines(height - _content.getLineCount(), meta.getWidth(),
55       meta.getCellPadding());
56   }
57
58   String JavaDoc getContent(int lineNum) {
59     ColumnMetaData meta = _row.getTable().getTableMetaData()
60                               .getColumnMetaDataAt(_index);
61     Line line = _content.getLineAt(lineNum);
62
63     //_content.addEmptyLines(height - _content.getLineCount(), meta.getWidth(), meta.getCellSpacing());
64
return line.render(meta.getWidth(), meta.getCellPadding());
65   }
66 }
67
Popular Tags