Search in sources :

Example 1 with BorderLayoutConstraint

use of com.github.bordertech.wcomponents.layout.BorderLayout.BorderLayoutConstraint in project wcomponents by BorderTech.

the class BorderLayoutRenderer method paintChildrenWithConstraint.

/**
 * Paints all the child components with the given constraint.
 *
 * @param children the list of potential children to paint.
 * @param renderContext the RenderContext to paint to.
 * @param constraint the target constraint.
 */
private void paintChildrenWithConstraint(final List<Duplet<WComponent, BorderLayoutConstraint>> children, final WebXmlRenderContext renderContext, final BorderLayoutConstraint constraint) {
    String containingTag = null;
    XmlStringBuilder xml = renderContext.getWriter();
    final int size = children.size();
    for (int i = 0; i < size; i++) {
        Duplet<WComponent, BorderLayoutConstraint> child = children.get(i);
        if (constraint.equals(child.getSecond())) {
            if (containingTag == null) {
                containingTag = getTag(constraint);
                xml.appendTag(containingTag);
            }
            child.getFirst().paint(renderContext);
        }
    }
    if (containingTag != null) {
        xml.appendEndTag(containingTag);
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) BorderLayoutConstraint(com.github.bordertech.wcomponents.layout.BorderLayout.BorderLayoutConstraint) BorderLayoutConstraint(com.github.bordertech.wcomponents.layout.BorderLayout.BorderLayoutConstraint)

Example 2 with BorderLayoutConstraint

use of com.github.bordertech.wcomponents.layout.BorderLayout.BorderLayoutConstraint in project wcomponents by BorderTech.

the class BorderLayoutRenderer method doRender.

/**
 * Paints the given WPanel's children.
 *
 * @param component the container to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WPanel panel = (WPanel) component;
    XmlStringBuilder xml = renderContext.getWriter();
    BorderLayout layout = (BorderLayout) panel.getLayout();
    Size hgap = layout.getHorizontalGap();
    String hgapString = hgap == null ? null : hgap.toString();
    Size vgap = layout.getVerticalGap();
    String vgapString = vgap == null ? null : vgap.toString();
    xml.appendTagOpen("ui:borderlayout");
    xml.appendOptionalAttribute("hgap", hgapString);
    xml.appendOptionalAttribute("vgap", vgapString);
    xml.appendClose();
    // Fetch the children and their constraints.
    final int childCount = panel.getChildCount();
    List<Duplet<WComponent, BorderLayoutConstraint>> children = new ArrayList<>(childCount);
    for (int i = 0; i < childCount; i++) {
        WComponent child = panel.getChildAt(i);
        children.add(new Duplet<>(child, getConstraints(panel, child)));
    }
    // Now paint them
    paintChildrenWithConstraint(children, renderContext, BorderLayout.NORTH);
    paintChildrenWithConstraint(children, renderContext, BorderLayout.EAST);
    paintChildrenWithConstraint(children, renderContext, BorderLayout.SOUTH);
    paintChildrenWithConstraint(children, renderContext, BorderLayout.WEST);
    paintChildrenWithConstraint(children, renderContext, BorderLayout.CENTER);
    xml.appendEndTag("ui:borderlayout");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) Duplet(com.github.bordertech.wcomponents.util.Duplet) BorderLayout(com.github.bordertech.wcomponents.layout.BorderLayout) Size(com.github.bordertech.wcomponents.Size) WPanel(com.github.bordertech.wcomponents.WPanel) ArrayList(java.util.ArrayList) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) BorderLayoutConstraint(com.github.bordertech.wcomponents.layout.BorderLayout.BorderLayoutConstraint)

Aggregations

WComponent (com.github.bordertech.wcomponents.WComponent)2 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)2 BorderLayoutConstraint (com.github.bordertech.wcomponents.layout.BorderLayout.BorderLayoutConstraint)2 Size (com.github.bordertech.wcomponents.Size)1 WPanel (com.github.bordertech.wcomponents.WPanel)1 BorderLayout (com.github.bordertech.wcomponents.layout.BorderLayout)1 Duplet (com.github.bordertech.wcomponents.util.Duplet)1 ArrayList (java.util.ArrayList)1