Search in sources :

Example 1 with GridBagLayoutInfo

use of org.eclipse.wb.internal.swing.model.layout.gbl.GridBagLayoutInfo in project windowbuilder by eclipse.

the class GridBagColumnTest method test_getAlignment_2.

/**
 * Test for {@link ColumnInfo#getAlignment()}.<br>
 * Single component with {@link GridBagConstraints#WEST}, so "left" alignment.
 */
public void test_getAlignment_2() throws Exception {
    ContainerInfo panel = parseContainer("class Test extends JPanel {", "  public Test() {", "    GridBagLayout layout = new GridBagLayout();", "    setLayout(layout);", "    {", "      JButton button = new JButton();", "      GridBagConstraints gbc = new GridBagConstraints();", "      gbc.gridx = 0;", "      gbc.gridy = 0;", "      gbc.anchor = GridBagConstraints.WEST;", "      add(button, gbc);", "    }", "  }", "}");
    panel.refresh();
    GridBagLayoutInfo layout = (GridBagLayoutInfo) panel.getLayout();
    assertEquals(1, layout.getColumns().size());
    assertSame(ColumnInfo.Alignment.LEFT, layout.getColumns().get(0).getAlignment());
}
Also used : GridBagLayoutInfo(org.eclipse.wb.internal.swing.model.layout.gbl.GridBagLayoutInfo) ContainerInfo(org.eclipse.wb.internal.swing.model.component.ContainerInfo)

Example 2 with GridBagLayoutInfo

use of org.eclipse.wb.internal.swing.model.layout.gbl.GridBagLayoutInfo in project windowbuilder by eclipse.

the class GridBagColumnTest method test_insert.

// //////////////////////////////////////////////////////////////////////////
// 
// INSERT
// 
// //////////////////////////////////////////////////////////////////////////
/**
 * Simple test for {@link DimensionOperations#insert(int)}.<br>
 * When we append new column, this causes gaps in previously last column.
 */
public void test_insert() throws Exception {
    ContainerInfo panel = parseContainer("class Test extends JPanel {", "  public Test() {", "    GridBagLayout layout = new GridBagLayout();", "    layout.columnWidths = new int[] {1, 2};", "    layout.rowHeights = new int[] {0, 0};", "    layout.columnWeights = new double[] {0.1, Double.MIN_VALUE};", "    layout.rowWeights = new double[] {0.0, Double.MIN_VALUE};", "    setLayout(layout);", "    {", "      JButton button_0 = new JButton();", "      GridBagConstraints gbc = new GridBagConstraints();", "      gbc.gridx = 0;", "      gbc.gridy = 0;", "      add(button_0, gbc);", "    }", "  }", "}");
    panel.refresh();
    final GridBagLayoutInfo layout = (GridBagLayoutInfo) panel.getLayout();
    assertEquals(1, layout.getColumns().size());
    assertEquals(1, layout.getRows().size());
    // append column
    ExecutionUtils.run(panel, new RunnableEx() {

        @Override
        public void run() throws Exception {
            layout.getColumnOperations().insert(1);
        }
    });
    assertEquals(2, layout.getColumns().size());
    assertEquals(1, layout.getRows().size());
    assertEditor("class Test extends JPanel {", "  public Test() {", "    GridBagLayout layout = new GridBagLayout();", "    layout.columnWidths = new int[] {1, 0, 2};", "    layout.rowHeights = new int[] {0, 0};", "    layout.columnWeights = new double[] {0.1, 0.0, Double.MIN_VALUE};", "    layout.rowWeights = new double[] {0.0, Double.MIN_VALUE};", "    setLayout(layout);", "    {", "      JButton button_0 = new JButton();", "      GridBagConstraints gbc = new GridBagConstraints();", "      gbc.insets = new Insets(0, 0, 0, 5);", "      gbc.gridx = 0;", "      gbc.gridy = 0;", "      add(button_0, gbc);", "    }", "  }", "}");
}
Also used : GridBagLayoutInfo(org.eclipse.wb.internal.swing.model.layout.gbl.GridBagLayoutInfo) ContainerInfo(org.eclipse.wb.internal.swing.model.component.ContainerInfo) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx)

Example 3 with GridBagLayoutInfo

use of org.eclipse.wb.internal.swing.model.layout.gbl.GridBagLayoutInfo in project windowbuilder by eclipse.

the class GridBagColumnTest method test_setSize_1.

// //////////////////////////////////////////////////////////////////////////
// 
// size/weight
// 
// //////////////////////////////////////////////////////////////////////////
/**
 * Test for {@link DimensionInfo#setSize(int)}.<br>
 * Assignment to <code>columnWidths</code> exists, so just replace element.
 */
public void test_setSize_1() throws Exception {
    ContainerInfo panel = parseContainer("class Test extends JPanel {", "  public Test() {", "    GridBagLayout layout = new GridBagLayout();", "    layout.columnWidths = new int[]{0};", "    setLayout(layout);", "    {", "      JButton button = new JButton();", "      GridBagConstraints gbc = new GridBagConstraints();", "      gbc.gridx = 0;", "      gbc.gridy = 0;", "      add(button, gbc);", "    }", "  }", "}");
    panel.refresh();
    GridBagLayoutInfo layout = (GridBagLayoutInfo) panel.getLayout();
    // prepare column
    assertEquals(1, layout.getColumns().size());
    ColumnInfo column = layout.getColumns().get(0);
    assertEquals(0, column.getSize());
    // set size
    column.setSize(100);
    assertEquals(100, column.getSize());
    assertEditor("class Test extends JPanel {", "  public Test() {", "    GridBagLayout layout = new GridBagLayout();", "    layout.columnWidths = new int[]{100};", "    setLayout(layout);", "    {", "      JButton button = new JButton();", "      GridBagConstraints gbc = new GridBagConstraints();", "      gbc.gridx = 0;", "      gbc.gridy = 0;", "      add(button, gbc);", "    }", "  }", "}");
}
Also used : GridBagLayoutInfo(org.eclipse.wb.internal.swing.model.layout.gbl.GridBagLayoutInfo) ContainerInfo(org.eclipse.wb.internal.swing.model.component.ContainerInfo) ColumnInfo(org.eclipse.wb.internal.swing.model.layout.gbl.ColumnInfo)

Example 4 with GridBagLayoutInfo

use of org.eclipse.wb.internal.swing.model.layout.gbl.GridBagLayoutInfo in project windowbuilder by eclipse.

the class GridBagColumnTest method test_setWeight_1.

/**
 * Test for {@link DimensionInfo#setWeight(double)}.<br>
 * Assignment to <code>columnWeights</code> exists, so just replace element.
 */
public void test_setWeight_1() throws Exception {
    ContainerInfo panel = parseContainer("class Test extends JPanel {", "  public Test() {", "    GridBagLayout layout = new GridBagLayout();", "    layout.columnWeights = new double[]{0.0};", "    setLayout(layout);", "    {", "      JButton button = new JButton();", "      GridBagConstraints gbc = new GridBagConstraints();", "      gbc.gridx = 0;", "      gbc.gridy = 0;", "      add(button, gbc);", "    }", "  }", "}");
    panel.refresh();
    GridBagLayoutInfo layout = (GridBagLayoutInfo) panel.getLayout();
    // prepare column
    assertEquals(1, layout.getColumns().size());
    ColumnInfo column = layout.getColumns().get(0);
    assertEquals(0.0, column.getWeight(), 1.0E-6);
    // set size
    column.setWeight(2.0);
    assertEquals(2.0, column.getWeight(), 1.0E-6);
    assertEditor("class Test extends JPanel {", "  public Test() {", "    GridBagLayout layout = new GridBagLayout();", "    layout.columnWeights = new double[]{2.0};", "    setLayout(layout);", "    {", "      JButton button = new JButton();", "      GridBagConstraints gbc = new GridBagConstraints();", "      gbc.gridx = 0;", "      gbc.gridy = 0;", "      add(button, gbc);", "    }", "  }", "}");
}
Also used : GridBagLayoutInfo(org.eclipse.wb.internal.swing.model.layout.gbl.GridBagLayoutInfo) ContainerInfo(org.eclipse.wb.internal.swing.model.component.ContainerInfo) ColumnInfo(org.eclipse.wb.internal.swing.model.layout.gbl.ColumnInfo)

Example 5 with GridBagLayoutInfo

use of org.eclipse.wb.internal.swing.model.layout.gbl.GridBagLayoutInfo in project windowbuilder by eclipse.

the class GridBagColumnTest method test_getAlignment_3.

/**
 * Test for {@link ColumnInfo#getAlignment()}.<br>
 * Two components with different alignments, so "unknown" alignment for {@link ColumnInfo}.
 */
public void test_getAlignment_3() throws Exception {
    ContainerInfo panel = parseContainer("class Test extends JPanel {", "  public Test() {", "    GridBagLayout layout = new GridBagLayout();", "    setLayout(layout);", "    {", "      JButton button = new JButton();", "      GridBagConstraints gbc = new GridBagConstraints();", "      gbc.gridx = 0;", "      gbc.gridy = 0;", "      gbc.anchor = GridBagConstraints.WEST;", "      add(button, gbc);", "    }", "    {", "      JButton button = new JButton();", "      GridBagConstraints gbc = new GridBagConstraints();", "      gbc.gridx = 0;", "      gbc.gridy = 1;", "      gbc.anchor = GridBagConstraints.EAST;", "      add(button, gbc);", "    }", "  }", "}");
    panel.refresh();
    GridBagLayoutInfo layout = (GridBagLayoutInfo) panel.getLayout();
    // prepare column
    ColumnInfo column;
    {
        assertEquals(1, layout.getColumns().size());
        column = layout.getColumns().get(0);
    }
    // no common alignment
    assertSame(ColumnInfo.Alignment.UNKNOWN, column.getAlignment());
    // set alignment
    column.setAlignment(ColumnInfo.Alignment.RIGHT);
    assertSame(ColumnInfo.Alignment.RIGHT, column.getAlignment());
    assertEditor("class Test extends JPanel {", "  public Test() {", "    GridBagLayout layout = new GridBagLayout();", "    setLayout(layout);", "    {", "      JButton button = new JButton();", "      GridBagConstraints gbc = new GridBagConstraints();", "      gbc.gridx = 0;", "      gbc.gridy = 0;", "      gbc.anchor = GridBagConstraints.EAST;", "      add(button, gbc);", "    }", "    {", "      JButton button = new JButton();", "      GridBagConstraints gbc = new GridBagConstraints();", "      gbc.gridx = 0;", "      gbc.gridy = 1;", "      gbc.anchor = GridBagConstraints.EAST;", "      add(button, gbc);", "    }", "  }", "}");
}
Also used : GridBagLayoutInfo(org.eclipse.wb.internal.swing.model.layout.gbl.GridBagLayoutInfo) ContainerInfo(org.eclipse.wb.internal.swing.model.component.ContainerInfo) ColumnInfo(org.eclipse.wb.internal.swing.model.layout.gbl.ColumnInfo)

Aggregations

GridBagLayoutInfo (org.eclipse.wb.internal.swing.model.layout.gbl.GridBagLayoutInfo)86 ContainerInfo (org.eclipse.wb.internal.swing.model.component.ContainerInfo)82 RunnableEx (org.eclipse.wb.internal.core.utils.execution.RunnableEx)42 AbstractGridBagLayoutInfo (org.eclipse.wb.internal.swing.model.layout.gbl.AbstractGridBagLayoutInfo)40 ComponentInfo (org.eclipse.wb.internal.swing.model.component.ComponentInfo)37 IGridInfo (org.eclipse.wb.core.gef.policy.layout.grid.IGridInfo)12 ColumnInfo (org.eclipse.wb.internal.swing.model.layout.gbl.ColumnInfo)9 Rectangle (org.eclipse.wb.draw2d.geometry.Rectangle)6 List (java.util.List)4 FlowLayoutInfo (org.eclipse.wb.internal.swing.model.layout.FlowLayoutInfo)4 LayoutInfo (org.eclipse.wb.internal.swing.model.layout.LayoutInfo)4 JTextField (javax.swing.JTextField)3 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)3 GridBagConstraintsInfo (org.eclipse.wb.internal.swing.model.layout.gbl.GridBagConstraintsInfo)3 RowInfo (org.eclipse.wb.internal.swing.model.layout.gbl.RowInfo)3 JLabel (javax.swing.JLabel)2 Interval (org.eclipse.wb.draw2d.geometry.Interval)2 JTable (javax.swing.JTable)1 IAction (org.eclipse.jface.action.IAction)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1