public class GridRuleBuilderTestCase
extends FormatRuleBuilderTestAbstract {
public void testStyling() throws Exception {
LayoutBuilder builder = new LayoutBuilder(new RuntimeLayoutFactory());
// Create the layout.
builder.createLayout(LayoutType.CANVAS);
// Push grid
builder.pushFormat(FormatType.GRID.getTypeName(), 0);
builder.setAttribute(Grid.COLUMNS_ATTRIBUTE, "3");
builder.setAttribute(Grid.ROWS_ATTRIBUTE, "2");
builder.setAttribute(FormatConstants.BACKGROUND_COLOUR_ATTRIBUTE, "red");
builder.setAttribute(FormatConstants.BORDER_WIDTH_ATTRIBUTE, "2");
builder.setAttribute(FormatConstants.CELL_PADDING_ATTRIBUTE, "4");
builder.setAttribute(FormatConstants.CELL_SPACING_ATTRIBUTE, "6");
builder.setAttribute(FormatConstants.WIDTH_ATTRIBUTE, "100");
builder.setAttribute(FormatConstants.WIDTH_UNITS_ATTRIBUTE,
FormatConstants.WIDTH_UNITS_VALUE_PERCENT);
builder.setAttribute(FormatConstants.HEIGHT_ATTRIBUTE, "50");
builder.setAttribute(FormatConstants.HORIZONTAL_ALIGNMENT_ATTRIBUTE,
FormatConstants.HORIZONTAL_ALIGNMENT_VALUE_RIGHT);
builder.setAttribute(FormatConstants.VERTICAL_ALIGNMENT_ATTRIBUTE,
FormatConstants.VERTICAL_ALIGNMENT_VALUE_CENTER);
builder.attributesRead();
// Row 0
builder.createSubComponent(Grid.ROW_FORMAT_TYPE, 0);
builder.setAttribute(FormatConstants.HEIGHT_ATTRIBUTE, "10");
builder.attributesRead();
// Row 1
builder.createSubComponent(Grid.ROW_FORMAT_TYPE, 1);
builder.setAttribute(FormatConstants.HEIGHT_ATTRIBUTE, "20");
builder.setAttribute(FormatConstants.HEIGHT_UNITS_ATTRIBUTE,
FormatConstants.HEIGHT_UNITS_VALUE_PERCENT);
builder.attributesRead();
// Column 0
builder.createSubComponent(Grid.COLUMN_FORMAT_TYPE, 0);
builder.setAttribute(FormatConstants.WIDTH_ATTRIBUTE, "15");
builder.attributesRead();
// Column 1
builder.createSubComponent(Grid.COLUMN_FORMAT_TYPE, 1);
builder.setAttribute(FormatConstants.WIDTH_ATTRIBUTE, "25");
builder.setAttribute(FormatConstants.WIDTH_UNITS_ATTRIBUTE,
FormatConstants.WIDTH_UNITS_VALUE_PIXELS);
builder.attributesRead();
// Push panes.
String[] horizontalAlign = new String[]{
FormatConstants.HORIZONTAL_ALIGNMENT_VALUE_LEFT,
FormatConstants.HORIZONTAL_ALIGNMENT_VALUE_CENTER,
FormatConstants.HORIZONTAL_ALIGNMENT_VALUE_RIGHT,
FormatConstants.HORIZONTAL_ALIGNMENT_VALUE_LEFT,
FormatConstants.HORIZONTAL_ALIGNMENT_VALUE_CENTER,
FormatConstants.HORIZONTAL_ALIGNMENT_VALUE_RIGHT,
};
String[] verticalAlign = new String[] {
FormatConstants.VERTICAL_ALIGNMENT_VALUE_TOP,
FormatConstants.VERTICAL_ALIGNMENT_VALUE_CENTER,
FormatConstants.VERTICAL_ALIGNMENT_VALUE_BOTTOM,
FormatConstants.VERTICAL_ALIGNMENT_VALUE_TOP,
FormatConstants.VERTICAL_ALIGNMENT_VALUE_CENTER,
FormatConstants.VERTICAL_ALIGNMENT_VALUE_BOTTOM,
};
for (int i = 0; i < 6; i += 1) {
// Make an empty cell.
if (i == 4) continue;
builder.pushFormat(FormatType.PANE.getTypeName(), i);
builder.setAttribute(FormatConstants.NAME_ATTRIBUTE, "Pane" + i);
builder.setAttribute(FormatConstants.HORIZONTAL_ALIGNMENT_ATTRIBUTE,
horizontalAlign[i]);
builder.setAttribute(FormatConstants.VERTICAL_ALIGNMENT_ATTRIBUTE,
verticalAlign[i]);
builder.attributesRead();
builder.popFormat();
}
// Pop grid
Grid grid = (Grid) builder.popFormat();
Layout layout = builder.getLayout();
FormatStylingEngine formatStylingEngine =
createFormatStylingEngine(layout);
Styles actualStyles;