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.hivemind.Resource; |
22 |
| import org.apache.tapestry.AbstractComponent; |
23 |
| import org.apache.tapestry.IAsset; |
24 |
| import org.apache.tapestry.IEngine; |
25 |
| import org.apache.tapestry.IMarkupWriter; |
26 |
| import org.apache.tapestry.IRequestCycle; |
27 |
| import org.apache.tapestry.IScript; |
28 |
| import org.apache.tapestry.PageRenderSupport; |
29 |
| import org.apache.tapestry.Tapestry; |
30 |
| import org.apache.tapestry.TapestryUtils; |
31 |
| import org.apache.tapestry.components.ILinkComponent; |
32 |
| import org.apache.tapestry.components.LinkEventType; |
33 |
| import org.apache.tapestry.engine.IScriptSource; |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| public abstract class Rollover extends AbstractComponent |
45 |
| { |
46 |
| private IScript _parsedScript; |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
0
| protected String getAssetURL(IAsset asset, IRequestCycle cycle)
|
54 |
| { |
55 |
0
| if (asset == null)
|
56 |
0
| return null;
|
57 |
| |
58 |
0
| return asset.buildURL(cycle);
|
59 |
| } |
60 |
| |
61 |
0
| protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
|
62 |
| { |
63 |
| |
64 |
| |
65 |
| |
66 |
0
| if (cycle.isRewinding())
|
67 |
0
| return;
|
68 |
| |
69 |
0
| String imageURL = null;
|
70 |
0
| String focusURL = null;
|
71 |
0
| String blurURL = null;
|
72 |
0
| boolean dynamic = false;
|
73 |
0
| String imageName = null;
|
74 |
| |
75 |
0
| PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, this);
|
76 |
| |
77 |
0
| ILinkComponent serviceLink = (ILinkComponent) cycle
|
78 |
| .getAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME); |
79 |
| |
80 |
0
| if (serviceLink == null)
|
81 |
0
| throw new ApplicationRuntimeException(Tapestry
|
82 |
| .getMessage("Rollover.must-be-contained-by-link"), this, null, null); |
83 |
| |
84 |
0
| boolean linkDisabled = serviceLink.isDisabled();
|
85 |
| |
86 |
0
| if (linkDisabled)
|
87 |
| { |
88 |
0
| imageURL = getAssetURL(getDisabled(), cycle);
|
89 |
| |
90 |
0
| if (imageURL == null)
|
91 |
0
| imageURL = getAssetURL(getImage(), cycle);
|
92 |
| } |
93 |
| else |
94 |
| { |
95 |
0
| imageURL = getAssetURL(getImage(), cycle);
|
96 |
0
| focusURL = getAssetURL(getFocus(), cycle);
|
97 |
0
| blurURL = getAssetURL(getBlur(), cycle);
|
98 |
| |
99 |
0
| dynamic = (focusURL != null) || (blurURL != null);
|
100 |
| } |
101 |
| |
102 |
0
| if (imageURL == null)
|
103 |
0
| throw Tapestry.createRequiredParameterException(this, "image");
|
104 |
| |
105 |
0
| writer.beginEmpty("img");
|
106 |
| |
107 |
0
| writer.attribute("src", imageURL);
|
108 |
| |
109 |
0
| writer.attribute("border", 0);
|
110 |
| |
111 |
0
| if (dynamic)
|
112 |
| { |
113 |
0
| if (focusURL == null)
|
114 |
0
| focusURL = imageURL;
|
115 |
| |
116 |
0
| if (blurURL == null)
|
117 |
0
| blurURL = imageURL;
|
118 |
| |
119 |
0
| imageName = writeScript(cycle, pageRenderSupport, serviceLink, focusURL, blurURL);
|
120 |
| |
121 |
0
| writer.attribute("name", imageName);
|
122 |
| } |
123 |
| |
124 |
0
| renderInformalParameters(writer, cycle);
|
125 |
| |
126 |
0
| writer.closeTag();
|
127 |
| |
128 |
| } |
129 |
| |
130 |
0
| private IScript getParsedScript()
|
131 |
| { |
132 |
0
| if (_parsedScript == null)
|
133 |
| { |
134 |
0
| IEngine engine = getPage().getEngine();
|
135 |
0
| IScriptSource source = engine.getScriptSource();
|
136 |
| |
137 |
0
| Resource scriptLocation = getSpecification().getSpecificationLocation()
|
138 |
| .getRelativeResource("Rollover.script"); |
139 |
| |
140 |
0
| _parsedScript = source.getScript(scriptLocation);
|
141 |
| } |
142 |
| |
143 |
0
| return _parsedScript;
|
144 |
| } |
145 |
| |
146 |
0
| private String writeScript(IRequestCycle cycle, PageRenderSupport pageRenderSupport,
|
147 |
| ILinkComponent link, String focusURL, String blurURL) |
148 |
| { |
149 |
0
| String imageName = pageRenderSupport.getUniqueString(getId());
|
150 |
0
| String focusImageURL = pageRenderSupport.getPreloadedImageReference(focusURL);
|
151 |
0
| String blurImageURL = pageRenderSupport.getPreloadedImageReference(blurURL);
|
152 |
| |
153 |
0
| Map symbols = new HashMap();
|
154 |
| |
155 |
0
| symbols.put("imageName", imageName);
|
156 |
0
| symbols.put("focusImageURL", focusImageURL);
|
157 |
0
| symbols.put("blurImageURL", blurImageURL);
|
158 |
| |
159 |
0
| getParsedScript().execute(cycle, pageRenderSupport, symbols);
|
160 |
| |
161 |
| |
162 |
| |
163 |
| |
164 |
| |
165 |
| |
166 |
0
| link.addEventHandler(LinkEventType.MOUSE_OVER, (String) symbols.get("onMouseOverName"));
|
167 |
0
| link.addEventHandler(LinkEventType.MOUSE_OUT, (String) symbols.get("onMouseOutName"));
|
168 |
| |
169 |
0
| return imageName;
|
170 |
| } |
171 |
| |
172 |
| public abstract IAsset getBlur(); |
173 |
| |
174 |
| public abstract IAsset getDisabled(); |
175 |
| |
176 |
| public abstract IAsset getFocus(); |
177 |
| |
178 |
| public abstract IAsset getImage(); |
179 |
| } |