001 package org.apache.myfaces.tobago.renderkit;
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 09.03.2004 12:26:39.
022 * $Id: BoxRendererBase.java 578592 2007-09-23 18:51:32Z bommel $
023 */
024
025
026 import org.apache.commons.logging.Log;
027 import org.apache.commons.logging.LogFactory;
028 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_HEIGHT;
029 import org.apache.myfaces.tobago.component.ComponentUtil;
030 import org.apache.myfaces.tobago.component.UILayout;
031 import org.apache.myfaces.tobago.util.LayoutUtil;
032
033 import javax.faces.component.UIComponent;
034 import javax.faces.context.FacesContext;
035
036 public abstract class BoxRendererBase extends LayoutableRendererBase {
037
038 private static final Log LOG = LogFactory.getLog(BoxRendererBase.class);
039
040 public boolean getRendersChildren() {
041 return true;
042 }
043
044 public int getFixedHeight(FacesContext facesContext, UIComponent component) {
045
046 int height =
047 ComponentUtil.getIntAttribute(component, ATTR_HEIGHT, -1);
048 if (height != -1) {
049 return height;
050 }
051
052 // ask layoutManager
053 UIComponent layout = UILayout.getLayout(component);
054 if (layout != null) {
055 LayoutInformationProvider renderer = ComponentUtil.getRenderer(facesContext, layout);
056 height = renderer.getFixedHeight(facesContext, component);
057 if (height > -1) {
058 return height;
059 }
060 }
061
062 if (LOG.isInfoEnabled()) {
063 LOG.info("Can't calculate fixedHeight! "
064 + "using estimation by contained components. ");
065 }
066
067 height = LayoutUtil.calculateFixedHeightForChildren(facesContext, component);
068 height += getHeaderHeight(facesContext, component);
069 height += getPaddingHeight(facesContext, component);
070 return height;
071 }
072
073 }