View Javadoc

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.GridBagLayout;
19  import java.awt.LayoutManager;
20  
21  import org.apache.commons.jelly.JellyTagException;
22  import org.apache.commons.jelly.XMLOutput;
23  import org.apache.commons.jelly.tags.swing.impl.Cell;
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  
27  /***
28   * A Layout tag which mimicks the table, tr and td tags of HTML.
29   *
30   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
31   * @version $Revision: 155420 $
32   */
33  public class TableLayoutTag extends LayoutTagSupport {
34  
35      /*** The Log to which logging calls will be made. */
36      private static final Log log = LogFactory.getLog(LayoutTagSupport.class);
37  
38      private int rowCount;
39  
40      public TableLayoutTag() {
41      }
42  
43      /***
44       * Adds a new cell to the current grid
45       */
46      public void addCell(Cell cell) throws JellyTagException {
47          // find the parent container and add the component with the grid bag constraints
48          addLayoutComponent(cell.getComponent(), cell.getConstraints());
49      }
50  
51      /***
52       * Creates a new row index for child <tr> tags
53       */
54      public int nextRowIndex() {
55          return rowCount++;
56      }
57  
58      // Tag interface
59      //-------------------------------------------------------------------------
60      public void doTag(final XMLOutput output) throws JellyTagException {
61          rowCount = 0;
62          super.doTag(output);
63      }
64  
65      // Implementation methods
66      //-------------------------------------------------------------------------
67  
68  
69      /***
70       * Creates a GridBagLayout
71       */
72      protected LayoutManager createLayoutManager() {
73          return new GridBagLayout();
74      }
75  }