use of com.github.bordertech.wcomponents.layout.ListLayout in project wcomponents by BorderTech.
the class WPanelTypeExample method setUpUtilBar.
/**
* Add some UI to a "utility bar" type structure.
*/
private void setUpUtilBar() {
utilBar.setLayout(new ListLayout(ListLayout.Type.FLAT, ListLayout.Alignment.RIGHT, ListLayout.Separator.NONE, false));
WTextField selectOther = new WTextField();
selectOther.setToolTip("Enter text.");
utilBar.add(selectOther);
utilBar.add(new WButton("Go"));
utilBar.add(new WButton("A"));
utilBar.add(new WButton("B"));
utilBar.add(new WButton("C"));
utilBar.setVisible(false);
}
use of com.github.bordertech.wcomponents.layout.ListLayout in project wcomponents by BorderTech.
the class ListLayoutRenderer_Test method testDoRenderWhenEmpty.
@Test
public void testDoRenderWhenEmpty() throws IOException, SAXException, XpathException {
WPanel panel = new WPanel();
panel.setLayout(new ListLayout(ListLayout.Type.FLAT, ListLayout.Alignment.LEFT, ListLayout.Separator.NONE, false));
assertSchemaMatch(panel);
assertXpathExists("//ui:panel/ui:listlayout", panel);
assertXpathNotExists("//ui:panel/ui:listlayout/ui:cell", panel);
assertXpathNotExists("//ui:panel/ui:listlayout/@gap", panel);
assertXpathNotExists("//ui:panel/ui:listlayout/@align", panel);
assertXpathNotExists("//ui:panel/ui:listlayout/@separator", panel);
assertXpathNotExists("//ui:panel/ui:listlayout/@ordered", panel);
assertXpathEvaluatesTo("flat", "//ui:panel/ui:listlayout/@type", panel);
panel.setLayout(new ListLayout(ListLayout.Type.STRIPED, ListLayout.Alignment.CENTER, ListLayout.Separator.NONE, false));
assertXpathEvaluatesTo("striped", "//ui:panel/ui:listlayout/@type", panel);
assertXpathEvaluatesTo("center", "//ui:panel/ui:listlayout/@align", panel);
assertXpathNotExists("//ui:panel/ui:listlayout/ui:cell", panel);
assertXpathNotExists("//ui:panel/ui:listlayout/@gap", panel);
assertXpathNotExists("//ui:panel/ui:listlayout/@separator", panel);
assertXpathNotExists("//ui:panel/ui:listlayout/@ordered", panel);
panel.setLayout(new ListLayout(ListLayout.Type.STACKED, ListLayout.Alignment.RIGHT, ListLayout.Separator.NONE, false, GAP));
assertXpathEvaluatesTo("stacked", "//ui:panel/ui:listlayout/@type", panel);
assertXpathEvaluatesTo("right", "//ui:panel/ui:listlayout/@align", panel);
assertXpathEvaluatesTo(GAP.toString(), "//ui:panel/ui:listlayout/@gap", panel);
assertXpathNotExists("//ui:panel/ui:listlayout/ui:cell", panel);
assertXpathNotExists("//ui:panel/ui:listlayout/@separator", panel);
assertXpathNotExists("//ui:panel/ui:listlayout/@ordered", panel);
}
use of com.github.bordertech.wcomponents.layout.ListLayout in project wcomponents by BorderTech.
the class ListLayoutRenderer 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();
ListLayout layout = (ListLayout) panel.getLayout();
int childCount = panel.getChildCount();
Size gap = layout.getSpace();
String gapString = gap != null ? gap.toString() : null;
xml.appendTagOpen("ui:listlayout");
switch(layout.getType()) {
case FLAT:
xml.appendAttribute("type", "flat");
break;
case STACKED:
xml.appendAttribute("type", "stacked");
break;
case STRIPED:
xml.appendAttribute("type", "striped");
break;
default:
throw new IllegalArgumentException("Invalid type: " + layout.getType());
}
switch(layout.getAlignment()) {
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.getAlignment());
}
switch(layout.getSeparator()) {
case NONE:
// none is assumed if omitted
break;
case BAR:
xml.appendAttribute("separator", "bar");
break;
case DOT:
xml.appendAttribute("separator", "dot");
break;
default:
throw new IllegalArgumentException("Invalid separator: " + layout.getSeparator());
}
xml.appendOptionalAttribute("ordered", layout.isOrdered(), "true");
xml.appendOptionalAttribute("gap", gapString);
xml.appendClose();
// Paint children
for (int i = 0; i < childCount; i++) {
xml.appendTag("ui:cell");
panel.getChildAt(i).paint(renderContext);
xml.appendEndTag("ui:cell");
}
xml.appendEndTag("ui:listlayout");
}
use of com.github.bordertech.wcomponents.layout.ListLayout in project wcomponents by BorderTech.
the class ListLayoutRenderer_Test method testDoRender.
@Test
public void testDoRender() throws IOException, SAXException, XpathException {
final String text1 = "FlowRenderer_Test.testPaint.text1";
final String text2 = "FlowRenderer_Test.testPaint.text2";
WPanel panel = new WPanel();
panel.setLayout(new ListLayout(ListLayout.Type.STRIPED, ListLayout.Alignment.LEFT, ListLayout.Separator.DOT, true, GAP));
assertSchemaMatch(panel);
assertXpathNotExists("//ui:panel/ui:listlayout/ui:cell", panel);
panel.add(new WText(text1));
panel.add(new WText(text2));
assertXpathEvaluatesTo("2", "count(//ui:panel/ui:listlayout/ui:cell)", panel);
assertXpathEvaluatesTo(text1, "normalize-space(//ui:panel/ui:listlayout/ui:cell[1])", panel);
assertXpathEvaluatesTo(text2, "normalize-space(//ui:panel/ui:listlayout/ui:cell[2])", panel);
}
Aggregations