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