1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
package org.apache.tapestry.html; |
16 |
|
|
17 |
|
import org.apache.hivemind.ApplicationRuntimeException; |
18 |
|
import org.apache.tapestry.*; |
19 |
|
import org.apache.tapestry.components.ILinkComponent; |
20 |
|
import org.apache.tapestry.form.IFormComponent; |
21 |
|
import org.apache.tapestry.form.LinkSubmit; |
22 |
|
|
23 |
|
import java.util.HashMap; |
24 |
|
import java.util.Map; |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
0 |
public abstract class Rollover extends AbstractComponent |
38 |
|
{ |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
protected String getAssetURL(IAsset asset) |
50 |
|
{ |
51 |
0 |
if (asset == null) |
52 |
0 |
return null; |
53 |
|
|
54 |
0 |
return asset.buildURL(); |
55 |
|
} |
56 |
|
|
57 |
|
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) |
58 |
|
{ |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
0 |
if (cycle.isRewinding()) |
63 |
0 |
return; |
64 |
|
|
65 |
0 |
String imageURL = null; |
66 |
0 |
String mouseOverURL = null; |
67 |
0 |
String mouseOutURL = null; |
68 |
0 |
boolean dynamic = false; |
69 |
|
String imageId; |
70 |
0 |
boolean linkDisabled = false; |
71 |
|
|
72 |
0 |
PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, this); |
73 |
|
|
74 |
0 |
Object serviceLink = cycle.getAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME); |
75 |
0 |
if (serviceLink == null) |
76 |
|
{ |
77 |
0 |
serviceLink = cycle.getAttribute(LinkSubmit.ATTRIBUTE_NAME); |
78 |
|
|
79 |
0 |
if (serviceLink != null) |
80 |
0 |
linkDisabled = ((IFormComponent) serviceLink).isDisabled(); |
81 |
|
} else |
82 |
|
{ |
83 |
0 |
linkDisabled = ((ILinkComponent) serviceLink).isDisabled(); |
84 |
|
} |
85 |
|
|
86 |
0 |
if (serviceLink == null) |
87 |
0 |
throw new ApplicationRuntimeException(Tapestry.getMessage("Rollover.must-be-contained-by-link"), this, null, null); |
88 |
|
|
89 |
0 |
if (linkDisabled) |
90 |
|
{ |
91 |
0 |
imageURL = getAssetURL(getDisabled()); |
92 |
|
|
93 |
0 |
if (imageURL == null) |
94 |
0 |
imageURL = getAssetURL(getImage()); |
95 |
|
} |
96 |
|
else |
97 |
|
{ |
98 |
0 |
imageURL = getAssetURL(getImage()); |
99 |
0 |
mouseOverURL = getAssetURL(getMouseOver()); |
100 |
0 |
mouseOutURL = getAssetURL(getMouseOut()); |
101 |
|
|
102 |
0 |
dynamic = (mouseOverURL != null) || (mouseOutURL != null); |
103 |
|
} |
104 |
|
|
105 |
0 |
if (imageURL == null) |
106 |
0 |
throw Tapestry.createRequiredParameterException(this, "image"); |
107 |
|
|
108 |
0 |
writer.beginEmpty("img"); |
109 |
|
|
110 |
0 |
writer.attribute("src", imageURL); |
111 |
|
|
112 |
0 |
if (dynamic) |
113 |
|
{ |
114 |
0 |
if (mouseOverURL == null) |
115 |
0 |
mouseOverURL = imageURL; |
116 |
|
|
117 |
0 |
if (mouseOutURL == null) |
118 |
0 |
mouseOutURL = imageURL; |
119 |
|
|
120 |
0 |
imageId = writeScript(cycle, pageRenderSupport, serviceLink, mouseOverURL, mouseOutURL); |
121 |
|
|
122 |
0 |
writer.attribute("id", imageId); |
123 |
|
} |
124 |
|
|
125 |
0 |
renderInformalParameters(writer, cycle); |
126 |
|
|
127 |
0 |
writer.closeTag(); |
128 |
|
|
129 |
0 |
} |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
public abstract IScript getScript(); |
134 |
|
|
135 |
|
private String writeScript(IRequestCycle cycle, PageRenderSupport pageRenderSupport, |
136 |
|
Object link, String mouseOverImageURL, String mouseOutImageURL) |
137 |
|
{ |
138 |
0 |
String imageId = pageRenderSupport.getUniqueString(getId()); |
139 |
|
|
140 |
0 |
String preloadedMouseOverImageURL = pageRenderSupport.getPreloadedImageReference(this, mouseOverImageURL); |
141 |
0 |
String preloadedMouseOutImageURL = pageRenderSupport.getPreloadedImageReference(this, mouseOutImageURL); |
142 |
|
|
143 |
0 |
Map symbols = new HashMap(); |
144 |
|
|
145 |
0 |
symbols.put("link", link); |
146 |
0 |
symbols.put("imageId", imageId); |
147 |
0 |
symbols.put("mouseOverImageURL", preloadedMouseOverImageURL); |
148 |
0 |
symbols.put("mouseOutImageURL", preloadedMouseOutImageURL); |
149 |
|
|
150 |
0 |
getScript().execute(this, cycle, pageRenderSupport, symbols); |
151 |
|
|
152 |
0 |
return imageId; |
153 |
|
} |
154 |
|
|
155 |
|
public abstract IAsset getMouseOut(); |
156 |
|
|
157 |
|
public abstract IAsset getDisabled(); |
158 |
|
|
159 |
|
public abstract IAsset getMouseOver(); |
160 |
|
|
161 |
|
public abstract IAsset getImage(); |
162 |
|
} |