Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -81,31 +80,30 @@ 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);
}
}
}""");
}

/**
* Test that horizontal grab/fill for {@link JTextField} can be disabled.
*/
@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
Expand All @@ -115,31 +113,30 @@ 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);
}
}
}""");
}

/**
* For {@link JTable} marked as required horizontal/vertical grab/fill.
*/
@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
Expand All @@ -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");
}
}
}""");
}

/**
Expand All @@ -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
Expand All @@ -185,38 +181,37 @@ 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");
}
}
}""");
}

/**
* Check that automatic "right alignment" feature for {@link JLabel} can be disabled.
*/
@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
Expand All @@ -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");
}
}
}""");
}

/**
Expand All @@ -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
Expand All @@ -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);
}
}
}""");
}
}
Loading
Loading