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());
}
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);
}
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);
}
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");
}
Aggregations