Clover coverage report - Code Coverage for tapestry release 4.0-alpha-2
Coverage timestamp: Thu May 5 2005 09:57:44 EDT
file stats: LOC: 155   Methods: 2
NCLOC: 72   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 0% 0% 0% 0%
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.IActionListener;
 20   
 import org.apache.tapestry.IAsset;
 21   
 import org.apache.tapestry.IBinding;
 22   
 import org.apache.tapestry.IForm;
 23   
 import org.apache.tapestry.IMarkupWriter;
 24   
 import org.apache.tapestry.IRequestCycle;
 25   
 import org.apache.tapestry.Tapestry;
 26   
 
 27   
 /**
 28   
  * Used to create an image button inside a {@link Form}. Although it is occasionally useful to know
 29   
  * the {@link Point}on the image that was clicked (i.e., use the image as a kind of image map,
 30   
  * which was the original intent of the HTML element), it is more commonly used to provide a graphic
 31   
  * image for the user to click, rather than the rather plain &lt;input type=submit&gt;. [ <a
 32   
  * href="../../../../../ComponentReference/ImageSubmit.html">Component Reference </a>]
 33   
  * 
 34   
  * @author Howard Lewis Ship
 35   
  */
 36   
 
 37   
 public abstract class ImageSubmit extends AbstractFormComponent
 38   
 {
 39  0
     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
 40   
     {
 41  0
         IForm form = getForm(cycle);
 42   
 
 43  0
         if (form.wasPrerendered(writer, this))
 44  0
             return;
 45   
 
 46  0
         boolean rewinding = form.isRewinding();
 47   
 
 48  0
         String nameOverride = getNameOverride();
 49   
 
 50  0
         String name = nameOverride == null ? form.getElementId(this) : form.getElementId(
 51   
                 this,
 52   
                 nameOverride);
 53   
 
 54  0
         if (rewinding)
 55   
         {
 56   
             // If disabled, do nothing.
 57   
 
 58  0
             if (isDisabled())
 59  0
                 return;
 60   
 
 61   
             // Image clicks get submitted as two request parameters:
 62   
             // foo.x and foo.y
 63   
 
 64  0
             String parameterName = name + ".x";
 65   
 
 66  0
             String value = cycle.getParameter(parameterName);
 67   
 
 68  0
             if (value == null)
 69  0
                 return;
 70   
 
 71   
             // The point parameter is not really used, unless the
 72   
             // ImageButton is used for its original purpose (as a kind
 73   
             // of image map). In modern usage, we only care about
 74   
             // whether the user clicked on the image (and thus submitted
 75   
             // the form), not where in the image the user actually clicked.
 76   
 
 77  0
             IBinding pointBinding = getBinding("point");
 78   
 
 79  0
             if (pointBinding != null)
 80   
             {
 81  0
                 int x = Integer.parseInt(value);
 82   
 
 83  0
                 parameterName = name + ".y";
 84  0
                 value = cycle.getParameter(parameterName);
 85   
 
 86  0
                 int y = Integer.parseInt(value);
 87   
 
 88  0
                 pointBinding.setObject(new Point(x, y));
 89   
             }
 90   
 
 91   
             // Notify the application, by setting the select parameter
 92   
             // to the tag parameter.
 93   
 
 94  0
             IBinding selectedBinding = getBinding("selected");
 95   
 
 96  0
             if (selectedBinding != null)
 97  0
                 selectedBinding.setObject(getTag());
 98   
 
 99  0
             IActionListener listener = getListener();
 100   
 
 101  0
             if (listener != null)
 102  0
                 listener.actionTriggered(this, cycle);
 103   
 
 104  0
             return;
 105   
         }
 106   
 
 107   
         // Not rewinding, do the real render
 108   
 
 109  0
         boolean disabled = isDisabled();
 110  0
         IAsset disabledImage = getDisabledImage();
 111   
 
 112  0
         IAsset finalImage = (disabled && disabledImage != null) ? disabledImage : getImage();
 113   
 
 114  0
         String imageURL = finalImage.buildURL(cycle);
 115   
 
 116  0
         writer.beginEmpty("input");
 117  0
         writer.attribute("type", "image");
 118  0
         writer.attribute("name", name);
 119   
 
 120  0
         if (disabled)
 121  0
             writer.attribute("disabled", "disabled");
 122   
 
 123   
         // NN4 places a border unless you tell it otherwise.
 124   
         // IE ignores the border attribute and never shows a border.
 125   
 
 126  0
         writer.attribute("border", 0);
 127   
 
 128  0
         writer.attribute("src", imageURL);
 129   
 
 130  0
         renderInformalParameters(writer, cycle);
 131   
 
 132  0
         writer.closeTag();
 133   
     }
 134   
 
 135   
     public abstract boolean isDisabled();
 136   
 
 137   
     public abstract IAsset getDisabledImage();
 138   
 
 139   
     public abstract IAsset getImage();
 140   
 
 141   
     public abstract IActionListener getListener();
 142   
 
 143   
     public abstract Object getTag();
 144   
 
 145   
     public abstract String getNameOverride();
 146   
 
 147  0
     protected void prepareForRender(IRequestCycle cycle)
 148   
     {
 149  0
         super.prepareForRender(cycle);
 150   
 
 151  0
         if (getImage() == null)
 152  0
             throw Tapestry.createRequiredParameterException(this, "image");
 153   
     }
 154   
 
 155   
 }