001: /*
002: * Copyright 2005 Joe Walker
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.directwebremoting.proxy.scriptaculous;
017:
018: import java.util.Collection;
019:
020: import org.directwebremoting.ScriptBuffer;
021: import org.directwebremoting.ScriptSession;
022: import org.directwebremoting.proxy.ScriptProxy;
023:
024: /**
025: * A server side proxy the the Scriptaculous Effect class
026: * @author Joe Walker [joe at getahead dot ltd dot uk]
027: * @author Mitch Gorman
028: */
029: public class Effect extends ScriptProxy {
030: /**
031: * Http thread constructor, that affects no browsers.
032: * Calls to {@link Effect#addScriptSession(ScriptSession)} or to
033: * {@link Effect#addScriptSessions(Collection)} will be needed
034: */
035: public Effect() {
036: }
037:
038: /**
039: * Http thread constructor that alters a single browser
040: * @param scriptSession The browser to alter
041: */
042: public Effect(ScriptSession scriptSession) {
043: super (scriptSession);
044: }
045:
046: /**
047: * Http thread constructor that alters a number of browsers
048: * @param scriptSessions A collection of ScriptSessions that we should act on.
049: */
050: public Effect(Collection<ScriptSession> scriptSessions) {
051: super (scriptSessions);
052: }
053:
054: /**
055: * Call the script.aculo.us <code>Effect.fade()</code> function.
056: * @param elementId The element to effect
057: */
058: public void fade(String elementId) {
059: callEffect(elementId, "Fade");
060: }
061:
062: /**
063: * Call the script.aculo.us <code>Effect.appear()</code> function.
064: * @param elementId The element to effect
065: */
066: public void appear(String elementId) {
067: callEffect(elementId, "Appear");
068: }
069:
070: /**
071: * Call the script.aculo.us <code>Effect.puff()</code> function.
072: * @param elementId The element to effect
073: */
074: public void puff(String elementId) {
075: callEffect(elementId, "Puff");
076: }
077:
078: /**
079: * Call the script.aculo.us <code>Effect.blindUp()</code> function.
080: * @param elementId The element to effect
081: */
082: public void blindUp(String elementId) {
083: callEffect(elementId, "BlindUp");
084: }
085:
086: /**
087: * Call the script.aculo.us <code>Effect.blindDown()</code> function.
088: * @param elementId The element to effect
089: */
090: public void blindDown(String elementId) {
091: callEffect(elementId, "BlindDown");
092: }
093:
094: /**
095: * Call the script.aculo.us <code>Effect.switchOff()</code> function.
096: * @param elementId The element to effect
097: */
098: public void switchOff(String elementId) {
099: callEffect(elementId, "SwitchOff");
100: }
101:
102: /**
103: * Call the script.aculo.us <code>Effect.dropOut()</code> function.
104: * @param elementId The element to effect
105: */
106: public void dropOut(String elementId) {
107: callEffect(elementId, "DropOut");
108: }
109:
110: /**
111: * Call the script.aculo.us <code>Effect.shake()</code> function.
112: * @param elementId The element to effect
113: */
114: public void shake(String elementId) {
115: callEffect(elementId, "Shake");
116: }
117:
118: /**
119: * Call the script.aculo.us <code>Effect.slideDown()</code> function.
120: * @param elementId The element to effect
121: */
122: public void slideDown(String elementId) {
123: callEffect(elementId, "SlideDown");
124: }
125:
126: /**
127: * Call the script.aculo.us <code>Effect.slideUp()</code> function.
128: * @param elementId The element to effect
129: */
130: public void slideUp(String elementId) {
131: callEffect(elementId, "SlideUp");
132: }
133:
134: /**
135: * Call the script.aculo.us <code>Effect.squish()</code> function.
136: * @param elementId The element to effect
137: */
138: public void squish(String elementId) {
139: callEffect(elementId, "Squish");
140: }
141:
142: /**
143: * Call the script.aculo.us <code>Effect.grow()</code> function.
144: * @param elementId The element to effect
145: */
146: public void grow(String elementId) {
147: callEffect(elementId, "Grow");
148: }
149:
150: /**
151: * Call the script.aculo.us <code>Effect.shrink()</code> function.
152: * @param elementId The element to effect
153: */
154: public void shrink(String elementId) {
155: callEffect(elementId, "Shrink");
156: }
157:
158: /**
159: * Call the script.aculo.us <code>Effect.pulsate()</code> function.
160: * @param elementId The element to effect
161: */
162: public void pulsate(String elementId) {
163: callEffect(elementId, "Pulsate");
164: }
165:
166: /**
167: * Call the script.aculo.us <code>Effect.fold()</code> function.
168: * @param elementId The element to effect
169: */
170: public void fold(String elementId) {
171: callEffect(elementId, "Fold");
172: }
173:
174: /**
175: * Call the script.aculo.us <code>Effect.Highlight()</code> function.
176: * @param elementId The element to effect
177: */
178: public void highlight(String elementId) {
179: callEffect(elementId, "Highlight");
180: }
181:
182: /**
183: * Call the script.aculo.us <code>Effect.Highlight()</code> function.
184: * @param elementId The element to affect
185: * @param options A string containing options to pass to the fade effect, as specified at http://script.aculo.us/
186: */
187: public void highlight(String elementId, String options) {
188: callEffect(elementId, "Highlight", options);
189: }
190:
191: /**
192: * Call the script.aculo.us <code>Effect.Fade()</code> function.
193: * @param elementId The element to affect
194: * @param options A string containing options to pass to the fade effect, as specified at http://script.aculo.us/
195: */
196: public void fade(String elementId, String options) {
197: callEffect(elementId, "Fade", options);
198: }
199:
200: /**
201: * Call the script.aculo.us <code>Effect.Appear()</code> function.
202: * @param elementId The element to affect
203: * @param options A string containing options to pass to the appear effect, as specified at http://script.aculo.us/
204: */
205: public void appear(String elementId, String options) {
206: callEffect(elementId, "Appear", options);
207: }
208:
209: /**
210: * Call the script.aculo.us <code>Effect.Puff()</code> function.
211: * @param elementId The element to affect
212: * @param options A string containing options to pass to the puff effect, as specified at http://script.aculo.us/
213: */
214: public void puff(String elementId, String options) {
215: callEffect(elementId, "Puff", options);
216: }
217:
218: /**
219: * Call the script.aculo.us <code>Effect.BlindUp()</code> function.
220: * @param elementId The element to affect
221: * @param options A string containing options to pass to the blindup effect, as specified at http://script.aculo.us/
222: */
223: public void blindUp(String elementId, String options) {
224: callEffect(elementId, "BlindUp", options);
225: }
226:
227: /**
228: * Call the script.aculo.us <code>Effect.BlindDown()</code> function.
229: * @param elementId The element to affect
230: * @param options A string containing options to pass to the blinddown effect, as specified at http://script.aculo.us/
231: */
232: public void blindDown(String elementId, String options) {
233: callEffect(elementId, "BlindDown", options);
234: }
235:
236: /**
237: * Call the script.aculo.us <code>Effect.SwitchOff()</code> function.
238: * @param elementId The element to affect
239: * @param options A string containing options to pass to the switchf effect, as specified at http://script.aculo.us/
240: */
241: public void switchOff(String elementId, String options) {
242: callEffect(elementId, "SwitchOff", options);
243: }
244:
245: /**
246: * Call the script.aculo.us <code>Effect.DropOut()</code> function.
247: * @param elementId The element to affect
248: * @param options A string containing options to pass to the dropout effect, as specified at http://script.aculo.us/
249: */
250: public void dropOut(String elementId, String options) {
251: callEffect(elementId, "DropOut", options);
252: }
253:
254: /**
255: * Call the script.aculo.us <code>Effect.Shake()</code> function.
256: * @param elementId The element to affect
257: * @param options A string containing options to pass to the shake effect, as specified at http://script.aculo.us/
258: */
259: public void shake(String elementId, String options) {
260: callEffect(elementId, "Shake", options);
261: }
262:
263: /**
264: * Call the script.aculo.us <code>Effect.SlideDown()</code> function.
265: * @param elementId The element to affect
266: * @param options A string containing options to pass to the slidedown effect, as specified at http://script.aculo.us/
267: */
268: public void slideDown(String elementId, String options) {
269: callEffect(elementId, "SlideDown", options);
270: }
271:
272: /**
273: * Call the script.aculo.us <code>Effect.SlideUp()</code> function.
274: * @param elementId The element to affect
275: * @param options A string containing options to pass to the slideup effect, as specified at http://script.aculo.us/
276: */
277: public void slideUp(String elementId, String options) {
278: callEffect(elementId, "SlideUp", options);
279: }
280:
281: /**
282: * Call the script.aculo.us <code>Effect.Squish()</code> function.
283: * @param elementId The element to affect
284: * @param options A string containing options to pass to the squish effect, as specified at http://script.aculo.us/
285: */
286: public void squish(String elementId, String options) {
287: callEffect(elementId, "Squish", options);
288: }
289:
290: /**
291: * Call the script.aculo.us <code>Effect.Grow()</code> function.
292: * @param elementId The element to affect
293: * @param options A string containing options to pass to the grow effect, as specified at http://script.aculo.us/
294: */
295: public void grow(String elementId, String options) {
296: callEffect(elementId, "Grow", options);
297: }
298:
299: /**
300: * Call the script.aculo.us <code>Effect.Shrink()</code> function.
301: * @param elementId The element to affect
302: * @param options A string containing options to pass to the shrink effect, as specified at http://script.aculo.us/
303: */
304: public void shrink(String elementId, String options) {
305: callEffect(elementId, "Shrink", options);
306: }
307:
308: /**
309: * Call the script.aculo.us <code>Effect.Pulsate()</code> function.
310: * @param elementId The element to affect
311: * @param options A string containing options to pass to the pulsate effect, as specified at http://script.aculo.us/
312: */
313: public void pulsate(String elementId, String options) {
314: callEffect(elementId, "Pulsate", options);
315: }
316:
317: /**
318: * Call the script.aculo.us <code>Effect.Fold()</code> function.
319: * @param elementId The element to affect
320: * @param options A string containing options to pass to the fold effect, as specified at http://script.aculo.us/
321: */
322: public void fold(String elementId, String options) {
323: callEffect(elementId, "Fold", options);
324: }
325:
326: /**
327: * @param elementId The element to affect
328: * @param function The script.aculo.us effect to employ
329: */
330: private void callEffect(String elementId, String function) {
331: callEffect(elementId, function, null);
332: }
333:
334: /**
335: * @param elementId The element to affect
336: * @param function The script.aculo.us effect to employ
337: * @param options A string containing options to pass to the script.aculo.us effect, as specified at http://script.aculo.us/
338: */
339: private void callEffect(String elementId, String function,
340: String options) {
341: ScriptBuffer script = new ScriptBuffer();
342: script.appendScript("new Effect.").appendScript(function)
343: .appendScript("('").appendScript(elementId)
344: .appendScript("'");
345: if (options != null && options.length() > 0) {
346: script.appendScript(", ").appendScript(options);
347: }
348: script.appendScript(");");
349: addScript(script);
350: }
351: }
|