001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/jsf/widgets/src/java/org/theospi/jsf/renderer/TabRenderer.java $
003: * $Id: TabRenderer.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: import org.theospi.jsf.component.TabComponent;
032: import org.theospi.jsf.util.OspxTagHelper;
033:
034: /**
035: * This creates a split content area. It divides a space in two.
036: * This creates a table of size width x height. It the uses
037: * the divider position to give the first cell a height or width
038: * based on if the direction is vertical or horizontal, respectively.
039: * <br><br>
040: * This class depends on the splitdivider tag to create the actual divide
041: * The second class makes the second cell.
042: *
043: * @author andersjb
044: *
045: */
046:
047: public class TabRenderer extends Renderer {
048: public boolean supportsComponentType(UIComponent component) {
049: return (component instanceof UIOutput);
050: }
051:
052: /**
053: * This renders html for the beginning of the tag.
054: *
055: * @param context
056: * @param component
057: * @throws IOException
058: */
059: public void encodeBegin(FacesContext context, UIComponent component)
060: throws IOException {
061: ResponseWriter writer = context.getResponseWriter();
062:
063: String title = (String) RendererUtil.getAttribute(context,
064: component, "title");
065: String directionStr = (String) RendererUtil.getAttribute(
066: context, component.getParent(), "direction");
067: String selected = (String) RendererUtil.getAttribute(context,
068: component, "selected");
069: String cssclass = (String) RendererUtil.getAttribute(context,
070: component, "cssclass");
071: TabComponent tab = (TabComponent) component;
072: boolean isSelected = false;
073:
074: if (selected.equalsIgnoreCase("true")) {
075: tab.setSelected("true");
076: isSelected = true;
077: }
078: if (cssclass == null)
079: cssclass = "";
080:
081: //checks for vertical, its abbr., and the y axis
082: if (OspxTagHelper.isVertical(directionStr))
083: writer.write("<div style=\"padding:2px;\">");
084:
085: writer.write("<input type=\"submit\" class=\"osp_tab"
086: + (isSelected ? "_selected" : "") + " " + cssclass
087: + "\" value=\"" + title + "\" "
088: + (isSelected ? "disabled=\"disabled\"" : "") + " />");
089: //checks for vertical, its abbr., and the y axis
090: if (OspxTagHelper.isVertical(directionStr))
091: writer.write("</div>");
092:
093: }
094:
095: /**
096: * @param context FacesContext for the request we are processing
097: * @param component UIComponent to be rendered
098: * @exception IOException if an input/output error occurs while rendering
099: * @exception NullPointerException if <code>context</code> or <code>component</code> is null
100: */
101: public void encodeEnd(FacesContext context, UIComponent component)
102: throws IOException {
103: }
104:
105: public void encodeChildren(FacesContext context,
106: UIComponent component) throws IOException {
107: //Do nothing
108: }
109:
110: public boolean getRendersChildren() {
111: //Set to false so the content can be rendered in the correct place by the TabArea
112: return true;
113: }
114:
115: }
|