KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > context > effects > Effect


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.context.effects;
35
36 /**
37  * Base class for all javascript effects
38  */

39 public abstract class Effect {
40
41
42     protected EffectsArguments ea = new EffectsArguments();
43     private boolean queued;
44     private boolean queueEnd;
45     private boolean fired;
46     private boolean transitory = true;
47     private float duration;
48     private float fps; // Max 25fps
49
private float from;
50     private float to;
51     private boolean sync;
52     private float delay;
53     private String JavaDoc queue;
54     private boolean submit;
55     private String JavaDoc id;
56     private String JavaDoc sequence;
57     private int sequenceId;
58
59
60     /**
61      * Transitory effects return a component to its original state. This flag is
62      * used to stop javascript from performing a partial submit at the end of an
63      * effect.
64      * <p/>
65      * Example highlight.
66      *
67      * @return
68      */

69     public boolean isTransitory() {
70         return transitory;
71     }
72
73     /**
74      * Transitory effects do not alter the display state. (Example: pulsate, shake)
75      * However other effects change css style properties, and in some cases
76      * the application needs to be aware of these changes. (For refreshing a page for example)
77      *
78      * When css changes need to be sent to the application you need to set the transitory
79      * property to false. The framework will then populate a hidden field with the new style
80      * information. Ready to be sent on the next submit.
81      *
82      * However, if you need to send the new style information immediately you need to set the submit attribute
83      * to true as well. This will fire a partial submit at the end of the effect.
84      *
85      *
86      * Default is true
87      *
88      * @param transitory true to not populate the css style changes, false to populate css style changes
89      */

90     public void setTransitory(boolean transitory) {
91         this.transitory = transitory;
92     }
93
94     /**
95      * @return
96      * @deprecated
97      */

98     public boolean isQueued() {
99         return queued;
100     }
101
102     /**
103      * @param queued
104      * @deprecated
105      */

106     public void setQueued(boolean queued) {
107         this.queued = queued;
108     }
109
110     /**
111      * @return
112      * @deprecated
113      */

114     public boolean isQueueEnd() {
115         return queueEnd;
116     }
117
118     /**
119      * @param queueEnd
120      * @deprecated
121      */

122     public void setQueueEnd(boolean queueEnd) {
123         this.queueEnd = queueEnd;
124     }
125
126     /**
127      * Has this effect been fired. ONly effects that have not been fired are
128      * sent to the browser
129      *
130      * @return
131      */

132     public boolean isFired() {
133         return fired;
134     }
135
136     /**
137      * Set if this effect has been fired. When this flag is set to false
138      * the effect will be sent to the browser on the next render pass.
139      *
140      * After being fired Icefaces will set this flag to true. To resend this
141      * effect set the flag to false.
142      *
143      * @param fired
144      */

145     public void setFired(boolean fired) {
146         this.fired = fired;
147     }
148
149     /**
150      * Get the duration of the effect (In seconds)
151      *
152      * @return
153      */

154     public float getDuration() {
155         return duration;
156     }
157
158     /**
159      * Set the duration of the effect (In seconds)
160      *
161      * @param duration
162      */

163     public void setDuration(float duration) {
164         this.duration = duration;
165         ea.add("duration", duration);
166     }
167
168     /**
169      * Get the frames per second of this effect
170      *
171      * @return
172      */

173     public float getFps() {
174         return fps;
175     }
176
177     /**
178      * Set the frames per second of this effect. max is 25
179      *
180      * @param fps
181      */

182     public void setFps(float fps) {
183         if (fps > 25f) {
184             throw new IllegalArgumentException JavaDoc("FPS max is 25");
185         }
186         this.fps = fps;
187         ea.add("fps", fps);
188     }
189
190     /**
191      * Gets the starting point of the transition, a float between 0.0 and 1.0.
192      * Defaults to 0.0.
193      *
194      * @return
195      */

196     public float getFrom() {
197         return from;
198     }
199
200     /**
201      * Sets the starting point of the transition, a float between 0.0 and 1.0.
202      * Defaults to 0.0.
203      *
204      * @param from
205      */

206     public void setFrom(float from) {
207         this.from = from;
208         ea.add("from", from);
209     }
210
211     /**
212      * Gets the end point of the transition, a float between 0.0 and 1.0.
213      * Defaults to 1.0.
214      *
215      * @return
216      */

217     public float getTo() {
218         return to;
219     }
220
221     /**
222      * Sets the end point of the transition, a float between 0.0 and 1.0.
223      * Defaults to 1.0.
224      *
225      * @param to
226      */

227     public void setTo(float to) {
228         this.to = to;
229         ea.add("to", to);
230     }
231
232     /**
233      * Gets whether the effect should render new frames automatically (which it
234      * does by default). If true, you can render frames manually by calling the
235      * render() instance method of an effect. This is used by
236      * Effect.Parallel().
237      *
238      * @return
239      */

240     public boolean isSync() {
241         return sync;
242     }
243
244     /**
245      * Sets whether the effect should render new frames automatically (which it
246      * does by default). If true, you can render frames manually by calling the
247      * render() instance method of an effect. This is used by
248      * Effect.Parallel().
249      *
250      * @param sync
251      */

252     public void setSync(boolean sync) {
253         this.sync = sync;
254         ea.add("sync", sync);
255     }
256
257
258     /**
259      * Gets the delay before invoking the effect
260      *
261      * @return
262      */

263     public float getDelay() {
264         return delay;
265     }
266
267     /**
268      * Sets the delay before invoking the effect
269      *
270      * @param delay
271      */

272     public void setDelay(float delay) {
273         this.delay = delay;
274         ea.add("delay", delay);
275     }
276
277     /**
278      * Gets queuing options. When used with a string, can be 'front' or 'end' to
279      * queue the effect in the global effects queue at the beginning or end, or
280      * a queue parameter object that can have {position:'front/end',
281      * scope:'scope', limit:1}
282      *
283      * @return
284      */

285     public String JavaDoc getQueue() {
286         return queue;
287     }
288
289     /**
290      * Sets queuing options. When used with a string, can be 'front' or 'end' to
291      * queue the effect in the global effects queue at the beginning or end, or
292      * a queue parameter object that can have {position:'front/end',
293      * scope:'scope', limit:1}
294      *
295      * @param queue
296      */

297     public void setQueue(String JavaDoc queue) {
298         this.queue = queue;
299         ea.add("queue", queue);
300     }
301
302     /**
303      * Gets is this effect should fire partial submit when finished
304      *
305      * @return
306      */

307     public boolean isSubmit() {
308         return submit;
309     }
310
311     /**
312      * Sets is this effect should fire partial submit when finished.
313      * Transitory also needs to be set to true.
314      *
315      * default is false
316      *
317      * @param submit
318      */

319     public void setSubmit(boolean submit) {
320         this.submit = submit;
321         ea.add("submit", submit);
322     }
323
324
325     /**
326      * get the name of the Function call to invoke the effect
327      *
328      * @return
329      */

330     public abstract String JavaDoc getFunctionName();
331
332
333     public String JavaDoc toString(String JavaDoc var, String JavaDoc lastCall) {
334         if (queued) {
335             ea.add("queue", "front");
336         }
337         if (queueEnd) {
338             ea.add("queue", "end");
339         }
340         if (!transitory) {
341             ea.add("uploadCSS", "true");
342         }
343         if (lastCall != null) {
344             ea.addFunction("iceFinish", "function(){" + lastCall + "}");
345         }
346         return getFunctionName() + "(" + var + ea.toString();
347     }
348
349     public String JavaDoc toString() {
350         return toString("id", null);
351     }
352
353     /**
354      * Get the HTML ID of the element t
355      *
356      * @return
357      */

358     public String JavaDoc getId() {
359         return id;
360     }
361
362     /**
363      * Set the HTML ID of the element t
364      *
365      * @param id
366      */

367     public void setId(String JavaDoc id) {
368         this.id = id;
369     }
370
371
372     /**
373      * Get the name of the sequence this effect is in
374      *
375      * @return
376      */

377     public String JavaDoc getSequence() {
378         return sequence;
379     }
380
381     /**
382      * Set the name of the sequence this effect is in.
383      *
384      * @param sequence
385      */

386     public void setSequence(String JavaDoc sequence) {
387         this.sequence = sequence;
388     }
389
390     /**
391      * Get the ID or position of this effect in a sequence
392      *
393      * @return
394      */

395     public int getSequenceId() {
396         return sequenceId;
397     }
398
399     /**
400      * Set the ID or position of this effect in a sequence
401      *
402      * @param sequenceId
403      */

404     public void setSequenceId(int sequenceId) {
405         this.sequenceId = sequenceId;
406     }
407
408     public void setOptions(String JavaDoc options){
409         ea.setOptions(options);
410     }
411
412     public int hashCode() {
413         return getIntfromString(toString());
414     }
415
416     public int getIntfromString(String JavaDoc s) {
417         int r = 0;
418         char[] ca = s.toCharArray();
419         for (int i = 0; i < ca.length; i++) {
420             r += (int) ca[i];
421         }
422         return r;
423     }
424
425 }
426
Popular Tags