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());
}
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);", " }", " }", "}");
}
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);", " }", " }", "}");
}
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);", " }", " }", "}");
}
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);", " }", " }", "}");
}
Aggregations