1 /* 2 * Copyright (c) 2014, 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 java.awt.AWTException; 25 import java.awt.Color; 26 import java.awt.Component; 27 import java.awt.Frame; 28 import java.awt.Graphics; 29 import java.awt.Label; 30 import java.awt.Point; 31 32 /** 33 * @test 34 * @key headful 35 * @bug 7157680 36 * @library ../../../lib/testlibrary 37 * @build ExtendedRobot 38 * @author Sergey Bylokhov 39 @ @run main PaintNativeOnUpdate 40 */ 41 public final class PaintNativeOnUpdate extends Label { 42 43 private boolean fullUpdate = true; 44 45 public static void main(final String[] args) throws AWTException { 46 ExtendedRobot robot = new ExtendedRobot(); 47 robot.setAutoDelay(50); 48 final Frame frame = new Frame(); 49 final Component label = new PaintNativeOnUpdate(); 50 frame.setBackground(Color.RED); 51 frame.add(label); 52 frame.setSize(300, 300); 53 frame.setUndecorated(true); 54 frame.setLocationRelativeTo(null); 55 frame.setVisible(true); 56 robot.waitForIdle(1000); 57 label.repaint();// first paint 58 robot.waitForIdle(1000); 59 label.repaint();// incremental paint 60 robot.waitForIdle(1000); 61 62 Point point = label.getLocationOnScreen(); 63 Color color = robot.getPixelColor(point.x + label.getWidth() / 2, 64 point.y + label.getHeight() / 2); 65 if (!color.equals(Color.GREEN)) { 66 System.err.println("Expected color = " + Color.GREEN); 67 System.err.println("Actual color = " + color); 68 throw new RuntimeException(); 69 } 70 frame.dispose(); 71 } 72 73 @Override 74 public void update(final Graphics g) { 75 if (fullUpdate) { 76 //full paint 77 g.setColor(Color.GREEN); 78 g.fillRect(0, 0, getWidth(), getHeight()); 79 fullUpdate = false; 80 } else { 81 // Do nothing 82 // incremental paint 83 } 84 } 85 86 @Override 87 public void paint(final Graphics g) { 88 // Do nothing 89 } 90 }