Search in sources :

Example 1 with Size

use of com.github.bordertech.wcomponents.Size in project wcomponents by BorderTech.

the class WListRenderer method doRender.

/**
 * Paints the given WList.
 *
 * @param component the WList to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WList list = (WList) component;
    XmlStringBuilder xml = renderContext.getWriter();
    WList.Type type = list.getType();
    WList.Separator separator = list.getSeparator();
    Size gap = list.getSpace();
    String gapString = gap == null ? null : gap.toString();
    xml.appendTagOpen("ui:panel");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("type", list.isRenderBorder(), "box");
    xml.appendClose();
    // Render margin
    MarginRendererUtil.renderMargin(list, renderContext);
    xml.appendTagOpen("ui:listlayout");
    xml.appendOptionalAttribute("gap", gapString);
    if (type != null) {
        switch(type) {
            case FLAT:
                xml.appendAttribute("type", "flat");
                break;
            case STACKED:
                xml.appendAttribute("type", "stacked");
                break;
            case STRIPED:
                xml.appendAttribute("type", "striped");
                break;
            default:
                throw new SystemException("Unknown list type: " + type);
        }
    }
    if (separator != null) {
        switch(separator) {
            case BAR:
                xml.appendAttribute("separator", "bar");
                break;
            case DOT:
                xml.appendAttribute("separator", "dot");
                break;
            case NONE:
                break;
            default:
                throw new SystemException("Unknown list type: " + type);
        }
    }
    xml.appendClose();
    paintRows(list, renderContext);
    xml.appendEndTag("ui:listlayout");
    xml.appendEndTag("ui:panel");
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) Size(com.github.bordertech.wcomponents.Size) WList(com.github.bordertech.wcomponents.WList) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 2 with Size

use of com.github.bordertech.wcomponents.Size in project wcomponents by BorderTech.

the class ColumnLayoutRenderer 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();
    ColumnLayout layout = (ColumnLayout) panel.getLayout();
    int childCount = panel.getChildCount();
    Size hgap = layout.getHorizontalGap();
    String hgapString = hgap == null ? null : hgap.toString();
    Size vgap = layout.getVerticalGap();
    String vgapString = vgap == null ? null : vgap.toString();
    int cols = layout.getColumnCount();
    xml.appendTagOpen("ui:columnlayout");
    xml.appendOptionalAttribute("hgap", hgapString);
    xml.appendOptionalAttribute("vgap", vgapString);
    xml.appendClose();
    // Column Definitions
    for (int col = 0; col < cols; col++) {
        xml.appendTagOpen("ui:column");
        int width = layout.getColumnWidth(col);
        xml.appendOptionalAttribute("width", width > 0, width);
        switch(layout.getColumnAlignment(col)) {
            case LEFT:
                // left is assumed if omitted
                break;
            case RIGHT:
                xml.appendAttribute("align", "right");
                break;
            case CENTER:
                xml.appendAttribute("align", "center");
                break;
            default:
                throw new IllegalArgumentException("Invalid alignment: " + layout.getColumnAlignment(col));
        }
        xml.appendEnd();
    }
    for (int i = 0; i < childCount; i++) {
        xml.appendTag("ui:cell");
        WComponent child = panel.getChildAt(i);
        child.paint(renderContext);
        xml.appendEndTag("ui:cell");
    }
    xml.appendEndTag("ui:columnlayout");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) Size(com.github.bordertech.wcomponents.Size) WPanel(com.github.bordertech.wcomponents.WPanel) ColumnLayout(com.github.bordertech.wcomponents.layout.ColumnLayout) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 3 with Size

use of com.github.bordertech.wcomponents.Size 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)

Example 4 with Size

use of com.github.bordertech.wcomponents.Size in project wcomponents by BorderTech.

the class FlowLayoutRenderer 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();
    FlowLayout layout = (FlowLayout) panel.getLayout();
    Size gap = layout.getSpace();
    String gapString = gap != null ? gap.toString() : null;
    FlowLayout.Alignment align = layout.getAlignment();
    xml.appendTagOpen("ui:flowlayout");
    switch(align) {
        case RIGHT:
            {
                xml.appendAttribute("align", "right");
                break;
            }
        case CENTER:
            {
                xml.appendAttribute("align", "center");
                break;
            }
        case LEFT:
            {
                xml.appendAttribute("align", "left");
                break;
            }
        case VERTICAL:
            xml.appendAttribute("align", "vertical");
            break;
        default:
            throw new IllegalStateException("Unknown layout type: " + layout.getAlignment());
    }
    if (layout.getContentAlignment() != null) {
        switch(layout.getContentAlignment()) {
            case TOP:
                {
                    xml.appendAttribute("valign", "top");
                    break;
                }
            case MIDDLE:
                {
                    xml.appendAttribute("valign", "middle");
                    break;
                }
            case BASELINE:
                {
                    xml.appendAttribute("valign", "baseline");
                    break;
                }
            case BOTTOM:
                xml.appendAttribute("valign", "bottom");
                break;
            default:
                throw new IllegalStateException("Unknown content alignment type: " + layout.getContentAlignment());
        }
    }
    xml.appendOptionalAttribute("gap", gapString);
    xml.appendClose();
    int size = panel.getChildCount();
    for (int i = 0; i < size; i++) {
        xml.appendTag("ui:cell");
        WComponent child = panel.getChildAt(i);
        child.paint(renderContext);
        xml.appendEndTag("ui:cell");
    }
    xml.appendEndTag("ui:flowlayout");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) FlowLayout(com.github.bordertech.wcomponents.layout.FlowLayout) Size(com.github.bordertech.wcomponents.Size) WPanel(com.github.bordertech.wcomponents.WPanel) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 5 with Size

use of com.github.bordertech.wcomponents.Size in project wcomponents by BorderTech.

the class GridLayoutRenderer 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();
    GridLayout layout = (GridLayout) panel.getLayout();
    Size hgap = layout.getHorizontalGap();
    String hgapString = hgap == null ? null : hgap.toString();
    Size vgap = layout.getVerticalGap();
    String vgapString = vgap == null ? null : vgap.toString();
    int rows = layout.getRows();
    int cols = layout.getCols();
    xml.appendTagOpen("ui:gridlayout");
    xml.appendAttribute("rows", rows > 0 ? String.valueOf(rows) : "0");
    xml.appendAttribute("cols", cols > 0 ? String.valueOf(cols) : "0");
    xml.appendOptionalAttribute("hgap", hgapString);
    xml.appendOptionalAttribute("vgap", vgapString);
    xml.appendClose();
    int size = panel.getChildCount();
    for (int i = 0; i < size; i++) {
        xml.appendTag("ui:cell");
        WComponent child = panel.getChildAt(i);
        child.paint(renderContext);
        xml.appendEndTag("ui:cell");
    }
    xml.appendEndTag("ui:gridlayout");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) GridLayout(com.github.bordertech.wcomponents.layout.GridLayout) Size(com.github.bordertech.wcomponents.Size) WPanel(com.github.bordertech.wcomponents.WPanel) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Aggregations

Size (com.github.bordertech.wcomponents.Size)8 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)8 WPanel (com.github.bordertech.wcomponents.WPanel)5 WComponent (com.github.bordertech.wcomponents.WComponent)4 Margin (com.github.bordertech.wcomponents.Margin)1 WList (com.github.bordertech.wcomponents.WList)1 WRow (com.github.bordertech.wcomponents.WRow)1 BorderLayout (com.github.bordertech.wcomponents.layout.BorderLayout)1 BorderLayoutConstraint (com.github.bordertech.wcomponents.layout.BorderLayout.BorderLayoutConstraint)1 ColumnLayout (com.github.bordertech.wcomponents.layout.ColumnLayout)1 FlowLayout (com.github.bordertech.wcomponents.layout.FlowLayout)1 GridLayout (com.github.bordertech.wcomponents.layout.GridLayout)1 ListLayout (com.github.bordertech.wcomponents.layout.ListLayout)1 Duplet (com.github.bordertech.wcomponents.util.Duplet)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1 ArrayList (java.util.ArrayList)1