001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/jsf/widgets/src/java/org/theospi/jsf/renderer/ScrollableAreaRenderer.java $
003: * $Id: ScrollableAreaRenderer.java 10835 2006-06-17 03:25:03Z lance@indiana.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.theospi.jsf.renderer;
021:
022: import java.io.IOException;
023:
024: import javax.faces.component.UIComponent;
025: import javax.faces.component.UIOutput;
026: import javax.faces.context.FacesContext;
027: import javax.faces.context.ResponseWriter;
028: import javax.faces.render.Renderer;
029:
030: import org.sakaiproject.jsf.util.RendererUtil;
031:
032: /**
033: * This class renders a scrollable area. It does this by
034: * making a div and then making it "auto" overflow which places
035: * scroll bars at the right and/or bottom. If the content is
036: * small enough to fit into the div then no scroll bars are rendered.
037: * <br><br>
038: * There must be a height defined in this tag or by a surrounding tag.
039: * If there is not then there must be a parent tag that has a height defined.
040: * If there is not either, then the div will resize the height to
041: * the total size of the content thus making this tag moot.
042: *
043: * @author andersjb
044: *
045: */
046: public class ScrollableAreaRenderer extends Renderer {
047: public static final String SCROLL_VISIBLE = "visible";
048: public static final String SCROLL_SCROLL = "scroll";
049: public static final String SCROLL_HIDDEN = "hidden";
050: public static final String SCROLL_AUTO = "auto";
051:
052: public boolean supportsComponentType(UIComponent component) {
053: return (component instanceof UIOutput);
054: }
055:
056: /**
057: * This renders html for the beginning of the tag.
058: *
059: * @param context
060: * @param component
061: * @throws IOException
062: */
063: public void encodeBegin(FacesContext context, UIComponent component)
064: throws IOException {
065: ResponseWriter writer = context.getResponseWriter();
066:
067: String cssclass = (String) RendererUtil.getAttribute(context,
068: component, "cssclass");
069: String id = (String) RendererUtil.getAttribute(context,
070: component, "id");
071: String width = (String) RendererUtil.getAttribute(context,
072: component, "width");
073: String height = (String) RendererUtil.getAttribute(context,
074: component, "height");
075: String scrollXStyle = (String) RendererUtil.getAttribute(
076: context, component, "scrollXStyle");
077: String scrollYStyle = (String) RendererUtil.getAttribute(
078: context, component, "scrollYStyle");
079:
080: writer.startElement("div", component);
081:
082: if (cssclass != null)
083: writer.writeAttribute("class", cssclass, "class");
084:
085: if (id != null)
086: writer.writeAttribute("id", id, "id");
087:
088: String style = "";
089:
090: if (scrollXStyle == null && scrollYStyle == null) {
091: // set the div tag to have scroll bars when the innerHTML is larger than the div size
092: style += "overflow:auto;";
093: } else if (scrollYStyle == null) {
094: if (scrollXStyle.equals(SCROLL_SCROLL)
095: || scrollXStyle.equals(SCROLL_AUTO))
096: scrollYStyle = SCROLL_HIDDEN;
097: } else if (scrollXStyle == null) {
098: if (scrollYStyle.equals(SCROLL_SCROLL)
099: || scrollYStyle.equals(SCROLL_AUTO))
100: scrollXStyle = SCROLL_HIDDEN;
101: }
102: if (scrollXStyle != null)
103: style += "overflow-x:" + scrollXStyle + ";";
104:
105: if (scrollYStyle != null)
106: style += "overflow-y:" + scrollYStyle + ";";
107:
108: if (width != null) {
109: style += "width:" + width + ";";
110: }
111: if (height != null) {
112: style += "height:" + height + ";";
113: }
114:
115: if (style.length() > 0)
116: writer.writeAttribute("style", style, "style");
117: }
118:
119: /**
120: * @param context FacesContext for the request we are processing
121: * @param component UIComponent to be rendered
122: * @exception IOException if an input/output error occurs while rendering
123: * @exception NullPointerException if <code>context</code> or <code>component</code> is null
124: */
125: public void encodeEnd(FacesContext context, UIComponent component)
126: throws IOException {
127: ResponseWriter writer = context.getResponseWriter();
128:
129: writer.endElement("div");
130: }
131: }
|