8322140: javax/swing/JTable/JTableScrollPrintTest.java does not print the rows and columns of the table in Nimbus and Aqua LookAndFeel

Reviewed-by: psadhukhan, abhiscxk
This commit is contained in:
Tejesh R 2024-04-12 10:21:31 +00:00
parent aebfd53e9d
commit 717a07b932
4 changed files with 43 additions and 36 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -603,15 +603,11 @@ public class JViewport extends JComponent implements Accessible
private Graphics getBackingStoreGraphics(Graphics g) {
if (!SwingUtilities2.isPrinting(g)) {
Graphics bsg = backingStoreImage.getGraphics();
bsg.setColor(g.getColor());
bsg.setFont(g.getFont());
bsg.setClip(g.getClipBounds());
return bsg;
} else {
return g;
}
Graphics bsg = backingStoreImage.getGraphics();
bsg.setColor(g.getColor());
bsg.setFont(g.getFont());
bsg.setClip(g.getClipBounds());
return bsg;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -64,6 +64,7 @@ import java.awt.image.DataBuffer;
import java.awt.image.DataBufferInt;
import java.awt.image.ImageObserver;
import java.awt.image.IndexColorModel;
import java.awt.image.MultiResolutionImage;
import java.awt.image.Raster;
import java.awt.image.RenderedImage;
import java.awt.image.SampleModel;
@ -1132,6 +1133,9 @@ public abstract class PathGraphics extends ProxyGraphics2D {
// VI needs to make a new BI: this is unavoidable but
// I don't expect VI's to be "huge" in any case.
return ((VolatileImage)img).getSnapshot();
} else if (img instanceof MultiResolutionImage) {
return convertToBufferedImage((MultiResolutionImage) img,
img.getWidth(null), img.getHeight(null));
} else {
// may be null or may be some non-standard Image which
// shouldn't happen as Image is implemented by the platform
@ -1142,6 +1146,18 @@ public abstract class PathGraphics extends ProxyGraphics2D {
}
}
protected BufferedImage convertToBufferedImage(MultiResolutionImage multiResolutionImage,
double width, double height ) {
Image resolutionImage = multiResolutionImage.getResolutionVariant(width, height);
BufferedImage bufferedImage = new BufferedImage(resolutionImage.getWidth(null),
resolutionImage.getHeight(null),
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bufferedImage.createGraphics();
g2d.drawImage(resolutionImage, 0, 0, (int) width, (int) height, null);
g2d.dispose();
return bufferedImage;
}
/**
* Return true if the BufferedImage argument has non-opaque
* bits in it and therefore can not be directly rendered by

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -1317,7 +1317,7 @@ public class SwingUtilities2 {
* returns true if the Graphics is print Graphics
* false otherwise
*/
public static boolean isPrinting(Graphics g) {
static boolean isPrinting(Graphics g) {
return (g instanceof PrinterGraphics || g instanceof PrintGraphics);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -36,13 +36,12 @@ import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JViewport;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
/*
* @test
* @key headful
* @bug 8210807
* @bug 8210807 8322140
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @summary Test to check if JTable can be printed when JScrollPane added to it.
@ -50,32 +49,27 @@ import javax.swing.table.DefaultTableModel;
*/
public class JTableScrollPrintTest {
public static JFrame frame;
public static PassFailJFrame passFailJFrame;
public static void main(String[] args) throws Exception {
SwingUtilities.invokeAndWait(() -> {
try {
initialize();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
passFailJFrame.awaitAndCheck();
}
public static void initialize() throws Exception {
final String INSTRUCTIONS = """
String INSTRUCTIONS = """
Instructions to Test:
1. Print table onto Paper/PDF, using the Print Dialog.
2. If entire table is printed, then the Test is PASS.
3. If table is partially printed without table cells,
then the Test is FAIL.
""";
TestTable testTable = new TestTable(true);
frame = new JFrame("JTable Print Test");
passFailJFrame = new PassFailJFrame("Test Instructions", INSTRUCTIONS, 5L, 6, 35);
PassFailJFrame.builder()
.title("Test Instructions")
.instructions(INSTRUCTIONS)
.rows(6)
.columns(35)
.testUI(JTableScrollPrintTest::initialize)
.build()
.awaitAndCheck();
}
public static JFrame initialize() {
TestTable testTable = new TestTable(true);
JFrame frame = new JFrame("JTable Print Test");
PassFailJFrame.addTestWindow(frame);
PassFailJFrame.positionTestWindow(frame, PassFailJFrame.Position.VERTICAL);
frame.add(testTable);
@ -83,6 +77,7 @@ public class JTableScrollPrintTest {
frame.setVisible(true);
PrintUtilities printerJob = new PrintUtilities(testTable);
printerJob.print("Test BackingStore Image Print");
return frame;
}
public static class TestTable extends JPanel {
@ -103,7 +98,7 @@ public class JTableScrollPrintTest {
JTable table = new JTable(model);
if (useScrollPane == true) {
if (useScrollPane) {
JScrollPane sp = new JScrollPane(table,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
@ -117,7 +112,7 @@ public class JTableScrollPrintTest {
}
static class PrintUtilities implements Printable {
private Component componentToBePrinted;
private final Component componentToBePrinted;
public void printComponent(Component c, String jobname) {
new PrintUtilities(c).print(jobname);