View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag;
21  
22  import org.apache.myfaces.tobago.component.Attributes;
23  import org.apache.myfaces.tobago.component.UIFlowLayout;
24  import org.apache.myfaces.tobago.config.Configurable;
25  import org.apache.myfaces.tobago.layout.LayoutContainer;
26  import org.apache.myfaces.tobago.layout.Measure;
27  import org.apache.myfaces.tobago.renderkit.MarginValues;
28  import org.apache.myfaces.tobago.renderkit.RendererBase;
29  import org.apache.myfaces.tobago.renderkit.SpacingValues;
30  import org.apache.myfaces.tobago.renderkit.css.Classes;
31  import org.apache.myfaces.tobago.renderkit.css.Style;
32  import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
33  import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
34  import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
35  import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
36  
37  import javax.faces.component.UIComponent;
38  import javax.faces.context.FacesContext;
39  import java.io.IOException;
40  
41  public class FlowLayoutRenderer extends RendererBase implements SpacingValues, MarginValues {
42  
43    @Override
44    public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
45      TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
46      UIFlowLayout layout = (UIFlowLayout) component;
47      writer.startElement(HtmlElements.DIV, layout);
48      writer.writeClassAttribute(Classes.create(layout));
49      Style style = new Style();
50      style.setMarginLeft(getMarginLeft(facesContext, layout));
51      style.setMarginRight(getMarginRight(facesContext, layout));
52      style.setMarginTop(getMarginTop(facesContext, layout));
53      style.setMarginBottom(getMarginBottom(facesContext, layout));
54      style.setTextAlign(layout.getTextAlign());
55      writer.writeStyleAttribute(style);
56    }
57  
58    @Override
59    public void encodeChildren(FacesContext facesContext, UIComponent component) throws IOException {
60      UIComponent container = component.getParent();
61      if (container instanceof LayoutContainer && !((LayoutContainer) container).isLayoutChildren()) {
62        return;
63      }
64      RenderUtils.encodeChildren(facesContext, container);
65    }
66  
67    @Override
68    public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
69      TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
70      writer.endElement(HtmlElements.DIV);
71    }
72  
73    public Measure getColumnSpacing(FacesContext facesContext, Configurable component) {
74      return getResourceManager().getThemeMeasure(facesContext, component, Attributes.COLUMN_SPACING);
75    }
76  
77    public Measure getRowSpacing(FacesContext facesContext, Configurable component) {
78      return getResourceManager().getThemeMeasure(facesContext, component, Attributes.ROW_SPACING);
79    }
80  
81    public Measure getMarginLeft(FacesContext facesContext, Configurable component) {
82      Configurable parent = (Configurable) ((UIComponent) component).getParent();
83      return getResourceManager().getThemeMeasure(facesContext, parent, Attributes.MARGIN_LEFT);
84    }
85  
86    public Measure getMarginRight(FacesContext facesContext, Configurable component) {
87      Configurable parent = (Configurable) ((UIComponent) component).getParent();
88      return getResourceManager().getThemeMeasure(facesContext, parent, Attributes.MARGIN_RIGHT);
89    }
90  
91    public Measure getMarginTop(FacesContext facesContext, Configurable component) {
92      Configurable parent = (Configurable) ((UIComponent) component).getParent();
93      return getResourceManager().getThemeMeasure(facesContext, parent, Attributes.MARGIN_TOP);
94    }
95  
96    public Measure getMarginBottom(FacesContext facesContext, Configurable component) {
97      Configurable parent = (Configurable) ((UIComponent) component).getParent();
98      return getResourceManager().getThemeMeasure(facesContext, parent, Attributes.MARGIN_BOTTOM);
99    }
100 
101 }