Skip to content
Permalink
Browse files
8274465: Fix javax/swing/text/ParagraphView/6364882/bug6364882.java f…
…ailures

Reviewed-by: jiefu, serb
  • Loading branch information
aivanov-jdk committed Oct 1, 2021
1 parent 05d3860 commit bb4500d0d227cbb238bd6c862e143f864106a31a
Showing 1 changed file with 57 additions and 44 deletions.
@@ -64,7 +64,7 @@ public class bug6364882 {
+ "</body></html>";

private static final int WIDTH = 580;
private static final int HEIGHT = 600;
private static final int HEIGHT = 300;

public static final String IMAGE_FILENAME = "editorPane.png";

@@ -84,11 +84,18 @@ public static void main(String[] args) throws Exception {
createUI(showFrame);

BufferedImage image = paintToImage();
errors = checkJustification();

if (errors.size() > 0 || saveImage) {
saveImage(image);
dumpViews();
boolean exceptionThrown = false;
try {
errors = checkJustification();
} catch (Throwable t) {
exceptionThrown = true;
throw t;
} finally {
if (exceptionThrown || errors.size() > 0 || saveImage) {
saveImage(image);
dumpViews();
}
}
});

@@ -133,57 +140,62 @@ private static List<Error> checkJustification() {
: "blockView doesn't have 2 child views";
final View bodyView = blockView.getView(1);
final View paragraphView = bodyView.getView(0);
// Expected to have 6 rows in the paragraph
assert paragraphView.getViewCount() == 6
: "paragraph doesn't have 6 rows of text";

final Rectangle bounds = editorPane.getBounds();
final int rowCount = paragraphView.getViewCount();
if (rowCount < 4) {
errors.add(new Error("Less than 4 lines of text: no justified lines"));
return errors;
}

// Three rows should be justified
final int oneX = getEndOfLineX(paragraphView.getView(0), bounds);
if (oneX < bounds.width - 15) {
errors.add(new Error("Text is not justified at line " + 0 + ": "
+ oneX + " < " + (bounds.width - 15)));
final Rectangle bounds = editorPane.getBounds();
final int rightMargin = bounds.width - 15;

// First lines should be justified
int lineNo = 0;
final int oneX = getEndOfLineX(paragraphView.getView(lineNo++), bounds);
if (oneX < rightMargin) {
errors.add(new Error("Text is not justified at line " + lineNo + ": "
+ oneX + " < " + rightMargin));
}
for (int i = 1; i < 2; i++) {
int lineX = getEndOfLineX(paragraphView.getView(i),
// Justified lines should have the same width
while (lineNo < rowCount - 3) {
int lineX = getEndOfLineX(paragraphView.getView(lineNo++),
bounds);
if (oneX != lineX) {
errors.add(new Error("Text is not justified at line " + i
errors.add(new Error("Text is not justified at line " + lineNo
+ ": " + oneX + " != " + lineX));
}
}

// Fourth row should not be justified
final int fourX = getEndOfLineX(paragraphView.getView(3), bounds);
if (oneX == fourX) {
errors.add(new Error("Fourth line is justified: "
+ oneX + " vs " + fourX));
// The last line of the wrapped text, before the first <br>,
// should not be justified
final int twoX = getEndOfLineX(paragraphView.getView(lineNo++), bounds);
if (oneX == twoX) {
errors.add(new Error("Line " + lineNo + " is justified: "
+ oneX + " vs " + twoX));
}
if (fourX > (bounds.width - bounds.width / 4)) {
errors.add(new Error("Fourth line is justified: "
+ fourX + " > "
+ (bounds.width - bounds.width / 4)));
if (twoX > rightMargin) {
errors.add(new Error("Line " + lineNo + " is justified: "
+ twoX + " > " + rightMargin));
}

// Fifth and sixth lines should not be justified
final int fiveX = getEndOfLineX(paragraphView.getView(4), bounds);
if (oneX == fiveX) {
errors.add(new Error("Fifth line is justified: "
+ oneX + "==" + fiveX));
// The next two lines are created by line break <br>
// They should not be justified and should be of the same width
final int threeX = getEndOfLineX(paragraphView.getView(lineNo++), bounds);
if (oneX == threeX) {
errors.add(new Error("Line " + lineNo + " is justified: "
+ oneX + " == " + threeX));
}
if (fiveX > bounds.width / 2) {
errors.add(new Error("Fifth line is justified: "
+ fiveX + " > " + (bounds.width / 2)));
if (threeX > bounds.width / 2) {
errors.add(new Error("Line " + lineNo + " is justified: "
+ threeX + " > " + (bounds.width / 2)));
}
if (fiveX > fourX) {
errors.add(new Error("Fifth line is justified: "
+ fiveX + " > " + fourX));
}
final int sixX = getEndOfLineX(paragraphView.getView(5), bounds);
if (fiveX != sixX) {
errors.add(new Error("Fifth and sixth lines aren't of the "
+ "same width: " + fiveX + " != " + sixX));

final int lastX = getEndOfLineX(paragraphView.getView(lineNo), bounds);
if (threeX != lastX) {
errors.add(new Error("Line " + lineNo + " and " + (lineNo + 1)
+ " have different width: "
+ threeX + " != " + lastX));
}

return errors;
@@ -218,7 +230,8 @@ private static void saveImage(BufferedImage image) {
try {
ImageIO.write(image, "png", new File(IMAGE_FILENAME));
} catch (IOException e) {
throw new RuntimeException(e);
// Don't propagate the exception
e.printStackTrace();
}
}

@@ -228,7 +241,7 @@ private static void dumpViews() {
}

private static void dumpViews(final View view, final String indent) {
System.out.println(indent + view.getClass().getName() + ": "
System.err.println(indent + view.getClass().getName() + ": "
+ view.getStartOffset() + ", " + view.getEndOffset()
+ "; span: " + view.getPreferredSpan(View.X_AXIS));
final String nestedIndent = indent + " ";

3 comments on commit bb4500d

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on bb4500d Oct 1, 2021

Choose a reason for hiding this comment

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

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on bb4500d Jan 5, 2022

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 bb4500d Jan 5, 2022

Choose a reason for hiding this comment

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

@GoeLin the backport was successfully created on the branch GoeLin-backport-bb4500d0 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 bb4500d0 from the openjdk/jdk repository.

The commit being backported was authored by Alexey Ivanov on 1 Oct 2021 and was reviewed by Jie Fu and Sergey Bylokhov.

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 GoeLin-backport-bb4500d0:GoeLin-backport-bb4500d0
$ git checkout GoeLin-backport-bb4500d0
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-bb4500d0

Please sign in to comment.