Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8274465: Fix javax/swing/text/ParagraphView/6364882/bug6364882.java failures #5761

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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 + " ";