Search in sources :

Example 1 with WColumn

use of com.github.bordertech.wcomponents.WColumn in project wcomponents by BorderTech.

the class WRowExample method createRow.

/**
 * Creates a row containing columns with the given widths.
 *
 * @param hgap the horizontal gap between columns, in pixels.
 * @param colWidths the percentage widths for each column.
 * @return a WRow containing columns with the given widths.
 */
private WRow createRow(final int hgap, final int[] colWidths) {
    WRow row = new WRow(hgap);
    for (int i = 0; i < colWidths.length; i++) {
        WColumn col = new WColumn(colWidths[i]);
        WPanel box = new WPanel(WPanel.Type.BOX);
        box.add(new WText(colWidths[i] + "%"));
        col.add(box);
        row.add(col);
    }
    return row;
}
Also used : WText(com.github.bordertech.wcomponents.WText) WPanel(com.github.bordertech.wcomponents.WPanel) WRow(com.github.bordertech.wcomponents.WRow) WColumn(com.github.bordertech.wcomponents.WColumn)

Example 2 with WColumn

use of com.github.bordertech.wcomponents.WColumn in project wcomponents by BorderTech.

the class WColumnRenderer method doRender.

/**
 * Paints the given WButton.
 *
 * @param component the WColumn to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WColumn col = (WColumn) component;
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen("ui:column");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    int width = col.getWidth();
    xml.appendOptionalAttribute("width", width > 0, width);
    switch(col.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: " + col.getAlignment());
    }
    xml.appendClose();
    // Paint column contents
    paintChildren(col, renderContext);
    xml.appendEndTag("ui:column");
}
Also used : WColumn(com.github.bordertech.wcomponents.WColumn) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 3 with WColumn

use of com.github.bordertech.wcomponents.WColumn in project wcomponents by BorderTech.

the class WColumnRenderer_Test method testPaintWhenEmpty.

@Test
public void testPaintWhenEmpty() throws IOException, SAXException {
    WColumn column = new WColumn(100);
    // A Column is not valid by itself, so we must add it to a row.
    WRow row = new WRow();
    row.add(column);
    assertSchemaMatch(row);
}
Also used : WRow(com.github.bordertech.wcomponents.WRow) WColumn(com.github.bordertech.wcomponents.WColumn) Test(org.junit.Test)

Example 4 with WColumn

use of com.github.bordertech.wcomponents.WColumn in project wcomponents by BorderTech.

the class WColumnRenderer_Test method testPaint.

@Test
public void testPaint() throws IOException, SAXException, XpathException {
    WRow row = new WRow();
    WColumn column = new WColumn(100);
    row.add(column);
    column.add(new WLabel("dummy"));
    assertSchemaMatch(row);
    assertXpathEvaluatesTo(column.getId(), "//ui:column/@id", row);
    assertXpathEvaluatesTo("100", "//ui:column/@width", row);
    assertXpathNotExists("//ui:column/@align", row);
    column.setAlignment(WColumn.Alignment.LEFT);
    assertSchemaMatch(row);
    assertXpathNotExists("//ui:column/@align", row);
    column.setAlignment(WColumn.Alignment.CENTER);
    assertSchemaMatch(row);
    assertXpathEvaluatesTo("center", "//ui:column/@align", row);
    column.setAlignment(WColumn.Alignment.RIGHT);
    assertSchemaMatch(row);
    assertXpathEvaluatesTo("right", "//ui:column/@align", row);
}
Also used : WRow(com.github.bordertech.wcomponents.WRow) WColumn(com.github.bordertech.wcomponents.WColumn) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 5 with WColumn

use of com.github.bordertech.wcomponents.WColumn in project wcomponents by BorderTech.

the class WRowExample method createRow.

/**
 * Creates a row containing columns with the given widths.
 *
 * @param gap the horizontal gap between columns
 * @param colWidths the percentage widths for each column
 * @return a WRow containing columns with the given widths
 */
private WRow createRow(final Size gap, final int[] colWidths) {
    WRow row = new WRow(gap);
    for (int i = 0; i < colWidths.length; i++) {
        WColumn col = new WColumn(colWidths[i]);
        WPanel box = new WPanel(WPanel.Type.BOX);
        box.add(new WText(colWidths[i] + "%"));
        col.add(box);
        row.add(col);
    }
    return row;
}
Also used : WText(com.github.bordertech.wcomponents.WText) WPanel(com.github.bordertech.wcomponents.WPanel) WRow(com.github.bordertech.wcomponents.WRow) WColumn(com.github.bordertech.wcomponents.WColumn)

Aggregations

WColumn (com.github.bordertech.wcomponents.WColumn)10 WRow (com.github.bordertech.wcomponents.WRow)8 Test (org.junit.Test)6 WText (com.github.bordertech.wcomponents.WText)3 WPanel (com.github.bordertech.wcomponents.WPanel)2 Margin (com.github.bordertech.wcomponents.Margin)1 WHeading (com.github.bordertech.wcomponents.WHeading)1 WLabel (com.github.bordertech.wcomponents.WLabel)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)1