1 21 22 package org.armedbear.j; 23 24 public final class Table 26 { 27 private int columnIndex; 28 private int[] widths = new int[10]; 29 30 public Table() 31 { 32 } 33 34 public final int getColumnIndex() 35 { 36 return columnIndex; 37 } 38 39 public final void nextRow() 40 { 41 columnIndex = -1; 42 } 43 44 public void nextColumn() 45 { 46 ++columnIndex; 47 Debug.assertTrue(columnIndex >= 0); 48 if (columnIndex >= widths.length) { 49 int[] newArray = new int[widths.length * 2 + 2]; 50 System.arraycopy(widths, 0, newArray, 0, widths.length); 51 widths = newArray; 52 } 53 } 54 55 public void setColumnWidth(int width) 57 { 58 Debug.assertTrue(columnIndex >= 0); 59 Debug.assertTrue(columnIndex < widths.length); 60 if (width > widths[columnIndex]) 61 widths[columnIndex] = width; 62 } 63 64 public int getColumnWidth() 66 { 67 Debug.assertTrue(columnIndex >= 0); 68 Debug.assertTrue(columnIndex < widths.length); 69 return widths[columnIndex]; 70 } 71 72 public int getMinimumOffset() 75 { 76 Debug.assertTrue(columnIndex >= 0); 77 Debug.assertTrue(columnIndex < widths.length); 78 int offset = 0; 79 for (int i = 0; i < columnIndex; i++) 80 offset += widths[i]; 81 return offset; 82 } 83 } 84 | Popular Tags |