Search in sources :

Example 1 with GridLayout

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

the class GridLayoutOptionsExample method applySettings.

/**
 * reset the container that holds the grid layout and create a new grid layout with the appropriate properties.
 */
private void applySettings() {
    container.reset();
    // Now show an example of the number of different columns
    WPanel gridLayoutPanel = new WPanel();
    if (cbResponsive.isSelected()) {
        gridLayoutPanel.setHtmlClass(HtmlClassProperties.RESPOND);
    }
    GridLayout layout = new GridLayout(rowCount.getValue().intValue(), columnCount.getValue().intValue(), hGap.getValue().intValue(), vGap.getValue().intValue());
    gridLayoutPanel.setLayout(layout);
    // give approx 3 rows, with a different number
    addBoxes(gridLayoutPanel, boxCount.getValue().intValue());
    // of boxes on the final row
    container.add(gridLayoutPanel);
    gridLayoutPanel.setVisible(cbVisible.isSelected());
}
Also used : GridLayout(com.github.bordertech.wcomponents.layout.GridLayout) WPanel(com.github.bordertech.wcomponents.WPanel)

Example 2 with GridLayout

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

the class GridLayoutRenderer_Test method testDoRenderWhenEmpty.

@Test
public void testDoRenderWhenEmpty() throws IOException, SAXException, XpathException {
    WPanel panel = new WPanel();
    panel.setLayout(new GridLayout(0, 1));
    assertSchemaMatch(panel);
    assertXpathExists("//ui:panel/ui:gridlayout", panel);
    assertXpathNotExists("//ui:panel/ui:gridlayout/ui:cell", panel);
    assertXpathEvaluatesTo("0", "//ui:panel/ui:gridlayout/@rows", panel);
    assertXpathEvaluatesTo("1", "//ui:panel/ui:gridlayout/@cols", panel);
    assertXpathNotExists("//ui:panel/ui:gridlayout/@hgap", panel);
    assertXpathNotExists("//ui:panel/ui:gridlayout/@vgap", panel);
}
Also used : GridLayout(com.github.bordertech.wcomponents.layout.GridLayout) WPanel(com.github.bordertech.wcomponents.WPanel) Test(org.junit.Test)

Example 3 with GridLayout

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

the class GridLayoutRenderer_Test method testDoRender.

@Test
public void testDoRender() throws IOException, SAXException, XpathException {
    final String text1 = "GridRenderer_Test.testPaint.text1";
    final String text2 = "GridRenderer_Test.testPaint.text2";
    WPanel panel = new WPanel();
    panel.setLayout(new GridLayout(1, 2, GAP, BIG_GAP));
    assertSchemaMatch(panel);
    assertXpathEvaluatesTo("1", "//ui:panel/ui:gridlayout/@rows", panel);
    assertXpathEvaluatesTo("2", "//ui:panel/ui:gridlayout/@cols", panel);
    assertXpathEvaluatesTo(GAP.toString(), "//ui:panel/ui:gridlayout/@hgap", panel);
    assertXpathEvaluatesTo(BIG_GAP.toString(), "//ui:panel/ui:gridlayout/@vgap", panel);
    assertXpathNotExists("//ui:panel/ui:gridlayout/ui:cell", panel);
    panel.add(new WText(text1));
    panel.add(new WText(text2));
    assertXpathEvaluatesTo("2", "count(//ui:panel/ui:gridlayout/ui:cell)", panel);
    assertXpathEvaluatesTo(text1, "normalize-space(//ui:panel/ui:gridlayout/ui:cell[1])", panel);
    assertXpathEvaluatesTo(text2, "normalize-space(//ui:panel/ui:gridlayout/ui:cell[2])", panel);
}
Also used : GridLayout(com.github.bordertech.wcomponents.layout.GridLayout) WText(com.github.bordertech.wcomponents.WText) WPanel(com.github.bordertech.wcomponents.WPanel) Test(org.junit.Test)

Example 4 with GridLayout

use of com.github.bordertech.wcomponents.layout.GridLayout 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

WPanel (com.github.bordertech.wcomponents.WPanel)4 GridLayout (com.github.bordertech.wcomponents.layout.GridLayout)4 Test (org.junit.Test)2 Size (com.github.bordertech.wcomponents.Size)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WText (com.github.bordertech.wcomponents.WText)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1