1 package org.sapia.console.table; 2 3 4 9 public class Row { 10 private Table _table; 11 private Cell[] _cells; 12 private boolean _flushed; 13 14 17 Row(Table owner) { 18 _table = owner; 19 _cells = new Cell[owner.getTableMetaData().getColumnCount()]; 20 21 for (int i = 0; i < _cells.length; i++) { 22 _cells[i] = new Cell(this, i); 23 } 24 } 25 26 public Table getTable() { 27 return _table; 28 } 29 30 public Cell getCellAt(int index) { 31 return _cells[index]; 32 } 33 34 public int getCellCount() { 35 return _cells.length; 36 } 37 38 public void flush() { 39 if (_flushed) { 40 return; 41 } 42 43 StringBuffer content = new StringBuffer (); 44 45 Cell biggest = null; 46 47 for (int i = 0; i < _cells.length; i++) { 48 _cells[i].format(); 49 50 if (biggest == null) { 51 biggest = _cells[i]; 52 } else if (_cells[i].getHeight() > biggest.getHeight()) { 53 biggest = _cells[i]; 54 } 55 } 56 57 int h = biggest.getHeight(); 58 59 for (int i = 0; i < _cells.length; i++) { 60 _cells[i].pack(h); 61 } 62 63 int lines = biggest.getHeight(); 64 65 for (int i = 0; i < h; i++) { 66 for (int j = 0; j < _cells.length; j++) { 67 String cell = _cells[j].getContent(i); 68 content.append(cell); 69 } 70 71 if (i < (h - 1)) { 72 content.append(System.getProperty("line.separator")); 73 } 74 } 75 76 _table.getWriter().println(content.toString()); 77 _table.getWriter().flush(); 78 _flushed = true; 79 } 80 } 81 | Popular Tags |