diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/AbstractMigLayoutTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/AbstractMigLayoutTest.java index 64a0cef85..b793c6250 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/AbstractMigLayoutTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/AbstractMigLayoutTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2024 Google, Inc. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -50,18 +50,18 @@ public void setUp() throws Exception { // create IConstants with C_* constants setFileContentSrc( "test/IConstants.java", - getSourceDQ( - "package test;", - "public interface IConstants {", - " String C_1 = '1';", - " String C_2 = '2';", - " String C_3 = '3';", - " String C_4 = '4';", - " String C_5 = '5';", - " String C_6 = '6';", - " String C_7 = '7';", - " String C_8 = '8';", - "}")); + """ + package test; + public interface IConstants { + String C_1 = "1"; + String C_2 = "2"; + String C_3 = "3"; + String C_4 = "4"; + String C_5 = "5"; + String C_6 = "6"; + String C_7 = "7"; + String C_8 = "8"; + }"""); waitForAutoBuild(); } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutAutoAlignmentTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutAutoAlignmentTest.java index 292c039a8..7774c6da3 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutAutoAlignmentTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutAutoAlignmentTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Google, Inc. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -66,13 +66,12 @@ public void _test_exit() throws Exception { */ @Test public void test_CREATE_Text() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout()); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // create @@ -81,17 +80,17 @@ public void test_CREATE_Text() throws Exception { layout.command_CREATE(newComponent, 0, false, 0, false); } // check source - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[grow]', '[]'));", - " {", - " JTextField textField = new JTextField();", - " add(textField, 'cell 0 0,growx');", - " textField.setColumns(10);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[grow]", "[]")); + { + JTextField textField = new JTextField(); + add(textField, 'cell 0 0,growx'); + textField.setColumns(10); + } + } + }"""); } /** @@ -99,13 +98,12 @@ public void test_CREATE_Text() throws Exception { */ @Test public void test_CREATE_Text_disabled() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout()); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // create @@ -115,17 +113,17 @@ public void test_CREATE_Text_disabled() throws Exception { layout.command_CREATE(newComponent, 0, false, 0, false); } // check source - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JTextField textField = new JTextField();", - " add(textField, 'cell 0 0');", - " textField.setColumns(10);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout()); + { + JTextField textField = new JTextField(); + add(textField, "cell 0 0"); + textField.setColumns(10); + } + } + }"""); } /** @@ -133,13 +131,12 @@ public void test_CREATE_Text_disabled() throws Exception { */ @Test public void test_CREATE_Table() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout()); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // create @@ -148,16 +145,16 @@ public void test_CREATE_Table() throws Exception { layout.command_CREATE(newComponent, 0, false, 0, false); } // check source - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[grow]', '[grow]'));", - " {", - " JTable table = new JTable();", - " add(table, 'cell 0 0,grow');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[grow]", "[grow]")); + { + JTable table = new JTable(); + add(table, "cell 0 0,grow"); + } + } + }"""); } /** @@ -166,17 +163,16 @@ public void test_CREATE_Table() throws Exception { */ @Test public void test_CREATE_LabelBeforeText() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[][]', '[]'));", - " {", - " JTextField textField = new JTextField();", - " add(textField, 'cell 1 0, growx');", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[][]", "[]")); + { + JTextField textField = new JTextField(); + add(textField, "cell 1 0, growx"); + } + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // create @@ -185,20 +181,20 @@ public void test_CREATE_LabelBeforeText() throws Exception { layout.command_CREATE(newComponent, 0, false, 0, false); } // check source - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[][]', '[]'));", - " {", - " JLabel label = new JLabel('New label');", - " add(label, 'cell 0 0,alignx trailing');", - " }", - " {", - " JTextField textField = new JTextField();", - " add(textField, 'cell 1 0, growx');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[][]", "[]")); + { + JLabel label = new JLabel("New label"); + add(label, "cell 0 0,alignx trailing"); + } + { + JTextField textField = new JTextField(); + add(textField, "cell 1 0, growx"); + } + } + }"""); } /** @@ -206,17 +202,16 @@ public void test_CREATE_LabelBeforeText() throws Exception { */ @Test public void test_CREATE_LabelBeforeText_disabled() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[][]', '[]'));", - " {", - " JTextField textField = new JTextField();", - " add(textField, 'cell 1 0, growx');", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[][]", "[]")); + { + JTextField textField = new JTextField(); + add(textField, "cell 1 0, growx"); + } + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // create @@ -228,20 +223,20 @@ public void test_CREATE_LabelBeforeText_disabled() throws Exception { layout.command_CREATE(newComponent, 0, false, 0, false); } // check source - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[][]', '[]'));", - " {", - " JLabel label = new JLabel('New label');", - " add(label, 'cell 0 0');", - " }", - " {", - " JTextField textField = new JTextField();", - " add(textField, 'cell 1 0, growx');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[][]", "[]")); + { + JLabel label = new JLabel("New label"); + add(label, "cell 0 0"); + } + { + JTextField textField = new JTextField(); + add(textField, "cell 1 0, growx"); + } + } + }"""); } /** @@ -250,17 +245,16 @@ public void test_CREATE_LabelBeforeText_disabled() throws Exception { */ @Test public void test_CREATE_TextAfterLabel() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[][]', '[]'));", - " {", - " JLabel label = new JLabel('New label');", - " add(label, 'cell 0 0');", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[][]", "[]")); + { + JLabel label = new JLabel("New label"); + add(label, "cell 0 0"); + } + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // create @@ -269,20 +263,20 @@ public void test_CREATE_TextAfterLabel() throws Exception { layout.command_CREATE(newComponent, 1, false, 0, false); } // check source - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[][grow]', '[]'));", - " {", - " JLabel label = new JLabel('New label');", - " add(label, 'cell 0 0,alignx trailing');", - " }", - " {", - " JTextField textField = new JTextField();", - " add(textField, 'cell 1 0,growx');", - " textField.setColumns(10);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[][grow]", "[]")); + { + JLabel label = new JLabel("New label"); + add(label, "cell 0 0,alignx trailing"); + } + { + JTextField textField = new JTextField(); + add(textField, "cell 1 0,growx"); + textField.setColumns(10); + } + } + }"""); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutConstraintsPropertiesTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutConstraintsPropertiesTest.java index cac830d0a..00d487b74 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutConstraintsPropertiesTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutConstraintsPropertiesTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2025 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -53,14 +53,13 @@ public void _test_exit() throws Exception { @BeforeEach public void setUp() throws Exception { super.setUp(); - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][][]', '[][][][]'));", - " add(new JButton(C_1), 'cell 1 2');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][][]", "[][][][]")); + add(new JButton(C_1), "cell 1 2"); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); m_constraints = MigLayoutInfo.getConstraints(button); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutConstraintsTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutConstraintsTest.java index c5f863336..b3eddfead 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutConstraintsTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutConstraintsTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2025 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -67,14 +67,13 @@ public void _test_exit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_newConstraints() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 1 2 3 4');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 1 2 3 4"); + } + }"""); panel.refresh(); // ComponentInfo newButton = createJButton(); @@ -95,14 +94,13 @@ public void test_newConstraints() throws Exception { @Test public void test_parseString_getBounds() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 1 2 3 4');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 1 2 3 4"); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); // check constraints @@ -111,14 +109,13 @@ public void test_parseString_getBounds() throws Exception { @Test public void test_parseCC_getBounds() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), new CC().cell(1,2,3,4));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), new CC().cell(1,2,3,4)); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); // check constraints @@ -130,15 +127,14 @@ public void test_parseCC_getBounds() throws Exception { */ @Test public void test_parseString_noCell() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][]'));", - " add(new JButton(C_1), 'wrap');", - " add(new JButton(C_2), 'skip');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][]")); + add(new JButton(C_1), "wrap"); + add(new JButton(C_2), "skip"); + } + }"""); panel.refresh(); { ComponentInfo button_1 = panel.getChildrenComponents().get(0); @@ -155,16 +151,15 @@ public void test_parseString_noCell() throws Exception { */ @Test public void test_parseString_span() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[]'));", - " add(new JButton(C_1), 'span');", - " add(new JButton(C_2), 'cell 0 1');", - " add(new JButton(C_3), 'cell 1 1');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[]")); + add(new JButton(C_1), "span"); + add(new JButton(C_2), "cell 0 1"); + add(new JButton(C_3), "cell 1 1"); + } + }"""); panel.refresh(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); assertCellBounds(button_1, 0, 0, 2, 1); @@ -177,29 +172,27 @@ public void test_parseString_span() throws Exception { public void test_parse_hidemode3() throws Exception { // we don't execute java.awt.Component.setVisible(), so use other method setFileContentSrc( - "test/MyButton.java", - getTestSource( - "public class MyButton extends JButton {", - " public MyButton() {", - " }", - " public void setVisible2(boolean b) {", - " setVisible(b);", - " }", - "}")); + "test/MyButton.java", getTestSource(""" + public class MyButton extends JButton { + public MyButton() { + } + public void setVisible2(boolean b) { + setVisible(b); + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('hidemode 3', '[][]'));", - " {", - " MyButton button = new MyButton();", - " button.setVisible2(false);", - " add(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("hidemode 3", "[][]")); + { + MyButton button = new MyButton(); + button.setVisible2(false); + add(button); + } + } + }"""); panel.refresh(); { ComponentInfo button = panel.getChildrenComponents().get(0); @@ -212,32 +205,32 @@ public void test_parse_hidemode3() throws Exception { */ @Test public void test_write_hidemode() throws Exception { - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JButton button = new JButton();", - " add(button, 'hidemode 0,cell 0 0');", - " }", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + { + JButton button = new JButton(); + add(button, "hidemode 0,cell 0 0"); + } + } + }"""); refresh(); ComponentInfo button = getJavaInfoByName("button"); // update constraints CellConstraintsSupport constraints = MigLayoutInfo.getConstraints(button); constraints.setX(1); constraints.write(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JButton button = new JButton();", - " add(button, 'hidemode 0,cell 1 0');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + { + JButton button = new JButton(); + add(button, "hidemode 0,cell 1 0"); + } + } + }"""); refresh(); } @@ -246,14 +239,13 @@ public void test_write_hidemode() throws Exception { */ @Test public void test_setBounds_1() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 1 2 3 4');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 1 2 3 4"); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); // update constraints @@ -263,13 +255,13 @@ public void test_setBounds_1() throws Exception { constraints.setWidth(4); constraints.setHeight(5); constraints.write(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 2 3 4 5');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 2 3 4 5"); + } + }"""); } /** @@ -277,14 +269,13 @@ public void test_setBounds_1() throws Exception { */ @Test public void test_setBounds_2() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1)); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); // update constraints @@ -294,13 +285,13 @@ public void test_setBounds_2() throws Exception { constraints.setWidth(4); constraints.setHeight(5); constraints.write(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 2 3 4 5');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 2 3 4 5"); + } + }"""); } /** @@ -308,14 +299,13 @@ public void test_setBounds_2() throws Exception { */ @Test public void test_updateBounds() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 1 2 3 4');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 1 2 3 4"); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); // update constraints @@ -325,13 +315,13 @@ public void test_updateBounds() throws Exception { constraints.updateWidth(1); constraints.updateHeight(1); constraints.write(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 2 3 4 5');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 2 3 4 5"); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -345,14 +335,13 @@ public void test_updateBounds() throws Exception { */ @Test public void test_setString() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(), '');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout()); + add(new JButton(), ""); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); CellConstraintsSupport constraints = MigLayoutInfo.getConstraints(button); @@ -401,94 +390,94 @@ private String getCellConstraintsSource(CellConstraintsSupport cell) { //////////////////////////////////////////////////////////////////////////// @Test public void test_cleanUpSource_gapleft() throws Exception { - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'gap 1');", - " add(new JButton(C_2), 'gap 2,wrap');", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "gap 1"); + add(new JButton(C_2), "gap 2,wrap"); + } + }"""); refresh(); // write rewriteConstraints(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'gapx 1');", - " add(new JButton(C_2), 'gapx 2,wrap');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "gapx 1"); + add(new JButton(C_2), "gapx 2,wrap"); + } + }"""); } @Test public void test_cleanUpSource_gapright() throws Exception { - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'gapright 1');", - " add(new JButton(C_2), 'gapright 2,wrap');", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "gapright 1"); + add(new JButton(C_2), "gapright 2,wrap"); + } + }"""); refresh(); // write rewriteConstraints(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'gapright 1');", - " add(new JButton(C_2), 'gapright 2,wrap');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "gapright 1"); + add(new JButton(C_2), "gapright 2,wrap"); + } + }"""); } @Test public void test_cleanUpSource_gaptop() throws Exception { - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'gaptop 1');", - " add(new JButton(C_2), 'gaptop 2,wrap');", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "gaptop 1"); + add(new JButton(C_2), "gaptop 2,wrap"); + } + }"""); refresh(); // write rewriteConstraints(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'gapy 1');", - " add(new JButton(C_2), 'gapy 2,wrap');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "gapy 1"); + add(new JButton(C_2), "gapy 2,wrap"); + } + }"""); } @Test public void test_cleanUpSource_gapbottom() throws Exception { - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'gapbottom 1');", - " add(new JButton(C_2), 'gapbottom 2,wrap');", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "gapbottom 1"); + add(new JButton(C_2), "gapbottom 2,wrap"); + } + }"""); refresh(); // write rewriteConstraints(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'gapbottom 1');", - " add(new JButton(C_2), 'gapbottom 2,wrap');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "gapbottom 1"); + add(new JButton(C_2), "gapbottom 2,wrap"); + } + }"""); } private static void rewriteConstraints() throws Exception { @@ -507,170 +496,163 @@ private static void rewriteConstraints() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_makeExplicitCell_flow() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), '');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), ""); + } + }"""); panel.refresh(); // convert to explicit cells makeExplicitCell(panel); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + } + }"""); } @Test public void test_makeExplicitCell_wrap() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'wrap');", - " add(new JButton(C_2), '');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "wrap"); + add(new JButton(C_2), ""); + } + }"""); panel.refresh(); // convert to explicit cells makeExplicitCell(panel); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 1');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 1"); + } + }"""); } @Test public void test_makeExplicitCell_newline() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), '');", - " add(new JButton(C_2), 'newline');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), ""); + add(new JButton(C_2), "newline"); + } + }"""); panel.refresh(); // convert to explicit cells makeExplicitCell(panel); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 1');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 1"); + } + }"""); } @Test public void test_makeExplicitCell_skip() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), '');", - " add(new JButton(C_2), 'skip');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), ""); + add(new JButton(C_2), "skip"); + } + }"""); panel.refresh(); // convert to explicit cells makeExplicitCell(panel); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 2 0');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 2 0"); + } + }"""); } @Test public void test_makeExplicitCell_wrap_skip() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'wrap');", - " add(new JButton(C_2), 'skip');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "wrap"); + add(new JButton(C_2), "skip"); + } + }"""); panel.refresh(); // convert to explicit cells makeExplicitCell(panel); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 1');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 1"); + } + }"""); } @Test public void test_makeExplicitCell_hasDock() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'north');", - " add(new JButton(C_2), 'skip');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "north"); + add(new JButton(C_2), "skip"); + } + }"""); panel.refresh(); // convert to explicit cells makeExplicitCell(panel); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'north');", - " add(new JButton(C_2), 'cell 1 0');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "north"); + add(new JButton(C_2), "cell 1 0"); + } + }"""); } @Test public void test_makeExplicitCell_split_span_wrap() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'split, span');", - " add(new JButton(C_2), 'wrap');", - " add(new JButton(C_3), '');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "split, span"); + add(new JButton(C_2), "wrap"); + add(new JButton(C_3), ""); + } + }"""); panel.refresh(); // convert to explicit cells makeExplicitCell(panel); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 0');", - " add(new JButton(C_3), 'cell 0 1');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 0"); + add(new JButton(C_3), "cell 0 1"); + } + }"""); } /** @@ -692,14 +674,13 @@ private static void makeExplicitCell(ContainerInfo container) throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_alignment_UNKNOWN() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); CellConstraintsSupport constraints = MigLayoutInfo.getConstraints(button); @@ -711,78 +692,77 @@ public void test_alignment_UNKNOWN() throws Exception { constraints.setHorizontalAlignment(MigColumnInfo.Alignment.CENTER); constraints.setVerticalAlignment(MigRowInfo.Alignment.BOTTOM); constraints.write(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0,alignx center,aligny bottom');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0,alignx center,aligny bottom"); + } + }"""); } // new alignments: 2 { constraints.setHorizontalAlignment(MigColumnInfo.Alignment.FILL); constraints.setVerticalAlignment(MigRowInfo.Alignment.FILL); constraints.write(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0,grow');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0,grow"); + } + }"""); } // new alignments: 3 { constraints.setHorizontalAlignment(MigColumnInfo.Alignment.LEFT); constraints.setVerticalAlignment(MigRowInfo.Alignment.FILL); constraints.write(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0,alignx left,growy');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0,alignx left,growy"); + } + }"""); } // new alignments: 3 { constraints.setHorizontalAlignment(MigColumnInfo.Alignment.LEADING); constraints.setVerticalAlignment(MigRowInfo.Alignment.BASELINE); constraints.write(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0,alignx leading,aligny baseline');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0,alignx leading,aligny baseline"); + } + }"""); } // new alignments: 4 { constraints.setHorizontalAlignment(MigColumnInfo.Alignment.DEFAULT); constraints.setVerticalAlignment(MigRowInfo.Alignment.DEFAULT); constraints.write(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + } + }"""); } } @Test public void test_setAlignment_2() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0, grow');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0, grow"); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); CellConstraintsSupport constraints = MigLayoutInfo.getConstraints(button); @@ -793,25 +773,25 @@ public void test_setAlignment_2() throws Exception { { constraints.setHorizontalAlignment(MigColumnInfo.Alignment.DEFAULT); constraints.write(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0,growy');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0,growy"); + } + }"""); } // new alignments: 2 { constraints.setVerticalAlignment(MigRowInfo.Alignment.DEFAULT); constraints.write(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + } + }"""); } } @@ -857,14 +837,13 @@ public void test_alignmentImageHorizontal_TRAILING() throws Exception { private void check_alignmentImageHorizontal(MigColumnInfo.Alignment alignment, ImageDescriptor descriptor) throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); // check constraints @@ -912,14 +891,13 @@ public void test_alignmentImageVertical_BASELINE() throws Exception { private void check_alignmentImageVertical(MigRowInfo.Alignment alignment, ImageDescriptor descriptor) throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); // check constraints @@ -941,14 +919,13 @@ private void check_alignmentImageVertical(MigRowInfo.Alignment alignment, ImageD */ @Test public void test_contextMenu_ConstraintsAction() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(), '');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout()); + add(new JButton(), ""); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); final CellConstraintsSupport constraints = MigLayoutInfo.getConstraints(button); @@ -984,13 +961,13 @@ public void accept(SWTBot bot) { // changes of "constraints" rolled back assertEquals("", constraints.getString()); // editor also not changed - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(), '');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout()); + add(new JButton(), ""); + } + }"""); } waitEventLoop(5); // open dialog, commit changes @@ -1010,13 +987,13 @@ public void accept(SWTBot bot) { shell.button("OK").click(); } }); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(), 'width 100px');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout()); + add(new JButton(), "width 100px"); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1115,14 +1092,13 @@ private void check_contextMenu_alignment(String managerText, MigColumnInfo.Alignment expectedHorizontalAlignment, MigRowInfo.Alignment expectedVerticalAlignment, String expectedConstraintsSource) throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); // prepare alignment manager @@ -1142,13 +1118,13 @@ private void check_contextMenu_alignment(String managerText, CellConstraintsSupport constraints = MigLayoutInfo.getConstraints(button); assertSame(expectedHorizontalAlignment, constraints.getHorizontalAlignment()); assertSame(expectedVerticalAlignment, constraints.getVerticalAlignment()); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0," + expectedConstraintsSource + "');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0,%s'); + } + }""".formatted(expectedConstraintsSource)); } //////////////////////////////////////////////////////////////////////////// @@ -1158,18 +1134,17 @@ private void check_contextMenu_alignment(String managerText, //////////////////////////////////////////////////////////////////////////// @Test public void test_dock_getDockSide() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'north');", - " add(new JButton(C_2), 'west');", - " add(new JButton(C_3), 'south');", - " add(new JButton(C_4), 'east');", - " add(new JButton(C_5), '');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "north"); + add(new JButton(C_2), "west"); + add(new JButton(C_3), "south"); + add(new JButton(C_4), "east"); + add(new JButton(C_5), ""); + } + }"""); panel.refresh(); { ComponentInfo button_1 = panel.getChildrenComponents().get(0); @@ -1200,14 +1175,13 @@ public void test_dock_getDockSide() throws Exception { @Test public void test_dock_setDockSide() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), '');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), ""); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); CellConstraintsSupport constraints = MigLayoutInfo.getConstraints(button); @@ -1225,13 +1199,13 @@ private void check_setDockSide(CellConstraintsSupport constraints, constraints.setDockSide(sideToSet); assertSame(sideToSet, constraints.getDockSide()); constraints.write(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), '" + expectedConstraints + "');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "%s"); + } + }""".formatted(expectedConstraints)); } //////////////////////////////////////////////////////////////////////////// @@ -1246,15 +1220,14 @@ private void check_setDockSide(CellConstraintsSupport constraints, */ @Test public void test_isHorizontalSplit_1() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0,flowx');", - " add(new JButton(C_2), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0,flowx"); + add(new JButton(C_2), "cell 0 0"); + } + }"""); panel.refresh(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); // @@ -1268,15 +1241,14 @@ public void test_isHorizontalSplit_1() throws Exception { */ @Test public void test_isHorizontalSplit_2() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0,flowy');", - " add(new JButton(C_2), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0,flowy"); + add(new JButton(C_2), "cell 0 0"); + } + }"""); panel.refresh(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); // @@ -1290,15 +1262,14 @@ public void test_isHorizontalSplit_2() throws Exception { */ @Test public void test_isHorizontalSplit_3() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 0"); + } + }"""); panel.refresh(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); // @@ -1312,15 +1283,14 @@ public void test_isHorizontalSplit_3() throws Exception { */ @Test public void test_isHorizontalSplit_4() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout(new LC().flowY()));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout(new LC().flowY())); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 0"); + } + }"""); panel.refresh(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); // @@ -1337,14 +1307,13 @@ public void test_isHorizontalSplit_4() throws Exception { */ @Test public void test_setHorizontalSplit_setExplicitTrue() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + } + }"""); panel.refresh(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); // @@ -1352,13 +1321,13 @@ public void test_setHorizontalSplit_setExplicitTrue() throws Exception { constraints.setHorizontalSplit(Boolean.TRUE); assertTrue(constraints.isHorizontalSplit()); constraints.write(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'flowx,cell 0 0');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "flowx,cell 0 0"); + } + }"""); } /** @@ -1366,14 +1335,13 @@ public void test_setHorizontalSplit_setExplicitTrue() throws Exception { */ @Test public void test_setHorizontalSplit_setExplicitFalse() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + } + }"""); panel.refresh(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); // @@ -1381,13 +1349,13 @@ public void test_setHorizontalSplit_setExplicitFalse() throws Exception { constraints.setHorizontalSplit(Boolean.FALSE); assertFalse(constraints.isHorizontalSplit()); constraints.write(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'flowy,cell 0 0');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "flowy,cell 0 0"); + } + }"""); } /** @@ -1395,14 +1363,13 @@ public void test_setHorizontalSplit_setExplicitFalse() throws Exception { */ @Test public void test_setHorizontalSplit_removeExplicit() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'flowy,cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "flowy,cell 0 0"); + } + }"""); panel.refresh(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); // @@ -1411,12 +1378,12 @@ public void test_setHorizontalSplit_removeExplicit() throws Exception { constraints.setHorizontalSplit(null); assertTrue(constraints.isHorizontalSplit()); constraints.write(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + } + }"""); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutConverterTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutConverterTest.java index 8f3e40b30..719c23f1e 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutConverterTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutConverterTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Google, Inc. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -45,24 +45,23 @@ public void _test_exit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_noComponents() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setSize(450, 300);", - " setLayout(null);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setSize(450, 300); + setLayout(null); + } + }"""); panel.refresh(); // setLayout(panel, MigLayout.class); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setSize(450, 300);", - " setLayout(new MigLayout('', '[]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setSize(450, 300); + setLayout(new MigLayout("", "[]", "[]")); + } + }"""); } /** @@ -71,31 +70,30 @@ public void test_noComponents() throws Exception { */ @Test public void test_zeroSizeComponent() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " JTable table = new JTable();", - " add(table);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler filler filler + public class Test extends JPanel { + public Test() { + { + JTable table = new JTable(); + add(table); + } + } + }"""); panel.refresh(); // setLayout(panel, MigLayout.class); - assertEditor( - "// filler filler filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[1px]', '[1px]'));", - " {", - " JTable table = new JTable();", - " add(table, 'cell 0 0,alignx left,aligny top');", - " }", - " }", - "}"); + assertEditor(""" + // filler filler filler filler filler + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[1px]", "[1px]")); + { + JTable table = new JTable(); + add(table, "cell 0 0,alignx left,aligny top"); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -105,162 +103,158 @@ public void test_zeroSizeComponent() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_oneColumn_LEFT() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setSize(450, 300);", - " setLayout(null);", - " {", - " JButton button = new JButton(C_1);", - " button.setBounds(10, 4, 50, 100);", - " add(button);", - " }", - " {", - " JButton button = new JButton(C_2);", - " button.setBounds(11, 120, 20, 80);", - " add(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setSize(450, 300); + setLayout(null); + { + JButton button = new JButton(C_1); + button.setBounds(10, 4, 50, 100); + add(button); + } + { + JButton button = new JButton(C_2); + button.setBounds(11, 120, 20, 80); + add(button); + } + } + }"""); panel.refresh(); // setLayout(panel, MigLayout.class); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setSize(450, 300);", - " setLayout(new MigLayout('', '[50px]', '[100px][80px]'));", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'cell 0 0,grow');", - " }", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 0 1,alignx left,growy');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setSize(450, 300); + setLayout(new MigLayout("", "[50px]", "[100px][80px]")); + { + JButton button = new JButton(C_1); + add(button, "cell 0 0,grow"); + } + { + JButton button = new JButton(C_2); + add(button, "cell 0 1,alignx left,growy"); + } + } + }"""); } @Test public void test_oneColumn_CENTER() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setSize(450, 300);", - " setLayout(null);", - " {", - " JButton button = new JButton(C_1);", - " button.setBounds(10, 4, 80, 100);", - " add(button);", - " }", - " {", - " JButton button = new JButton(C_2);", - " button.setBounds(40, 120, 20, 80);", - " add(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setSize(450, 300); + setLayout(null); + { + JButton button = new JButton(C_1); + button.setBounds(10, 4, 80, 100); + add(button); + } + { + JButton button = new JButton(C_2); + button.setBounds(40, 120, 20, 80); + add(button); + } + } + }"""); panel.refresh(); // setLayout(panel, MigLayout.class); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setSize(450, 300);", - " setLayout(new MigLayout('', '[80px]', '[100px][80px]'));", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'cell 0 0,grow');", - " }", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 0 1,alignx center,growy');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setSize(450, 300); + setLayout(new MigLayout("", "[80px]", "[100px][80px]")); + { + JButton button = new JButton(C_1); + add(button, "cell 0 0,grow"); + } + { + JButton button = new JButton(C_2); + add(button, "cell 0 1,alignx center,growy"); + } + } + }"""); } @Test public void test_oneColumn_RIGHT() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(null);", - " setSize(450, 300);", - " {", - " JButton button = new JButton(C_1);", - " button.setBounds(10, 4, 50, 100);", - " add(button);", - " }", - " {", - " JButton button = new JButton(C_2);", - " button.setBounds(39, 120, 20, 80);", - " add(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(null); + setSize(450, 300); + { + JButton button = new JButton(C_1); + button.setBounds(10, 4, 50, 100); + add(button); + } + { + JButton button = new JButton(C_2); + button.setBounds(39, 120, 20, 80); + add(button); + } + } + }"""); panel.refresh(); // setLayout(panel, MigLayout.class); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setSize(450, 300);", - " setLayout(new MigLayout('', '[50px]', '[100px][80px]'));", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'cell 0 0,grow');", - " }", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 0 1,alignx right,growy');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setSize(450, 300); + setLayout(new MigLayout("", "[50px]", "[100px][80px]")); + { + JButton button = new JButton(C_1); + add(button, "cell 0 0,grow"); + } + { + JButton button = new JButton(C_2); + add(button, "cell 0 1,alignx right,growy"); + } + } + }"""); } @Test public void test_oneColumn_FILL() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setSize(450, 300);", - " setLayout(null);", - " {", - " JButton button = new JButton(C_1);", - " button.setBounds(10, 4, 50, 100);", - " add(button);", - " }", - " {", - " JButton button = new JButton(C_2);", - " button.setBounds(11, 120, 49, 80);", - " add(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setSize(450, 300); + setLayout(null); + { + JButton button = new JButton(C_1); + button.setBounds(10, 4, 50, 100); + add(button); + } + { + JButton button = new JButton(C_2); + button.setBounds(11, 120, 49, 80); + add(button); + } + } + }"""); panel.refresh(); // setLayout(panel, MigLayout.class); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setSize(450, 300);", - " setLayout(new MigLayout('', '[50px]', '[100px][80px]'));", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'cell 0 0,grow');", - " }", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 0 1,grow');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setSize(450, 300); + setLayout(new MigLayout("", "[50px]", "[100px][80px]")); + { + JButton button = new JButton(C_1); + add(button, "cell 0 0,grow"); + } + { + JButton button = new JButton(C_2); + add(button, "cell 0 1,grow"); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -270,163 +264,159 @@ public void test_oneColumn_FILL() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_oneRow_top() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setSize(450, 300);", - " setLayout(null);", - " {", - " JButton button = new JButton(C_1);", - " button.setBounds(4, 10, 100, 50);", - " add(button);", - " }", - " {", - " JButton button = new JButton(C_2);", - " button.setBounds(120, 11, 80, 20);", - " add(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setSize(450, 300); + setLayout(null); + { + JButton button = new JButton(C_1); + button.setBounds(4, 10, 100, 50); + add(button); + } + { + JButton button = new JButton(C_2); + button.setBounds(120, 11, 80, 20); + add(button); + } + } + }"""); panel.refresh(); // setLayout(panel, MigLayout.class); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setSize(450, 300);", - " setLayout(new MigLayout('', '[100px][80px]', '[50px]'));", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'cell 0 0,grow');", - " }", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 1 0,growx,aligny top');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setSize(450, 300); + setLayout(new MigLayout("", "[100px][80px]", "[50px]")); + { + JButton button = new JButton(C_1); + add(button, "cell 0 0,grow"); + } + { + JButton button = new JButton(C_2); + add(button, "cell 1 0,growx,aligny top"); + } + } + }"""); } @Test public void test_oneRow_center() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setSize(450, 300);", - " setLayout(null);", - " {", - " JButton button = new JButton(C_1);", - " button.setBounds(4, 10, 100, 50);", - " add(button);", - " }", - " {", - " JButton button = new JButton(C_2);", - " button.setBounds(120, 25, 80, 20);", - " add(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setSize(450, 300); + setLayout(null); + { + JButton button = new JButton(C_1); + button.setBounds(4, 10, 100, 50); + add(button); + } + { + JButton button = new JButton(C_2); + button.setBounds(120, 25, 80, 20); + add(button); + } + } + }"""); panel.refresh(); // setLayout(panel, MigLayout.class); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setSize(450, 300);", - " setLayout(new MigLayout('', '[100px][80px]', '[50px]'));", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'cell 0 0,grow');", - " }", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 1 0,growx,aligny center');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setSize(450, 300); + setLayout(new MigLayout("", "[100px][80px]", "[50px]")); + { + JButton button = new JButton(C_1); + add(button, "cell 0 0,grow"); + } + { + JButton button = new JButton(C_2); + add(button, "cell 1 0,growx,aligny center"); + } + } + }"""); } @Test public void test_oneRow_bottom() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setSize(450, 300);", - " setLayout(null);", - " {", - " JButton button = new JButton(C_1);", - " button.setBounds(4, 10, 100, 50);", - " add(button);", - " }", - " {", - " JButton button = new JButton(C_2);", - " button.setBounds(120, 39, 80, 20);", - " add(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setSize(450, 300); + setLayout(null); + { + JButton button = new JButton(C_1); + button.setBounds(4, 10, 100, 50); + add(button); + } + { + JButton button = new JButton(C_2); + button.setBounds(120, 39, 80, 20); + add(button); + } + } + }"""); panel.refresh(); // setLayout(panel, MigLayout.class); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setSize(450, 300);", - " setLayout(new MigLayout('', '[100px][80px]', '[50px]'));", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'cell 0 0,grow');", - " }", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 1 0,growx,aligny bottom');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setSize(450, 300); + setLayout(new MigLayout("", "[100px][80px]", "[50px]")); + { + JButton button = new JButton(C_1); + add(button, "cell 0 0,grow"); + } + { + JButton button = new JButton(C_2); + add(button, "cell 1 0,growx,aligny bottom"); + } + } + }"""); } @Disabled @Test public void test_oneRow_fill() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setSize(450, 300);", - " setLayout(null);", - " {", - " JButton button = new JButton(C_1);", - " button.setBounds(4, 10, 100, 50);", - " add(button);", - " }", - " {", - " JButton button = new JButton(C_2);", - " button.setBounds(120, 11, 80, 39);", - " add(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setSize(450, 300); + setLayout(null); + { + JButton button = new JButton(C_1); + button.setBounds(4, 10, 100, 50); + add(button); + } + { + JButton button = new JButton(C_2); + button.setBounds(120, 11, 80, 39); + add(button); + } + } + }"""); panel.refresh(); // setLayout(panel, MigLayout.class); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setSize(450, 300);", - " setLayout(new MigLayout('', '[100px][80px]', '[50px]'));", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'cell 0 0,grow');", - " }", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 1 0,grow');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setSize(450, 300); + setLayout(new MigLayout("", "[100px][80px]", "[50px]")); + { + JButton button = new JButton(C_1); + add(button, "cell 0 0,grow"); + } + { + JButton button = new JButton(C_2); + add(button, "cell 1 0,grow"); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -436,104 +426,102 @@ public void test_oneRow_fill() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_twoRows_spanColumns() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setSize(450, 300);", - " setLayout(null);", - " {", - " JButton button = new JButton(C_1);", - " button.setBounds(0, 10, 100, 40);", - " add(button);", - " }", - " {", - " JButton button = new JButton(C_2);", - " button.setBounds(110, 10, 80, 20);", - " add(button);", - " }", - " {", - " JButton button = new JButton(C_3);", - " button.setBounds(45, 60, 90, 40);", - " add(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setSize(450, 300); + setLayout(null); + { + JButton button = new JButton(C_1); + button.setBounds(0, 10, 100, 40); + add(button); + } + { + JButton button = new JButton(C_2); + button.setBounds(110, 10, 80, 20); + add(button); + } + { + JButton button = new JButton(C_3); + button.setBounds(45, 60, 90, 40); + add(button); + } + } + }"""); panel.refresh(); // setLayout(panel, MigLayout.class); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setSize(450, 300);", - " setLayout(new MigLayout('', '[100px][10px][80px]', '[40px][40px]'));", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'cell 0 0,grow');", - " }", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 2 0,growx,aligny top');", - " }", - " {", - " JButton button = new JButton(C_3);", - " add(button, 'cell 0 1 3 1,alignx center,growy');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setSize(450, 300); + setLayout(new MigLayout("", "[100px][10px][80px]", "[40px][40px]")); + { + JButton button = new JButton(C_1); + add(button, "cell 0 0,grow"); + } + { + JButton button = new JButton(C_2); + add(button, "cell 2 0,growx,aligny top"); + } + { + JButton button = new JButton(C_3); + add(button, "cell 0 1 3 1,alignx center,growy"); + } + } + }"""); } @Disabled @Test public void test_Switching_fromGridBagLayout() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " GridBagLayout gridBagLayout = new GridBagLayout();", - " gridBagLayout.columnWidths = new int[] { 0, 0, 0, 0 };", - " gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0 };", - " gridBagLayout.columnWeights = new double[] { 0.0, 1.0, 0.0, Double.MIN_VALUE };", - " gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE };", - " setLayout(gridBagLayout);", - " {", - " JComboBox comboBox = new JComboBox();", - " GridBagConstraints gbc = new GridBagConstraints();", - " gbc.insets = new Insets(0, 0, 5, 5);", - " gbc.fill = GridBagConstraints.HORIZONTAL;", - " gbc.gridx = 1;", - " gbc.gridy = 0;", - " add(comboBox, gbc);", - " }", - " {", - " JLabel label = new JLabel('New label');", - " GridBagConstraints gbc = new GridBagConstraints();", - " gbc.insets = new Insets(0, 0, 5, 5);", - " gbc.anchor = GridBagConstraints.EAST;", - " gbc.gridx = 0;", - " gbc.gridy = 1;", - " add(label, gbc);", - " }", - " {", - " JTextField textField = new JTextField();", - " GridBagConstraints gbc = new GridBagConstraints();", - " gbc.gridwidth = 2;", - " gbc.insets = new Insets(0, 0, 5, 5);", - " gbc.fill = GridBagConstraints.HORIZONTAL;", - " gbc.gridx = 1;", - " gbc.gridy = 1;", - " add(textField, gbc);", - " textField.setColumns(10);", - " }", - " {", - " JButton button = new JButton('New button');", - " GridBagConstraints gbc = new GridBagConstraints();", - " gbc.gridx = 2;", - " gbc.gridy = 2;", - " add(button, gbc);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + GridBagLayout gridBagLayout = new GridBagLayout(); + gridBagLayout.columnWidths = new int[] { 0, 0, 0, 0 }; + gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0 }; + gridBagLayout.columnWeights = new double[] { 0.0, 1.0, 0.0, Double.MIN_VALUE }; + gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE }; + setLayout(gridBagLayout); + { + JComboBox comboBox = new JComboBox(); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.insets = new Insets(0, 0, 5, 5); + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.gridx = 1; + gbc.gridy = 0; + add(comboBox, gbc); + } + { + JLabel label = new JLabel('New label'); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.insets = new Insets(0, 0, 5, 5); + gbc.anchor = GridBagConstraints.EAST; + gbc.gridx = 0; + gbc.gridy = 1; + add(label, gbc); + } + { + JTextField textField = new JTextField(); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.gridwidth = 2; + gbc.insets = new Insets(0, 0, 5, 5); + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.gridx = 1; + gbc.gridy = 1; + add(textField, gbc); + textField.setColumns(10); + } + { + JButton button = new JButton("New button"); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.gridx = 2; + gbc.gridy = 2; + add(button, gbc); + } + } + }"""); panel.refresh(); // set FormLayout try { @@ -541,28 +529,28 @@ public void test_Switching_fromGridBagLayout() throws Exception { } finally { panel.refresh_dispose(); } - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[46px][305px][5px][89px]', '[20px][20px][23px]'));", - " {", - " JComboBox comboBox = new JComboBox();", - " add(comboBox, 'cell 1 0,growx,aligny center');", - " }", - " {", - " JLabel label = new JLabel('New label');", - " add(label, 'cell 0 1,alignx right,aligny center');", - " }", - " {", - " JTextField textField = new JTextField();", - " add(textField, 'cell 1 1 3 1,growx,aligny center');", - " textField.setColumns(10);", - " }", - " {", - " JButton button = new JButton('New button');", - " add(button, 'cell 3 2,alignx center,aligny center');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[46px][305px][5px][89px]", "[20px][20px][23px]")); + { + JComboBox comboBox = new JComboBox(); + add(comboBox, "cell 1 0,growx,aligny center"); + } + { + JLabel label = new JLabel("New label"); + add(label, "cell 0 1,alignx right,aligny center"); + } + { + JTextField textField = new JTextField(); + add(textField, "cell 1 1 3 1,growx,aligny center"); + textField.setColumns(10); + } + { + JButton button = new JButton("New button"); + add(button, "cell 3 2,alignx center,aligny center"); + } + } + }"""); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutSelectionActionsTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutSelectionActionsTest.java index 0ccd6caa5..3d8bad3a4 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutSelectionActionsTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutSelectionActionsTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Google, Inc. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -48,14 +48,13 @@ public void _test_exit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_selectionActions_ALL() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(), "cell 0 0"); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); // prepare actions @@ -77,13 +76,12 @@ public void test_selectionActions_ALL() throws Exception { @Test public void test_selectionActions_noSelection() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + } + }"""); panel.refresh(); // prepare actions List actions = new ArrayList<>(); @@ -94,13 +92,12 @@ public void test_selectionActions_noSelection() throws Exception { @Test public void test_selectionActions_invalidSelection() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + } + }"""); panel.refresh(); // prepare actions List actions = new ArrayList<>(); @@ -112,14 +109,13 @@ public void test_selectionActions_invalidSelection() throws Exception { @Test public void test_horizontalAlignment() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(), 'cell 0 0,alignx leading');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(), "cell 0 0,alignx leading"); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); // prepare actions @@ -136,25 +132,24 @@ public void test_horizontalAlignment() throws Exception { rightAction.setChecked(true); rightAction.run(); } - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(), 'cell 0 0,alignx right');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(), "cell 0 0,alignx right"); + } + }"""); } @Test public void test_verticalAlignment() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(), 'cell 0 0,aligny top');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(), "cell 0 0,aligny top"); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); // prepare actions @@ -171,12 +166,12 @@ public void test_verticalAlignment() throws Exception { bottomAction.setChecked(true); bottomAction.run(); } - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(), 'cell 0 0,aligny bottom');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(), "cell 0 0,aligny bottom"); + } + }"""); } } \ No newline at end of file diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutSurroundSupportTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutSurroundSupportTest.java index d21753d98..e1cc8572f 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutSurroundSupportTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutSurroundSupportTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Google, Inc. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -58,25 +58,24 @@ public void _test_exit() throws Exception { */ @Test public void test_0() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JButton button_00 = new JButton();", - " add(button_00, 'cell 0 0');", - " }", - " {", - " JButton button_BAD = new JButton();", - " add(button_BAD, 'cell 0 1');", - " }", - " {", - " JButton button_11 = new JButton();", - " add(button_11, 'cell 1 1');", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout()); + { + JButton button_00 = new JButton(); + add(button_00, "cell 0 0"); + } + { + JButton button_BAD = new JButton(); + add(button_BAD, "cell 0 1"); + } + { + JButton button_11 = new JButton(); + add(button_11, "cell 1 1"); + } + } + }"""); panel.refresh(); ComponentInfo button_00 = getButtons(panel).get(0); ComponentInfo button_11 = getButtons(panel).get(2); @@ -89,35 +88,34 @@ public void test_0() throws Exception { */ @Test public void test_1() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JTable table = new JTable();", - " add(table, 'cell 0 0');", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout()); + { + JTable table = new JTable(); + add(table, "cell 0 0"); + } + } + }"""); panel.refresh(); ComponentInfo table = panel.getChildrenComponents().get(0); // run action runSurround("javax.swing.JScrollPane", table); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[]', '[]'));", - " {", - " JScrollPane scrollPane = new JScrollPane();", - " add(scrollPane, 'cell 0 0,grow');", - " {", - " JTable table = new JTable();", - " scrollPane.setViewportView(table);", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[]", "[]")); + { + JScrollPane scrollPane = new JScrollPane(); + add(scrollPane, "cell 0 0,grow"); + { + JTable table = new JTable(); + scrollPane.setViewportView(table); + } + } + } + }"""); } /** @@ -125,45 +123,44 @@ public void test_1() throws Exception { */ @Test public void test_2() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[][]', '[]'));", - " {", - " JButton button_00 = new JButton();", - " add(button_00, 'cell 0 0');", - " }", - " {", - " JButton button_10 = new JButton();", - " add(button_10, 'cell 1 0');", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[][]", "[]")); + { + JButton button_00 = new JButton(); + add(button_00, "cell 0 0"); + } + { + JButton button_10 = new JButton(); + add(button_10, "cell 1 0"); + } + } + }"""); panel.refresh(); ComponentInfo button_00 = getButtons(panel).get(0); ComponentInfo button_10 = getButtons(panel).get(1); // run action runSurround_Composite(button_00, button_10); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[]', '[]'));", - " {", - " JPanel panel = new JPanel();", - " add(panel, 'cell 0 0,grow');", - " panel.setLayout(new MigLayout('', '[][]', '[]'));", - " {", - " JButton button_00 = new JButton();", - " panel.add(button_00, 'cell 0 0');", - " }", - " {", - " JButton button_10 = new JButton();", - " panel.add(button_10, 'cell 1 0');", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[]", "[]")); + { + JPanel panel = new JPanel(); + add(panel, "cell 0 0,grow"); + panel.setLayout(new MigLayout("", "[][]", "[]")); + { + JButton button_00 = new JButton(); + panel.add(button_00, "cell 0 0"); + } + { + JButton button_10 = new JButton(); + panel.add(button_10, "cell 1 0"); + } + } + } + }"""); } /** @@ -171,45 +168,44 @@ public void test_2() throws Exception { */ @Test public void test_3() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[][]', '[][]'));", - " {", - " JButton button_00 = new JButton();", - " add(button_00, 'cell 0 0');", - " }", - " {", - " JButton button_11 = new JButton();", - " add(button_11, 'cell 1 1');", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[][]", "[][]")); + { + JButton button_00 = new JButton(); + add(button_00, "cell 0 0"); + } + { + JButton button_11 = new JButton(); + add(button_11, "cell 1 1"); + } + } + }"""); panel.refresh(); ComponentInfo button_00 = getButtons(panel).get(0); ComponentInfo button_11 = getButtons(panel).get(1); // run action runSurround_Composite(button_00, button_11); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[]', '[]'));", - " {", - " JPanel panel = new JPanel();", - " add(panel, 'cell 0 0,grow');", - " panel.setLayout(new MigLayout('', '[][]', '[][]'));", - " {", - " JButton button_00 = new JButton();", - " panel.add(button_00, 'cell 0 0');", - " }", - " {", - " JButton button_11 = new JButton();", - " panel.add(button_11, 'cell 1 1');", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[]", "[]")); + { + JPanel panel = new JPanel(); + add(panel, "cell 0 0,grow"); + panel.setLayout(new MigLayout("", "[][]", "[][]")); + { + JButton button_00 = new JButton(); + panel.add(button_00, "cell 0 0"); + } + { + JButton button_11 = new JButton(); + panel.add(button_11, "cell 1 1"); + } + } + } + }"""); } /** @@ -217,54 +213,53 @@ public void test_3() throws Exception { */ @Test public void test_4() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[][]', '[][]'));", - " {", - " JButton button_00 = new JButton();", - " add(button_00, 'cell 0 0');", - " }", - " {", - " JButton button_10 = new JButton();", - " add(button_10, 'cell 1 0');", - " }", - " {", - " JButton button_01 = new JButton();", - " add(button_01, 'cell 0 1 2 1,growx,aligny bottom');", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[][]", "[][]")); + { + JButton button_00 = new JButton(); + add(button_00, "cell 0 0"); + } + { + JButton button_10 = new JButton(); + add(button_10, "cell 1 0"); + } + { + JButton button_01 = new JButton(); + add(button_01, "cell 0 1 2 1,growx,aligny bottom"); + } + } + }"""); panel.refresh(); ComponentInfo button_00 = getButtons(panel).get(0); ComponentInfo button_10 = getButtons(panel).get(1); ComponentInfo button_01 = getButtons(panel).get(2); // run action runSurround_Composite(button_00, button_10, button_01); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[]', '[]'));", - " {", - " JPanel panel = new JPanel();", - " add(panel, 'cell 0 0,grow');", - " panel.setLayout(new MigLayout('', '[][]', '[][]'));", - " {", - " JButton button_00 = new JButton();", - " panel.add(button_00, 'cell 0 0');", - " }", - " {", - " JButton button_10 = new JButton();", - " panel.add(button_10, 'cell 1 0');", - " }", - " {", - " JButton button_01 = new JButton();", - " panel.add(button_01, 'cell 0 1 2 1,growx,aligny bottom');", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[]", "[]")); + { + JPanel panel = new JPanel(); + add(panel, "cell 0 0,grow"); + panel.setLayout(new MigLayout("", "[][]", "[][]")); + { + JButton button_00 = new JButton(); + panel.add(button_00, "cell 0 0"); + } + { + JButton button_10 = new JButton(); + panel.add(button_10, "cell 1 0"); + } + { + JButton button_01 = new JButton(); + panel.add(button_01, "cell 0 1 2 1,growx,aligny bottom"); + } + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutTest.java index 1b3d48c19..9f12ddbfa 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2024 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -91,13 +91,12 @@ public void test_Activator() throws Exception { public void test_setLayoutFromContextMenu() throws Exception { do_projectDispose(); do_projectCreate(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); assertTrue(panel.hasLayout()); // prepare "Set Layout" menu manager IMenuManager layoutManager; @@ -112,14 +111,14 @@ public void test_setLayoutFromContextMenu() throws Exception { IAction action = findChildAction(layoutManager, "MigLayout"); action.run(); m_includeMigImports = false; - assertEditor( - "import net.miginfocom.swing.MigLayout;", - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[]', '[]'));", - " }", - "}"); + assertEditor(""" + import net.miginfocom.swing.MigLayout; + // filler filler filler + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[]", "[]")); + } + }"""); } } @@ -133,15 +132,15 @@ public void test_setLayoutFromContextMenu() throws Exception { */ @Test public void test_dangling() throws Exception { - parseContainer( - "public class Test extends JPanel {", - " private MigLayout m_layout = new MigLayout();", - " public Test() {", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JPanel} {this} {}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}"); + parseContainer(""" + public class Test extends JPanel { + private MigLayout m_layout = new MigLayout(); + public Test() { + } + }"""); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}"""); } /** @@ -149,23 +148,23 @@ public void test_dangling() throws Exception { */ @Test public void test_nonVisual() throws Exception { - parseContainer( - "import java.util.ArrayList;", - "class Test extends JPanel {", - " /**", - " * @wbp.nonvisual location=10,20", - " */", - " private JPanel inner = new JPanel();", - " Test() {", - " inner.setLayout(new MigLayout());", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JPanel} {this} {}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}", - " {NonVisualBeans}", - " {new: javax.swing.JPanel} {field-initializer: inner} {/new JPanel()/ /inner.setLayout(new MigLayout())/}", - " {new: net.miginfocom.swing.MigLayout} {empty} {/inner.setLayout(new MigLayout())/}"); + parseContainer(""" + import java.util.ArrayList; + class Test extends JPanel { + /** + * @wbp.nonvisual location=10,20 + */ + private JPanel inner = new JPanel(); + Test() { + inner.setLayout(new MigLayout()); + } + }"""); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {} + {NonVisualBeans} + {new: javax.swing.JPanel} {field-initializer: inner} {/new JPanel()/ /inner.setLayout(new MigLayout())/} + {new: net.miginfocom.swing.MigLayout} {empty} {/inner.setLayout(new MigLayout())/}"""); refresh(); assertNoErrors(m_lastParseInfo); } @@ -176,23 +175,22 @@ public void test_nonVisual() throws Exception { */ @Test public void test_writeDimensions_constructorProperties() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // do write layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[]", "[]")); + } + }"""); { ConstructorCreationSupport creationSupport = (ConstructorCreationSupport) layout.getCreationSupport(); @@ -207,23 +205,22 @@ public void test_writeDimensions_constructorProperties() throws Exception { */ @Test public void test_writeDimensions_LC() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout(new LC().insets('10 20 30 40')));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout(new LC().insets("10 20 30 40"))); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // do write layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('insets 10 20 30 40', '[]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("insets 10 20 30 40", "[]", "[]")); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -237,16 +234,15 @@ public void test_writeDimensions_LC() throws Exception { @Disabled @Test public void test_IGridInfo() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0, width 100px, height 40px');", - " add(new JButton(C_2), 'cell 1 1, width 150px');", - " add(new JButton(C_3), 'cell 2 1, width 50px');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0, width 100px, height 40px"); + add(new JButton(C_2), "cell 1 1, width 150px"); + add(new JButton(C_3), "cell 2 1, width 50px"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); @@ -331,13 +327,12 @@ public void test_IGridInfo() throws Exception { */ @Test public void test_IGridInfo_emptyColumnRow() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); IGridInfo gridInfo = layout.getGridInfo(); @@ -371,13 +366,12 @@ public void test_IGridInfo_emptyColumnRow() throws Exception { */ @Test public void test_IGridInfo_getCellsRectangle_empty() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][]'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][]")); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); IGridInfo gridInfo = layout.getGridInfo(); @@ -393,15 +387,14 @@ public void test_IGridInfo_getCellsRectangle_empty() throws Exception { */ @Test public void test_IGridInfo_withContainerInsets() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setBorder(new EmptyBorder(10, 20, 30, 40));", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setBorder(new EmptyBorder(10, 20, 30, 40)); + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); IGridInfo gridInfo = layout.getGridInfo(); @@ -430,15 +423,14 @@ public void test_IGridInfo_withContainerInsets() throws Exception { */ @Test public void test_IGridInfo_withSpanSplit() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0 2 1');", - " add(new JButton(C_2), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0 2 1"); + add(new JButton(C_2), "cell 0 0"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); @@ -456,16 +448,15 @@ public void test_IGridInfo_withSpanSplit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_dimensions_1() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0, width 100px, height 40px');", - " add(new JButton(C_2), 'cell 1 1, width 150px');", - " add(new JButton(C_3), 'cell 2 1, width 50px');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0, width 100px, height 40px"); + add(new JButton(C_2), "cell 1 1, width 150px"); + add(new JButton(C_3), "cell 2 1, width 50px"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); { @@ -480,13 +471,12 @@ public void test_dimensions_1() throws Exception { @Test public void test_dimensions_2() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][]', '[][][][]'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][]", "[][][][]")); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); { @@ -504,13 +494,12 @@ public void test_dimensions_2() throws Exception { */ @Test public void test_dimensions_getString() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[10mm:3cm:3in][left]', '[100px,top][]'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[10mm:3cm:3in][left]", "[100px,top][]")); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); { @@ -543,13 +532,12 @@ public void test_dimensions_getString() throws Exception { */ @Test public void test_dimensions_setString() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[]', '[]'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[]", "[]")); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // column := [100px:null,grow] @@ -558,12 +546,12 @@ public void test_dimensions_setString() throws Exception { column.setString("[100px:null,grow]"); assertEquals("[100px:null,grow]", column.getString(true)); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[100px:null,grow]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[100px:null,grow]", "[]")); + } + }"""); } // column := [] { @@ -571,12 +559,12 @@ public void test_dimensions_setString() throws Exception { column.setString("[]"); assertEquals("[]", column.getString(true)); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[]", "[]")); + } + }"""); } // row := [20mm,fill] { @@ -584,12 +572,12 @@ public void test_dimensions_setString() throws Exception { row.setString("[20mm,fill]"); assertEquals("[20mm,fill]", row.getString(true)); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[]', '[20mm,fill]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[]", "[20mm,fill]")); + } + }"""); } } @@ -598,13 +586,12 @@ public void test_dimensions_setString() throws Exception { */ @Test public void test_dimensions_getTooltip() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[10mm:3cm:3in][left]', '[100px,top][]'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[10mm:3cm:3in][left]", "[100px,top][]")); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); { @@ -636,13 +623,12 @@ public void test_dimensions_getTooltip() throws Exception { */ @Test public void test_dimensions_isGrab() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[]', '[]'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[]", "[]")); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); MigColumnInfo column = layout.getColumns().get(0); @@ -652,22 +638,22 @@ public void test_dimensions_isGrab() throws Exception { column.flipGrow(); assertTrue(column.hasGrow()); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[grow]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[grow]", "[]")); + } + }"""); // flip to "false" column.flipGrow(); assertFalse(column.hasGrow()); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[]", "[]")); + } + }"""); } /** @@ -675,13 +661,12 @@ public void test_dimensions_isGrab() throws Exception { */ @Test public void test_dimensions_growWeightPriority() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[]', '[]'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[]", "[]")); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); MigColumnInfo column = layout.getColumns().get(0); @@ -692,67 +677,67 @@ public void test_dimensions_growWeightPriority() throws Exception { { column.setGrow(150f); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[grow 150]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[grow 150]", "[]")); + } + }"""); } // priority := 200 { column.setGrowPriority(200); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[growprio 200,grow 150]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[growprio 200,grow 150]", "[]")); + } + }"""); } // weight := 100, i.e. default { column.setGrow(100f); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[growprio 200,grow]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[growprio 200,grow]", "[]")); + } + }"""); } // weight := 0, i.e. no grow { column.setGrow(0f); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[growprio 200,grow 0]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[growprio 200,grow 0]", "[]")); + } + }"""); } // weight := null, i.e. no grow { column.setGrow(null); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[growprio 200]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[growprio 200]", "[]")); + } + }"""); } // priority := 100, i.e. default { column.setGrowPriority(100); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[]", "[]")); + } + }"""); } } @@ -761,13 +746,12 @@ public void test_dimensions_growWeightPriority() throws Exception { */ @Test public void test_dimensions_shrinkWeightPriority() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[]', '[]'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[]", "[]")); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); MigColumnInfo column = layout.getColumns().get(0); @@ -778,67 +762,67 @@ public void test_dimensions_shrinkWeightPriority() throws Exception { { column.setShrink(150f); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[shrink 150]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[shrink 150]", "[]")); + } + }"""); } // priority := 200 { column.setShrinkPriority(200); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[shrinkprio 200,shrink 150]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[shrinkprio 200,shrink 150]", "[]")); + } + }"""); } // weight := 100, i.e. default { column.setShrink(100f); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[shrinkprio 200]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[shrinkprio 200]", "[]")); + } + }"""); } // weight := 0, i.e. no shrink { column.setShrink(0f); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[shrinkprio 200,shrink 0]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[shrinkprio 200,shrink 0]", "[]")); + } + }"""); } // weight := null, i.e. default shrink { column.setShrink(null); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[shrinkprio 200]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[shrinkprio 200]", "[]")); + } + }"""); } // priority := 100, i.e. default { column.setShrinkPriority(100); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[]", "[]")); + } + }"""); } } @@ -852,15 +836,14 @@ public void test_dimensions_shrinkWeightPriority() throws Exception { */ @Test public void test_ColumnInfo_getAlignment_0() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 0"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // @@ -920,13 +903,12 @@ public void test_ColumnInfo_getAlignment_UNKNOWN() throws Exception { */ private void check_ColumnInfo_getAlignment(String alignmentString, MigColumnInfo.Alignment expectedAlignment) throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '" + alignmentString + "'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "%s")); + } + }""".formatted(alignmentString)); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // check alignment @@ -1024,25 +1006,24 @@ private void check_ColumnInfo_setAlignment(MigColumnInfo.Alignment alignment, private void check_ColumnInfo_setAlignment(String initialArgs, MigColumnInfo.Alignment alignment, String expectedArgs) throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout(" + initialArgs + "));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout(%s)); + } + }""".formatted(initialArgs)); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // set alignment MigColumnInfo column = layout.getColumns().get(0); column.setAlignment(alignment); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout(" + expectedArgs + "));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout(%s)); + } + }""".formatted(expectedArgs)); } //////////////////////////////////////////////////////////////////////////// @@ -1055,15 +1036,14 @@ private void check_ColumnInfo_setAlignment(String initialArgs, */ @Test public void test_RowInfo_getAlignment_0() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 1');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 1"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // @@ -1118,13 +1098,12 @@ public void test_RowInfo_getAlignment_UNKNOWN() throws Exception { */ private void check_RowInfo_getAlignment(String alignmentString, MigRowInfo.Alignment expectedAlignment) throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '', '" + alignmentString + "'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "", "%s")); + } + }""".formatted(alignmentString)); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // check alignment @@ -1205,25 +1184,24 @@ private void check_RowInfo_setAlignment(MigRowInfo.Alignment alignment, String e private void check_RowInfo_setAlignment(String initialArgs, MigRowInfo.Alignment alignment, String expectedArgs) throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout(" + initialArgs + "));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout(%s)); + } + }""".formatted(initialArgs)); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // set alignment MigRowInfo row = layout.getRows().get(0); row.setAlignment(alignment); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout(" + expectedArgs + "));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout(%s)); + } + }""".formatted(expectedArgs)); } //////////////////////////////////////////////////////////////////////////// @@ -1233,13 +1211,12 @@ private void check_RowInfo_setAlignment(String initialArgs, //////////////////////////////////////////////////////////////////////////// @Test public void test_dimensionSize_setCheck() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[100px]', '[]'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[100px]", "[]")); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); MigColumnInfo column = layout.getColumns().get(0); @@ -1253,12 +1230,12 @@ public void test_dimensionSize_setCheck() throws Exception { assertNotNull(column.getMinimumSize()); assertEquals("1cm", column.getString(column.getMinimumSize())); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[1cm:100px]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[1cm:100px]", "[]")); + } + }"""); } // min := 10% { @@ -1266,12 +1243,12 @@ public void test_dimensionSize_setCheck() throws Exception { assertNotNull(column.getMinimumSize()); assertEquals("10%", column.getString(column.getMinimumSize())); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[10%:100px]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[10%:100px]", "[]")); + } + }"""); } // min := null { @@ -1279,24 +1256,24 @@ public void test_dimensionSize_setCheck() throws Exception { assertNull(column.getMinimumSize()); assertEquals(null, column.getString(column.getMinimumSize())); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[100px]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[100px]", "[]")); + } + }"""); } // max := 5cm { column.setMaximumSize("5cm"); assertNotNull(column.getMaximumSize()); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[:100px:5cm]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[:100px:5cm]", "[]")); + } + }"""); } // pref := 20mm { @@ -1307,34 +1284,34 @@ public void test_dimensionSize_setCheck() throws Exception { assertNotNull(column.getPreferredSize()); assertNotNull(column.getMaximumSize()); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[1cm:20mm:5cm]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[1cm:20mm:5cm]", "[]")); + } + }"""); } // size := 1in:2in:3in { column.setSize("1in:2in:3in"); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[1in:2in:3in]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[1in:2in:3in]", "[]")); + } + }"""); } // size := default { column.setSize(null); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[]", "[]")); + } + }"""); } } @@ -1344,13 +1321,12 @@ public void test_dimensionSize_setCheck() throws Exception { @Disabled @Test public void test_dimensionSize_toUnitString() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); { @@ -1397,27 +1373,26 @@ public void test_dimensionSize_toUnitString() throws Exception { */ @Test public void test_normalizeSpanning_1() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(), 'cell 0 0');", - " add(new JButton(), 'cell 1 1');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(), "cell 0 0"); + add(new JButton(), "cell 1 1"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // layout.normalizeSpanning(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][]', '[][]'));", - " add(new JButton(), 'cell 0 0');", - " add(new JButton(), 'cell 1 1');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][]", "[][]")); + add(new JButton(), "cell 0 0"); + add(new JButton(), "cell 1 1"); + } + }"""); } /** @@ -1425,25 +1400,24 @@ public void test_normalizeSpanning_1() throws Exception { */ @Test public void test_normalizeSpanning_2() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[10][20]', '[30][40]'));", - " add(new JButton(), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[10][20]", "[30][40]")); + add(new JButton(), "cell 0 0"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // layout.normalizeSpanning(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[10]', '[30]'));", - " add(new JButton(), 'cell 0 0');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[10]", "[30]")); + add(new JButton(), "cell 0 0"); + } + }"""); } /** @@ -1451,25 +1425,24 @@ public void test_normalizeSpanning_2() throws Exception { */ @Test public void test_normalizeSpanning_3() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[10][20]', '[30][40]'));", - " add(new JButton(), 'cell 1 1');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[10][20]", "[30][40]")); + add(new JButton(), "cell 1 1"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // layout.normalizeSpanning(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[20]', '[40]'));", - " add(new JButton(), 'cell 0 0');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[20]", "[40]")); + add(new JButton(), "cell 0 0"); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1479,30 +1452,29 @@ public void test_normalizeSpanning_3() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_setCells() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 1');", - " add(new JButton(C_3), 'cell 1 2');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 1"); + add(new JButton(C_3), "cell 1 2"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); ComponentInfo button_3 = panel.getChildrenComponents().get(2); // layout.command_setCells(button_3, new Rectangle(0, 1, 1, 2)); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][]', '[][][]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 1');", - " add(new JButton(C_3), 'cell 0 1 1 2');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][]", "[][][]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 1"); + add(new JButton(C_3), "cell 0 1 1 2"); + } + }"""); assertCellBounds(button_3, 0, 1, 1, 2); } @@ -1513,55 +1485,53 @@ public void test_setCells() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_CREATE_existingCell() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // ComponentInfo newButton = createJButton(); layout.command_CREATE(newButton, 0, false, 0, false); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JButton button = new JButton();", - " add(button, 'cell 0 0');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + { + JButton button = new JButton(); + add(button, "cell 0 0"); + } + } + }"""); assertCellBounds(newButton, 0, 0, 1, 1); } @Test public void test_CREATE_appendColumnRow() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // ComponentInfo newButton = createJButton(); layout.command_CREATE(newButton, 1, false, 2, false); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][]', '[][][]'));", - " {", - " JButton button = new JButton();", - " add(button, 'cell 1 2');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][]", "[][][]")); + { + JButton button = new JButton(); + add(button, "cell 1 2"); + } + } + }"""); assertCellBounds(newButton, 1, 2, 1, 1); } @@ -1570,30 +1540,29 @@ public void test_CREATE_appendColumnRow() throws Exception { */ @Test public void test_CREATE_insertColumnRow_1() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 1');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 1"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // ComponentInfo newButton = createJButton(); layout.command_CREATE(newButton, 0, true, 0, true); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][]', '[][][]'));", - " {", - " JButton button = new JButton();", - " add(button, 'cell 0 0');", - " }", - " add(new JButton(C_1), 'cell 1 2');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][]", "[][][]")); + { + JButton button = new JButton(); + add(button, "cell 0 0"); + } + add(new JButton(C_1), "cell 1 2"); + } + }"""); assertCellBounds(newButton, 0, 0, 1, 1); } @@ -1602,34 +1571,33 @@ public void test_CREATE_insertColumnRow_1() throws Exception { */ @Test public void test_CREATE_insertColumnRow_2() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 1');", - " add(new JButton(C_3), 'cell 0 2 2 1');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 1"); + add(new JButton(C_3), "cell 0 2 2 1"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // ComponentInfo newButton = createJButton(); layout.command_CREATE(newButton, 1, true, 3, false); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][][]', '[][][][]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 2 1');", - " add(new JButton(C_3), 'cell 0 2 3 1');", - " {", - " JButton button = new JButton();", - " add(button, 'cell 1 3');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][][]", "[][][][]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 2 1"); + add(new JButton(C_3), "cell 0 2 3 1"); + { + JButton button = new JButton(); + add(button, "cell 1 3"); + } + } + }"""); assertCellBounds(newButton, 1, 3, 1, 1); } @@ -1638,34 +1606,33 @@ public void test_CREATE_insertColumnRow_2() throws Exception { */ @Test public void test_CREATE_insertColumnRow_3() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 1');", - " add(new JButton(C_3), 'cell 2 0 1 2');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 1"); + add(new JButton(C_3), "cell 2 0 1 2"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // ComponentInfo newButton = createJButton(); layout.command_CREATE(newButton, 3, false, 1, true); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][][][]', '[][][]'));", - " add(new JButton(C_1), 'cell 0 0');", - " {", - " JButton button = new JButton();", - " add(button, 'cell 3 1');", - " }", - " add(new JButton(C_2), 'cell 1 2');", - " add(new JButton(C_3), 'cell 2 0 1 3');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][][][]", "[][][]")); + add(new JButton(C_1), "cell 0 0"); + { + JButton button = new JButton(); + add(button, "cell 3 1"); + } + add(new JButton(C_2), "cell 1 2"); + add(new JButton(C_3), "cell 2 0 1 3"); + } + }"""); assertCellBounds(newButton, 3, 1, 1, 1); } @@ -1674,32 +1641,31 @@ public void test_CREATE_insertColumnRow_3() throws Exception { */ @Test public void test_CREATE_insertColumnRow_4() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'north');", - " add(new JButton(C_2), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "north"); + add(new JButton(C_2), "cell 0 0"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // ComponentInfo newButton = createJButton(); layout.command_CREATE(newButton, 0, true, 0, true); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][]', '[][]'));", - " add(new JButton(C_1), 'north');", - " {", - " JButton button = new JButton();", - " add(button, 'cell 0 0');", - " }", - " add(new JButton(C_2), 'cell 1 1');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][]", "[][]")); + add(new JButton(C_1), "north"); + { + JButton button = new JButton(); + add(button, "cell 0 0"); + } + add(new JButton(C_2), "cell 1 1"); + } + }"""); assertCellBounds(newButton, 0, 0, 1, 1); } @@ -1714,32 +1680,31 @@ public void test_CREATE_insertColumnRow_4() throws Exception { */ @Test public void test_MOVE_1() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'cell 0 0');", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + { + JButton button = new JButton(C_1); + add(button, "cell 0 0"); + } + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); ComponentInfo button = panel.getChildrenComponents().get(0); // layout.command_MOVE(button, 1, false, 1, false); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][]', '[][]'));", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'cell 1 1');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][]", "[][]")); + { + JButton button = new JButton(C_1); + add(button, "cell 1 1"); + } + } + }"""); assertCellBounds(button, 1, 1, 1, 1); } @@ -1749,36 +1714,35 @@ public void test_MOVE_1() throws Exception { */ @Test public void test_MOVE_2() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 1');", - " {", - " JButton button = new JButton(C_3);", - " add(button, 'cell 0 2 2 1');", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 1"); + { + JButton button = new JButton(C_3); + add(button, "cell 0 2 2 1"); + } + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); ComponentInfo button_3 = panel.getChildrenComponents().get(2); // layout.command_MOVE(button_3, 0, false, 1, false); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " {", - " JButton button = new JButton(C_3);", - " add(button, 'cell 0 1');", - " }", - " add(new JButton(C_2), 'cell 1 1');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + { + JButton button = new JButton(C_3); + add(button, "cell 0 1"); + } + add(new JButton(C_2), "cell 1 1"); + } + }"""); assertCellBounds(button_3, 0, 1, 1, 1); } @@ -1788,25 +1752,24 @@ public void test_MOVE_2() throws Exception { */ @Test public void test_MOVE_3() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'wrap');", - " }", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'skip');", - " }", - " {", - " JButton button = new JButton(C_3);", - " add(button, '');", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + { + JButton button = new JButton(C_1); + add(button, "wrap"); + } + { + JButton button = new JButton(C_2); + add(button, "skip"); + } + { + JButton button = new JButton(C_3); + add(button, ""); + } + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); @@ -1821,24 +1784,24 @@ public void test_MOVE_3() throws Exception { assertCellBounds(button_1, 0, 0, 1, 1); assertCellBounds(button_2, 1, 2, 1, 1); assertCellBounds(button_3, 2, 1, 1, 1); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][][]', '[][][]'));", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'cell 0 0');", - " }", - " {", - " JButton button = new JButton(C_3);", - " add(button, 'cell 2 1');", - " }", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 1 2');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][][]", "[][][]")); + { + JButton button = new JButton(C_1); + add(button, "cell 0 0"); + } + { + JButton button = new JButton(C_3); + add(button, "cell 2 1"); + } + { + JButton button = new JButton(C_2); + add(button, "cell 1 2"); + } + } + }"""); } /** @@ -1847,25 +1810,24 @@ public void test_MOVE_3() throws Exception { */ @Test public void test_MOVE_4() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'north');", - " }", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 0 0');", - " }", - " {", - " JButton button = new JButton(C_3);", - " add(button, 'cell 1 1');", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + { + JButton button = new JButton(C_1); + add(button, "north"); + } + { + JButton button = new JButton(C_2); + add(button, "cell 0 0"); + } + { + JButton button = new JButton(C_3); + add(button, "cell 1 1"); + } + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // prepare button @@ -1877,24 +1839,24 @@ public void test_MOVE_4() throws Exception { layout.command_MOVE(button, 0, false, 1, false); assertSame(null, constraints.getDockSide()); assertCellBounds(button, 0, 1, 1, 1); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 0 0');", - " }", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'cell 0 1');", - " }", - " {", - " JButton button = new JButton(C_3);", - " add(button, 'cell 1 1');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + { + JButton button = new JButton(C_2); + add(button, "cell 0 0"); + } + { + JButton button = new JButton(C_1); + add(button, "cell 0 1"); + } + { + JButton button = new JButton(C_3); + add(button, "cell 1 1"); + } + } + }"""); } /** @@ -1903,41 +1865,40 @@ public void test_MOVE_4() throws Exception { */ @Test public void test_ADD() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JPanel panel = new JPanel();", - " add(panel, 'cell 0 0');", - " {", - " JButton button = new JButton(C_1);", - " panel.add(button);", - " }", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + { + JPanel panel = new JPanel(); + add(panel, "cell 0 0"); + { + JButton button = new JButton(C_1); + panel.add(button); + } + } + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); ContainerInfo innerPanel = (ContainerInfo) panel.getChildrenComponents().get(0); ComponentInfo button = innerPanel.getChildrenComponents().get(0); // layout.command_MOVE(button, 0, true, 0, true); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][]', '[][]'));", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'cell 0 0');", - " }", - " {", - " JPanel panel = new JPanel();", - " add(panel, 'cell 1 1');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][]", "[][]")); + { + JButton button = new JButton(C_1); + add(button, "cell 0 0"); + } + { + JPanel panel = new JPanel(); + add(panel, "cell 1 1"); + } + } + }"""); assertCellBounds(button, 0, 0, 1, 1); } @@ -1951,18 +1912,17 @@ public void test_ADD() throws Exception { */ @Test public void test_getCellComponents() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 0');", - " add(new JButton(C_3), 'cell 1 0');", - " add(new JButton(C_4), 'cell 1 1');", - " add(new JButton(C_5), 'cell 0 2 2 1');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 0"); + add(new JButton(C_3), "cell 1 0"); + add(new JButton(C_4), "cell 1 1"); + add(new JButton(C_5), "cell 0 2 2 1"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // prepare buttons @@ -1986,15 +1946,14 @@ public void test_getCellComponents() throws Exception { */ @Test public void test_isHorizontalSplit_1() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0,flowx');", - " add(new JButton(C_2), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0,flowx"); + add(new JButton(C_2), "cell 0 0"); + } + }"""); panel.refresh(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); // @@ -2007,15 +1966,14 @@ public void test_isHorizontalSplit_1() throws Exception { */ @Test public void test_isHorizontalSplit_2() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0,flowy');", - " add(new JButton(C_2), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0,flowy"); + add(new JButton(C_2), "cell 0 0"); + } + }"""); panel.refresh(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); // @@ -2028,15 +1986,14 @@ public void test_isHorizontalSplit_2() throws Exception { */ @Test public void test_isHorizontalSplit_3() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 0"); + } + }"""); panel.refresh(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); // @@ -2049,15 +2006,14 @@ public void test_isHorizontalSplit_3() throws Exception { */ @Test public void test_isHorizontalSplit_4() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout(new LC().flowY()));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout(new LC().flowY())); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 0"); + } + }"""); panel.refresh(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); // @@ -2071,31 +2027,30 @@ public void test_isHorizontalSplit_4() throws Exception { */ @Test public void test_splitCREATE_1() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); // ComponentInfo newButton = createJButton(); layout.command_splitCREATE(0, 0, true, newButton, button_1); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JButton button = new JButton();", - " add(button, 'flowx,cell 0 0');", - " }", - " add(new JButton(C_1), 'cell 0 0');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + { + JButton button = new JButton(); + add(button, "flowx,cell 0 0"); + } + add(new JButton(C_1), "cell 0 0"); + } + }"""); } /** @@ -2105,30 +2060,29 @@ public void test_splitCREATE_1() throws Exception { */ @Test public void test_splitCREATE_2() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "cell 0 0"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // ComponentInfo newButton = createJButton(); layout.command_splitCREATE(0, 0, false, newButton, null); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'flowy,cell 0 0');", - " {", - " JButton button = new JButton();", - " add(button, 'cell 0 0');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "flowy,cell 0 0"); + { + JButton button = new JButton(); + add(button, "cell 0 0"); + } + } + }"""); } /** @@ -2138,32 +2092,31 @@ public void test_splitCREATE_2() throws Exception { */ @Test public void test_splitCREATE_3() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'flowy,cell 0 0');", - " add(new JButton(C_2), 'cell 0 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "flowy,cell 0 0"); + add(new JButton(C_2), "cell 0 0"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // ComponentInfo newButton = createJButton(); layout.command_splitCREATE(0, 0, false, newButton, null); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'flowy,cell 0 0');", - " add(new JButton(C_2), 'cell 0 0');", - " {", - " JButton button = new JButton();", - " add(button, 'cell 0 0');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "flowy,cell 0 0"); + add(new JButton(C_2), "cell 0 0"); + { + JButton button = new JButton(); + add(button, "cell 0 0"); + } + } + }"""); } /** @@ -2173,41 +2126,40 @@ public void test_splitCREATE_3() throws Exception { */ @Test public void test_splitMOVE_1() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'flowy,cell 0 0');", - " }", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 0 0');", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + { + JButton button = new JButton(C_1); + add(button, "flowy,cell 0 0"); + } + { + JButton button = new JButton(C_2); + add(button, "cell 0 0"); + } + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); ComponentInfo button_2 = panel.getChildrenComponents().get(1); // layout.command_splitMOVE(0, 0, true, button_2, button_1); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'flowy,cell 0 0');", - " }", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'cell 0 0');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + { + JButton button = new JButton(C_2); + add(button, "flowy,cell 0 0"); + } + { + JButton button = new JButton(C_1); + add(button, "cell 0 0"); + } + } + }"""); } /** @@ -2217,40 +2169,39 @@ public void test_splitMOVE_1() throws Exception { */ @Test public void test_splitMOVE_2() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'cell 0 0');", - " }", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 1 0');", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + { + JButton button = new JButton(C_1); + add(button, "cell 0 0"); + } + { + JButton button = new JButton(C_2); + add(button, "cell 1 0"); + } + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); ComponentInfo button_2 = panel.getChildrenComponents().get(1); // layout.command_splitMOVE(0, 0, true, button_2, null); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'flowx,cell 0 0');", - " }", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 0 0');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + { + JButton button = new JButton(C_1); + add(button, "flowx,cell 0 0"); + } + { + JButton button = new JButton(C_2); + add(button, "cell 0 0"); + } + } + }"""); } /** @@ -2258,48 +2209,47 @@ public void test_splitMOVE_2() throws Exception { */ @Test public void test_splitMOVE_3() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'flowx,cell 0 0');", - " }", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 0 0');", - " }", - " {", - " JButton button = new JButton(C_3);", - " add(button, 'cell 0 0');", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + { + JButton button = new JButton(C_1); + add(button, "flowx,cell 0 0"); + } + { + JButton button = new JButton(C_2); + add(button, "cell 0 0"); + } + { + JButton button = new JButton(C_3); + add(button, "cell 0 0"); + } + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); // layout.command_MOVE(button_1, 1, false, 0, false); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][]', '[]'));", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'flowx,cell 0 0');", - " }", - " {", - " JButton button = new JButton(C_3);", - " add(button, 'cell 0 0');", - " }", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'cell 1 0');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][]", "[]")); + { + JButton button = new JButton(C_2); + add(button, "flowx,cell 0 0"); + } + { + JButton button = new JButton(C_3); + add(button, "cell 0 0"); + } + { + JButton button = new JButton(C_1); + add(button, "cell 1 0"); + } + } + }"""); } /** @@ -2307,43 +2257,42 @@ public void test_splitMOVE_3() throws Exception { */ @Test public void test_splitDELETE_1() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'flowx,cell 0 0');", - " }", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 0 0');", - " }", - " {", - " JButton button = new JButton(C_3);", - " add(button, 'cell 0 0');", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + { + JButton button = new JButton(C_1); + add(button, "flowx,cell 0 0"); + } + { + JButton button = new JButton(C_2); + add(button, "cell 0 0"); + } + { + JButton button = new JButton(C_3); + add(button, "cell 0 0"); + } + } + }"""); panel.refresh(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); // button_1.delete(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'flowx,cell 0 0');", - " }", - " {", - " JButton button = new JButton(C_3);", - " add(button, 'cell 0 0');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + { + JButton button = new JButton(C_2); + add(button, "flowx,cell 0 0"); + } + { + JButton button = new JButton(C_3); + add(button, "cell 0 0"); + } + } + }"""); } /** @@ -2352,35 +2301,34 @@ public void test_splitDELETE_1() throws Exception { */ @Test public void test_splitDELETE_2() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JButton button = new JButton(C_1);", - " add(button, 'flowx,cell 0 0');", - " }", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 0 0');", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + { + JButton button = new JButton(C_1); + add(button, "flowx,cell 0 0"); + } + { + JButton button = new JButton(C_2); + add(button, "cell 0 0"); + } + } + }"""); panel.refresh(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); // button_1.delete(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " {", - " JButton button = new JButton(C_2);", - " add(button, 'cell 0 0');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + { + JButton button = new JButton(C_2); + add(button, "cell 0 0"); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -2390,16 +2338,15 @@ public void test_splitDELETE_2() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_dock_1() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout());", - " add(new JButton(C_1), 'dock north');", - " add(new JButton(C_2), 'west');", - " add(new JButton('long text'), '');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout()); + add(new JButton(C_1), "dock north"); + add(new JButton(C_2), "west"); + add(new JButton("long text"), ""); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // check constraints @@ -2425,13 +2372,12 @@ public void test_dock_1() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_gaps_1() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[]10px[]20px[]', '[]'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[]10px[]20px[]", "[]")); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // prepare columns @@ -2461,12 +2407,12 @@ public void test_gaps_1() throws Exception { assertEquals("5mm", column_1.getString(column_1.getGapBefore())); assertEquals("5mm", column_0.getString(column_0.getGapAfter())); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[]5mm[]20px[]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[]5mm[]20px[]", "[]")); + } + }"""); } // setGapAfter() { @@ -2474,12 +2420,12 @@ public void test_gaps_1() throws Exception { assertEquals("10mm", column_1.getString(column_1.getGapAfter())); assertEquals("10mm", column_2.getString(column_2.getGapBefore())); layout.writeDimensions(); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[]5mm[]10mm[]', '[]'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[]5mm[]10mm[]", "[]")); + } + }"""); } } @@ -2493,29 +2439,28 @@ public void test_gaps_1() throws Exception { */ @Test public void test_column_INSERT() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[100px][200px]', ''));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 1 2 1');", - " add(new JButton(C_3), 'cell 1 2');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[100px][200px]", "")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 1 2 1"); + add(new JButton(C_3), "cell 1 2"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // layout.insertColumn(1); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[100px][][200px]', '[][][]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 1 3 1');", - " add(new JButton(C_3), 'cell 2 2');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[100px][][200px]", "[][][]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 1 3 1"); + add(new JButton(C_3), "cell 2 2"); + } + }"""); } /** @@ -2523,30 +2468,29 @@ public void test_column_INSERT() throws Exception { */ @Test public void test_column_DELETE() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[100px][150px][200px]', '[][][]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 1 3 1');", - " add(new JButton(C_3), 'cell 2 2');", - " add(new JButton(C_4), 'cell 1 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[100px][150px][200px]", "[][][]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 1 3 1"); + add(new JButton(C_3), "cell 2 2"); + add(new JButton(C_4), "cell 1 0"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // layout.deleteColumn(1); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[100px][200px]', '[][][]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 1 2 1');", - " add(new JButton(C_3), 'cell 1 2');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[100px][200px]", "[][][]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 1 2 1"); + add(new JButton(C_3), "cell 1 2"); + } + }"""); } /** @@ -2554,30 +2498,29 @@ public void test_column_DELETE() throws Exception { */ @Test public void test_column_CLEAR() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[100px][150px][200px]', '[][][]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 1 3 1');", - " add(new JButton(C_3), 'cell 2 2');", - " add(new JButton(C_4), 'cell 1 0');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[100px][150px][200px]", "[][][]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 1 3 1"); + add(new JButton(C_3), "cell 2 2"); + add(new JButton(C_4), "cell 1 0"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // layout.clearColumn(1); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[100px][150px][200px]', '[][][]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 1 3 1');", - " add(new JButton(C_3), 'cell 2 2');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[100px][150px][200px]", "[][][]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 1 3 1"); + add(new JButton(C_3), "cell 2 2"); + } + }"""); } /** @@ -2585,29 +2528,28 @@ public void test_column_CLEAR() throws Exception { */ @Test public void test_column_SPLIT() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[100px][200px][300px]', '[][][]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 1');", - " add(new JButton(C_3), 'cell 2 2');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[100px][200px][300px]", "[][][]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 1"); + add(new JButton(C_3), "cell 2 2"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // layout.splitColumn(1); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[100px][200px][200px][300px]', '[][][]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 1 2 1');", - " add(new JButton(C_3), 'cell 3 2');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[100px][200px][200px][300px]", "[][][]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 1 2 1"); + add(new JButton(C_3), "cell 3 2"); + } + }"""); } /** @@ -2633,33 +2575,32 @@ public void test_column_SPLIT() throws Exception { */ @Test public void test_column_MOVE_backward() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[10px][20px][30px][40px][50px]', '[][][][][]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 1 2 1');", - " add(new JButton(C_3), 'cell 3 2');", - " add(new JButton(C_4), 'cell 2 3 3 1');", - " add(new JButton(C_5), 'cell 4 4');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[10px][20px][30px][40px][50px]", "[][][][][]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 1 2 1"); + add(new JButton(C_3), "cell 3 2"); + add(new JButton(C_4), "cell 2 3 3 1"); + add(new JButton(C_5), "cell 4 4"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // layout.moveColumn(3, 1); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[10px][40px][20px][30px][50px]', '[][][][][]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 1 3 1');", - " add(new JButton(C_3), 'cell 1 2');", - " add(new JButton(C_4), 'cell 3 3 2 1');", - " add(new JButton(C_5), 'cell 4 4');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[10px][40px][20px][30px][50px]", "[][][][][]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 1 3 1"); + add(new JButton(C_3), "cell 1 2"); + add(new JButton(C_4), "cell 3 3 2 1"); + add(new JButton(C_5), "cell 4 4"); + } + }"""); } /** @@ -2685,33 +2626,32 @@ public void test_column_MOVE_backward() throws Exception { */ @Test public void test_column_MOVE_forward() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[10px][40px][20px][30px][50px]', '[][][][][]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 1 3 1');", - " add(new JButton(C_3), 'cell 1 2');", - " add(new JButton(C_4), 'cell 3 3 2 1');", - " add(new JButton(C_5), 'cell 4 4');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[10px][40px][20px][30px][50px]", "[][][][][]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 1 3 1"); + add(new JButton(C_3), "cell 1 2"); + add(new JButton(C_4), "cell 3 3 2 1"); + add(new JButton(C_5), "cell 4 4"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // layout.moveColumn(1, 4); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[10px][20px][30px][40px][50px]', '[][][][][]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 0 1 2 1');", - " add(new JButton(C_3), 'cell 3 2');", - " add(new JButton(C_4), 'cell 2 3 3 1');", - " add(new JButton(C_5), 'cell 4 4');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[10px][20px][30px][40px][50px]", "[][][][][]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 0 1 2 1"); + add(new JButton(C_3), "cell 3 2"); + add(new JButton(C_4), "cell 2 3 3 1"); + add(new JButton(C_5), "cell 4 4"); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -2735,29 +2675,28 @@ public void test_column_MOVE_forward() throws Exception { */ @Test public void test_row_INSERT() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][][]', '[100px][200px]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 0 1 2');", - " add(new JButton(C_3), 'cell 2 1');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][][]", "[100px][200px]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 0 1 2"); + add(new JButton(C_3), "cell 2 1"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // layout.insertRow(1); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][][]', '[100px][][200px]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 0 1 3');", - " add(new JButton(C_3), 'cell 2 2');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][][]", "[100px][][200px]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 0 1 3"); + add(new JButton(C_3), "cell 2 2"); + } + }"""); } /** @@ -2776,30 +2715,29 @@ public void test_row_INSERT() throws Exception { */ @Test public void test_row_DELETE() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][][]', '[100px][][200px]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 0 1 3');", - " add(new JButton(C_3), 'cell 2 2');", - " add(new JButton(C_4), 'cell 2 1');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][][]", "[100px][][200px]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 0 1 3"); + add(new JButton(C_3), "cell 2 2"); + add(new JButton(C_4), "cell 2 1"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // layout.deleteRow(1); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][][]', '[100px][200px]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 0 1 2');", - " add(new JButton(C_3), 'cell 2 1');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][][]", "[100px][200px]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 0 1 2"); + add(new JButton(C_3), "cell 2 1"); + } + }"""); } /** @@ -2819,30 +2757,29 @@ public void test_row_DELETE() throws Exception { */ @Test public void test_row_CLEAR() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][][]', '[100px][200px][300px]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 0 1 3');", - " add(new JButton(C_3), 'cell 2 2');", - " add(new JButton(C_4), 'cell 2 1');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][][]", "[100px][200px][300px]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 0 1 3"); + add(new JButton(C_3), "cell 2 2"); + add(new JButton(C_4), "cell 2 1"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // layout.clearRow(1); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][][]', '[100px][200px][300px]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 0 1 3');", - " add(new JButton(C_3), 'cell 2 2');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][][]", "[100px][200px][300px]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 0 1 3"); + add(new JButton(C_3), "cell 2 2"); + } + }"""); } /** @@ -2863,29 +2800,28 @@ public void test_row_CLEAR() throws Exception { */ @Test public void test_row_SPLIT() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][][]', '[100px][200px][300px]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 1');", - " add(new JButton(C_3), 'cell 2 2');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][][]", "[100px][200px][300px]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 1"); + add(new JButton(C_3), "cell 2 2"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // layout.splitRow(1); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][][]', '[100px][200px][200px][300px]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 1 1 2');", - " add(new JButton(C_3), 'cell 2 3');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][][]", "[100px][200px][200px][300px]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 1 1 2"); + add(new JButton(C_3), "cell 2 3"); + } + }"""); } /** @@ -2909,33 +2845,32 @@ public void test_row_SPLIT() throws Exception { */ @Test public void test_row_MOVE_backward() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][][][][]', '[10px][20px][30px][40px][50px]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 0 1 2');", - " add(new JButton(C_3), 'cell 2 3');", - " add(new JButton(C_4), 'cell 3 2 1 3');", - " add(new JButton(C_5), 'cell 4 4');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][][][][]", "[10px][20px][30px][40px][50px]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 0 1 2"); + add(new JButton(C_3), "cell 2 3"); + add(new JButton(C_4), "cell 3 2 1 3"); + add(new JButton(C_5), "cell 4 4"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // layout.moveRow(3, 1); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][][][][]', '[10px][40px][20px][30px][50px]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 0 1 3');", - " add(new JButton(C_3), 'cell 2 1');", - " add(new JButton(C_4), 'cell 3 3 1 2');", - " add(new JButton(C_5), 'cell 4 4');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][][][][]", "[10px][40px][20px][30px][50px]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 0 1 3"); + add(new JButton(C_3), "cell 2 1"); + add(new JButton(C_4), "cell 3 3 1 2"); + add(new JButton(C_5), "cell 4 4"); + } + }"""); } /** @@ -2959,33 +2894,32 @@ public void test_row_MOVE_backward() throws Exception { */ @Test public void test_row_MOVE_forward() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][][][][]', '[10px][40px][20px][30px][50px]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 0 1 3');", - " add(new JButton(C_3), 'cell 2 1');", - " add(new JButton(C_4), 'cell 3 3 1 2');", - " add(new JButton(C_5), 'cell 4 4');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][][][][]", "[10px][40px][20px][30px][50px]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 0 1 3"); + add(new JButton(C_3), "cell 2 1"); + add(new JButton(C_4), "cell 3 3 1 2"); + add(new JButton(C_5), "cell 4 4"); + } + }"""); panel.refresh(); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); // layout.moveRow(1, 4); - assertEditor( - "public class Test extends JPanel implements IConstants {", - " public Test() {", - " setLayout(new MigLayout('', '[][][][][]', '[10px][20px][30px][40px][50px]'));", - " add(new JButton(C_1), 'cell 0 0');", - " add(new JButton(C_2), 'cell 1 0 1 2');", - " add(new JButton(C_3), 'cell 2 3');", - " add(new JButton(C_4), 'cell 3 2 1 3');", - " add(new JButton(C_5), 'cell 4 4');", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel implements IConstants { + public Test() { + setLayout(new MigLayout("", "[][][][][]", "[10px][20px][30px][40px][50px]")); + add(new JButton(C_1), "cell 0 0"); + add(new JButton(C_2), "cell 1 0 1 2"); + add(new JButton(C_3), "cell 2 3"); + add(new JButton(C_4), "cell 3 2 1 3"); + add(new JButton(C_5), "cell 4 4"); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -2998,13 +2932,12 @@ public void test_row_MOVE_forward() throws Exception { */ @Test public void test_canChangeDimensions_constructor() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout()); + } + }"""); // MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); assertTrue(layout.canChangeDimensions()); @@ -3016,25 +2949,23 @@ public void test_canChangeDimensions_constructor() throws Exception { @Test public void test_canChangeDimensions_implicit() throws Exception { setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class MyPanel extends JPanel {", - " public MyPanel() {", - " setLayout(new MigLayout());", - " }", - "}")); + "test/MyPanel.java", getTestSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class MyPanel extends JPanel { + public MyPanel() { + setLayout(new MigLayout()); + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); assertFalse(layout.canChangeDimensions()); @@ -3050,13 +2981,12 @@ public void test_canChangeDimensions_implicit() throws Exception { */ @Test public void test_DimensionsProperty() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[10mm:3cm:3in][left]', '[100px,top][]'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[10mm:3cm:3in][left]", "[100px,top][]")); + } + }"""); MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout(); panel.refresh(); // columnSpecs @@ -3084,13 +3014,12 @@ public void test_DimensionsProperty() throws Exception { */ @Test public void test_editColumnsRowsActions() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new MigLayout('', '[10mm:3cm:3in][left]', '[100px,top][]'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new MigLayout("", "[10mm:3cm:3in][left]", "[100px,top][]")); + } + }"""); // check for actions MenuManager menuManager = getDesignerMenuManager(); panel.getBroadcastObject().addContextMenu(List.of(panel), panel, menuManager);