001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020 package org.apache.myfaces.tobago.renderkit;
021
022 /*
023 * Created 09.03.2004 12:26:39.
024 * $Id: BoxRendererBase.java 1368577 2012-08-02 16:20:31Z lofwyr $
025 */
026
027
028 import org.apache.commons.logging.Log;
029 import org.apache.commons.logging.LogFactory;
030 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_HEIGHT;
031 import org.apache.myfaces.tobago.component.ComponentUtil;
032 import org.apache.myfaces.tobago.component.UILayout;
033 import org.apache.myfaces.tobago.util.LayoutUtil;
034
035 import javax.faces.component.UIComponent;
036 import javax.faces.context.FacesContext;
037
038 public abstract class BoxRendererBase extends LayoutableRendererBase {
039
040 private static final Log LOG = LogFactory.getLog(BoxRendererBase.class);
041
042 public boolean getRendersChildren() {
043 return true;
044 }
045
046 public int getFixedHeight(FacesContext facesContext, UIComponent component) {
047
048 int height =
049 ComponentUtil.getIntAttribute(component, ATTR_HEIGHT, -1);
050 if (height != -1) {
051 return height;
052 }
053
054 // ask layoutManager
055 UIComponent layout = UILayout.getLayout(component);
056 if (layout != null) {
057 LayoutInformationProvider renderer = ComponentUtil.getRenderer(facesContext, layout);
058 height = renderer.getFixedHeight(facesContext, component);
059 if (height > -1) {
060 return height;
061 }
062 }
063
064 if (LOG.isInfoEnabled()) {
065 LOG.info("Can't calculate fixedHeight! "
066 + "using estimation by contained components. ");
067 }
068
069 height = LayoutUtil.calculateFixedHeightForChildren(facesContext, component);
070 height += getHeaderHeight(facesContext, component);
071 height += getPaddingHeight(facesContext, component);
072 return height;
073 }
074
075 }