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