use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class UIRegistryAmicableImpl method getUI.
/**
* Retrieves the user interface that was registered with the given key. If the UI has not been registered, this
* attempts to load the UI using the key as a class name.
*
* @param key The registration key.
* @return the UI for the given key. The UI may be newly created.
*/
@Override
public synchronized WComponent getUI(final String key) {
WComponent ui = registry.get(key);
if (ui == null) {
// Looks like we haven't tried loading this UI yet, so do it now.
ui = loadUI(key);
ui.setLocked(true);
// Cache the result only if the UI was successfully loaded.
if (ui instanceof ErrorPage) {
LOG.debug("Returning non-cached ErrorPage WComponent. Key=" + key);
} else {
register(key, ui);
LOG.debug("Returning cached WComponent. Key=" + key);
}
} else {
LOG.debug("Returning cached WComponent. Key=" + key);
}
return ui;
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class BorderLayoutRenderer method paintChildrenWithConstraint.
/**
* Paints all the child components with the given constraint.
*
* @param children the list of potential children to paint.
* @param renderContext the RenderContext to paint to.
* @param constraint the target constraint.
*/
private void paintChildrenWithConstraint(final List<Duplet<WComponent, BorderLayoutConstraint>> children, final WebXmlRenderContext renderContext, final BorderLayoutConstraint constraint) {
String containingTag = null;
XmlStringBuilder xml = renderContext.getWriter();
final int size = children.size();
for (int i = 0; i < size; i++) {
Duplet<WComponent, BorderLayoutConstraint> child = children.get(i);
if (constraint.equals(child.getSecond())) {
if (containingTag == null) {
containingTag = getTag(constraint);
xml.appendTag(containingTag);
}
child.getFirst().paint(renderContext);
}
}
if (containingTag != null) {
xml.appendEndTag(containingTag);
}
}
use of com.github.bordertech.wcomponents.WComponent 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");
}
use of com.github.bordertech.wcomponents.WComponent 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.WComponent 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