Search in sources :

Example 1 with GridLayoutInfo

use of org.eclipse.wb.internal.xwt.model.layout.grid.GridLayoutInfo in project windowbuilder by eclipse.

the class GridLayoutTest method test_normalizeSpanning_4.

/**
 * Test for {@link GridLayoutInfo#command_normalizeSpanning()}.<br>
 * Do normalize: no control for second column.
 */
public void test_normalizeSpanning_4() throws Exception {
    parse("// filler filler filler filler filler", "<Shell>", "  <Shell.layout>", "    <GridLayout wbp:name='layout' numColumns='2'/>", "  </Shell.layout>", "  <Button wbp:name='button_1'>", "    <Button.layoutData>", "      <GridData horizontalSpan='2'/>", "    </Button.layoutData>", "  </Button>", "  <Button wbp:name='button_2'/>", "  <Label/>", "</Shell>");
    refresh();
    GridLayoutInfo layout = getObjectByName("layout");
    // 
    layout.command_normalizeSpanning();
    assertXML("// filler filler filler filler filler", "<Shell>", "  <Shell.layout>", "    <GridLayout wbp:name='layout'/>", "  </Shell.layout>", "  <Button wbp:name='button_1'/>", "  <Button wbp:name='button_2'/>", "</Shell>");
}
Also used : GridLayoutInfo(org.eclipse.wb.internal.xwt.model.layout.grid.GridLayoutInfo)

Example 2 with GridLayoutInfo

use of org.eclipse.wb.internal.xwt.model.layout.grid.GridLayoutInfo in project windowbuilder by eclipse.

the class GridLayoutTest method test_CREATE_appendColumnRow.

public void test_CREATE_appendColumnRow() throws Exception {
    parse("// filler filler filler filler filler", "<Shell>", "  <Shell.layout>", "    <GridLayout wbp:name='layout'/>", "  </Shell.layout>", "  <Button text='0'/>", "</Shell>");
    refresh();
    GridLayoutInfo layout = getObjectByName("layout");
    // 
    ControlInfo newButton = createButton();
    layout.command_CREATE(newButton, 1, false, 1, false);
    assertXML("// filler filler filler filler filler", "<Shell>", "  <Shell.layout>", "    <GridLayout wbp:name='layout' numColumns='2'/>", "  </Shell.layout>", "  <Button text='0'/>", "  <Label/>", "  <Label/>", "  <Button/>", "</Shell>");
}
Also used : GridLayoutInfo(org.eclipse.wb.internal.xwt.model.layout.grid.GridLayoutInfo) ControlInfo(org.eclipse.wb.internal.xwt.model.widgets.ControlInfo)

Example 3 with GridLayoutInfo

use of org.eclipse.wb.internal.xwt.model.layout.grid.GridLayoutInfo in project windowbuilder by eclipse.

the class GridLayoutTest method test_fixGrid_leadingImplicitControls.

/**
 * It is possible that there are existing {@link Control}-s created in superclass. We should not
 * try to "fix" this by adding fillers.
 */
public void test_fixGrid_leadingImplicitControls() throws Exception {
    setFileContentSrc("test/MyShell.java", getJavaSource("public class MyShell extends Shell {", "  public MyShell() {", "    setLayout(new GridLayout());", "    new Text(this, SWT.NONE);", "  }", "  protected void checkSubclass() {", "  }", "}"));
    waitForAutoBuild();
    // 
    CompositeInfo shell = parse("// filler filler filler filler filler", "// filler filler filler filler filler", "<t:MyShell>", "  <Button/>", "</t:MyShell>");
    refresh();
    GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout();
    // do "fix"
    ReflectionUtils.invokeMethod(layout, "fixGrid()");
    assertXML("// filler filler filler filler filler", "// filler filler filler filler filler", "<t:MyShell>", "  <Button/>", "</t:MyShell>");
}
Also used : GridLayoutInfo(org.eclipse.wb.internal.xwt.model.layout.grid.GridLayoutInfo) CompositeInfo(org.eclipse.wb.internal.xwt.model.widgets.CompositeInfo)

Example 4 with GridLayoutInfo

use of org.eclipse.wb.internal.xwt.model.layout.grid.GridLayoutInfo in project windowbuilder by eclipse.

the class GridLayoutTest method test_CREATE_insertColumn.

public void test_CREATE_insertColumn() throws Exception {
    parse("// filler filler filler filler filler", "<Shell>", "  <Shell.layout>", "    <GridLayout wbp:name='layout' numColumns='2'/>", "  </Shell.layout>", "  <Button text='0'/>", "  <Label />", "  <Label  />", "  <Button text='1'/>", "</Shell>");
    refresh();
    GridLayoutInfo layout = getObjectByName("layout");
    // 
    ControlInfo newButton = createButton();
    layout.command_CREATE(newButton, 1, true, 0, false);
    assertXML("// filler filler filler filler filler", "<Shell>", "  <Shell.layout>", "    <GridLayout wbp:name='layout' numColumns='3'/>", "  </Shell.layout>", "  <Button text='0'/>", "  <Button/>", "  <Label />", "  <Label  />", "  <Label/>", "  <Button text='1'/>", "</Shell>");
}
Also used : GridLayoutInfo(org.eclipse.wb.internal.xwt.model.layout.grid.GridLayoutInfo) ControlInfo(org.eclipse.wb.internal.xwt.model.widgets.ControlInfo)

Example 5 with GridLayoutInfo

use of org.eclipse.wb.internal.xwt.model.layout.grid.GridLayoutInfo in project windowbuilder by eclipse.

the class GridLayoutTest method test_gridInfo.

// //////////////////////////////////////////////////////////////////////////
// 
// IGridInfo
// 
// //////////////////////////////////////////////////////////////////////////
/**
 * Test for {@link IGridInfo}.
 */
public void test_gridInfo() throws Exception {
    parse("// filler filler filler filler filler", "<Shell>", "  <Shell.layout>", "    <GridLayout wbp:name='layout' numColumns='2'/>", "  </Shell.layout>", "  <Button wbp:name='button_0'/>", "  <Label/>", "  <Label/>", "  <Button wbp:name='button_1'/>", "  <Button wbp:name='button_2'>", "    <Button.layoutData>", "      <GridData horizontalSpan='2'/>", "    </Button.layoutData>", "  </Button>", "</Shell>");
    refresh();
    GridLayoutInfo layout = getObjectByName("layout");
    ControlInfo button_0 = getObjectByName("button_0");
    ControlInfo button_1 = getObjectByName("button_1");
    ControlInfo button_2 = getObjectByName("button_2");
    // 
    IGridInfo gridInfo = layout.getGridInfo();
    assertNotNull(gridInfo);
    // check count of column/row
    assertEquals(2, gridInfo.getColumnCount());
    assertEquals(3, gridInfo.getRowCount());
    // check column intervals
    {
        int[] columnOrigins = layout.getColumnOrigins();
        Interval[] columnIntervals = gridInfo.getColumnIntervals();
        assertEquals(columnOrigins.length, columnIntervals.length);
        for (int i = 0; i < columnOrigins.length; i++) {
            int origin = columnOrigins[i];
            Interval interval = columnIntervals[i];
            assertEquals(origin, interval.begin);
        }
    }
    // check row intervals
    {
        int[] rowOrigins = layout.getRowOrigins();
        Interval[] rowIntervals = gridInfo.getRowIntervals();
        assertEquals(rowOrigins.length, rowIntervals.length);
    }
    // check component cells
    {
        assertEquals(new Rectangle(0, 0, 1, 1), gridInfo.getComponentCells(button_0));
        assertEquals(new Rectangle(1, 1, 1, 1), gridInfo.getComponentCells(button_1));
        assertEquals(new Rectangle(0, 2, 2, 1), gridInfo.getComponentCells(button_2));
    }
    // check cells rectangle
    {
        Rectangle rectangle = gridInfo.getCellsRectangle(new Rectangle(0, 0, 1, 1));
        assertEquals(5, rectangle.x);
        assertEquals(5, rectangle.y);
    }
    // not RTL
    assertFalse(gridInfo.isRTL());
    // insets
    assertEquals(new Insets(0, 0, 0, 0), gridInfo.getInsets());
    // check "virtual" feedback sizes
    {
        assertTrue(gridInfo.hasVirtualColumns());
        assertTrue(gridInfo.hasVirtualRows());
        assertEquals(25, gridInfo.getVirtualColumnSize());
        assertEquals(5, gridInfo.getVirtualColumnGap());
        assertEquals(25, gridInfo.getVirtualRowSize());
        assertEquals(5, gridInfo.getVirtualRowGap());
    }
    // check occupied cells
    {
        assertSame(button_0, gridInfo.getOccupied(0, 0));
        assertSame(button_1, gridInfo.getOccupied(1, 1));
        assertSame(button_2, gridInfo.getOccupied(0, 2));
        assertSame(button_2, gridInfo.getOccupied(1, 2));
        assertNull(gridInfo.getOccupied(1, 0));
        assertNull(gridInfo.getOccupied(0, 1));
    }
}
Also used : IGridInfo(org.eclipse.wb.core.gef.policy.layout.grid.IGridInfo) Insets(org.eclipse.wb.draw2d.geometry.Insets) GridLayoutInfo(org.eclipse.wb.internal.xwt.model.layout.grid.GridLayoutInfo) Rectangle(org.eclipse.wb.draw2d.geometry.Rectangle) ControlInfo(org.eclipse.wb.internal.xwt.model.widgets.ControlInfo) Interval(org.eclipse.wb.draw2d.geometry.Interval)

Aggregations

GridLayoutInfo (org.eclipse.wb.internal.xwt.model.layout.grid.GridLayoutInfo)65 ControlInfo (org.eclipse.wb.internal.xwt.model.widgets.ControlInfo)40 CompositeInfo (org.eclipse.wb.internal.xwt.model.widgets.CompositeInfo)12 Rectangle (org.eclipse.wb.draw2d.geometry.Rectangle)9 RunnableEx (org.eclipse.wb.internal.core.utils.execution.RunnableEx)9 IGridInfo (org.eclipse.wb.core.gef.policy.layout.grid.IGridInfo)5 GridDataInfo (org.eclipse.wb.internal.xwt.model.layout.grid.GridDataInfo)4 Dimension (org.eclipse.wb.draw2d.geometry.Dimension)2 PreferencesRepairer (org.eclipse.wb.tests.designer.core.PreferencesRepairer)2 Insets (org.eclipse.wb.draw2d.geometry.Insets)1 Interval (org.eclipse.wb.draw2d.geometry.Interval)1