# HG changeset patch # User rupashka # Date 1299163661 -10800 # Node ID 52bdb4237d5eefa456620ef8626a4b57f187688d # Parent 67d4b2e2e5b16f9f147fe202592bd1139ab8f876 6796710: Html content in JEditorPane is overlapping on swing components while resizing the application. Reviewed-by: alexp diff -r 67d4b2e2e5b1 -r 52bdb4237d5e src/share/classes/javax/swing/text/html/CSSBorder.java --- a/src/share/classes/javax/swing/text/html/CSSBorder.java Thu Mar 03 16:40:13 2011 +0300 +++ b/src/share/classes/javax/swing/text/html/CSSBorder.java Thu Mar 03 17:47:41 2011 +0300 @@ -203,10 +203,11 @@ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { - assert (g instanceof Graphics2D) : "need Graphics2D instanse"; - Graphics2D g2 = (Graphics2D) g; - Color savedColor = g2.getColor(); - Shape savedClip = g2.getClip(); + if (!(g instanceof Graphics2D)) { + return; + } + + Graphics2D g2 = (Graphics2D) g.create(); int[] widths = getWidths(); @@ -238,16 +239,16 @@ BorderPainter painter = getBorderPainter(i); double angle = i * Math.PI / 2; + g2.setClip(g.getClip()); // Restore initial clip g2.translate(intCorners[i][0], intCorners[i][1]); g2.rotate(angle); - g2.setClip(shape); - painter.paint(shape, g, color, i); + g2.clip(shape); + painter.paint(shape, g2, color, i); g2.rotate(-angle); g2.translate(-intCorners[i][0], -intCorners[i][1]); } } - g2.setColor(savedColor); - g2.setClip(savedClip); + g2.dispose(); } diff -r 67d4b2e2e5b1 -r 52bdb4237d5e test/javax/swing/regtesthelpers/Util.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/regtesthelpers/Util.java Thu Mar 03 17:47:41 2011 +0300 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2011, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import javax.swing.*; +import java.awt.*; +import java.awt.image.BufferedImage; + +/** + *

This class contains utilities useful for regression testing. + *

When using jtreg you would include this class via something like: + *

+ *
+ * @library ../../regtesthelpers
+ * @build Util
+ * 
+ */ + +public class Util { + /** + * Convert a rectangle from coordinate system of Component c to + * screen coordinate system. + * + * @param r a non-null Rectangle + * @param c a Component whose coordinate system is used for conversion + */ + public static void convertRectToScreen(Rectangle r, Component c) { + Point p = new Point(r.x, r.y); + SwingUtilities.convertPointToScreen(p, c); + r.x = p.x; + r.y = p.y; + } + + /** + * Compares two bufferedImages pixel-by-pixel. + * return true if all pixels in the two areas are identical + */ + public static boolean compareBufferedImages(BufferedImage bufferedImage0, BufferedImage bufferedImage1) { + int width = bufferedImage0.getWidth(); + int height = bufferedImage0.getHeight(); + + if (width != bufferedImage1.getWidth() || height != bufferedImage1.getHeight()) { + return false; + } + + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + if (bufferedImage0.getRGB(x, y) != bufferedImage1.getRGB(x, y)) { + return false; + } + } + } + + return true; + } +} diff -r 67d4b2e2e5b1 -r 52bdb4237d5e test/javax/swing/text/CSSBorder/6796710/bug6796710.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/text/CSSBorder/6796710/bug6796710.java Thu Mar 03 17:47:41 2011 +0300 @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2011, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 6796710 + * @summary Html content in JEditorPane is overlapping on swing components while resizing the application. + * @library ../../../regtesthelpers + * @build Util + * @author Pavel Porvatov + @run main bug6796710 + */ + +import javax.swing.*; +import java.awt.*; +import java.awt.image.BufferedImage; + +public class bug6796710 { + // The page is inlined because we want to be sure that the JEditorPane filled synchronously + public static final String TEXT = "" + + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + "
Col1Col2Col3
1. It's a regression from CR 4419748. The problem is in the CSSBorder#paintBorder, which ignores clip area while painting.2. It's a regression from CR 4419748. The problem is in the CSSBorder#paintBorder, which ignores clip area while painting.3. It's a regression from CR 4419748. The problem is in the CSSBorder#paintBorder, which ignores clip area while painting.
" + + "" + + ""; + + private static Robot robot; + + private static JFrame frame; + + private static JPanel pnBottom; + + public static void main(String[] args) throws Exception { + robot = new Robot(); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame = new JFrame(); + + pnBottom = new JPanel(); + pnBottom.add(new JLabel("Some label")); + pnBottom.add(new JButton("A button")); + + JEditorPane editorPane = new JEditorPane(); + + editorPane.setContentType("text/html"); + editorPane.setText(TEXT); + editorPane.setEditable(false); + + JPanel pnContent = new JPanel(new BorderLayout()); + + pnContent.add(new JScrollPane(editorPane), BorderLayout.CENTER); + pnContent.add(pnBottom, BorderLayout.SOUTH); + + frame.setContentPane(pnContent); + frame.setSize(400, 600); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setVisible(true); + } + }); + + robot.waitForIdle(); + + BufferedImage bufferedImage = getPnBottomImage(); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.setSize(400, 150); + } + }); + + robot.waitForIdle(); + + if (!Util.compareBufferedImages(bufferedImage, getPnBottomImage())) { + throw new RuntimeException("The test failed"); + } + + System.out.println("The test bug6796710 passed."); + } + + private static BufferedImage getPnBottomImage() { + Rectangle rect = pnBottom.getBounds(); + + Util.convertRectToScreen(rect, pnBottom.getParent()); + + return robot.createScreenCapture(rect); + } +}