Coverage report

  %line %branch
org.apache.commons.jelly.tags.swing.LayoutTagSupport
6% 
75% 

 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.LayoutManager;
 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  
  * An abstract base class used for concrete layout tags which create new LayoutManager implementations
 29  
  * and either export them as variables or set them on parent widgets.
 30  
  *
 31  
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 32  
  * @version $Revision: 155420 $
 33  
  */
 34  
 public abstract class LayoutTagSupport extends TagSupport {
 35  
 
 36  
     /** The Log to which logging calls will be made. */
 37  8
     private static final Log log = LogFactory.getLog(LayoutTagSupport.class);
 38  
 
 39  
     private String var;
 40  
 
 41  0
     public LayoutTagSupport() {
 42  0
     }
 43  
 
 44  
     /**
 45  
      * Adds the given layout component to the container with the specified constraints
 46  
      */
 47  
     public void addLayoutComponent(Component component, Object constraints) throws JellyTagException {
 48  0
         getComponentTag().addChild(component, constraints);
 49  0
     }
 50  
 
 51  
 
 52  
     // Tag interface
 53  
     //-------------------------------------------------------------------------
 54  
     public void doTag(final XMLOutput output) throws JellyTagException {
 55  
 
 56  0
         LayoutManager layout = createLayoutManager();
 57  
 
 58  0
         if (var != null) {
 59  0
             context.setVariable(var, layout);
 60  
         }
 61  
 
 62  0
         getComponentTag().setLayout(layout);
 63  
 
 64  
         // allow some nested tags to set properties
 65  0
         invokeBody(output);
 66  0
     }
 67  
 
 68  
     // Properties
 69  
     //-------------------------------------------------------------------------
 70  
 
 71  
 
 72  
     /**
 73  
      * Sets the name of the variable to use to expose the new LayoutManager object.
 74  
      * If this attribute is not set then the parent widget tag will have its
 75  
      * layout property set.
 76  
      */
 77  
     public void setVar(String var) {
 78  0
         this.var = class="keyword">var;
 79  0
     }
 80  
 
 81  
     // Implementation methods
 82  
     //-------------------------------------------------------------------------
 83  
 
 84  
     /**
 85  
      * @return the parent component tag or throw an exception
 86  
      */
 87  
     protected ComponentTag getComponentTag() throws JellyTagException {
 88  0
         ComponentTag tag = (ComponentTag) findAncestorWithClass( ComponentTag.class );
 89  0
         if ( tag == null ) {
 90  0
             throw new JellyTagException( "This tag must be nested within a JellySwing widget tag" );
 91  
         }
 92  0
         return tag;
 93  
     }
 94  
 
 95  
     /**
 96  
      * Factory method to create a new LayoutManager instance.
 97  
      */
 98  
     protected abstract LayoutManager createLayoutManager();
 99  
 }

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