Clover coverage report - Code Coverage for tapestry release 4.0-beta-8
Coverage timestamp: Sat Sep 24 2005 11:50:34 EDT
file stats: LOC: 122   Methods: 5
NCLOC: 56   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ImageSubmit.java 80% 88.5% 80% 85.4%
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    /**
 38    * @see org.apache.tapestry.form.AbstractFormComponent#setName(org.apache.tapestry.IForm)
 39    */
 40  8 protected void setName(IForm form)
 41    {
 42  8 String nameOverride = getNameOverride();
 43   
 44  8 setName((nameOverride == null) ? form.getElementId(this) : form.getElementId(this, nameOverride));
 45    }
 46   
 47  3 protected boolean isClicked(IRequestCycle cycle, String name)
 48    {
 49  3 String parameterName = name + ".x";
 50   
 51  3 return (cycle.getParameter(parameterName) != null);
 52    }
 53   
 54  4 protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 55    {
 56  4 boolean disabled = isDisabled();
 57  4 IAsset disabledImage = getDisabledImage();
 58   
 59  4 IAsset finalImage = (disabled && disabledImage != null) ? disabledImage : getImage();
 60   
 61  4 String imageURL = finalImage.buildURL(cycle);
 62   
 63  4 writer.beginEmpty("input");
 64  4 writer.attribute("type", "image");
 65  4 writer.attribute("name", getName());
 66   
 67  4 if (disabled)
 68  2 writer.attribute("disabled", "disabled");
 69   
 70    // NN4 places a border unless you tell it otherwise.
 71    // IE ignores the border attribute and never shows a border.
 72   
 73  4 writer.attribute("border", 0);
 74   
 75  4 writer.attribute("src", imageURL);
 76   
 77  4 renderIdAttribute(writer, cycle);
 78   
 79  4 renderInformalParameters(writer, cycle);
 80   
 81  4 writer.closeTag();
 82    }
 83   
 84  2 void handleClick(IRequestCycle cycle, IForm form)
 85    {
 86    // The point parameter is not really used, unless the
 87    // ImageButton is used for its original purpose (as a kind
 88    // of image map). In modern usage, we only care about
 89    // whether the user clicked on the image (and thus submitted
 90    // the form), not where in the image the user actually clicked.
 91   
 92  2 if (isParameterBound("point"))
 93    {
 94  1 int x = Integer.parseInt(cycle.getParameter(getName() + ".x"));
 95  1 int y = Integer.parseInt(cycle.getParameter(getName() + ".y"));
 96   
 97  1 setPoint(new Point(x, y));
 98    }
 99   
 100  2 super.handleClick(cycle, form);
 101    }
 102   
 103    /** parameter */
 104    public abstract IAsset getDisabledImage();
 105   
 106    /** parameter */
 107    public abstract IAsset getImage();
 108   
 109    /** parameter */
 110    public abstract String getNameOverride();
 111   
 112    /** parameter */
 113    public abstract void setPoint(Point point);
 114   
 115  0 protected void prepareForRender(IRequestCycle cycle)
 116    {
 117  0 super.prepareForRender(cycle);
 118   
 119  0 if (getImage() == null)
 120  0 throw Tapestry.createRequiredParameterException(this, "image");
 121    }
 122    }