1 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 34 35 public abstract class ImageSubmit extends Submit 36 { 37 40 protected void setName(IForm form) 41 { 42 String nameOverride = getNameOverride(); 43 44 setName((nameOverride == null) ? form.getElementId(this) : form.getElementId(this, nameOverride)); 45 } 46 47 protected boolean isClicked(IRequestCycle cycle, String name) 48 { 49 String parameterName = name + ".x"; 50 51 return (cycle.getParameter(parameterName) != null); 52 } 53 54 protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle) 55 { 56 boolean disabled = isDisabled(); 57 IAsset disabledImage = getDisabledImage(); 58 59 IAsset finalImage = (disabled && disabledImage != null) ? disabledImage : getImage(); 60 61 String imageURL = finalImage.buildURL(cycle); 62 63 writer.beginEmpty("input"); 64 writer.attribute("type", "image"); 65 writer.attribute("name", getName()); 66 67 if (disabled) 68 writer.attribute("disabled", "disabled"); 69 70 73 writer.attribute("border", 0); 74 75 writer.attribute("src", imageURL); 76 77 renderIdAttribute(writer, cycle); 78 79 renderInformalParameters(writer, cycle); 80 81 writer.closeTag(); 82 } 83 84 void handleClick(IRequestCycle cycle, IForm form) 85 { 86 92 if (isParameterBound("point")) 93 { 94 int x = Integer.parseInt(cycle.getParameter(getName() + ".x")); 95 int y = Integer.parseInt(cycle.getParameter(getName() + ".y")); 96 97 setPoint(new Point (x, y)); 98 } 99 100 super.handleClick(cycle, form); 101 } 102 103 104 public abstract IAsset getDisabledImage(); 105 106 107 public abstract IAsset getImage(); 108 109 110 public abstract String getNameOverride(); 111 112 113 public abstract void setPoint(Point point); 114 115 protected void prepareForRender(IRequestCycle cycle) 116 { 117 super.prepareForRender(cycle); 118 119 if (getImage() == null) 120 throw Tapestry.createRequiredParameterException(this, "image"); 121 } 122 } | Popular Tags |