Coverage Report - org.apache.tapestry.form.ImageSubmit
 
Classes in this File Line Coverage Branch Coverage Complexity
ImageSubmit
0%
0/32
0%
0/16
1.889
 
 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="../../../../../components/form/imagesubmit.html">Component Reference </a>]
 31  
  * 
 32  
  * @author Howard Lewis Ship
 33  
  */
 34  
 
 35  0
 public abstract class ImageSubmit extends Submit
 36  
 {
 37  
     /**
 38  
      * @see org.apache.tapestry.form.AbstractFormComponent#setName(org.apache.tapestry.IForm)
 39  
      */
 40  
     protected void setName(IForm form)
 41  
     {
 42  0
         String nameOverride = getNameOverride();
 43  
 
 44  0
         setName((nameOverride == null) ? form.getElementId(this) : form.getElementId(this, nameOverride));
 45  0
     }
 46  
 
 47  
     protected boolean isClicked(IRequestCycle cycle, String name)
 48  
     {
 49  0
         String parameterName = name + ".x";
 50  
         
 51  
         // the name.x parameter is not set for asynchronous submits
 52  0
         String value = cycle.getParameter(FormConstants.SUBMIT_NAME_PARAMETER);
 53  
 
 54  0
         return (cycle.getParameter(parameterName) != null) || name.equals(value);
 55  
     }
 56  
     
 57  
     protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 58  
     {
 59  0
         boolean disabled = isDisabled();
 60  0
         IAsset disabledImage = getDisabledImage();
 61  
 
 62  0
         IAsset finalImage = (disabled && disabledImage != null) ? disabledImage : getImage();
 63  
 
 64  0
         String imageURL = finalImage.buildURL();
 65  
 
 66  0
         writer.beginEmpty("input");
 67  0
         writer.attribute("type", "image");
 68  0
         writer.attribute("name", getName());
 69  
         
 70  0
         if (disabled)
 71  0
             writer.attribute("disabled", "disabled");        
 72  
         
 73  0
         writer.attribute("src", imageURL);
 74  
 
 75  0
         renderIdAttribute(writer, cycle);
 76  
 
 77  0
         renderInformalParameters(writer, cycle);
 78  
         
 79  0
         renderSubmitBindings(writer, cycle);
 80  
         
 81  0
         writer.closeTag();
 82  0
     }
 83  
 
 84  
     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  0
         if (isParameterBound("point"))
 93  
         {
 94  0
             int x = Integer.parseInt(cycle.getParameter(getName() + ".x"));
 95  0
             int y = Integer.parseInt(cycle.getParameter(getName() + ".y"));
 96  
 
 97  0
             setPoint(new Point(x, y));
 98  
         }
 99  
 
 100  0
         super.handleClick(cycle, form);
 101  0
     }
 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  
     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  0
     }
 122  
 }