Search in sources :

Example 1 with Duplet

use of com.github.bordertech.wcomponents.util.Duplet in project wcomponents by BorderTech.

the class UIManager method getRenderer.

/**
 * Retrieves a renderer which can renderer the given component to the context.
 *
 * @param component the component to retrieve the renderer for.
 * @param context the render context.
 * @return an appropriate renderer for the component and context, or null if a suitable renderer could not be found.
 */
public static Renderer getRenderer(final WComponent component, final RenderContext context) {
    Class<? extends WComponent> clazz = component.getClass();
    Duplet<String, Class<?>> key = new Duplet<String, Class<?>>(context.getRenderPackage(), clazz);
    Renderer renderer = INSTANCE.renderers.get(key);
    if (renderer == null) {
        renderer = INSTANCE.findRenderer(component, key);
    } else if (renderer == NULL_RENDERER) {
        return null;
    }
    return renderer;
}
Also used : Duplet(com.github.bordertech.wcomponents.util.Duplet) Renderer(com.github.bordertech.wcomponents.Renderer) VelocityRenderer(com.github.bordertech.wcomponents.render.webxml.VelocityRenderer)

Example 2 with Duplet

use of com.github.bordertech.wcomponents.util.Duplet 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

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