1 /*
   2  * Copyright (c) 2015, 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 import java.awt.Canvas;
  24 import java.awt.Component;
  25 import java.awt.Color;
  26 import java.awt.EventQueue;
  27 import java.awt.GraphicsDevice;
  28 import java.awt.GraphicsEnvironment;
  29 import javax.swing.JFrame;
  30 import javax.swing.JOptionPane;
  31 import javax.swing.SwingUtilities;
  32 
  33 /**
  34   * @test
  35   * @bug 7011935
  36   * @summary  Verifies a fullscreen window with proper background is shown.
  37   * @run main/manual AWTFullscreenTest
  38   */
  39 
  40 public class AWTFullScreenTest
  41 {
  42     public static void main(String[] arg) throws Exception
  43     {
  44         try {
  45             String temp1 = "The test should show a red canvas on topleft";
  46             String temp2 = " corner of blue fullscreen window";
  47             SwingUtilities.invokeAndWait(() -> {
  48                     JOptionPane.showMessageDialog(
  49                         (Component) null,
  50                          temp1.concat(temp2),
  51                         "information", JOptionPane.INFORMATION_MESSAGE);
  52             });
  53             final GraphicsDevice screen = 
  54                    GraphicsEnvironment.getLocalGraphicsEnvironment().
  55                    getDefaultScreenDevice();
  56             JFrame frame = new JFrame();
  57             frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  58             frame.getContentPane().setBackground(Color.BLUE);
  59             frame.getContentPane().setLayout(null);
  60             frame.setUndecorated(true);
  61 
  62             Canvas canvas = new Canvas();
  63             canvas.setBackground(Color.RED);
  64             canvas.setBounds(10, 10, 100, 100);
  65             frame.getContentPane().add(canvas);
  66 
  67             System.out.println("isFullscreenSupported=" + 
  68                                     screen.isFullScreenSupported());
  69             screen.setFullScreenWindow(frame);
  70             Thread.sleep(5000);
  71             String str1 = "Did a blue fullscreen window";
  72             String str2 = " was shown with red canvas on top?";
  73             SwingUtilities.invokeAndWait(() -> {
  74                 int confirm = JOptionPane.showConfirmDialog(
  75                          (Component) null,
  76                          str1.concat(str2),
  77                          "alert", JOptionPane.YES_NO_OPTION);
  78                 if (confirm == JOptionPane.YES_OPTION) {
  79                     System.out.println("Test passed");
  80                 } else {
  81                     System.out.println("Test failed");
  82                     throw new RuntimeException("Fullscreen window not shown");
  83                 }
  84             });
  85             SwingUtilities.invokeLater(() -> {
  86                 frame.dispose();
  87             });
  88         } catch (Exception e) {}
  89     }
  90 }