KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > component > ext > HtmlGraphicImage


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33
34 package com.icesoft.faces.component.ext;
35
36 import com.icesoft.faces.component.CSS_DEFAULT;
37 import com.icesoft.faces.component.ext.taglib.Util;
38 import com.icesoft.faces.context.effects.CurrentStyle;
39 import com.icesoft.faces.context.effects.Effect;
40 import com.icesoft.faces.context.effects.JavascriptContext;
41
42 import javax.faces.context.FacesContext;
43 import javax.faces.el.ValueBinding;
44
45 /**
46  * This is an extension of javax.faces.component.html.HtmlGraphicImage, which
47  * provides some additional behavior to this component such as: <ul> <li>changes
48  * the component's rendered state based on the authentication</li> <li>adds
49  * effects to the component</li> <ul>
50  */

51 public class HtmlGraphicImage
52         extends javax.faces.component.html.HtmlGraphicImage {
53     public static final String JavaDoc COMPONENT_TYPE =
54             "com.icesoft.faces.HtmlGraphicImage";
55     public static final String JavaDoc RENDERER_TYPE = "com.icesoft.faces.Image";
56
57     private static final boolean DEFAULT_VISIBLE = true;
58     private String JavaDoc renderedOnUserRole = null;
59     private Effect effect;
60     private Boolean JavaDoc visible = null;
61     private String JavaDoc styleClass = null;
62     private Effect onclickeffect;
63     private Effect ondblclickeffect;
64     private Effect onmousedowneffect;
65     private Effect onmouseupeffect;
66     private Effect onmousemoveeffect;
67     private Effect onmouseovereffect;
68     private Effect onmouseouteffect;
69     private Effect onkeypresseffect;
70     private Effect onkeydowneffect;
71     private Effect onkeyupeffect;
72     private CurrentStyle currentStyle;
73
74     public HtmlGraphicImage() {
75         super();
76         setRendererType(RENDERER_TYPE);
77     }
78
79     public void setValueBinding(String JavaDoc s, ValueBinding vb) {
80         if (s != null && s.indexOf("effect") != -1) {
81             // If this is an effect attribute make sure Ice Extras is included
82
JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
83                                          getFacesContext());
84         }
85         super.setValueBinding(s, vb);
86     }
87
88     /**
89      * <p>Set the value of the <code>effect</code> property.</p>
90      */

91     public void setEffect(Effect effect) {
92         JavascriptContext
93                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
94         this.effect = effect;
95     }
96
97     /**
98      * <p>Return the value of the <code>effect</code> property.</p>
99      */

100     public Effect getEffect() {
101         if (effect != null) {
102             return effect;
103         }
104         ValueBinding vb = getValueBinding("effect");
105         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
106     }
107
108     /**
109      * <p>Set the value of the <code>visible</code> property.</p>
110      */

111     public void setVisible(boolean visible) {
112         this.visible = Boolean.valueOf(visible);
113     }
114
115     /**
116      * <p>Return the value of the <code>visible</code> property.</p>
117      */

118     public boolean getVisible() {
119         if (visible != null) {
120             return visible.booleanValue();
121         }
122         ValueBinding vb = getValueBinding("visible");
123         Boolean JavaDoc boolVal =
124                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
125         return boolVal != null ? boolVal.booleanValue() : DEFAULT_VISIBLE;
126     }
127
128     /**
129      * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
130      */

131     public void setRenderedOnUserRole(String JavaDoc renderedOnUserRole) {
132         this.renderedOnUserRole = renderedOnUserRole;
133     }
134
135     /**
136      * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
137      */

138     public String JavaDoc getRenderedOnUserRole() {
139         if (renderedOnUserRole != null) {
140             return renderedOnUserRole;
141         }
142         ValueBinding vb = getValueBinding("renderedOnUserRole");
143         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
144     }
145
146     /**
147      * <p>Return the value of the <code>rendered</code> property.</p>
148      */

149     public boolean isRendered() {
150         if (!Util.isRenderedOnUserRole(this)) {
151             return false;
152         }
153         return super.isRendered();
154     }
155
156     /**
157      * <p>Return the value of the <code>onclickeffect</code> property.</p>
158      */

159     public Effect getOnclickeffect() {
160         if (onclickeffect != null) {
161             return onclickeffect;
162         }
163         ValueBinding vb = getValueBinding("onclickeffect");
164
165         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
166     }
167
168     /**
169      * <p>Set the value of the <code>onclickeffect</code> property.</p>
170      */

171     public void setOnclickeffect(Effect onclickeffect) {
172         JavascriptContext
173                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
174         this.onclickeffect = onclickeffect;
175     }
176
177     /**
178      * <p>Return the value of the <code>ondblclickeffect</code> property.</p>
179      */

180     public Effect getOndblclickeffect() {
181         if (ondblclickeffect != null) {
182             return ondblclickeffect;
183         }
184         ValueBinding vb = getValueBinding("ondblclickeffect");
185
186         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
187     }
188
189     /**
190      * <p>Set the value of the <code>ondblclickeffect</code> property.</p>
191      */

192     public void setOndblclickeffect(Effect ondblclickeffect) {
193         JavascriptContext
194                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
195         this.ondblclickeffect = ondblclickeffect;
196     }
197
198     /**
199      * <p>Return the value of the <code>onmousedowneffect</code> property.</p>
200      */

201     public Effect getOnmousedowneffect() {
202         if (onmousedowneffect != null) {
203             return onmousedowneffect;
204         }
205         ValueBinding vb = getValueBinding("onmousedowneffect");
206
207         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
208     }
209
210     /**
211      * <p>Set the value of the <code>onmousedowneffect</code> property.</p>
212      */

213     public void setOnmousedowneffect(Effect onmousedowneffect) {
214         JavascriptContext
215                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
216         this.onmousedowneffect = onmousedowneffect;
217     }
218
219     /**
220      * <p>Return the value of the <code>onmouseupeffect</code> property.</p>
221      */

222     public Effect getOnmouseupeffect() {
223         if (onmouseupeffect != null) {
224             return onmouseupeffect;
225         }
226         ValueBinding vb = getValueBinding("onmouseupeffect");
227
228         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
229     }
230
231     /**
232      * <p>Set the value of the <code>onmouseupeffect</code> property.</p>
233      */

234     public void setOnmouseupeffect(Effect onmouseupeffect) {
235         JavascriptContext
236                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
237         this.onmouseupeffect = onmouseupeffect;
238     }
239
240     /**
241      * <p>Return the value of the <code>onmousemoveeffect</code> property.</p>
242      */

243     public Effect getOnmousemoveeffect() {
244         if (onmousemoveeffect != null) {
245             return onmousemoveeffect;
246         }
247         ValueBinding vb = getValueBinding("onmousemoveeffect");
248
249         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
250     }
251
252     /**
253      * <p>Set the value of the <code>onmousemoveeffect</code> property.</p>
254      */

255     public void setOnmousemoveeffect(Effect onmousemoveeffect) {
256         JavascriptContext
257                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
258         this.onmousemoveeffect = onmousemoveeffect;
259     }
260
261     /**
262      * <p>Return the value of the <code>onmouseovereffect</code> property.</p>
263      */

264     public Effect getOnmouseovereffect() {
265         if (onmouseovereffect != null) {
266             return onmouseovereffect;
267         }
268         ValueBinding vb = getValueBinding("onmouseovereffect");
269
270         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
271     }
272
273     /**
274      * <p>Set the value of the <code>onmouseovereffect</code> property.</p>
275      */

276     public void setOnmouseovereffect(Effect onmouseovereffect) {
277         JavascriptContext
278                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
279         this.onmouseovereffect = onmouseovereffect;
280     }
281
282     /**
283      * <p>Return the value of the <code>onmouseouteffect</code> property.</p>
284      */

285     public Effect getOnmouseouteffect() {
286         if (onmouseouteffect != null) {
287             return onmouseouteffect;
288         }
289         ValueBinding vb = getValueBinding("onmouseouteffect");
290
291         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
292     }
293
294     /**
295      * <p>Set the value of the <code>onmouseouteffect</code> property.</p>
296      */

297     public void setOnmouseouteffect(Effect onmouseouteffect) {
298         JavascriptContext
299                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
300         this.onmouseouteffect = onmouseouteffect;
301     }
302
303     /**
304      * <p>Return the value of the <code>onkeypresseffect</code> property.</p>
305      */

306     public Effect getOnkeypresseffect() {
307         if (onkeypresseffect != null) {
308             return onkeypresseffect;
309         }
310         ValueBinding vb = getValueBinding("onkeypresseffect");
311
312         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
313     }
314
315     /**
316      * <p>Set the value of the <code>onkeypresseffect</code> property.</p>
317      */

318     public void setOnkeypresseffect(Effect onkeypresseffect) {
319         JavascriptContext
320                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
321         this.onkeypresseffect = onkeypresseffect;
322     }
323
324     /**
325      * <p>Return the value of the <code>onkeydowneffect</code> property.</p>
326      */

327     public Effect getOnkeydowneffect() {
328         if (onkeydowneffect != null) {
329             return onkeydowneffect;
330         }
331         ValueBinding vb = getValueBinding("onkeydowneffect");
332
333         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
334     }
335
336     /**
337      * <p>Set the value of the <code>onkeydowneffect</code> property.</p>
338      */

339     public void setOnkeydowneffect(Effect onkeydowneffect) {
340         JavascriptContext
341                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
342         this.onkeydowneffect = onkeydowneffect;
343     }
344
345     /**
346      * <p>Return the value of the <code>onkeyupeffect</code> property.</p>
347      */

348     public Effect getOnkeyupeffect() {
349         if (onkeyupeffect != null) {
350             return onkeyupeffect;
351         }
352         ValueBinding vb = getValueBinding("onkeyupeffect");
353
354         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
355     }
356
357     /**
358      * <p>Set the value of the <code>onkeyupeffect</code> property.</p>
359      */

360     public void setOnkeyupeffect(Effect onkeyupeffect) {
361         JavascriptContext
362                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
363         this.onkeyupeffect = onkeyupeffect;
364     }
365
366     /**
367      * <p>Return the value of the <code>currentStyle</code> property.</p>
368      */

369     public CurrentStyle getCurrentStyle() {
370         return currentStyle;
371     }
372
373     /**
374      * <p>Set the value of the <code>currentStyle</code> property.</p>
375      */

376     public void setCurrentStyle(CurrentStyle currentStyle) {
377         this.currentStyle = currentStyle;
378     }
379
380     /**
381      * <p>Set the value of the <code>styleClass</code> property.</p>
382      */

383     public void setStyleClass(String JavaDoc styleClass) {
384         this.styleClass = styleClass;
385     }
386
387     /**
388      * <p>Return the value of the <code>styleClass</code> property.</p>
389      */

390     public String JavaDoc getStyleClass() {
391         return Util.getQualifiedStyleClass(this,
392                 styleClass,
393                 CSS_DEFAULT.GRAPHIC_IMAGE_STYLE_CLASS,
394                 "styleClass");
395     }
396
397     /**
398      * <p>Gets the state of the instance as a <code>Serializable</code>
399      * Object.</p>
400      */

401     public Object JavaDoc saveState(FacesContext context) {
402         Object JavaDoc values[] = new Object JavaDoc[19];
403         values[0] = super.saveState(context);
404         values[1] = renderedOnUserRole;
405         values[2] = effect;
406         values[3] = onclickeffect;
407         values[4] = onclickeffect;
408         values[5] = ondblclickeffect;
409         values[6] = onmousedowneffect;
410         values[7] = onmouseupeffect;
411         values[8] = onmousemoveeffect;
412         values[9] = onmouseovereffect;
413         values[10] = onmouseouteffect;
414         values[14] = onkeypresseffect;
415         values[15] = onkeydowneffect;
416         values[16] = onkeyupeffect;
417         values[17] = currentStyle;
418         values[18] = visible;
419         return ((Object JavaDoc) (values));
420     }
421
422     /**
423      * <p>Perform any processing required to restore the state from the entries
424      * in the state Object.</p>
425      */

426     public void restoreState(FacesContext context, Object JavaDoc state) {
427         Object JavaDoc values[] = (Object JavaDoc[]) state;
428         super.restoreState(context, values[0]);
429         renderedOnUserRole = (String JavaDoc) values[1];
430         effect = (Effect) values[2];
431         onclickeffect = (Effect) values[4];
432         ondblclickeffect = (Effect) values[5];
433         onmousedowneffect = (Effect) values[6];
434         onmouseupeffect = (Effect) values[7];
435         onmousemoveeffect = (Effect) values[8];
436         onmouseovereffect = (Effect) values[9];
437         onmouseouteffect = (Effect) values[10];
438         onkeypresseffect = (Effect) values[14];
439         onkeydowneffect = (Effect) values[15];
440         onkeyupeffect = (Effect) values[16];
441         currentStyle = (CurrentStyle) values[17];
442         visible = (Boolean JavaDoc) values[18];
443     }
444 }
445
Popular Tags