rupashka | 3bcc9e9 | 2011-03-03 17:47:41 +0300 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
| 22 | */ |
| 23 | |
| 24 | import javax.swing.*; |
| 25 | import java.awt.*; |
| 26 | import java.awt.image.BufferedImage; |
| 27 | |
| 28 | /** |
| 29 | * <p>This class contains utilities useful for regression testing. |
| 30 | * <p>When using jtreg you would include this class via something like: |
| 31 | * <pre> |
| 32 | * |
| 33 | * @library ../../regtesthelpers |
| 34 | * @build Util |
| 35 | * </pre> |
| 36 | */ |
| 37 | |
| 38 | public class Util { |
| 39 | /** |
| 40 | * Convert a rectangle from coordinate system of Component c to |
| 41 | * screen coordinate system. |
| 42 | * |
| 43 | * @param r a non-null Rectangle |
| 44 | * @param c a Component whose coordinate system is used for conversion |
| 45 | */ |
| 46 | public static void convertRectToScreen(Rectangle r, Component c) { |
| 47 | Point p = new Point(r.x, r.y); |
| 48 | SwingUtilities.convertPointToScreen(p, c); |
| 49 | r.x = p.x; |
| 50 | r.y = p.y; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Compares two bufferedImages pixel-by-pixel. |
| 55 | * return true if all pixels in the two areas are identical |
| 56 | */ |
| 57 | public static boolean compareBufferedImages(BufferedImage bufferedImage0, BufferedImage bufferedImage1) { |
| 58 | int width = bufferedImage0.getWidth(); |
| 59 | int height = bufferedImage0.getHeight(); |
| 60 | |
| 61 | if (width != bufferedImage1.getWidth() || height != bufferedImage1.getHeight()) { |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | for (int y = 0; y < height; y++) { |
| 66 | for (int x = 0; x < width; x++) { |
| 67 | if (bufferedImage0.getRGB(x, y) != bufferedImage1.getRGB(x, y)) { |
| 68 | return false; |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | return true; |
| 74 | } |
| 75 | } |