test/jdk/java/awt/Paint/PaintNativeOnUpdate.java
author serb
Wed, 21 Feb 2018 12:49:00 -0800
changeset 49096 eaef201ec301
parent 47216 71c04702a3d5
child 52739 7199c4da1a6f
permissions -rw-r--r--
8198333: ProblemList should be updated for headless mode Reviewed-by: psadhukhan, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23264
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
     1
/*
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
     4
 *
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
     8
 *
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    13
 * accompanied this code).
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    14
 *
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    18
 *
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    21
 * questions.
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    22
 */
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    23
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    24
import java.awt.AWTException;
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    25
import java.awt.Color;
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    26
import java.awt.Component;
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    27
import java.awt.Frame;
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    28
import java.awt.Graphics;
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    29
import java.awt.Label;
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    30
import java.awt.Point;
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    31
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    32
/**
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    33
 * @test
40128
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 28087
diff changeset
    34
 * @key headful
23264
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    35
 * @bug 7157680
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 23264
diff changeset
    36
 * @library ../../../lib/testlibrary
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 23264
diff changeset
    37
 * @build ExtendedRobot
23264
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    38
 * @author Sergey Bylokhov
49096
eaef201ec301 8198333: ProblemList should be updated for headless mode
serb
parents: 47216
diff changeset
    39
 * @run main PaintNativeOnUpdate
23264
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    40
 */
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    41
public final class PaintNativeOnUpdate extends Label {
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    42
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    43
    private boolean fullUpdate = true;
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    44
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    45
    public static void main(final String[] args) throws AWTException {
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 23264
diff changeset
    46
        ExtendedRobot robot = new ExtendedRobot();
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 23264
diff changeset
    47
        robot.setAutoDelay(50);
23264
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    48
        final Frame frame = new Frame();
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    49
        final Component label = new PaintNativeOnUpdate();
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    50
        frame.setBackground(Color.RED);
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    51
        frame.add(label);
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    52
        frame.setSize(300, 300);
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    53
        frame.setUndecorated(true);
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    54
        frame.setLocationRelativeTo(null);
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    55
        frame.setVisible(true);
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 23264
diff changeset
    56
        robot.waitForIdle(1000);
23264
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    57
        label.repaint();// first paint
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 23264
diff changeset
    58
        robot.waitForIdle(1000);
23264
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    59
        label.repaint();// incremental paint
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 23264
diff changeset
    60
        robot.waitForIdle(1000);
23264
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    61
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    62
        Point point = label.getLocationOnScreen();
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    63
        Color color = robot.getPixelColor(point.x + label.getWidth() / 2,
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    64
                                          point.y + label.getHeight() / 2);
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    65
        if (!color.equals(Color.GREEN)) {
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    66
            System.err.println("Expected color = " + Color.GREEN);
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    67
            System.err.println("Actual color = " + color);
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    68
            throw new RuntimeException();
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    69
        }
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    70
        frame.dispose();
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    71
    }
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    72
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    73
    @Override
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    74
    public void update(final Graphics g) {
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    75
        if (fullUpdate) {
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    76
            //full paint
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    77
            g.setColor(Color.GREEN);
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    78
            g.fillRect(0, 0, getWidth(), getHeight());
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    79
            fullUpdate = false;
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    80
        } else {
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    81
            // Do nothing
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    82
            // incremental paint
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    83
        }
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    84
    }
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    85
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    86
    @Override
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    87
    public void paint(final Graphics g) {
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    88
        // Do nothing
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    89
    }
f9814afe56f3 7157680: XAWT: Native components should not paint native part on UPDATE event
serb
parents:
diff changeset
    90
}