use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class DiagnosticRenderUtil method renderHelper.
/**
* Render the diagnostics.
* @param renderContext the current renderContext
* @param diags the list of Diagnostic objects
* @param severity the severity we are rendering
*/
private static void renderHelper(final WebXmlRenderContext renderContext, final List<Diagnostic> diags, final int severity) {
if (diags.isEmpty()) {
return;
}
XmlStringBuilder xml = renderContext.getWriter();
xml.appendTagOpen(TAG_NAME);
xml.appendAttribute("type", getLevel(severity));
xml.appendClose();
for (Diagnostic diagnostic : diags) {
xml.appendTag(MESSAGE_TAG_NAME);
xml.appendEscaped(diagnostic.getDescription());
xml.appendEndTag(MESSAGE_TAG_NAME);
}
xml.appendEndTag(TAG_NAME);
}
use of com.github.bordertech.wcomponents.XmlStringBuilder 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");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder 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");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder 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.XmlStringBuilder in project wcomponents by BorderTech.
the class MarginRendererUtil method renderMargin.
/**
* @param component the marginable component to paint a margin
* @param renderContext the RenderContext to paint to.
*/
public static void renderMargin(final Marginable component, final WebXmlRenderContext renderContext) {
Margin margin = component.getMargin();
if (margin == null) {
return;
}
XmlStringBuilder xml = renderContext.getWriter();
if (margin.getMargin() != null) {
xml.appendTagOpen("ui:margin");
xml.appendAttribute("all", margin.getMargin().toString());
xml.appendEnd();
} else if (margin.getTop() != null || margin.getRight() != null || margin.getBottom() != null || margin.getLeft() != null) {
xml.appendTagOpen("ui:margin");
Size size = margin.getTop();
if (size != null) {
xml.appendAttribute("north", size.toString());
}
size = margin.getRight();
if (size != null) {
xml.appendAttribute("east", size.toString());
}
size = margin.getBottom();
if (size != null) {
xml.appendAttribute("south", size.toString());
}
size = margin.getLeft();
if (size != null) {
xml.appendAttribute("west", size.toString());
}
xml.appendEnd();
}
}
Aggregations