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