01: /*
02: * Copyright (C) 2004 TiongHiang Lee
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: * Email: thlee@onemindsoft.org
19: */
20:
21: package org.onemind.swingweb.component.layout;
22:
23: import java.awt.*;
24:
25: public class TableLayout extends GridBagLayout {
26:
27: private Container _container;
28:
29: private GridBagConstraints _constr = new GridBagConstraints();
30:
31: public TableLayout(Container c) {
32: _container = c;
33: _constr.gridx = -1; //so that the first add will work
34: _constr.gridy = 0;
35: _constr.gridwidth = 1;
36: _constr.gridheight = 1;
37: }
38:
39: public void addNextRow(Component com) {
40: addNextRow(com, 0);
41: }
42:
43: public void addNextRow(Component com, int startingCol) {
44: addNextRow(com, startingCol, 1);
45: }
46:
47: public void addNextRow(Component com, int startingCol, int colSpan) {
48: _constr.gridy++;
49: _constr.gridx = startingCol;
50: _constr.gridwidth = colSpan;
51: _add(com);
52: }
53:
54: public void addNextCell(Component com) {
55: addNextCell(com, 1);
56: }
57:
58: public void addNextCell(Component com, int colSpan) {
59: _constr.gridx++;
60: _constr.gridwidth = colSpan;
61: _add(com);
62: }
63:
64: private void _add(Component com) {
65: _container.add(com, _constr);
66: }
67:
68: private void addAtCell(Component com, int row, int col) {
69: _constr.gridx = col;
70: _constr.gridy = row;
71: _add(com);
72: }
73:
74: public GridBagConstraints getConstraint() {
75: return _constr;
76: }
77: }
|