Skip to content

Commit

Permalink
8294158: HTML formatting for PassFailJFrame instructions
Browse files Browse the repository at this point in the history
Reviewed-by: azvegint, prr
  • Loading branch information
aivanov-jdk committed Oct 25, 2023
1 parent d2d1592 commit 14090ef
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions test/jdk/java/awt/regtesthelpers/PassFailJFrame.java
Expand Up @@ -51,13 +51,17 @@
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.Timer;
import javax.swing.text.JTextComponent;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;

import static javax.swing.SwingUtilities.invokeAndWait;
import static javax.swing.SwingUtilities.isEventDispatchThread;
Expand All @@ -81,8 +85,11 @@ public class PassFailJFrame {
private static volatile boolean failed;
private static volatile boolean timeout;
private static volatile String testFailedReason;

private static final AtomicInteger imgCounter = new AtomicInteger(0);

private static JFrame frame;

private static Robot robot;

public enum Position {HORIZONTAL, VERTICAL, TOP_LEFT_CORNER}
Expand Down Expand Up @@ -169,7 +176,7 @@ public PassFailJFrame(String title, String instructions, long testTimeOut,
InvocationTargetException {
if (isEventDispatchThread()) {
createUI(title, instructions, testTimeOut, rows, columns,
enableScreenCapture);
enableScreenCapture);
} else {
invokeAndWait(() -> createUI(title, instructions, testTimeOut,
rows, columns, enableScreenCapture));
Expand All @@ -187,9 +194,11 @@ private static void createUI(String title, String instructions,
boolean enableScreenCapture) {
frame = new JFrame(title);
frame.setLayout(new BorderLayout());
JTextArea instructionsText = new JTextArea(instructions, rows, columns);
instructionsText.setEditable(false);
instructionsText.setLineWrap(true);

JTextComponent text = instructions.startsWith("<html>")
? configureHTML(instructions, rows, columns)
: configurePlainText(instructions, rows, columns);
text.setEditable(false);

long tTimeout = TimeUnit.MINUTES.toMillis(testTimeOut);

Expand All @@ -210,7 +219,7 @@ private static void createUI(String title, String instructions,
});
timer.start();
frame.add(testTimeoutLabel, BorderLayout.NORTH);
frame.add(new JScrollPane(instructionsText), BorderLayout.CENTER);
frame.add(new JScrollPane(text), BorderLayout.CENTER);

JButton btnPass = new JButton("Pass");
btnPass.addActionListener((e) -> {
Expand Down Expand Up @@ -249,6 +258,32 @@ public void windowClosing(WindowEvent e) {
windowList.add(frame);
}

private static JTextComponent configurePlainText(String instructions,
int rows, int columns) {
JTextArea text = new JTextArea(instructions, rows, columns);
text.setLineWrap(true);
text.setWrapStyleWord(true);
return text;
}

private static JTextComponent configureHTML(String instructions,
int rows, int columns) {
JEditorPane text = new JEditorPane("text/html", instructions);
text.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES,
Boolean.TRUE);
// Set preferred size as if it were JTextArea
text.setPreferredSize(new JTextArea(rows, columns).getPreferredSize());

HTMLEditorKit kit = (HTMLEditorKit) text.getEditorKit();
StyleSheet styles = kit.getStyleSheet();
// Reduce the default margins
styles.addRule("ol, ul { margin-left-ltr: 20; margin-left-rtl: 20 }");
// Make the size of code blocks the same as other text
styles.addRule("code { font-size: inherit }");

return text;
}

private static JComponent createCapturePanel() {
JComboBox<CaptureType> screenShortType = new JComboBox<>(CaptureType.values());

Expand Down

12 comments on commit 14090ef

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aivanov-jdk
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21u

@openjdk
Copy link

@openjdk openjdk bot commented on 14090ef Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aivanov-jdk Could not automatically backport 14090ef6 to openjdk/jdk21u due to conflicts in the following files:

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

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk21u. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk21u.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b aivanov-jdk-backport-14090ef6

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 14090ef6039ff2f3064f397a75219b2bc715cc27

# Backport the commit
$ git cherry-pick --no-commit 14090ef6039ff2f3064f397a75219b2bc715cc27
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 14090ef6039ff2f3064f397a75219b2bc715cc27'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk21u with the title Backport 14090ef6039ff2f3064f397a75219b2bc715cc27.

@aivanov-jdk
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21u

@openjdk
Copy link

@openjdk openjdk bot commented on 14090ef Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aivanov-jdk the backport was successfully created on the branch aivanov-jdk-backport-14090ef6 in my personal fork of openjdk/jdk21u. To create a pull request with this backport targeting openjdk/jdk21u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 14090ef6 from the openjdk/jdk repository.

The commit being backported was authored by Alexey Ivanov on 25 Oct 2023 and was reviewed by Alexander Zvegintsev and Phil Race.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u:

$ git fetch https://github.com/openjdk-bots/jdk21u.git aivanov-jdk-backport-14090ef6:aivanov-jdk-backport-14090ef6
$ git checkout aivanov-jdk-backport-14090ef6
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u.git aivanov-jdk-backport-14090ef6

@luchenlin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 14090ef Feb 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luchenlin Could not automatically backport 14090ef6 to openjdk/jdk17u-dev due to conflicts in the following files:

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

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk17u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk17u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b backport-luchenlin-14090ef6

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 14090ef6039ff2f3064f397a75219b2bc715cc27

# Backport the commit
$ git cherry-pick --no-commit 14090ef6039ff2f3064f397a75219b2bc715cc27
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 14090ef6039ff2f3064f397a75219b2bc715cc27'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk17u-dev with the title Backport 14090ef6039ff2f3064f397a75219b2bc715cc27.

Below you can find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 14090ef6 from the openjdk/jdk repository.

The commit being backported was authored by Alexey Ivanov on 25 Oct 2023 and was reviewed by Alexander Zvegintsev and Phil Race.

Thanks!

@aivanov-jdk
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luchenlin You probably need to backport a previous change before you can cleanly apply this one.

@luchenlin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 14090ef Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luchenlin the backport was successfully created on the branch backport-luchenlin-14090ef6 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 14090ef6 from the openjdk/jdk repository.

The commit being backported was authored by Alexey Ivanov on 25 Oct 2023 and was reviewed by Alexander Zvegintsev and Phil Race.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev.git backport-luchenlin-14090ef6:backport-luchenlin-14090ef6
$ git checkout backport-luchenlin-14090ef6
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev.git backport-luchenlin-14090ef6

@luchenlin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 14090ef Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luchenlin the backport was successfully created on the branch backport-luchenlin-14090ef6 in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 14090ef6 from the openjdk/jdk repository.

The commit being backported was authored by Alexey Ivanov on 25 Oct 2023 and was reviewed by Alexander Zvegintsev and Phil Race.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev.git backport-luchenlin-14090ef6:backport-luchenlin-14090ef6
$ git checkout backport-luchenlin-14090ef6
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev.git backport-luchenlin-14090ef6

Please sign in to comment.