1 /*
   2  * Copyright (c) 2011, 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  * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
  25  * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  26  */
  27 
  28 import java.awt.*;
  29 
  30 /*
  31  * @test
  32  * @key headful
  33  * @summary An attempt to set non-trivial background, shape, or translucency
  34  *          to a decorated toplevel should end with an exception.
  35  * @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
  36  * @library ../../../../lib/testlibrary
  37  * @build ExtendedRobot
  38  * @run main DecoratedExceptions
  39  */
  40 public class DecoratedExceptions {
  41     public static void main(String args[]) throws Exception{
  42         ExtendedRobot robot = new ExtendedRobot();
  43         Toolkit.getDefaultToolkit().getSystemEventQueue().invokeAndWait(() -> {
  44             Frame frame = new Frame("Frame");
  45             frame.setBounds(50,50,400,200);
  46             try {
  47                 frame.setOpacity(0.5f);
  48                 throw new RuntimeException("No exception when Opacity set to a decorated Frame");
  49             }catch(IllegalComponentStateException e) {
  50             }
  51             try {
  52                 frame.setShape(new Rectangle(50,50,400,200));
  53                 throw new RuntimeException("No exception when Shape set to a decorated Frame");
  54             }catch(IllegalComponentStateException e) {
  55             }
  56             try {
  57                 frame.setBackground(new Color(50, 50, 50, 100));
  58                 throw new RuntimeException("No exception when Alpha background set to a decorated Frame");
  59             }catch(IllegalComponentStateException e) {
  60             }
  61             frame.setVisible(true);
  62             Dialog dialog = new Dialog( frame );
  63             try {
  64                 dialog.setOpacity(0.5f);
  65                 throw new RuntimeException("No exception when Opacity set to a decorated Dialog");
  66             }catch(IllegalComponentStateException e) {
  67             }
  68             try {
  69                 dialog.setShape(new Rectangle(50,50,400,200));
  70                 throw new RuntimeException("No exception when Shape set to a decorated Dialog");
  71             }catch(IllegalComponentStateException e) {
  72             }
  73             try {
  74                 dialog.setBackground(new Color(50, 50, 50, 100));
  75                 throw new RuntimeException("No exception when Alpha background set to a decorated Dialog");
  76             }catch(IllegalComponentStateException e) {
  77             }
  78             dialog.setVisible(true);
  79         });
  80         robot.waitForIdle(1000);
  81     }
  82 }