Skip to content

Commit c181ce4

Browse files
committed
F!! converting paintables to jPanel
1 parent 5790251 commit c181ce4

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

approvaltests-tests/src/test/java/org/approvaltests/awt/ApprovalsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void customPanel()
1818
final CustomPanel panel = new CustomPanel();
1919
AwtApprovals.verify(panel);
2020
}
21-
// @DisabledOnJre({JRE.JAVA_8})
21+
// @DisabledOnJre({JRE.JAVA_8})
2222
@Disabled("continue here next week")
2323
@Test
2424
void customPanelWithText()

approvaltests-tests/src/test/java/org/approvaltests/awt/CustomPanel.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.spun.swing.Paintable;
44
import com.spun.swing.SwingUtils;
5+
import com.spun.util.WindowUtils;
56

67
import java.awt.Color;
78
import java.awt.Dimension;
@@ -10,6 +11,10 @@
1011

1112
public class CustomPanel implements Paintable
1213
{
14+
public static void main(String[] args)
15+
{
16+
WindowUtils.testPaintable(new CustomPanel());
17+
}
1318
private int length = 10;
1419
private boolean showCoordinated;
1520
public CustomPanel()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.spun.util;
2+
3+
import com.spun.swing.Paintable;
4+
5+
import java.awt.Graphics;
6+
import javax.swing.JPanel;
7+
8+
public class Paintables
9+
{
10+
public static JPanel asPanel(Paintable paintable)
11+
{
12+
return new JPanel()
13+
{
14+
{
15+
setPreferredSize(paintable.getSize());
16+
}
17+
@Override
18+
public void paint(Graphics g)
19+
{
20+
paintable.paint(g);
21+
}
22+
};
23+
}
24+
}

approvaltests-util/src/main/java/com/spun/util/WindowUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import javax.swing.JOptionPane;
88
import javax.swing.JPanel;
99

10+
import com.spun.swing.Paintable;
1011
import com.spun.util.logger.SimpleLogger;
1112

1213
public class WindowUtils
@@ -28,6 +29,10 @@ public static void testPanel(JPanel panel)
2829
test.getContentPane().add(panel);
2930
testFrame(test, true);
3031
}
32+
public static void testPaintable(Paintable paintable)
33+
{
34+
testPanel(Paintables.asPanel(paintable));
35+
}
3136
public static void testFrame(JFrame frame)
3237
{
3338
testFrame(frame, true);
@@ -68,4 +73,4 @@ public static void testFrame(JFrame frame, WindowAdapter... array)
6873
WindowUtils.centerWindow(frame);
6974
frame.setVisible(true);
7075
}
71-
}
76+
}

todo.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
* Approvals.options.forName.asMachineNameSpecificTest().onlyForEnvironments("Larss-Air.lan", "macbook13").run(this::extracted);
33
* better default FrontloadedReporter to handle CI
4-
4+
+ docs for graph for ci consistent
55

66
* easier API for custom file name & location?! (issue 2, 51)
77
** documentation for Options.forFile()

0 commit comments

Comments
 (0)