001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: package com.icesoft.faces.component.ext;
035:
036: import com.icesoft.faces.component.CSS_DEFAULT;
037: import com.icesoft.faces.component.ext.taglib.Util;
038: import com.icesoft.faces.context.effects.CurrentStyle;
039: import com.icesoft.faces.context.effects.Effect;
040: import com.icesoft.faces.context.effects.JavascriptContext;
041:
042: import javax.faces.context.FacesContext;
043: import javax.faces.el.ValueBinding;
044:
045: /**
046: * This is an extension of javax.faces.component.html.HtmlGraphicImage, which
047: * provides some additional behavior to this component such as: <ul> <li>changes
048: * the component's rendered state based on the authentication</li> <li>adds
049: * effects to the component</li> <ul>
050: */
051: public class HtmlGraphicImage extends
052: javax.faces.component.html.HtmlGraphicImage {
053: public static final String COMPONENT_TYPE = "com.icesoft.faces.HtmlGraphicImage";
054: public static final String RENDERER_TYPE = "com.icesoft.faces.Image";
055:
056: private static final boolean DEFAULT_VISIBLE = true;
057: private String renderedOnUserRole = null;
058: private Effect effect;
059: private Boolean visible = null;
060: private String styleClass = null;
061: private Effect onclickeffect;
062: private Effect ondblclickeffect;
063: private Effect onmousedowneffect;
064: private Effect onmouseupeffect;
065: private Effect onmousemoveeffect;
066: private Effect onmouseovereffect;
067: private Effect onmouseouteffect;
068: private Effect onkeypresseffect;
069: private Effect onkeydowneffect;
070: private Effect onkeyupeffect;
071: private CurrentStyle currentStyle;
072:
073: public HtmlGraphicImage() {
074: super ();
075: setRendererType(RENDERER_TYPE);
076: }
077:
078: public void setValueBinding(String s, ValueBinding vb) {
079: if (s != null && s.indexOf("effect") != -1) {
080: // If this is an effect attribute make sure Ice Extras is included
081: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
082: getFacesContext());
083: }
084: super .setValueBinding(s, vb);
085: }
086:
087: /**
088: * <p>Set the value of the <code>effect</code> property.</p>
089: */
090: public void setEffect(Effect effect) {
091: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
092: getFacesContext());
093: this .effect = effect;
094: }
095:
096: /**
097: * <p>Return the value of the <code>effect</code> property.</p>
098: */
099: public Effect getEffect() {
100: if (effect != null) {
101: return effect;
102: }
103: ValueBinding vb = getValueBinding("effect");
104: return vb != null ? (Effect) vb.getValue(getFacesContext())
105: : 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 boolVal = vb != null ? (Boolean) vb
124: .getValue(getFacesContext()) : null;
125: return boolVal != null ? boolVal.booleanValue()
126: : DEFAULT_VISIBLE;
127: }
128:
129: /**
130: * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
131: */
132: public void setRenderedOnUserRole(String renderedOnUserRole) {
133: this .renderedOnUserRole = renderedOnUserRole;
134: }
135:
136: /**
137: * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
138: */
139: public String getRenderedOnUserRole() {
140: if (renderedOnUserRole != null) {
141: return renderedOnUserRole;
142: }
143: ValueBinding vb = getValueBinding("renderedOnUserRole");
144: return vb != null ? (String) vb.getValue(getFacesContext())
145: : null;
146: }
147:
148: /**
149: * <p>Return the value of the <code>rendered</code> property.</p>
150: */
151: public boolean isRendered() {
152: if (!Util.isRenderedOnUserRole(this )) {
153: return false;
154: }
155: return super .isRendered();
156: }
157:
158: /**
159: * <p>Return the value of the <code>onclickeffect</code> property.</p>
160: */
161: public Effect getOnclickeffect() {
162: if (onclickeffect != null) {
163: return onclickeffect;
164: }
165: ValueBinding vb = getValueBinding("onclickeffect");
166:
167: return vb != null ? (Effect) vb.getValue(getFacesContext())
168: : null;
169: }
170:
171: /**
172: * <p>Set the value of the <code>onclickeffect</code> property.</p>
173: */
174: public void setOnclickeffect(Effect onclickeffect) {
175: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
176: getFacesContext());
177: this .onclickeffect = onclickeffect;
178: }
179:
180: /**
181: * <p>Return the value of the <code>ondblclickeffect</code> property.</p>
182: */
183: public Effect getOndblclickeffect() {
184: if (ondblclickeffect != null) {
185: return ondblclickeffect;
186: }
187: ValueBinding vb = getValueBinding("ondblclickeffect");
188:
189: return vb != null ? (Effect) vb.getValue(getFacesContext())
190: : null;
191: }
192:
193: /**
194: * <p>Set the value of the <code>ondblclickeffect</code> property.</p>
195: */
196: public void setOndblclickeffect(Effect ondblclickeffect) {
197: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
198: getFacesContext());
199: this .ondblclickeffect = ondblclickeffect;
200: }
201:
202: /**
203: * <p>Return the value of the <code>onmousedowneffect</code> property.</p>
204: */
205: public Effect getOnmousedowneffect() {
206: if (onmousedowneffect != null) {
207: return onmousedowneffect;
208: }
209: ValueBinding vb = getValueBinding("onmousedowneffect");
210:
211: return vb != null ? (Effect) vb.getValue(getFacesContext())
212: : null;
213: }
214:
215: /**
216: * <p>Set the value of the <code>onmousedowneffect</code> property.</p>
217: */
218: public void setOnmousedowneffect(Effect onmousedowneffect) {
219: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
220: getFacesContext());
221: this .onmousedowneffect = onmousedowneffect;
222: }
223:
224: /**
225: * <p>Return the value of the <code>onmouseupeffect</code> property.</p>
226: */
227: public Effect getOnmouseupeffect() {
228: if (onmouseupeffect != null) {
229: return onmouseupeffect;
230: }
231: ValueBinding vb = getValueBinding("onmouseupeffect");
232:
233: return vb != null ? (Effect) vb.getValue(getFacesContext())
234: : null;
235: }
236:
237: /**
238: * <p>Set the value of the <code>onmouseupeffect</code> property.</p>
239: */
240: public void setOnmouseupeffect(Effect onmouseupeffect) {
241: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
242: getFacesContext());
243: this .onmouseupeffect = onmouseupeffect;
244: }
245:
246: /**
247: * <p>Return the value of the <code>onmousemoveeffect</code> property.</p>
248: */
249: public Effect getOnmousemoveeffect() {
250: if (onmousemoveeffect != null) {
251: return onmousemoveeffect;
252: }
253: ValueBinding vb = getValueBinding("onmousemoveeffect");
254:
255: return vb != null ? (Effect) vb.getValue(getFacesContext())
256: : null;
257: }
258:
259: /**
260: * <p>Set the value of the <code>onmousemoveeffect</code> property.</p>
261: */
262: public void setOnmousemoveeffect(Effect onmousemoveeffect) {
263: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
264: getFacesContext());
265: this .onmousemoveeffect = onmousemoveeffect;
266: }
267:
268: /**
269: * <p>Return the value of the <code>onmouseovereffect</code> property.</p>
270: */
271: public Effect getOnmouseovereffect() {
272: if (onmouseovereffect != null) {
273: return onmouseovereffect;
274: }
275: ValueBinding vb = getValueBinding("onmouseovereffect");
276:
277: return vb != null ? (Effect) vb.getValue(getFacesContext())
278: : null;
279: }
280:
281: /**
282: * <p>Set the value of the <code>onmouseovereffect</code> property.</p>
283: */
284: public void setOnmouseovereffect(Effect onmouseovereffect) {
285: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
286: getFacesContext());
287: this .onmouseovereffect = onmouseovereffect;
288: }
289:
290: /**
291: * <p>Return the value of the <code>onmouseouteffect</code> property.</p>
292: */
293: public Effect getOnmouseouteffect() {
294: if (onmouseouteffect != null) {
295: return onmouseouteffect;
296: }
297: ValueBinding vb = getValueBinding("onmouseouteffect");
298:
299: return vb != null ? (Effect) vb.getValue(getFacesContext())
300: : null;
301: }
302:
303: /**
304: * <p>Set the value of the <code>onmouseouteffect</code> property.</p>
305: */
306: public void setOnmouseouteffect(Effect onmouseouteffect) {
307: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
308: getFacesContext());
309: this .onmouseouteffect = onmouseouteffect;
310: }
311:
312: /**
313: * <p>Return the value of the <code>onkeypresseffect</code> property.</p>
314: */
315: public Effect getOnkeypresseffect() {
316: if (onkeypresseffect != null) {
317: return onkeypresseffect;
318: }
319: ValueBinding vb = getValueBinding("onkeypresseffect");
320:
321: return vb != null ? (Effect) vb.getValue(getFacesContext())
322: : null;
323: }
324:
325: /**
326: * <p>Set the value of the <code>onkeypresseffect</code> property.</p>
327: */
328: public void setOnkeypresseffect(Effect onkeypresseffect) {
329: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
330: getFacesContext());
331: this .onkeypresseffect = onkeypresseffect;
332: }
333:
334: /**
335: * <p>Return the value of the <code>onkeydowneffect</code> property.</p>
336: */
337: public Effect getOnkeydowneffect() {
338: if (onkeydowneffect != null) {
339: return onkeydowneffect;
340: }
341: ValueBinding vb = getValueBinding("onkeydowneffect");
342:
343: return vb != null ? (Effect) vb.getValue(getFacesContext())
344: : null;
345: }
346:
347: /**
348: * <p>Set the value of the <code>onkeydowneffect</code> property.</p>
349: */
350: public void setOnkeydowneffect(Effect onkeydowneffect) {
351: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
352: getFacesContext());
353: this .onkeydowneffect = onkeydowneffect;
354: }
355:
356: /**
357: * <p>Return the value of the <code>onkeyupeffect</code> property.</p>
358: */
359: public Effect getOnkeyupeffect() {
360: if (onkeyupeffect != null) {
361: return onkeyupeffect;
362: }
363: ValueBinding vb = getValueBinding("onkeyupeffect");
364:
365: return vb != null ? (Effect) vb.getValue(getFacesContext())
366: : null;
367: }
368:
369: /**
370: * <p>Set the value of the <code>onkeyupeffect</code> property.</p>
371: */
372: public void setOnkeyupeffect(Effect onkeyupeffect) {
373: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
374: getFacesContext());
375: this .onkeyupeffect = onkeyupeffect;
376: }
377:
378: /**
379: * <p>Return the value of the <code>currentStyle</code> property.</p>
380: */
381: public CurrentStyle getCurrentStyle() {
382: return currentStyle;
383: }
384:
385: /**
386: * <p>Set the value of the <code>currentStyle</code> property.</p>
387: */
388: public void setCurrentStyle(CurrentStyle currentStyle) {
389: this .currentStyle = currentStyle;
390: }
391:
392: /**
393: * <p>Set the value of the <code>styleClass</code> property.</p>
394: */
395: public void setStyleClass(String styleClass) {
396: this .styleClass = styleClass;
397: }
398:
399: /**
400: * <p>Return the value of the <code>styleClass</code> property.</p>
401: */
402: public String getStyleClass() {
403: return Util.getQualifiedStyleClass(this , styleClass,
404: CSS_DEFAULT.GRAPHIC_IMAGE_STYLE_CLASS, "styleClass");
405: }
406:
407: /**
408: * <p>Gets the state of the instance as a <code>Serializable</code>
409: * Object.</p>
410: */
411: public Object saveState(FacesContext context) {
412: Object values[] = new Object[19];
413: values[0] = super .saveState(context);
414: values[1] = renderedOnUserRole;
415: values[2] = effect;
416: values[3] = onclickeffect;
417: values[4] = onclickeffect;
418: values[5] = ondblclickeffect;
419: values[6] = onmousedowneffect;
420: values[7] = onmouseupeffect;
421: values[8] = onmousemoveeffect;
422: values[9] = onmouseovereffect;
423: values[10] = onmouseouteffect;
424: values[14] = onkeypresseffect;
425: values[15] = onkeydowneffect;
426: values[16] = onkeyupeffect;
427: values[17] = currentStyle;
428: values[18] = visible;
429: return ((Object) (values));
430: }
431:
432: /**
433: * <p>Perform any processing required to restore the state from the entries
434: * in the state Object.</p>
435: */
436: public void restoreState(FacesContext context, Object state) {
437: Object values[] = (Object[]) state;
438: super .restoreState(context, values[0]);
439: renderedOnUserRole = (String) values[1];
440: effect = (Effect) values[2];
441: onclickeffect = (Effect) values[4];
442: ondblclickeffect = (Effect) values[5];
443: onmousedowneffect = (Effect) values[6];
444: onmouseupeffect = (Effect) values[7];
445: onmousemoveeffect = (Effect) values[8];
446: onmouseovereffect = (Effect) values[9];
447: onmouseouteffect = (Effect) values[10];
448: onkeypresseffect = (Effect) values[14];
449: onkeydowneffect = (Effect) values[15];
450: onkeyupeffect = (Effect) values[16];
451: currentStyle = (CurrentStyle) values[17];
452: visible = (Boolean) values[18];
453: }
454: }
|