KickJava   Java API By Example, From Geeks To Geeks.

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


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 import javax.faces.context.FacesContext;
37 import java.util.StringTokenizer JavaDoc;
38
39 /**
40  * Make HTML Elements draggable or droppable
41  * Makes the element drop (Move Down) and fade out at the same time.
42  */

43 public class DragDrop {
44
45
46     /**
47      * Make an HTML element draggable
48      * @param id
49      * @param handleId
50      * @param options
51      * @param mask
52      * @param facesContext
53      * @return
54      */

55     public static String JavaDoc addDragable(String JavaDoc id, String JavaDoc handleId, String JavaDoc options,
56                                      String JavaDoc mask,
57                                      FacesContext facesContext) {
58         boolean revert = false;
59         boolean ghosting = false;
60         boolean solid = false;
61         boolean dragGhost = false;
62         boolean pointerDraw = false;
63         if (options != null) {
64             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(options, ",");
65             while (st.hasMoreTokens()) {
66                 String JavaDoc token = st.nextToken();
67                 token = token.trim();
68                 if ("revert".equalsIgnoreCase(token)) {
69                     revert = true;
70                 } else if ("ghosting".equalsIgnoreCase(token)) {
71                     ghosting = true;
72                 }
73                 if ("solid".equalsIgnoreCase(token)) {
74                     solid = true;
75                 }
76                 if ("dragGhost".equalsIgnoreCase(token)) {
77                     dragGhost = true;
78                 }
79                 if ("pointerDraw".equalsIgnoreCase(token)) {
80                     pointerDraw = true;
81                 }
82             }
83         }
84         return addDragable(id, handleId, revert, ghosting, solid, dragGhost,
85                            pointerDraw, mask, facesContext);
86     }
87
88     /**
89      * make an HTML element draggable
90      * @param id
91      * @param handleId
92      * @param revert
93      * @param ghosting
94      * @param solid
95      * @param dragGhost
96      * @param pointerDraw
97      * @param mask
98      * @param facesContext
99      * @return
100      */

101     public static String JavaDoc addDragable(String JavaDoc id, String JavaDoc handleId, boolean revert,
102                                      boolean ghosting, boolean solid,
103                                      boolean dragGhost, boolean pointerDraw,
104                                      String JavaDoc mask, FacesContext facesContext) {
105
106         EffectsArguments ea = new EffectsArguments();
107         ea.add("handle", handleId);
108         ea.add("revert", revert);
109         ea.add("ghosting", ghosting);
110         ea.add("mask", mask);
111         ea.add("dragGhost", dragGhost);
112         ea.add("dragCursor", pointerDraw);
113         if (solid) {
114             //Setting start and end effect functions to blank to remove transparency while dragging.
115
ea.addFunction("starteffect", "function(){}");
116             ea.addFunction("endeffect", "function(){}");
117         }
118         String JavaDoc call = "new Draggable('" + id + "'" + ea.toString();
119
120         JavascriptContext.addJavascriptCall(facesContext, call);
121         return call;
122     }
123
124     /**
125      * Make an HTML element droppable
126      * @param id
127      * @param acceptClass
128      * @param facesContext
129      * @param mask
130      * @param hoverClass
131      * @return
132      */

133     public static String JavaDoc addDroptarget(String JavaDoc id, String JavaDoc acceptClass,
134                                        FacesContext facesContext, String JavaDoc mask,
135                                        String JavaDoc hoverClass) {
136         EffectsArguments ea = new EffectsArguments();
137         ea.add("accept", acceptClass);
138         ea.add("mask", mask);
139         ea.add("hoverclass", hoverClass);
140
141         String JavaDoc call = "Droppables.add('" + id + "'" + ea.toString();
142         JavascriptContext.addJavascriptCall(facesContext, call);
143         return call;
144     }
145 }
146
Popular Tags