Clover coverage report - Code Coverage for tapestry release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:05:49 EDT
file stats: LOC: 141   Methods: 3
NCLOC: 64   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
ImageSubmit.java 88.9% 91.7% 66.7% 89.5%
coverage coverage
 1   
 // Copyright 2004, 2005 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.tapestry.form;
 16   
 
 17   
 import java.awt.Point;
 18   
 
 19   
 import org.apache.tapestry.IAsset;
 20   
 import org.apache.tapestry.IForm;
 21   
 import org.apache.tapestry.IMarkupWriter;
 22   
 import org.apache.tapestry.IRequestCycle;
 23   
 import org.apache.tapestry.Tapestry;
 24   
 
 25   
 /**
 26   
  * Used to create an image button inside a {@link Form}. Although it is occasionally useful to know
 27   
  * the {@link Point}on the image that was clicked (i.e., use the image as a kind of image map,
 28   
  * which was the original intent of the HTML element), it is more commonly used to provide a graphic
 29   
  * image for the user to click, rather than the rather plain &lt;input type=submit&gt;. [ <a
 30   
  * href="../../../../../ComponentReference/ImageSubmit.html">Component Reference </a>]
 31   
  * 
 32   
  * @author Howard Lewis Ship
 33   
  */
 34   
 
 35   
 public abstract class ImageSubmit extends Submit
 36   
 {
 37  9
     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
 38   
     {
 39  9
         IForm form = getForm(cycle);
 40   
 
 41  9
         if (form.wasPrerendered(writer, this))
 42  1
             return;
 43   
 
 44  8
         boolean rewinding = form.isRewinding();
 45   
 
 46  8
         String nameOverride = getNameOverride();
 47   
 
 48  8
         String name = nameOverride == null ? form.getElementId(this) : form.getElementId(
 49   
                 this,
 50   
                 nameOverride);
 51   
 
 52  8
         setName(name);
 53   
 
 54  8
         if (rewinding)
 55   
         {
 56   
             // If disabled, do nothing.
 57   
 
 58  4
             if (isDisabled())
 59  1
                 return;
 60   
 
 61   
             // Image clicks get submitted as two request parameters:
 62   
             // foo.x and foo.y
 63   
 
 64  3
             String parameterName = name + ".x";
 65   
 
 66  3
             String value = cycle.getParameter(parameterName);
 67   
 
 68  3
             if (value != null)
 69  2
                 handleClick(cycle, form);
 70   
 
 71  3
             return;
 72   
         }
 73   
 
 74   
         // Not rewinding, do the real render
 75   
 
 76  4
         boolean disabled = isDisabled();
 77  4
         IAsset disabledImage = getDisabledImage();
 78   
 
 79  4
         IAsset finalImage = (disabled && disabledImage != null) ? disabledImage : getImage();
 80   
 
 81  4
         String imageURL = finalImage.buildURL(cycle);
 82   
 
 83  4
         writer.beginEmpty("input");
 84  4
         writer.attribute("type", "image");
 85  4
         writer.attribute("name", name);
 86   
 
 87  4
         if (disabled)
 88  2
             writer.attribute("disabled", "disabled");
 89   
 
 90   
         // NN4 places a border unless you tell it otherwise.
 91   
         // IE ignores the border attribute and never shows a border.
 92   
 
 93  4
         writer.attribute("border", 0);
 94   
 
 95  4
         writer.attribute("src", imageURL);
 96   
 
 97  4
         renderInformalParameters(writer, cycle);
 98   
 
 99  4
         writer.closeTag();
 100   
     }
 101   
 
 102  2
     void handleClick(IRequestCycle cycle, IForm form)
 103   
     {
 104   
         // The point parameter is not really used, unless the
 105   
         // ImageButton is used for its original purpose (as a kind
 106   
         // of image map). In modern usage, we only care about
 107   
         // whether the user clicked on the image (and thus submitted
 108   
         // the form), not where in the image the user actually clicked.
 109   
 
 110  2
         if (isParameterBound("point"))
 111   
         {
 112  1
             int x = Integer.parseInt(cycle.getParameter(getName() + ".x"));
 113  1
             int y = Integer.parseInt(cycle.getParameter(getName() + ".y"));
 114   
 
 115  1
             setPoint(new Point(x, y));
 116   
         }
 117   
 
 118  2
         super.handleClick(cycle, form);
 119   
     }
 120   
 
 121   
     /** parameter */
 122   
     public abstract IAsset getDisabledImage();
 123   
 
 124   
     /** parameter */
 125   
     public abstract IAsset getImage();
 126   
 
 127   
     /** parameter */
 128   
     public abstract String getNameOverride();
 129   
 
 130   
     /** parameter */
 131   
     public abstract void setPoint(Point point);
 132   
 
 133  0
     protected void prepareForRender(IRequestCycle cycle)
 134   
     {
 135  0
         super.prepareForRender(cycle);
 136   
 
 137  0
         if (getImage() == null)
 138  0
             throw Tapestry.createRequiredParameterException(this, "image");
 139   
     }
 140   
 
 141   
 }