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.context.effects;
035:
036: import javax.faces.context.FacesContext;
037: import java.util.StringTokenizer;
038:
039: /**
040: * Make HTML Elements draggable or droppable
041: * Makes the element drop (Move Down) and fade out at the same time.
042: */
043: public class DragDrop {
044:
045: /**
046: * Make an HTML element draggable
047: * @param id
048: * @param handleId
049: * @param options
050: * @param mask
051: * @param facesContext
052: * @return
053: */
054: public static String addDragable(String id, String handleId,
055: String options, String mask, FacesContext facesContext) {
056: boolean revert = false;
057: boolean ghosting = false;
058: boolean solid = false;
059: boolean dragGhost = false;
060: boolean pointerDraw = false;
061: if (options != null) {
062: StringTokenizer st = new StringTokenizer(options, ",");
063: while (st.hasMoreTokens()) {
064: String token = st.nextToken();
065: token = token.trim();
066: if ("revert".equalsIgnoreCase(token)) {
067: revert = true;
068: } else if ("ghosting".equalsIgnoreCase(token)) {
069: ghosting = true;
070: }
071: if ("solid".equalsIgnoreCase(token)) {
072: solid = true;
073: }
074: if ("dragGhost".equalsIgnoreCase(token)) {
075: dragGhost = true;
076: }
077: if ("pointerDraw".equalsIgnoreCase(token)) {
078: pointerDraw = true;
079: }
080: }
081: }
082: return addDragable(id, handleId, revert, ghosting, solid,
083: dragGhost, pointerDraw, mask, facesContext);
084: }
085:
086: /**
087: * make an HTML element draggable
088: * @param id
089: * @param handleId
090: * @param revert
091: * @param ghosting
092: * @param solid
093: * @param dragGhost
094: * @param pointerDraw
095: * @param mask
096: * @param facesContext
097: * @return
098: */
099: public static String addDragable(String id, String handleId,
100: boolean revert, boolean ghosting, boolean solid,
101: boolean dragGhost, boolean pointerDraw, String mask,
102: FacesContext facesContext) {
103:
104: EffectsArguments ea = new EffectsArguments();
105: ea.add("handle", handleId);
106: ea.add("revert", revert);
107: ea.add("ghosting", ghosting);
108: ea.add("mask", mask);
109: ea.add("dragGhost", dragGhost);
110: ea.add("dragCursor", pointerDraw);
111: if (solid) {
112: //Setting start and end effect functions to blank to remove transparency while dragging.
113: ea.addFunction("starteffect", "function(){}");
114: ea.addFunction("endeffect", "function(){}");
115: }
116: String call = "new Draggable('" + id + "'" + ea.toString();
117:
118: JavascriptContext.addJavascriptCall(facesContext, call);
119: return call;
120: }
121:
122: /**
123: * Make an HTML element droppable
124: * @param id
125: * @param acceptClass
126: * @param facesContext
127: * @param mask
128: * @param hoverClass
129: * @return
130: */
131: public static String addDroptarget(String id, String acceptClass,
132: FacesContext facesContext, String mask, String hoverClass) {
133: EffectsArguments ea = new EffectsArguments();
134: ea.add("accept", acceptClass);
135: ea.add("mask", mask);
136: ea.add("hoverclass", hoverClass);
137:
138: String call = "Droppables.add('" + id + "'" + ea.toString();
139: JavascriptContext.addJavascriptCall(facesContext, call);
140: return call;
141: }
142: }
|