Skip to content

Commit d278043

Browse files
committed
8367772: Refactor createUI in PassFailJFrame
Reviewed-by: dnguyen, honkar
1 parent 62fa971 commit d278043

File tree

1 file changed

+22
-47
lines changed

1 file changed

+22
-47
lines changed

test/jdk/java/awt/regtesthelpers/PassFailJFrame.java

Lines changed: 22 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,11 @@ public PassFailJFrame(String title, String instructions,
486486
long testTimeOut,
487487
int rows, int columns)
488488
throws InterruptedException, InvocationTargetException {
489-
invokeOnEDT(() -> createUI(title, instructions,
490-
testTimeOut,
491-
rows, columns));
489+
this(builder().title(title)
490+
.instructions(instructions)
491+
.testTimeOut(testTimeOut)
492+
.rows(rows)
493+
.columns(columns));
492494
}
493495

494496
/**
@@ -503,6 +505,7 @@ public PassFailJFrame(String title, String instructions,
503505
*/
504506
private PassFailJFrame(final Builder builder)
505507
throws InterruptedException, InvocationTargetException {
508+
builder.validate();
506509
invokeOnEDT(() -> createUI(builder));
507510

508511
if (!builder.splitUI && builder.panelCreator != null) {
@@ -584,39 +587,13 @@ private static void invokeOnEDTUncheckedException(Runnable doRun) {
584587
}
585588
}
586589

587-
private static void createUI(String title, String instructions,
588-
long testTimeOut, int rows, int columns) {
589-
frame = new JFrame(title);
590-
frame.setLayout(new BorderLayout());
591-
592-
frame.addWindowListener(windowClosingHandler);
593-
594-
frame.add(createInstructionUIPanel(instructions,
595-
testTimeOut,
596-
rows, columns,
597-
null,
598-
false,
599-
false, 0),
600-
BorderLayout.CENTER);
601-
frame.pack();
602-
frame.setLocationRelativeTo(null);
603-
addTestWindow(frame);
604-
}
605-
606590
private static void createUI(Builder builder) {
607591
frame = new JFrame(builder.title);
608592
frame.setLayout(new BorderLayout());
609593

610594
frame.addWindowListener(windowClosingHandler);
611595

612-
JComponent instructionUI =
613-
createInstructionUIPanel(builder.instructions,
614-
builder.testTimeOut,
615-
builder.rows, builder.columns,
616-
builder.hyperlinkListener,
617-
builder.screenCapture,
618-
builder.addLogArea,
619-
builder.logAreaRows);
596+
JComponent instructionUI = createInstructionUIPanel(builder);
620597
if (builder.splitUI) {
621598
JSplitPane splitPane = new JSplitPane(
622599
builder.splitUIOrientation,
@@ -632,24 +609,23 @@ private static void createUI(Builder builder) {
632609
addTestWindow(frame);
633610
}
634611

635-
private static JComponent createInstructionUIPanel(String instructions,
636-
long testTimeOut,
637-
int rows, int columns,
638-
HyperlinkListener hyperlinkListener,
639-
boolean enableScreenCapture,
640-
boolean addLogArea,
641-
int logAreaRows) {
612+
private static JComponent createInstructionUIPanel(final Builder builder) {
642613
JPanel main = new JPanel(new BorderLayout());
643614
main.setBorder(createFrameBorder());
644615

645-
timeoutHandlerPanel = new TimeoutHandlerPanel(testTimeOut);
616+
timeoutHandlerPanel = new TimeoutHandlerPanel(builder.testTimeOut);
646617
main.add(timeoutHandlerPanel, BorderLayout.NORTH);
647618

648-
JTextComponent text = instructions.startsWith("<html>")
649-
? configureHTML(instructions, rows, columns)
650-
: configurePlainText(instructions, rows, columns);
651-
if (hyperlinkListener != null && text instanceof JEditorPane ep) {
652-
ep.addHyperlinkListener(hyperlinkListener);
619+
JTextComponent text = builder.instructions.startsWith("<html>")
620+
? configureHTML(builder.instructions,
621+
builder.rows,
622+
builder.columns)
623+
: configurePlainText(builder.instructions,
624+
builder.rows,
625+
builder.columns);
626+
if (builder.hyperlinkListener != null
627+
&& text instanceof JEditorPane ep) {
628+
ep.addHyperlinkListener(builder.hyperlinkListener);
653629
}
654630
text.setEditable(false);
655631
text.setBorder(createTextBorder());
@@ -678,12 +654,12 @@ private static JComponent createInstructionUIPanel(String instructions,
678654
buttonsPanel.add(btnPass);
679655
buttonsPanel.add(btnFail);
680656

681-
if (enableScreenCapture) {
657+
if (builder.screenCapture) {
682658
buttonsPanel.add(createCapturePanel());
683659
}
684660

685-
if (addLogArea) {
686-
logArea = new JTextArea(logAreaRows, columns);
661+
if (builder.addLogArea) {
662+
logArea = new JTextArea(builder.logAreaRows, builder.columns);
687663
logArea.setEditable(false);
688664
logArea.setBorder(createTextBorder());
689665

@@ -1843,7 +1819,6 @@ public Builder position(Position position) {
18431819
public PassFailJFrame build() throws InterruptedException,
18441820
InvocationTargetException {
18451821
try {
1846-
validate();
18471822
return new PassFailJFrame(this);
18481823
} catch (final Throwable t) {
18491824
// Dispose of all the windows, including those that may not

0 commit comments

Comments
 (0)