Coverage report

  %line %branch
org.apache.commons.jelly.tags.swing.TdTag
2% 
80% 

 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  
 
 21  
 import org.apache.commons.jelly.JellyTagException;
 22  
 import org.apache.commons.jelly.TagSupport;
 23  
 import org.apache.commons.jelly.XMLOutput;
 24  
 import org.apache.commons.logging.Log;
 25  
 import org.apache.commons.logging.LogFactory;
 26  
 
 27  
 /**
 28  
  * Represents a tabular cell inside a <tl> tag inside a <tableLayout>
 29  
  * tag which mimicks the <td> HTML tag.
 30  
  *
 31  
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 32  
  * @version $Revision: 155420 $
 33  
  */
 34  
 public class TdTag extends TagSupport implements ContainerTag {
 35  
 
 36  
     /** The Log to which logging calls will be made. */
 37  8
     private static final Log log = LogFactory.getLog(TdTag.class);
 38  
 
 39  
     private String align;
 40  
     private String valign;
 41  0
     private int colspan = 1;
 42  0
     private int rowspan = 1;
 43  0
     private boolean colfill = false;
 44  0
     private boolean rowfill = false;
 45  
 
 46  0
     public TdTag() {
 47  0
     }
 48  
 
 49  
     // ContainerTag interface
 50  
     //-------------------------------------------------------------------------
 51  
 
 52  
     /**
 53  
      * Adds a child component to this parent
 54  
      */
 55  
     public void addChild(Component component, Object constraints) throws JellyTagException {
 56  
         // add my child component to the layout manager
 57  0
         TrTag tag = (TrTag) findAncestorWithClass( TrTag.class );
 58  0
         if (tag == null) {
 59  0
             throw new JellyTagException( "this tag must be nested within a <tr> tag" );
 60  
         }
 61  0
         tag.addCell(component, createConstraints());
 62  0
     }
 63  
 
 64  
 
 65  
     // Tag interface
 66  
     //-------------------------------------------------------------------------
 67  
     public void doTag(final XMLOutput output) throws JellyTagException {
 68  0
         invokeBody(output);
 69  0
     }
 70  
 
 71  
 
 72  
     // Properties
 73  
     //-------------------------------------------------------------------------
 74  
 
 75  
     /**
 76  
      * Sets the horizontal alignment to a case insensitive value of {LEFT, CENTER, RIGHT}
 77  
      */
 78  
     public void setAlign(String align) {
 79  0
         this.align = align;
 80  0
     }
 81  
 
 82  
     /**
 83  
      * Sets the vertical alignment to a case insensitive value of {TOP, MIDDLE, BOTTOM}
 84  
      */
 85  
     public void setValign(String valign) {
 86  0
         this.valign = valign;
 87  0
     }
 88  
 
 89  
 
 90  
     /**
 91  
      * Sets the number of columns that this cell should span. The default value is 1
 92  
      */
 93  
     public void setColspan(int colspan) {
 94  0
         this.colspan = colspan;
 95  0
     }
 96  
 
 97  
     /**
 98  
      * Sets the number of rows that this cell should span. The default value is 1
 99  
      */
 100  
     public void setRowspan(int rowspan) {
 101  0
         this.rowspan = rowspan;
 102  0
     }
 103  
 
 104  
     /**
 105  
      * Returns the colfill.
 106  
      * @return boolean
 107  
      */
 108  
     public boolean isColfill() {
 109  0
         return colfill;
 110  
     }
 111  
 
 112  
     /**
 113  
      * Returns the rowfill.
 114  
      * @return boolean
 115  
      */
 116  
     public boolean isRowfill() {
 117  0
         return rowfill;
 118  
     }
 119  
 
 120  
     /**
 121  
      * Sets whether or not this column should allow its component to stretch to fill the space available
 122  
      */
 123  
     public void setColfill(boolean colfill) {
 124  0
         this.colfill = colfill;
 125  0
     }
 126  
 
 127  
     /**
 128  
      * Sets whether or not this row should allow its component to stretch to fill the space available
 129  
      */
 130  
     public void setRowfill(boolean rowfill) {
 131  0
         this.rowfill = rowfill;
 132  0
     }
 133  
 
 134  
 
 135  
     // Implementation methods
 136  
     //-------------------------------------------------------------------------
 137  
 
 138  
     /**
 139  
      * Factory method to create a new constraints object
 140  
      */
 141  
     protected GridBagConstraints createConstraints() {
 142  0
         GridBagConstraints answer = new GridBagConstraints();
 143  0
         answer.anchor = getAnchor();
 144  0
         if (colspan < 1) {
 145  0
             colspan = 1;
 146  
         }
 147  0
         if (rowspan < 1) {
 148  0
             rowspan = 1;
 149  
         }
 150  0
         if (isColfill())  {
 151  0
             answer.fill = isRowfill()
 152  
                 ? GridBagConstraints.BOTH
 153  
                 : GridBagConstraints.HORIZONTAL;
 154  
         }
 155  
         else {
 156  0
             answer.fill = isRowfill()
 157  
                 ? GridBagConstraints.VERTICAL
 158  
                 : GridBagConstraints.NONE;
 159  
         }
 160  0
         answer.weightx = 0.2;
 161  0
         answer.weighty = 0;
 162  0
         answer.gridwidth = colspan;
 163  0
         answer.gridheight = rowspan;
 164  0
         return answer;
 165  
     }
 166  
 
 167  
     /**
 168  
      * @return the GridBagConstraints enumeration for achor
 169  
      */
 170  
     protected int getAnchor() {
 171  0
         boolean isTop = "top".equalsIgnoreCase(valign);
 172  0
         boolean isBottom = "bottom".equalsIgnoreCase(valign);
 173  
 
 174  0
         if ("center".equalsIgnoreCase(align)) {
 175  0
             if (isTop) {
 176  0
                 return GridBagConstraints.NORTH;
 177  
             }
 178  0
             else if (isBottom) {
 179  0
                 return GridBagConstraints.SOUTH;
 180  
             }
 181  
             else {
 182  0
                 return GridBagConstraints.CENTER;
 183  
             }
 184  
         }
 185  0
         else if ("right".equalsIgnoreCase(align)) {
 186  0
             if (isTop) {
 187  0
                 return GridBagConstraints.NORTHEAST;
 188  
             }
 189  0
             else if (isBottom) {
 190  0
                 return GridBagConstraints.SOUTHEAST;
 191  
             }
 192  
             else {
 193  0
                 return GridBagConstraints.EAST;
 194  
             }
 195  
         }
 196  
         else {
 197  
             // defaults to left
 198  0
             if (isTop) {
 199  0
                 return GridBagConstraints.NORTHWEST;
 200  
             }
 201  0
             else if (isBottom) {
 202  0
                 return GridBagConstraints.SOUTHWEST;
 203  
             }
 204  
             else {
 205  0
                 return GridBagConstraints.WEST;
 206  
             }
 207  
         }
 208  
     }
 209  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.