jdk/test/java/awt/Multiscreen/UpdateGCTest/UpdateGCTest.java
author sogoel
Fri, 05 Sep 2014 16:51:39 -0700
changeset 26529 10ec5e52bf75
parent 5506 202f599c92aa
child 39056 d99e63b6d962
permissions -rw-r--r--
8055079: Group 9c: golden files for tests in tools/javac dir Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
  @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
  @bug 4452373 6567564
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
  @summary Tests that all the child and toplevel components have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
their GraphicsConfiguration updated when the window moves from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
one screen to another, on Windows or Linux/Solaris + Xinerama
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
  @author artem.ananiev: area=awt.multiscreen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
  @library ../../regtesthelpers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
  @build Util
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
  @run main UpdateGCTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import test.java.awt.regtesthelpers.Util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class UpdateGCTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    public static void main(String[] args)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        GraphicsDevice[] gds = ge.getScreenDevices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        if (gds.length < 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            System.out.println("The test should be run in multi-screen configuration. Test PASSED/skipped");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        boolean virtualConfig = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        for (GraphicsDevice gd : gds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            GraphicsConfiguration gc = gd.getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            if ((gc.getBounds().x != 0) || (gc.getBounds().y != 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                virtualConfig = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        if (!virtualConfig)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            System.out.println("The test should be run in virtual multi-screen mode. Test PASSED/skipped");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            Robot robot = new Robot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            for (GraphicsDevice gdOrig : gds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                GraphicsConfiguration gcOrig = gdOrig.getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                // test Frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                Frame f = new Frame("F", gcOrig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                f.setSize(200, 200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                f.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                // test Canvas
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                f.add(new Canvas(gcOrig), BorderLayout.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                // test lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                Container c = new Container() {};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                c.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                // test hw inside lw
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                c.add(new Panel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                c.add(new Canvas(gcOrig));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                f.add(c, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                // test Panel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                Panel p = new Panel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                p.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                // test nested Canvas
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                p.add(new Canvas(gcOrig), BorderLayout.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                // test nested lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                p.add(new Component() {}, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                // test nested panel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                p.add(new Panel(), BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                f.add(p, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                f.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                for (GraphicsDevice gd : gds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                    GraphicsConfiguration gc = gd.getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    f.setLocation(gc.getBounds().x + 100, gc.getBounds().y + 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                    Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                    checkGC(f, gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        catch (Exception z)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            System.err.println("Unknown exception caught");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            z.printStackTrace(System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            throw new RuntimeException("Test FAILED: " + z.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        System.out.println("Test PASSED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private static void checkGC(Component c, GraphicsConfiguration gc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (c.getGraphicsConfiguration() != gc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            System.err.println("GC for component (" + c + ") is not updated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            System.err.println("Right GC: " + gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            System.err.println("Component GC: " + c.getGraphicsConfiguration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            throw new RuntimeException("Test FAILED: component GC is not updated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        System.out.println("Checked GC for component (" + c + "): OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (c instanceof Container)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            Container cc = (Container)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            Component[] children = cc.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            for (Component child : children)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                checkGC(child, gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
}