jdk/test/java/awt/Multiscreen/WindowGCChangeTest/WindowGCChangeTest.java
author malenkov
Tue, 11 Sep 2012 10:58:39 +0400
changeset 13773 69665c88db93
parent 5506 202f599c92aa
permissions -rw-r--r--
7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties Reviewed-by: rupashka
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) 2005, 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 4868278
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
  @summary Tests that GraphicsConfig for invisible (peerless) window is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
   updated after showing the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
  @author artem.ananiev, area=awt.multiscreen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
  @library ../../regtesthelpers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
  @build Util
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
  @run applet WindowGCChangeTest.html
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.applet.Applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import test.java.awt.regtesthelpers.Util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class WindowGCChangeTest extends Applet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    public void init()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public void start()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        Robot robot = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            robot = new Robot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        catch (Exception z)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            z.printStackTrace(System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            throw new RuntimeException("Test FAILED: couldn't create Robot instance", z);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        setSize(200, 200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        GraphicsDevice[] gds = ge.getScreenDevices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        // check 2-screens systems only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        if (gds.length != 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        int defGDNo = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        int nondefGDNo = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        boolean isVirtualScreen = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        GraphicsDevice defgd = ge.getDefaultScreenDevice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        for (int i = 0; i < gds.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            Rectangle r = gds[i].getDefaultConfiguration().getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            if ((r.x != 0) || (r.y != 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                isVirtualScreen = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            if (gds[i] == defgd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                defGDNo = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                nondefGDNo = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        // doesn't test separate screens
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (!isVirtualScreen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        GraphicsDevice defGD = gds[defGDNo];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        GraphicsDevice nondefGD = gds[nondefGDNo];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        final GraphicsConfiguration defGC = defGD.getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        final GraphicsConfiguration nondefGC = nondefGD.getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        final Frame f = new Frame(defGC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        f.setBounds(nondefGC.getBounds().x + 100, nondefGC.getBounds().y + 100, 100, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        f.addWindowListener(new WindowAdapter()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            public void windowActivated(WindowEvent ev)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                GraphicsConfiguration gcf = f.getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                if (gcf != nondefGC)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                    throw new RuntimeException("Test FAILED: graphics config is not updated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                f.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        f.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        // paranoia - change def to nondef and vice versa
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        final Frame g = new Frame(nondefGC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        g.setBounds(defGC.getBounds().x + 100, defGC.getBounds().y + 100, 100, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        g.addWindowListener(new WindowAdapter()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            public void windowActivated(WindowEvent ev)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                GraphicsConfiguration gcg = g.getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                if (gcg != defGC)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    throw new RuntimeException("Test FAILED: graphics config is not updated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        g.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        // test fullscreen changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        final Frame h = new Frame(defGC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        h.setBounds(defGC.getBounds().x + 100, defGC.getBounds().y + 100, 100, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        h.addWindowListener(new WindowAdapter()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            public void windowActivated(WindowEvent ev)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                GraphicsConfiguration gch = h.getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                if (gch != nondefGC)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    throw new RuntimeException("Test FAILED: graphics config is not updated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                h.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        h.setUndecorated(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        nondefGD.setFullScreenWindow(h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
}