01: /*
02: * Table.java
03: *
04: * Copyright (C) 1998-2003 Peter Graves
05: * $Id: Table.java,v 1.2 2003/07/26 18:54:13 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.j;
23:
24: // An HTML table.
25: public final class Table {
26: private int columnIndex;
27: private int[] widths = new int[10];
28:
29: public Table() {
30: }
31:
32: public final int getColumnIndex() {
33: return columnIndex;
34: }
35:
36: public final void nextRow() {
37: columnIndex = -1;
38: }
39:
40: public void nextColumn() {
41: ++columnIndex;
42: Debug.assertTrue(columnIndex >= 0);
43: if (columnIndex >= widths.length) {
44: int[] newArray = new int[widths.length * 2 + 2];
45: System.arraycopy(widths, 0, newArray, 0, widths.length);
46: widths = newArray;
47: }
48: }
49:
50: // Sets width of current column.
51: public void setColumnWidth(int width) {
52: Debug.assertTrue(columnIndex >= 0);
53: Debug.assertTrue(columnIndex < widths.length);
54: if (width > widths[columnIndex])
55: widths[columnIndex] = width;
56: }
57:
58: // Returns width of current column.
59: public int getColumnWidth() {
60: Debug.assertTrue(columnIndex >= 0);
61: Debug.assertTrue(columnIndex < widths.length);
62: return widths[columnIndex];
63: }
64:
65: // Returns minumum offset of start of current column, based on column
66: // widths of columns to the left of it.
67: public int getMinimumOffset() {
68: Debug.assertTrue(columnIndex >= 0);
69: Debug.assertTrue(columnIndex < widths.length);
70: int offset = 0;
71: for (int i = 0; i < columnIndex; i++)
72: offset += widths[i];
73: return offset;
74: }
75: }
|