KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > Table


1 /*
2  * Table.java
3  *
4  * Copyright (C) 1998-2003 Peter Graves
5  * $Id: Table.java,v 1.2 2003/07/26 18:54:13 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * 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 {
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     // Sets width of current column.
56
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     // Returns width of current column.
65
public int getColumnWidth()
66     {
67         Debug.assertTrue(columnIndex >= 0);
68         Debug.assertTrue(columnIndex < widths.length);
69         return widths[columnIndex];
70     }
71
72     // Returns minumum offset of start of current column, based on column
73
// widths of columns to the left of it.
74
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