001    package org.apache.myfaces.tobago.renderkit.html.speyside.standard.tag;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more
005     * contributor license agreements.  See the NOTICE file distributed with
006     * this work for additional information regarding copyright ownership.
007     * The ASF licenses this file to You under the Apache License, Version 2.0
008     * (the "License"); you may not use this file except in compliance with
009     * the License.  You may obtain a copy of the License at
010     *
011     *      http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing, software
014     * distributed under the License is distributed on an "AS IS" BASIS,
015     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016     * See the License for the specific language governing permissions and
017     * limitations under the License.
018     */
019    
020    /*
021     * Created 07.02.2003 16:00:00.
022     * $Id: TabGroupRenderer.java 644014 2008-04-02 19:36:26Z bommel $
023     */
024    
025    import org.apache.commons.logging.Log;
026    import org.apache.commons.logging.LogFactory;
027    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_BODY;
028    import org.apache.myfaces.tobago.component.UITab;
029    import org.apache.myfaces.tobago.renderkit.util.RenderUtil;
030    import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
031    import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtil;
032    import org.apache.myfaces.tobago.renderkit.html.HtmlStyleMap;
033    import org.apache.myfaces.tobago.renderkit.html.StyleClasses;
034    import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
035    
036    import javax.faces.context.FacesContext;
037    import java.io.IOException;
038    import java.text.MessageFormat;
039    
040    public class TabGroupRenderer extends
041        org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.TabGroupRenderer{
042    
043      private static final Log LOG = LogFactory.getLog(TabGroupRenderer.class);
044    
045      protected void encodeContent(TobagoResponseWriter writer,
046          FacesContext facesContext, UITab activeTab) throws IOException {
047    
048        HtmlStyleMap bodyStyle = (HtmlStyleMap)
049            activeTab.getParent().getAttributes().get(ATTR_STYLE_BODY);
050        writer.startElement(HtmlConstants.TR, null);
051        writer.startElement(HtmlConstants.TD, null);
052        if (bodyStyle != null) {
053          writer.writeStyleAttribute(bodyStyle);
054        }
055    
056        writer.startElement(HtmlConstants.DIV, null);
057        writer.writeClassAttribute("tobago-tab-shadow");
058        if (bodyStyle != null) {
059          writer.writeStyleAttribute(bodyStyle);
060        }
061    
062        writer.startElement(HtmlConstants.DIV, null);
063        StyleClasses classes = new StyleClasses();
064        classes.addClass("tab", "content");
065        classes.addMarkupClass(activeTab, "tab", "content");
066        writer.writeClassAttribute(classes);
067    
068        Integer height = HtmlRendererUtil.getStyleAttributeIntValue(bodyStyle, "height");
069        if (height != null) {
070          writer.writeStyleAttribute(MessageFormat.format("height: {0}px; overflow: auto;", height - 1));
071        }
072    
073        writer.flush();
074        RenderUtil.encodeChildren(facesContext, activeTab);
075    
076        writer.endElement(HtmlConstants.DIV);
077        writer.endElement(HtmlConstants.DIV);
078    
079        writer.endElement(HtmlConstants.TD);
080        writer.endElement(HtmlConstants.TR);
081    
082      }
083    
084    }
085