%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.swing.TrTag |
|
|
1 | /* |
|
2 | * Copyright 2002,2004 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
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 | 2 | public class TrTag extends TagSupport { |
39 | ||
40 | /** The Log to which logging calls will be made. */ |
|
41 | 2 | private static final Log log = LogFactory.getLog(TrTag.class); |
42 | ||
43 | private TableLayoutTag tableLayoutTag; |
|
44 | 0 | private List cells = new ArrayList(); |
45 | private int rowIndex; |
|
46 | ||
47 | 0 | public TrTag() { |
48 | 0 | } |
49 | ||
50 | /** |
|
51 | * Adds a new cell to this row |
|
52 | */ |
|
53 | public void addCell(Component component, GridBagConstraints constraints) throws JellyTagException { |
|
54 | 0 | constraints.gridx = cells.size(); |
55 | 0 | cells.add(new Cell(constraints, component)); |
56 | 0 | } |
57 | ||
58 | ||
59 | // Tag interface |
|
60 | //------------------------------------------------------------------------- |
|
61 | public void doTag(final XMLOutput output) throws JellyTagException { |
|
62 | 0 | tableLayoutTag = (TableLayoutTag) findAncestorWithClass( TableLayoutTag.class ); |
63 | 0 | if (tableLayoutTag == null) { |
64 | 0 | throw new JellyTagException( "this tag must be nested within a <tableLayout> tag" ); |
65 | } |
|
66 | 0 | rowIndex = tableLayoutTag.nextRowIndex(); |
67 | 0 | cells.clear(); |
68 | ||
69 | 0 | invokeBody(output); |
70 | ||
71 | // now iterate through the rows and add each one to the layout... |
|
72 | 0 | for (Iterator iter = cells.iterator(); iter.hasNext(); ) { |
73 | 0 | Cell cell = (Cell) iter.next(); |
74 | 0 | GridBagConstraints c = cell.getConstraints(); |
75 | ||
76 | // are we the last cell in the row |
|
77 | 0 | if ( iter.hasNext() ) { |
78 | // not last in row |
|
79 | 0 | c.gridwidth = GridBagConstraints.RELATIVE; |
80 | } |
|
81 | else { |
|
82 | // end of row |
|
83 | 0 | c.gridwidth = GridBagConstraints.REMAINDER; |
84 | } |
|
85 | 0 | c.gridy = rowIndex; |
86 | ||
87 | // now lets add the cell to the table |
|
88 | 0 | tableLayoutTag.addCell(cell); |
89 | } |
|
90 | 0 | cells.clear(); |
91 | 0 | } |
92 | ||
93 | // Properties |
|
94 | //------------------------------------------------------------------------- |
|
95 | ||
96 | /** |
|
97 | * @return the row index of this row |
|
98 | */ |
|
99 | public int getRowIndex() { |
|
100 | 0 | return rowIndex; |
101 | } |
|
102 | ||
103 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |