Skip to content
Merged
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
Expand Up @@ -18,7 +18,6 @@

import net.miginfocom.swing.MigLayout;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import javax.swing.JTable;
Expand Down Expand Up @@ -379,7 +378,6 @@ public Test() {
}""");
}

@Disabled
@Test
public void test_oneRow_fill() throws Exception {
ContainerInfo panel = parseContainer("""
Expand Down Expand Up @@ -472,7 +470,6 @@ public Test() {
}""");
}

@Disabled
@Test
public void test_Switching_fromGridBagLayout() throws Exception {
ContainerInfo panel = parseContainer("""
Expand All @@ -486,6 +483,8 @@ public Test() {
setLayout(gridBagLayout);
{
JComboBox comboBox = new JComboBox();
comboBox.setMinimumSize(new Dimension(46, 20));
comboBox.setPreferredSize(new Dimension(46, 20));
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(0, 0, 5, 5);
gbc.fill = GridBagConstraints.HORIZONTAL;
Expand All @@ -495,6 +494,8 @@ public Test() {
}
{
JLabel label = new JLabel('New label');
label.setMinimumSize(new Dimension(46, 20));
label.setPreferredSize(new Dimension(46, 20));
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(0, 0, 5, 5);
gbc.anchor = GridBagConstraints.EAST;
Expand All @@ -504,6 +505,8 @@ public Test() {
}
{
JTextField textField = new JTextField();
textField.setMinimumSize(new Dimension(140, 20));
textField.setPreferredSize(new Dimension(140, 20));
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridwidth = 2;
gbc.insets = new Insets(0, 0, 5, 5);
Expand All @@ -515,6 +518,8 @@ public Test() {
}
{
JButton button = new JButton("New button");
button.setMinimumSize(new Dimension(89, 23));
button.setPreferredSize(new Dimension(89, 23));
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 2;
gbc.gridy = 2;
Expand All @@ -535,19 +540,27 @@ public Test() {
setLayout(new MigLayout("", "[46px][305px][5px][89px]", "[20px][20px][23px]"));
{
JComboBox comboBox = new JComboBox();
comboBox.setMinimumSize(new Dimension(46, 20));
comboBox.setPreferredSize(new Dimension(46, 20));
add(comboBox, "cell 1 0,growx,aligny center");
}
{
JLabel label = new JLabel("New label");
label.setMinimumSize(new Dimension(46, 20));
label.setPreferredSize(new Dimension(46, 20));
add(label, "cell 0 1,alignx right,aligny center");
}
{
JTextField textField = new JTextField();
textField.setMinimumSize(new Dimension(140, 20));
textField.setPreferredSize(new Dimension(140, 20));
add(textField, "cell 1 1 3 1,growx,aligny center");
textField.setColumns(10);
}
{
JButton button = new JButton("New button");
button.setMinimumSize(new Dimension(89, 23));
button.setPreferredSize(new Dimension(89, 23));
add(button, "cell 3 2,alignx center,aligny center");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@
import org.eclipse.swt.widgets.Display;

import net.miginfocom.layout.LC;
import net.miginfocom.layout.PlatformDefaults;
import net.miginfocom.swing.MigLayout;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.awt.Toolkit;
import java.util.List;
import java.util.Locale;

import javax.swing.JButton;

Expand All @@ -61,6 +65,22 @@ public void _test_exit() throws Exception {
System.exit(0);
}

@BeforeAll
public static void setUpPlatformDefaults() {
// The actual DPI might be platform-specific
int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
PlatformDefaults.setDefaultDPI(96);
PlatformDefaults.setHorizontalScaleFactor(dpi / 96.0f);
PlatformDefaults.setVerticalScaleFactor(dpi / 96.0f);
}

@AfterAll
public static void tearDownPlatformDefaults() {
PlatformDefaults.setDefaultDPI(null);
PlatformDefaults.setHorizontalScaleFactor(null);
PlatformDefaults.setVerticalScaleFactor(null);
}

////////////////////////////////////////////////////////////////////////////
//
// Activator
Expand Down Expand Up @@ -228,16 +248,30 @@ public Test() {
/**
* Test for {@link IGridInfo}.
*/
@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");
setLayout(new MigLayout("insets 7 7 0 0, gapx 4, gapy 4"));
{
JButton button = new JButton(C_1);
button.setMinimumSize(new Dimension(40, 23));
button.setPreferredSize(new Dimension(40, 23));
add(button, "cell 0 0, width 100px, height 40px");
}
{
JButton button = new JButton(C_2);
button.setMinimumSize(new Dimension(40, 23));
button.setPreferredSize(new Dimension(40, 23));
add(button, "cell 1 1, width 150px");
}
{
JButton button = new JButton(C_2);
button.setMinimumSize(new Dimension(40, 23));
button.setPreferredSize(new Dimension(40, 23));
add(button, "cell 2 1, width 50px");
}
}
}""");
panel.refresh();
Expand All @@ -251,17 +285,17 @@ public Test() {
assertEquals(3, gridInfo.getColumnCount());
Interval[] columnIntervals = gridInfo.getColumnIntervals();
Assertions.assertThat(columnIntervals).hasSize(3);
assertEquals("Interval(7, 100)", columnIntervals[0].toString());
assertEquals("Interval(111, 150)", columnIntervals[1].toString());
assertEquals("Interval(265, 50)", columnIntervals[2].toString());
assertEquals("Interval[begin=7, length=100]", columnIntervals[0].toString());
assertEquals("Interval[begin=111, length=150]", columnIntervals[1].toString());
assertEquals("Interval[begin=265, length=50]", columnIntervals[2].toString());
}
// rows
{
assertEquals(2, gridInfo.getRowCount());
Interval[] rowIntervals = gridInfo.getRowIntervals();
Assertions.assertThat(rowIntervals).hasSize(2);
assertEquals("Interval(7, 40)", rowIntervals[0].toString());
assertEquals("Interval(51, 23)", rowIntervals[1].toString());
assertEquals("Interval[begin=7, length=40]", rowIntervals[0].toString());
assertEquals("Interval[begin=51, length=23]", rowIntervals[1].toString());
}
// cells
{
Expand Down Expand Up @@ -1300,7 +1334,6 @@ public Test() {
/**
* Test for {@link MigDimensionInfo#toUnitString(int, String)}.
*/
@Disabled
@Test
public void test_dimensionSize_toUnitString() throws Exception {
ContainerInfo panel = parseContainer("""
Expand All @@ -1316,35 +1349,23 @@ public Test() {
assertEquals("2.65cm", column.toUnitString(100, "cm"));
assertEquals("22.22%", column.toUnitString(100, "%"));
// check "sp" unit
String expected_sp;
int displayWidth = Display.getDefault().getBounds().width;
if (displayWidth == 1920) {
expected_sp = "5.21sp";
} else if (displayWidth == 1680) {
expected_sp = "5.95sp";
} else {
throw new AssertionError("Unknown display width: " + displayWidth);
}
String expected_sp = getScreenPercentage(100, Display.getDefault().getPrimaryMonitor().getBounds().width);
assertEquals(expected_sp, column.toUnitString(100, "sp"));
}
{
MigRowInfo row = layout.getRows().get(0);
assertEquals("2.65cm", row.toUnitString(100, "cm"));
assertEquals("33.33%", row.toUnitString(100, "%"));
// check "sp" unit
int displayHeight = Display.getDefault().getBounds().height;
String expected_sp;
if (displayHeight == 1200) {
expected_sp = "8.33sp";
} else if (displayHeight == 1050) {
expected_sp = "9.52sp";
} else {
throw new AssertionError("Unknown display width: " + displayHeight);
}
String expected_sp = getScreenPercentage(100, Display.getDefault().getPrimaryMonitor().getBounds().height);
assertEquals(expected_sp, row.toUnitString(100, "sp"));
}
}

private static String getScreenPercentage(int size, int monitorSize) {
return String.format(Locale.ENGLISH, "%.2fsp", size * (size / (float) monitorSize));
}

////////////////////////////////////////////////////////////////////////////
//
// normalizeSpanning()
Expand Down
Loading