1 /* 2 * Copyright (c) 2011, 2013, 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 /* 25 * @test 26 * @author mmcdougall; ported to jtreg by David Durrence 27 * @summary <rdar://problem/5191355> 28 * @summary Testcase for a repaints. 1.5 & 1.6: Failures in Nightly automated testing (OnTop) 29 * @summary com.apple.junit.java.awt.Window 30 * @library ../../regtesthelpers 31 * @build VisibilityValidator 32 * @run junit Repainter 33 */ 34 35 import java.awt.Color; 36 import java.awt.Dialog; 37 import java.awt.Frame; 38 import java.awt.Window; 39 import java.util.Vector; 40 41 import test.java.awt.regtesthelpers.VisibilityValidator; 42 43 public class Repainter { 44 private static final int NUM_REPAINTS = 12; 45 46 public static void main(String[] args) throws Exception { 47 Vector<Window> windows = null; 48 49 // create and initialize a variety of windows 50 windows = new Vector<Window>(); 51 Frame tf = new Frame("Test Frame"); 52 windows.add(tf); 53 Window tw = new Window(tf); 54 windows.add(tw); 55 Dialog td = new Dialog(tf); 56 windows.add(td); 57 58 // Just bring up several windows, and trigger (and watch for) repaints 59 try { 60 // set up some default values 61 int offset = 10; 62 for (Window w : windows) { 63 if (w == null) { 64 throw new RuntimeException("Should have a valid window"); 65 } 66 offset += 30; 67 w.setBounds(offset, offset, 200, 200); 68 } 69 70 // first paint red, and wait for it to appear 71 for (Window w : windows) { 72 w.setBackground(Color.red); 73 if (w instanceof Frame) { 74 VisibilityValidator.setVisibleAndConfirm( (Frame) w); 75 } else { 76 w.setVisible(true); 77 } 78 if (!VisibilityValidator.waitForColor(w, Color.red)) { 79 throw new RuntimeException("Timed out without seeing our red background"); 80 } 81 82 for (int i = 0; i < NUM_REPAINTS; i++) { 83 // now paint blue, and wait for it to appear 84 w.setBackground(Color.blue); 85 w.repaint(); 86 if (!VisibilityValidator.waitForColor(w, Color.blue)) { 87 throw new RuntimeException("Timed out without seeing our blue background"); 88 } 89 90 // now paint green, and wait for it to appear 91 w.setBackground(Color.green); 92 w.repaint(); 93 if (!VisibilityValidator.waitForColor(w, Color.green)) { 94 throw new RuntimeException("Timed out without seeing our green background"); 95 } 96 } 97 } 98 } finally { 99 // get rid of our collection of windows 100 for (Window w : windows) { 101 w.setVisible(false); 102 w.dispose(); 103 } 104 } 105 } 106 }