430N/A/*
2362N/A * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
430N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
430N/A *
430N/A * This code is free software; you can redistribute it and/or modify it
430N/A * under the terms of the GNU General Public License version 2 only, as
430N/A * published by the Free Software Foundation.
430N/A *
430N/A * This code is distributed in the hope that it will be useful, but WITHOUT
430N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
430N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
430N/A * version 2 for more details (a copy is included in the LICENSE file that
430N/A * accompanied this code).
430N/A *
430N/A * You should have received a copy of the GNU General Public License version
430N/A * 2 along with this work; if not, write to the Free Software Foundation,
430N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
430N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
430N/A */
430N/A/*
430N/A * @test
430N/A * @bug 6630702
430N/A * @summary Tests that scrolling after paint() is performed correctly.
430N/A * This is really only applicable to Vista
430N/A * @author Dmitri.Trembovetski@sun.com: area=Graphics
430N/A * @run main/othervm SwingOnScreenScrollingTest
430N/A * run main/othervm -Dsun.java2d.opengl=True SwingOnScreenScrollingTest
430N/A */
430N/A
430N/Aimport java.awt.AWTException;
430N/Aimport java.awt.Color;
430N/Aimport java.awt.Dimension;
430N/Aimport java.awt.EventQueue;
430N/Aimport java.awt.Graphics;
430N/Aimport java.awt.GraphicsEnvironment;
430N/Aimport java.awt.Point;
430N/Aimport java.awt.Rectangle;
430N/Aimport java.awt.Robot;
430N/Aimport java.awt.image.BufferedImage;
430N/Aimport java.io.File;
430N/Aimport java.lang.reflect.InvocationTargetException;
430N/Aimport javax.imageio.ImageIO;
430N/Aimport javax.swing.JFrame;
430N/Aimport javax.swing.JPanel;
430N/Aimport javax.swing.JScrollPane;
430N/A
430N/Apublic class SwingOnScreenScrollingTest extends JPanel {
430N/A
430N/A static JScrollPane pane;
430N/A static SwingOnScreenScrollingTest test;
430N/A
430N/A public SwingOnScreenScrollingTest() {
430N/A }
430N/A
430N/A public static void main(String[] args) {
430N/A int size = GraphicsEnvironment.
430N/A getLocalGraphicsEnvironment().
430N/A getDefaultScreenDevice().
430N/A getDefaultConfiguration().getColorModel().getPixelSize();
430N/A if (size < 16) {
430N/A System.err.println("<16 bit display mode detected. Test PASSED");
430N/A return;
430N/A }
430N/A
430N/A final JFrame f = new JFrame("SwingOnScreenScrollingTest");
430N/A try {
430N/A EventQueue.invokeAndWait(new Runnable() {
430N/A public void run() {
430N/A test = new SwingOnScreenScrollingTest();
430N/A pane = new JScrollPane(test);
430N/A f.add(pane);
430N/A f.pack();
430N/A f.setSize(100, 200);
430N/A f.setVisible(true);
430N/A }
430N/A });
430N/A } catch (InvocationTargetException ex) {
430N/A ex.printStackTrace();
430N/A } catch (InterruptedException ex) {
430N/A ex.printStackTrace();
430N/A }
430N/A try {
430N/A Thread.sleep(500);
430N/A } catch (InterruptedException ex) {
430N/A ex.printStackTrace();
430N/A }
430N/A EventQueue.invokeLater(new Runnable() {
430N/A public void run() {
430N/A BufferedImage bi;
430N/A bi = new BufferedImage(100, 300,
430N/A BufferedImage.TYPE_INT_RGB);
430N/A Graphics gg = bi.getGraphics();
430N/A test.paint(gg);
430N/A for (int y = 80; y < 200; y +=10) {
430N/A test.scrollRectToVisible(new Rectangle(0, y, 100, 100));
430N/A try {
430N/A Thread.sleep(200);
430N/A } catch (InterruptedException ex) {
430N/A ex.printStackTrace();
430N/A }
430N/A }
430N/A Point p = pane.getViewport().getLocationOnScreen();
430N/A Robot r = null;
430N/A try {
430N/A r = new Robot();
430N/A } catch (AWTException ex) {
430N/A throw new RuntimeException(ex);
430N/A }
430N/A bi = r.createScreenCapture(new Rectangle(p.x+5, p.y+5, 30, 30));
430N/A for (int y = 0; y < bi.getHeight(); y++) {
430N/A for (int x = 0; x < bi.getHeight(); x++) {
430N/A int rgb = bi.getRGB(x, y);
430N/A if (bi.getRGB(x, y) != Color.red.getRGB()) {
430N/A System.err.printf("Test Failed at (%d,%d) c=0x%x\n",
430N/A x, y, rgb);
430N/A try {
430N/A String name =
430N/A "SwingOnScreenScrollingTest_out.png";
430N/A ImageIO.write(bi, "png", new File(name));
430N/A System.err.println("Wrote grabbed image to "+
430N/A name);
430N/A } catch (Throwable ex) {}
430N/A throw new RuntimeException("Test failed");
430N/A }
430N/A }
430N/A }
430N/A System.out.println("Test PASSED.");
430N/A f.dispose();
430N/A }
430N/A });
430N/A }
430N/A
430N/A protected void paintComponent(Graphics g) {
430N/A g.setColor(Color.green);
430N/A g.fillRect(0, 0, getWidth(), 100);
430N/A g.setColor(Color.red);
430N/A g.fillRect(0, 100, getWidth(), getHeight()-100);
430N/A }
430N/A
430N/A public Dimension getPreferredSize() {
430N/A return new Dimension(100, 300);
430N/A }
430N/A}