KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > tags > databinding > datagrid > ImageCell


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.tags.databinding.datagrid;
19
20 import javax.servlet.jsp.JspException JavaDoc;
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22
23 import org.apache.beehive.netui.databinding.datagrid.api.rendering.CellModel;
24 import org.apache.beehive.netui.databinding.datagrid.runtime.model.cell.ImageCellModel;
25 import org.apache.beehive.netui.databinding.datagrid.runtime.rendering.cell.ImageCellDecorator;
26 import org.apache.beehive.netui.databinding.datagrid.runtime.util.JspUtil;
27 import org.apache.beehive.netui.tags.rendering.AbstractHtmlState;
28 import org.apache.beehive.netui.tags.rendering.AbstractRenderAppender;
29 import org.apache.beehive.netui.tags.rendering.ImageTag;
30 import org.apache.beehive.netui.tags.html.HtmlConstants;
31 import org.apache.beehive.netui.tags.IHtmlEvents;
32 import org.apache.beehive.netui.tags.IHtmlCore;
33 import org.apache.beehive.netui.tags.IHtmlI18n;
34
35 /**
36  * <p>
37  * Data grid cell that renders an HTML &lt;image&gt; tag containing the tag's <code>source</code> attribute. The
38  * span cell is rendered inside of an HTML table &lt;td&gt;. The image cell supports various nested tags including
39  * those that augment the available attribute set via the NetUI {@link org.apache.beehive.netui.tags.IAttributeConsumer}
40  * interface.
41  * </p>
42  * <p>
43  * The set of JSP implicit objects available to the body include:
44  * <ul>
45  * <li><code>dataGridModel</code> -- the {@link org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel}
46  * for the cell's containing data grid.</li>
47  * <li><code>container</code> -- the {@link org.apache.beehive.netui.script.common.IDataAccessProvider} instance
48  * that exposes the current data item and the current item's index</li>
49  * </ul>
50  * </p>
51  *
52  * @jsptagref.tagdescription
53  * <p>
54  * Data grid cell that renders an HTML &lt;image&gt; tag containing the tag's <code>source</code> attribute. The
55  * span cell is rendered inside of an HTML table &lt;td&gt;. The image cell supports various nested tags including
56  * those that augment the available attribute set via the NetUI {@link org.apache.beehive.netui.tags.IAttributeConsumer}
57  * interface.
58  * </p>
59  * <p>
60  * The set of JSP implicit objects available to the body include:
61  * <ul>
62  * <li><code>dataGridModel</code> -- the {@link org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel}
63  * for the cell's containing data grid.</li>
64  * <li><code>container</code> -- the {@link org.apache.beehive.netui.script.common.IDataAccessProvider} instance
65  * that exposes the current data item and the current item's index</li>
66  * </ul>
67  * </p>
68  * @netui:tag name="imageCell" body-content="scriptless"
69  * description="Data grid cell tag that renders an HTML img inside of an HTML table cell."
70  */

71 public class ImageCell
72     extends AbstractHtmlTableCell
73     implements IHtmlCore, IHtmlEvents, IHtmlI18n {
74
75     private static final ImageCellDecorator DECORATOR = new ImageCellDecorator();
76     private static final String JavaDoc IMAGE_FACET_NAME = "image";
77
78     private ImageCellModel _imageCellModel = new ImageCellModel();
79     private ImageTag.State _imageState = _imageCellModel.getImageState();
80
81     /**
82      * The name of this tag; this value is used for error reporting.
83      * @return the String name of this tag
84      */

85     public String JavaDoc getTagName() {
86         return "ImageCell";
87     }
88
89     /**
90      * Sets the onClick JavaScript event on the image tag.
91      *
92      * @param onClick the onClick event.
93      * @jsptagref.attributedescription The onClick JavaScript event on the image tag.
94      * @jsptagref.attributesyntaxvalue <i>string_onClick</i>
95      * @netui:attribute required="false" rtexprvalue="true" description="The onClick JavaScript event on the image tag."
96      */

97     public void setOnClick(String JavaDoc onClick) {
98         _imageState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONCLICK, onClick);
99     }
100
101     /**
102      * Sets the onDblClick JavaScript event on the image tag.
103      *
104      * @param onDblClick the onDblClick event.
105      * @jsptagref.attributedescription The onDblClick JavaScript event on the image tag.
106      * @jsptagref.attributesyntaxvalue <i>string_onDblClick</i>
107      * @netui:attribute required="false" rtexprvalue="true" description="The onDblClick JavaScript event on the image tag."
108      */

109     public void setOnDblClick(String JavaDoc onDblClick) {
110         _imageState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONDBLCLICK, onDblClick);
111     }
112
113     /**
114      * Sets the onKeyDown JavaScript event on the image tag.
115      *
116      * @param onKeyDown the onKeyDown event.
117      * @jsptagref.attributedescription The onKeyDown JavaScript event on the image tag.
118      * @jsptagref.attributesyntaxvalue <i>string_onKeyDown</i>
119      * @netui:attribute required="false" rtexprvalue="true" description="The onKeyDown JavaScript event on the image tag."
120      */

121     public void setOnKeyDown(String JavaDoc onKeyDown) {
122         _imageState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYDOWN, onKeyDown);
123     }
124
125     /**
126      * Sets the onKeyUp JavaScript event on the image tag.
127      *
128      * @param onKeyUp the onKeyUp event.
129      * @jsptagref.attributedescription The onKeyUp JavaScript event on the image tag.
130      * @jsptagref.attributesyntaxvalue <i>string_onKeyUp</i>
131      * @netui:attribute required="false" rtexprvalue="true" description="The onKeyUp JavaScript event on the image tag."
132      */

133     public void setOnKeyUp(String JavaDoc onKeyUp) {
134         _imageState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYUP, onKeyUp);
135     }
136
137     /**
138      * Sets the onKeyPress JavaScript event on the image tag.
139      *
140      * @param onKeyPress the onKeyPress event.
141      * @jsptagref.attributedescription The onKeyPress JavaScript event on the image tag.
142      * @jsptagref.attributesyntaxvalue <i>string_onKeyPress</i>
143      * @netui:attribute required="false" rtexprvalue="true" description="The onKeyPress JavaScript event on the image tag."
144      */

145     public void setOnKeyPress(String JavaDoc onKeyPress) {
146         _imageState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYPRESS, onKeyPress);
147     }
148
149     /**
150      * Sets the onMouseDown JavaScript event on the image tag.
151      *
152      * @param onMouseDown the onMouseDown event.
153      * @jsptagref.attributedescription The onMouseDown JavaScript event on the image tag.
154      * @jsptagref.attributesyntaxvalue <i>string_onMouseDown</i>
155      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseDown JavaScript event on the image tag."
156      */

157     public void setOnMouseDown(String JavaDoc onMouseDown) {
158         _imageState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEDOWN, onMouseDown);
159     }
160
161     /**
162      * Sets the onMouseUp JavaScript event on the image tag.
163      *
164      * @param onMouseUp the onMouseUp event.
165      * @jsptagref.attributedescription The onMouseUp JavaScript event on the image tag.
166      * @jsptagref.attributesyntaxvalue <i>string_onMouseUp</i>
167      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseUp JavaScript event on the image tag."
168      */

169     public void setOnMouseUp(String JavaDoc onMouseUp) {
170         _imageState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEUP, onMouseUp);
171     }
172
173     /**
174      * Sets the onMouseMove JavaScript event on the image tag.
175      *
176      * @param onMouseMove the onMouseMove event.
177      * @jsptagref.attributedescription The onMouseMove JavaScript event on the image tag.
178      * @jsptagref.attributesyntaxvalue <i>string_onMouseMove</i>
179      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseMove JavaScript event on the image tag."
180      */

181     public void setOnMouseMove(String JavaDoc onMouseMove) {
182         _imageState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEMOVE, onMouseMove);
183     }
184
185     /**
186      * Sets the onMouseOut JavaScript event on the image tag.
187      *
188      * @param onMouseOut the onMouseOut event.
189      * @jsptagref.attributedescription The onMouseOut JavaScript event on the image tag.
190      * @jsptagref.attributesyntaxvalue <i>string_onMouseOut</i>
191      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseOut JavaScript event on the image tag."
192      */

193     public void setOnMouseOut(String JavaDoc onMouseOut) {
194         _imageState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEOUT, onMouseOut);
195     }
196
197     /**
198      * Sets the onMouseOver JavaScript event on the image tag.
199      *
200      * @param onMouseOver the onMouseOver event.
201      * @jsptagref.attributedescription The onMouseOver JavaScript event on the image tag.
202      * @jsptagref.attributesyntaxvalue <i>string_onMouseOver</i>
203      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseOver JavaScript event on the image tag."
204      */

205     public void setOnMouseOver(String JavaDoc onMouseOver) {
206         _imageState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEOVER, onMouseOver);
207     }
208
209     /**
210      * Sets the style of the rendered html tag.
211      *
212      * @param style the html style.
213      * @jsptagref.attributedescription The style.
214      * @jsptagref.attributesyntaxvalue <i>string_style</i>
215      * @netui:attribute required="false" rtexprvalue="true" description="The style."
216      */

217     public void setStyle(String JavaDoc style) {
218         if("".equals(style)) return;
219
220         _imageState.style = style;
221     }
222
223     /**
224      * Sets the style class of the rendered html tag.
225      *
226      * @param styleClass the html style class.
227      * @jsptagref.attributedescription The style class.
228      * @jsptagref.attributesyntaxvalue <i>string_style_class</i>
229      * @netui:attribute required="false" rtexprvalue="true" description="The style class."
230      */

231     public void setStyleClass(String JavaDoc styleClass) {
232         if("".equals(styleClass)) return;
233
234         _imageState.styleClass = styleClass;
235     }
236
237     /**
238      * Sets the value of the title attribute.
239      *
240      * @param title
241      * @jsptagref.attributedescription The title.
242      * @jsptagref.attributesyntaxvalue <i>string_title</i>
243      * @netui:attribute required="false" rtexprvalue="true" description="The title. "
244      */

245     public void setTitle(String JavaDoc title) {
246         _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.TITLE, title);
247     }
248
249     /**
250      * Sets the lang attribute for the HTML element.
251      * @param lang
252      * @jsptagref.attributedescription The lang.
253      * @jsptagref.attributesyntaxvalue <i>string_lang</i>
254      * @netui:attribute required="false" rtexprvalue="true"
255      * description="The lang."
256      */

257     public void setLang(String JavaDoc lang)
258     {
259         _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.LANG, lang);
260     }
261
262     /**
263      * Sets the dir attribute for the HTML image tag.
264      * @param dir
265      * @jsptagref.attributedescription The dir for the image tag.
266      * @jsptagref.attributesyntaxvalue <i>string_dir</i>
267      * @netui:attribute required="false" rtexprvalue="true" description="The dir attribhte on the image tag."
268      */

269     public void setDir(String JavaDoc dir)
270     {
271         _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.DIR, dir);
272     }
273
274     /**
275      * Set the image source to render on the HTML image tag.
276      *
277      * @jsptagref.attributedescription The source of the image to display.
278      * @jsptagref.attributesyntaxvalue <i>literal_or_expression_src</i>
279      * @netui:attribute required="true" rtexprvalue="true" description="The image source to render on the HTML image tag"
280      */

281     public void setSrc(String JavaDoc src) {
282         _imageState.src = src;
283     }
284
285     /**
286      * Sets the property to specify where to align the image.
287      *
288      * @param align the image alignment.
289      * @jsptagref.attributedescription The alignment of the image.
290      * @jsptagref.attributesyntaxvalue <i>string_align</i>
291      * @netui:attribute required="false" rtexprvalue="true" description="The alignment of the image."
292      */

293     public void setAlign(String JavaDoc align) {
294         _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.ALIGN, align);
295     }
296
297     /**
298      * Sets the the horizontal spacing around the image.
299      *
300      * @param hspace the horizontal spacing.
301      * @jsptagref.attributedescription The horizontal spacing around the image.
302      * @jsptagref.attributesyntaxvalue <i>integer_hspace</i>
303      * @netui:attribute required="false" rtexprvalue="true" description="The horizontal spacing around the image."
304      */

305     public void setHspace(String JavaDoc hspace) {
306         _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.HSPACE, hspace);
307     }
308
309     /**
310      * Set the vertical spacing around the image.
311      *
312      * @jsptagref.attributedescription The width of the border around the image.
313      * @jsptagref.attributesyntaxvalue <i>integer_border</i>
314      * @netui:attribute required="false" rtexprvalue="true" description="The vertical spacing around the image"
315      */

316     public void setVspace(String JavaDoc vspace) {
317         _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.VSPACE, vspace);
318     }
319
320     /**
321      * Set the border attribute for the image.
322      *
323      * @jsptagref.attributedescription The border attribute of the image.
324      * @jsptagref.attributesyntaxvalue <i>height</i>
325      * @netui:attribute required="false" rtexprvalue="true" description="The border attribute for the image"
326      */

327     public void setBorder(String JavaDoc border) {
328         _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.BORDER, border);
329     }
330
331     /**
332      * Set the height of the image to display.
333      *
334      * @jsptagref.attributedescription The height of the image to be displayed.
335      * @jsptagref.attributesyntaxvalue <i>integer_height</i>
336      * @netui:attribute required="false" rtexprvalue="true" description="The height attribute for the image."
337      */

338     public void setHeight(String JavaDoc height) {
339         _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.HEIGHT, height);
340     }
341
342     /**
343      * Set the width of the image to display.
344      *
345      * @jsptagref.attributedescription The width of the image to be displayed.
346      * @jsptagref.attributesyntaxvalue <i>width</i>
347      * @netui:attribute required="false" rtexprvalue="true" description="The width attribute for the image"
348      */

349     public void setWidth(String JavaDoc width) {
350         _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.WIDTH, width);
351     }
352
353     /**
354      * Sets the property to specify the longdesc of the image tag.
355      *
356      * @param longdesc the longdesc attribute
357      * @jsptagref.attributedescription The alternative text of the image tag
358      * @jsptagref.attributesyntaxvalue <i>string_longdesc</i>
359      * @netui:attribute required="false" rtexprvalue="true" description="The longdesc of the image tag."
360      */

361     public void setLongdesc(String JavaDoc longdesc) {
362         _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.LONGDESC, longdesc);
363     }
364
365     /**
366      * Sets the property to specify the alt text of the image tag.
367      *
368      * @param alt the image alignment.
369      * @jsptagref.attributedescription The alternative text of the image tag
370      * @jsptagref.attributesyntaxvalue <i>string_alt</i>
371      * @netui:attribute required="false" rtexprvalue="true" description="The alternative text for the image tag."
372      */

373     public void setAlt(String JavaDoc alt) {
374         _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.ALT, alt);
375     }
376
377     /**
378      * Set the name of the tagId for the image tag.
379      *
380      * @param tagId the the name of the tagId for the image tag.
381      * @jsptagref.attributedescription The tagId.
382      * @jsptagref.attributesyntaxvalue <i>string_tagId</i>
383      * @netui:attribute required="false" rtexprvalue="true"
384      * description="String value. Sets the id (or name) attribute of the rendered HTML image tag."
385      */

386     public void setTagId(String JavaDoc tagId)
387         throws JspException JavaDoc {
388         applyIndexedTagId(_imageState, tagId);
389     }
390
391     /**
392      * <p>
393      * Implementation of {@link org.apache.beehive.netui.tags.IAttributeConsumer} interface. This
394      * allows a page author to add additional attributes to the HTML rendered by this tag. The attribute
395      * facets which can be consumed include:
396      * <ul>
397      * <li><code>image</code> -- attributes set using this facet will be rendered as HTML attributes on the
398      * rendered HTML &lt;image&gt; tag.</li>
399      * </ul>
400      * </p>
401      * <p>
402      * This tag also accepts facets supported by {@link AbstractHtmlTableCell#setAttribute(String, String, String)}
403      * </p>
404      *
405      * @param name the name of the attribute
406      * @param value the value of the attribute
407      * @param facet the facet for the attribute; this value must be match one of the facets supported by the JSP tags
408      * @throws JspException thrown when the given facet String is not recognized as a valid facet name
409      */

410     public void setAttribute(String JavaDoc name, String JavaDoc value, String JavaDoc facet)
411             throws JspException JavaDoc {
412         if(facet == null || facet.equals(IMAGE_FACET_NAME))
413             super.addStateAttribute(_imageState, name, value);
414         else
415             super.setAttribute(name, value, facet);
416     }
417
418     /**
419      * Render the cell's contents. This method implements support for executing the image cell's decorator.
420      *
421      * @param appender the {@link AbstractRenderAppender} used to collect the rendered output
422      * @param jspFragmentOutput the String result of having evaluated the image cell's {@link javax.servlet.jsp.tagext.JspFragment}
423      */

424     protected void renderDataCellContents(AbstractRenderAppender appender, String JavaDoc jspFragmentOutput) {
425         /* render any JavaScript needed to support framework features */
426         if (_imageState.id != null) {
427             HttpServletRequest JavaDoc request = JspUtil.getRequest(getJspContext());
428             String JavaDoc script = renderNameAndId(request, _imageState, null);
429             _imageCellModel.setJavascript(script);
430         }
431
432         DECORATOR.decorate(getJspContext(), appender, _imageCellModel);
433     }
434
435     /**
436      * Implementation of {@link AbstractHtmlTableCell#internalGetCellModel()} that exposes the
437      * {@link org.apache.beehive.netui.databinding.datagrid.runtime.model.cell.ImageCellModel}
438      * which is storing state for this tag.
439      * @return this tag's image cell model
440      */

441     protected CellModel internalGetCellModel() {
442         return _imageCellModel;
443     }
444 }
445
Popular Tags