myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From we...@apache.org
Subject svn commit: r292786 - in /myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/effect: EffectRenderer.java EffectTag.java
Date Fri, 30 Sep 2005 15:50:48 GMT
Author: werpu
Date: Fri Sep 30 08:50:44 2005
New Revision: 292786

URL: http://svn.apache.org/viewcvs?rev=292786&view=rev
Log: (empty)

Added:
    myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/effect/EffectRenderer.java
    myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/effect/EffectTag.java

Added: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/effect/EffectRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/effect/EffectRenderer.java?rev=292786&view=auto
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/effect/EffectRenderer.java (added)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/effect/EffectRenderer.java Fri
Sep 30 08:50:44 2005
@@ -0,0 +1,243 @@
+/*
+ * Copyright 2002,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.myfaces.custom.effect;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.apache.myfaces.component.html.util.AddResource;
+import org.apache.myfaces.custom.div.Div;
+import org.apache.myfaces.custom.prototype.PrototypeResourceLoader;
+import org.apache.myfaces.renderkit.JSFAttr;
+import org.apache.myfaces.renderkit.RendererUtils;
+import org.apache.myfaces.renderkit.html.HTML;
+import org.apache.myfaces.renderkit.html.HtmlRenderer;
+import org.apache.myfaces.renderkit.html.HtmlRendererUtils;
+
+/**
+ * For the fade, we only need a simple renderer and a backend javascript
+ * inclusion so that we can serve it out of the jar
+ *
+ * @author Werner Punz werpu@gmx.at
+ */
+/**
+ * Fade field only currently the renderer is implemented and the tag, because we
+ * do not store any extra functionality over a simple div in here
+ *
+ * @author Werner Punz werpu@gmx.at
+ * @version $Revision:  $ $Date: $
+ */
+public class EffectRenderer extends HtmlRenderer {
+
+	private static final String	JAVASCRIPT_ENCODED	= "org.apache.myfaces.inputsuggestajax.JAVASCRIPT_ENCODED";
+
+	/**
+	 * Encodes any stand-alone javascript functions that are needed. Uses either
+	 * the extension filter, or a user-supplied location for the javascript
+	 * files.
+	 *
+	 * @param context
+	 *            FacesContext
+	 * @param component
+	 *            UIComponent
+	 * @throws java.io.IOException
+	 */
+	private void encodeJavascript(FacesContext context, UIComponent component) throws IOException
{
+		// check to see if javascript has already been written (which could
+		// happen if more than one tree on the same page)
+		if (context.getExternalContext().getRequestMap().containsKey(JAVASCRIPT_ENCODED)) {
+			return;
+		}
+
+		// render javascript function for client-side toggle (it won't be used
+		// if user has opted for server-side toggle)
+		ResponseWriter out = context.getResponseWriter();
+		String javascriptLocation = (String) component.getAttributes().get(JSFAttr.JAVASCRIPT_LOCATION);
+		if (javascriptLocation == null) {
+			AddResource.addJavaScriptToHeader(PrototypeResourceLoader.class, "prototype.js", context);
+			AddResource.addJavaScriptToHeader(PrototypeResourceLoader.class, "effects.js", context);
+			AddResource.addJavaScriptToHeader(EffectRenderer.class, "fat.js", context);
+
+
+		} else {
+			out.startElement(HTML.SCRIPT_ELEM, null);
+			out.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
+			out.writeAttribute(HTML.SRC_ATTR, javascriptLocation + "/prototype.js", null);
+			out.endElement(HTML.SCRIPT_ELEM);
+
+			out.startElement(HTML.SCRIPT_ELEM, null);
+			out.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
+			out.writeAttribute(HTML.SRC_ATTR, javascriptLocation + "/effects.js", null);
+			out.endElement(HTML.SCRIPT_ELEM);
+
+			out.startElement(HTML.SCRIPT_ELEM, null);
+			out.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
+			out.writeAttribute(HTML.SRC_ATTR, javascriptLocation + "/dragdrop.js", null);
+			out.endElement(HTML.SCRIPT_ELEM);
+
+			out.startElement(HTML.SCRIPT_ELEM, null);
+			out.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
+			out.writeAttribute(HTML.SRC_ATTR, javascriptLocation + "/controls.js", null);
+			out.endElement(HTML.SCRIPT_ELEM);
+
+		}
+
+		context.getExternalContext().getRequestMap().put(JAVASCRIPT_ENCODED, Boolean.TRUE);
+	}
+
+	public boolean getRendersChildren() {
+		return true;
+	}
+
+	public static final String	RENDERER_TYPE	= "script.aculo.us.renderer";
+
+	/**
+	 * We only need an encodeBeing method because the fade control, does not
+	 * have any childs
+	 *
+	 * The fading is done via a styleClass tag according to the FAT specs, for
+	 * now this is more flexible than embedding yet another tag in another tag
+	 * but less flexible for styleClass usage reasons (but you always can use
+	 * x:div for handling this issue in a proper manner)
+	 *
+	 * we have to do a full overload unfortunately because it is altered
+	 * severely
+	 *
+	 */
+	public void encodeBegin(FacesContext context, UIComponent component) throws IOException
{
+		if ((context == null) || (component == null)) {
+			throw new NullPointerException();
+		}
+
+		Boolean rendered = (Boolean) component.getAttributes().get("rendered");
+
+		if ((rendered != null) && (!rendered.booleanValue()))
+			return;
+		encodeJavascript(context, component);
+		super.encodeBegin(context, component);
+		prepareFade(component);
+		renderEffectsBegin(context, component);
+	}
+
+	/**
+	 * prepares the styleClasses for the fading renderer
+	 *
+	 * @param component
+	 */
+	private void prepareFade(UIComponent component) {
+		Div theComponent = (Div) component;
+		Boolean fade = (Boolean) component.getAttributes().get(EffectTag.TAG_PARAM_FADE);
+
+		String theStyleClass = theComponent.getStyleClass();
+		if (theStyleClass == null)
+			theStyleClass = "";
+		if (fade != null && fade.booleanValue() && !(theStyleClass.indexOf("fade")
!= -1)) {
+
+			if (theStyleClass != null && !theStyleClass.trim().equalsIgnoreCase(""))
+				theStyleClass += ";fade";
+			else
+				theStyleClass = "fade";
+
+			String fadeColor = (String) component.getAttributes().get(EffectTag.TAG_PARAM_FADECOLOR);
+
+			fadeColor = (fadeColor != null) ? fadeColor : "";
+			fadeColor = fadeColor.replaceAll("#", "");
+			if (fadeColor.length() != 0)
+				fadeColor = "-" + fadeColor;
+
+			theStyleClass += fadeColor;
+			theComponent.setStyleClass(theStyleClass);
+		}
+	}
+
+	public void renderEffectsBegin(FacesContext context, UIComponent component) throws IOException
{
+
+		// dump all the parameters which affect us into we dont set a central
+		// unchecked here to keep the warning level high
+		Boolean squish 		= (Boolean) component.getAttributes().get(EffectTag.TAG_PARAM_SQUISH);
+		Boolean puff 		= (Boolean) component.getAttributes().get(EffectTag.TAG_PARAM_PUFF);
+		Boolean scale 		= (Boolean) component.getAttributes().get(EffectTag.TAG_PARAM_SCALE);
+		Boolean pulsate 	= (Boolean) component.getAttributes().get(EffectTag.TAG_PARAM_PULSATE);
+		Integer scaleSize 	= (Integer) component.getAttributes().get(EffectTag.TAG_PARAM_SCALE_SIZE);
+
+		Div div = (Div) component;
+		ResponseWriter writer = context.getResponseWriter();
+
+		// if(fade != null && fade.booleanValue())
+		// ScriptController.renderScriptWithDeps(context, component, writer,
+		// ScriptController.FAT_VIEW_ID);
+
+		writer.startElement(HTML.DIV_ELEM, component);
+		HtmlRendererUtils.writeIdIfNecessary(writer, component, context);
+
+		String styleClass = div.getStyleClass();
+		String style = div.getStyle();
+		if (null != styleClass && null != style) {
+			throw new IllegalStateException("Only one of style or styleClass can be specified");
+		}
+		if (null != styleClass) {
+			writer.writeAttribute(HTML.CLASS_ATTR, styleClass, null);
+		}
+		if (null != style) {
+			writer.writeAttribute(HTML.STYLE_ATTR, style, null);
+		}
+		// todo check the existing code for already existent javascript code
+		// not needed now, but probably in the long run
+
+		if (puff != null && puff.booleanValue()) {
+			writer.writeAttribute(HTML.ONCLICK_ATTR, "javascript:new Effect.Puff(this);", null);
+		}
+		if (squish != null && squish.booleanValue()) {
+			writer.writeAttribute(HTML.ONCLICK_ATTR, "javascript:new Effect.Squish(this);", null);
+		}
+		if(pulsate != null && pulsate.booleanValue()) {
+			writer.writeAttribute(HTML.ONCLICK_ATTR, "javascript:new Effect.Pulsate(this);", null);
+		}
+		if (scale != null && scale.booleanValue()) {
+			writer.writeAttribute(HTML.ONMOUSEOVER_ATTR, "javascript:new Effect.Scale(this," + scaleSize.toString()
+ ");", null);
+			writer.writeAttribute(HTML.ONMOUSEOUT_ATTR, "javascript:new Effect.Scale(this,100);",
null);
+		}
+
+	}
+
+	/*
+	 * (non-Javadoc)
+	 *
+	 * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext,
+	 *      javax.faces.component.UIComponent)
+	 */
+	public void encodeChildren(FacesContext facesContext, UIComponent uiComponent) throws IOException
{
+
+		RendererUtils.renderChildren(facesContext, uiComponent);
+		HtmlRendererUtils.writePrettyLineSeparator(facesContext);
+	}
+
+	/**
+	 * Standard encode end
+	 *
+	 */
+	public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException
{
+		ResponseWriter writer = facesContext.getResponseWriter();
+		writer.endElement(HTML.DIV_ELEM);
+		HtmlRendererUtils.writePrettyLineSeparator(facesContext);
+		super.encodeEnd(facesContext, component);
+	}
+
+}

Added: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/effect/EffectTag.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/effect/EffectTag.java?rev=292786&view=auto
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/effect/EffectTag.java (added)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/effect/EffectTag.java Fri Sep
30 08:50:44 2005
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.custom.effect;
+
+import javax.faces.component.UIComponent;
+
+import org.apache.myfaces.custom.div.DivTag;
+
+/**
+ * The tag for the fade, it wont have any attributes just a plain tag, which
+ * does the inclusion of the fader
+ *
+ * 6/10/2005 The fade now is altered into a general effects tag which will work
+ * like that
+ *
+ * <x:effects squish="true" fade="true" fadeColor="#afafaf">content</x:effects>
+ * <x:effects fade="true"/>
+ *
+ * @author Werner Punz
+ * @version $Revision:  $ $Date: $
+ */
+
+public class EffectTag extends DivTag {
+
+	public static final String	TAG_PARAM_FADECOLOR		= "fadeColor";
+
+	public static final String	TAG_PARAM_FADE			= "fade";
+
+	public static final String	TAG_PARAM_SQUISH		= "squish";
+
+	public static final String	TAG_PARAM_SCALE			= "scale";
+
+	public static final String	TAG_PARAM_SCALE_SIZE	= "scaleSize";
+
+	public static final String	TAG_PARAM_PUFF			= "puff";
+
+	public static final String  TAG_PARAM_PULSATE 		= "pulsate";
+
+	/**
+	 * only one param, to keep it as simple as possible it will hover out at
+	 * 100% and the default hover in is 150% there is no real need for a
+	 * different hover out than 100% that I can see for now but feel free to add
+	 * one if you need it
+	 */
+
+	String						_fadeColor				= "";
+
+	String						_fade					= "false";
+
+	String						_puff					= "false";
+
+	String						_scale					= "false";
+
+	String						_scaleSize				= "150";
+
+	String						_squish					= "false";
+
+	String 						_pulsate				= "false";
+
+	protected void setProperties(UIComponent component) {
+		super.setProperties(component);
+		super.setStringProperty(component, TAG_PARAM_FADECOLOR, _fadeColor);
+		super.setIntegerProperty(component, TAG_PARAM_SCALE_SIZE, _scaleSize);
+		super.setBooleanProperty(component, TAG_PARAM_FADE, _fade);
+
+
+		super.setBooleanProperty(component, TAG_PARAM_PUFF, _puff);
+		super.setBooleanProperty(component, TAG_PARAM_SCALE, _scale);
+		super.setBooleanProperty(component, TAG_PARAM_SQUISH, _squish);
+		super.setBooleanProperty(component, TAG_PARAM_PULSATE, _pulsate);
+	}
+
+	/**
+	 * release method
+	 */
+	public void release() {
+		super.release();
+		_fadeColor = null;
+		_fade = null;
+		_puff = null;
+		_scale = null;
+		_squish = null;
+		_scaleSize = null;
+		_pulsate = null;
+	}
+
+	public String getComponentType() {
+		return super.getComponentType();
+	}
+
+	public String getRendererType() {
+		return EffectRenderer.RENDERER_TYPE;
+	}
+
+	/**
+	 * Setter for the fade color now in place
+	 *
+	 * @param fadeColor
+	 */
+	public void setFadeColor(String fadeColor) {
+		_fadeColor = fadeColor;
+	}
+
+	/**
+	 * enable the fading effect
+	 *
+	 * @param fade
+	 */
+	public void setFade(String fade) {
+		_fade = fade;
+	}
+
+	/**
+	 * enable the scaleing effect
+	 *
+	 * @param incoming
+	 */
+	public void setscale(String incoming) {
+		_scale = incoming;
+	}
+
+	/**
+	 * enable the puffing effect
+	 *
+	 * @param puff
+	 */
+	public void setPuff(String puff) {
+		_puff = puff;
+	}
+
+	/**
+	 * enable the squishing effect
+	 *
+	 * @param sqish
+	 */
+	public void setSquish(String sqish) {
+		_squish = sqish;
+	}
+
+	/**
+	 * Scale size for the hover out adjustment of the scale effect
+	 *
+	 * @param size
+	 */
+	public void setScaleSize(String size) {
+		_scaleSize = size;
+	}
+
+	public void setPulsate(String pulsate) {
+		_pulsate = pulsate;
+	}
+}



Mime
View raw message