mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-27 07:10:45 +00:00
8367772: Refactor createUI in PassFailJFrame
Reviewed-by: dnguyen, honkar
This commit is contained in:
parent
62fa971f31
commit
d278043ddb
@ -486,9 +486,11 @@ public final class PassFailJFrame {
|
||||
long testTimeOut,
|
||||
int rows, int columns)
|
||||
throws InterruptedException, InvocationTargetException {
|
||||
invokeOnEDT(() -> createUI(title, instructions,
|
||||
testTimeOut,
|
||||
rows, columns));
|
||||
this(builder().title(title)
|
||||
.instructions(instructions)
|
||||
.testTimeOut(testTimeOut)
|
||||
.rows(rows)
|
||||
.columns(columns));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -503,6 +505,7 @@ public final class PassFailJFrame {
|
||||
*/
|
||||
private PassFailJFrame(final Builder builder)
|
||||
throws InterruptedException, InvocationTargetException {
|
||||
builder.validate();
|
||||
invokeOnEDT(() -> createUI(builder));
|
||||
|
||||
if (!builder.splitUI && builder.panelCreator != null) {
|
||||
@ -584,39 +587,13 @@ public final class PassFailJFrame {
|
||||
}
|
||||
}
|
||||
|
||||
private static void createUI(String title, String instructions,
|
||||
long testTimeOut, int rows, int columns) {
|
||||
frame = new JFrame(title);
|
||||
frame.setLayout(new BorderLayout());
|
||||
|
||||
frame.addWindowListener(windowClosingHandler);
|
||||
|
||||
frame.add(createInstructionUIPanel(instructions,
|
||||
testTimeOut,
|
||||
rows, columns,
|
||||
null,
|
||||
false,
|
||||
false, 0),
|
||||
BorderLayout.CENTER);
|
||||
frame.pack();
|
||||
frame.setLocationRelativeTo(null);
|
||||
addTestWindow(frame);
|
||||
}
|
||||
|
||||
private static void createUI(Builder builder) {
|
||||
frame = new JFrame(builder.title);
|
||||
frame.setLayout(new BorderLayout());
|
||||
|
||||
frame.addWindowListener(windowClosingHandler);
|
||||
|
||||
JComponent instructionUI =
|
||||
createInstructionUIPanel(builder.instructions,
|
||||
builder.testTimeOut,
|
||||
builder.rows, builder.columns,
|
||||
builder.hyperlinkListener,
|
||||
builder.screenCapture,
|
||||
builder.addLogArea,
|
||||
builder.logAreaRows);
|
||||
JComponent instructionUI = createInstructionUIPanel(builder);
|
||||
if (builder.splitUI) {
|
||||
JSplitPane splitPane = new JSplitPane(
|
||||
builder.splitUIOrientation,
|
||||
@ -632,24 +609,23 @@ public final class PassFailJFrame {
|
||||
addTestWindow(frame);
|
||||
}
|
||||
|
||||
private static JComponent createInstructionUIPanel(String instructions,
|
||||
long testTimeOut,
|
||||
int rows, int columns,
|
||||
HyperlinkListener hyperlinkListener,
|
||||
boolean enableScreenCapture,
|
||||
boolean addLogArea,
|
||||
int logAreaRows) {
|
||||
private static JComponent createInstructionUIPanel(final Builder builder) {
|
||||
JPanel main = new JPanel(new BorderLayout());
|
||||
main.setBorder(createFrameBorder());
|
||||
|
||||
timeoutHandlerPanel = new TimeoutHandlerPanel(testTimeOut);
|
||||
timeoutHandlerPanel = new TimeoutHandlerPanel(builder.testTimeOut);
|
||||
main.add(timeoutHandlerPanel, BorderLayout.NORTH);
|
||||
|
||||
JTextComponent text = instructions.startsWith("<html>")
|
||||
? configureHTML(instructions, rows, columns)
|
||||
: configurePlainText(instructions, rows, columns);
|
||||
if (hyperlinkListener != null && text instanceof JEditorPane ep) {
|
||||
ep.addHyperlinkListener(hyperlinkListener);
|
||||
JTextComponent text = builder.instructions.startsWith("<html>")
|
||||
? configureHTML(builder.instructions,
|
||||
builder.rows,
|
||||
builder.columns)
|
||||
: configurePlainText(builder.instructions,
|
||||
builder.rows,
|
||||
builder.columns);
|
||||
if (builder.hyperlinkListener != null
|
||||
&& text instanceof JEditorPane ep) {
|
||||
ep.addHyperlinkListener(builder.hyperlinkListener);
|
||||
}
|
||||
text.setEditable(false);
|
||||
text.setBorder(createTextBorder());
|
||||
@ -678,12 +654,12 @@ public final class PassFailJFrame {
|
||||
buttonsPanel.add(btnPass);
|
||||
buttonsPanel.add(btnFail);
|
||||
|
||||
if (enableScreenCapture) {
|
||||
if (builder.screenCapture) {
|
||||
buttonsPanel.add(createCapturePanel());
|
||||
}
|
||||
|
||||
if (addLogArea) {
|
||||
logArea = new JTextArea(logAreaRows, columns);
|
||||
if (builder.addLogArea) {
|
||||
logArea = new JTextArea(builder.logAreaRows, builder.columns);
|
||||
logArea.setEditable(false);
|
||||
logArea.setBorder(createTextBorder());
|
||||
|
||||
@ -1843,7 +1819,6 @@ public final class PassFailJFrame {
|
||||
public PassFailJFrame build() throws InterruptedException,
|
||||
InvocationTargetException {
|
||||
try {
|
||||
validate();
|
||||
return new PassFailJFrame(this);
|
||||
} catch (final Throwable t) {
|
||||
// Dispose of all the windows, including those that may not
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user