|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
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 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| public abstract class ImageSubmit extends Submit |
|
36 |
| { |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
24
| protected void setName(IForm form)
|
|
41 |
| { |
|
42 |
24
| String nameOverride = getNameOverride();
|
|
43 |
| |
|
44 |
24
| setName((nameOverride == null) ? form.getElementId(this) : form.getElementId(this, nameOverride));
|
|
45 |
| } |
|
46 |
| |
|
47 |
9
| protected boolean isClicked(IRequestCycle cycle, String name)
|
|
48 |
| { |
|
49 |
9
| String parameterName = name + ".x";
|
|
50 |
| |
|
51 |
9
| return (cycle.getParameter(parameterName) != null);
|
|
52 |
| } |
|
53 |
| |
|
54 |
12
| protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
|
|
55 |
| { |
|
56 |
12
| boolean disabled = isDisabled();
|
|
57 |
12
| IAsset disabledImage = getDisabledImage();
|
|
58 |
| |
|
59 |
12
| IAsset finalImage = (disabled && disabledImage != null) ? disabledImage : getImage();
|
|
60 |
| |
|
61 |
12
| String imageURL = finalImage.buildURL();
|
|
62 |
| |
|
63 |
12
| writer.beginEmpty("input");
|
|
64 |
12
| writer.attribute("type", "image");
|
|
65 |
12
| writer.attribute("name", getName());
|
|
66 |
| |
|
67 |
12
| if (disabled)
|
|
68 |
6
| writer.attribute("disabled", "disabled");
|
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
12
| writer.attribute("border", 0);
|
|
74 |
| |
|
75 |
12
| writer.attribute("src", imageURL);
|
|
76 |
| |
|
77 |
12
| renderIdAttribute(writer, cycle);
|
|
78 |
| |
|
79 |
12
| renderInformalParameters(writer, cycle);
|
|
80 |
| |
|
81 |
12
| writer.closeTag();
|
|
82 |
| } |
|
83 |
| |
|
84 |
6
| void handleClick(IRequestCycle cycle, IForm form)
|
|
85 |
| { |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
6
| if (isParameterBound("point"))
|
|
93 |
| { |
|
94 |
3
| int x = Integer.parseInt(cycle.getParameter(getName() + ".x"));
|
|
95 |
3
| int y = Integer.parseInt(cycle.getParameter(getName() + ".y"));
|
|
96 |
| |
|
97 |
3
| setPoint(new Point(x, y));
|
|
98 |
| } |
|
99 |
| |
|
100 |
6
| 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 |
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 |
| } |