1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.swing;
17
18 import java.awt.Component;
19 import java.awt.GridBagConstraints;
20 import java.util.ArrayList;
21 import java.util.Iterator;
22 import java.util.List;
23
24 import org.apache.commons.jelly.JellyTagException;
25 import org.apache.commons.jelly.TagSupport;
26 import org.apache.commons.jelly.XMLOutput;
27 import org.apache.commons.jelly.tags.swing.impl.Cell;
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30
31 /***
32 * Represents a tabular row inside a <tableLayout> tag which mimicks the
33 * <tr> HTML tag.
34 *
35 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
36 * @version $Revision: 1.7 $
37 */
38 public class TrTag extends TagSupport {
39
40 /*** The Log to which logging calls will be made. */
41 private static final Log log = LogFactory.getLog(TrTag.class);
42
43 private TableLayoutTag tableLayoutTag;
44 private List cells = new ArrayList();
45 private int rowIndex;
46
47 public TrTag() {
48 }
49
50 /***
51 * Adds a new cell to this row
52 */
53 public void addCell(Component component, GridBagConstraints constraints) throws JellyTagException {
54 constraints.gridx = cells.size();
55 cells.add(new Cell(constraints, component));
56 }
57
58
59
60
61 public void doTag(final XMLOutput output) throws JellyTagException {
62 tableLayoutTag = (TableLayoutTag) findAncestorWithClass( TableLayoutTag.class );
63 if (tableLayoutTag == null) {
64 throw new JellyTagException( "this tag must be nested within a <tableLayout> tag" );
65 }
66 rowIndex = tableLayoutTag.nextRowIndex();
67 cells.clear();
68
69 invokeBody(output);
70
71
72 for (Iterator iter = cells.iterator(); iter.hasNext(); ) {
73 Cell cell = (Cell) iter.next();
74 GridBagConstraints c = cell.getConstraints();
75
76
77 if ( iter.hasNext() ) {
78
79 c.gridwidth = GridBagConstraints.RELATIVE;
80 }
81 else {
82
83 c.gridwidth = GridBagConstraints.REMAINDER;
84 }
85 c.gridy = rowIndex;
86
87
88 tableLayoutTag.addCell(cell);
89 }
90 cells.clear();
91 }
92
93
94
95
96 /***
97 * @return the row index of this row
98 */
99 public int getRowIndex() {
100 return rowIndex;
101 }
102
103 }