1/*
2 * Copyright (c) 2007, 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
24import javax.swing.*;
25import java.awt.*;
26import java.util.Locale;
27
28/*
29 * @test
30 * @summary Check that JLayeredPane constructor and methods do not throw unexpected
31 *          exceptions in headless mode
32 * @run main/othervm -Djava.awt.headless=true HeadlessJLayeredPane
33 */
34
35public class HeadlessJLayeredPane {
36    public static void main(String args[]) {
37        JLayeredPane lp = new JLayeredPane();
38        lp.getAccessibleContext();
39        lp.isFocusTraversable();
40        lp.setEnabled(false);
41        lp.setEnabled(true);
42        lp.requestFocus();
43        lp.requestFocusInWindow();
44        lp.getPreferredSize();
45        lp.getMaximumSize();
46        lp.getMinimumSize();
47        lp.contains(1, 2);
48        Component c1 = lp.add(new Component(){});
49        Component c2 = lp.add(new Component(){});
50        Component c3 = lp.add(new Component(){});
51        Insets ins = lp.getInsets();
52        lp.getAlignmentY();
53        lp.getAlignmentX();
54        lp.getGraphics();
55        lp.setVisible(false);
56        lp.setVisible(true);
57        lp.setForeground(Color.red);
58        lp.setBackground(Color.red);
59        for (String font : Toolkit.getDefaultToolkit().getFontList()) {
60            for (int j = 8; j < 17; j++) {
61                Font f1 = new Font(font, Font.PLAIN, j);
62                Font f2 = new Font(font, Font.BOLD, j);
63                Font f3 = new Font(font, Font.ITALIC, j);
64                Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j);
65
66                lp.setFont(f1);
67                lp.setFont(f2);
68                lp.setFont(f3);
69                lp.setFont(f4);
70
71                lp.getFontMetrics(f1);
72                lp.getFontMetrics(f2);
73                lp.getFontMetrics(f3);
74                lp.getFontMetrics(f4);
75            }
76        }
77        lp.enable();
78        lp.disable();
79        lp.reshape(10, 10, 10, 10);
80        lp.getBounds(new Rectangle(1, 1, 1, 1));
81        lp.getSize(new Dimension(1, 2));
82        lp.getLocation(new Point(1, 2));
83        lp.getX();
84        lp.getY();
85        lp.getWidth();
86        lp.getHeight();
87        lp.isOpaque();
88        lp.isValidateRoot();
89        lp.isOptimizedDrawingEnabled();
90        lp.isDoubleBuffered();
91        lp.getComponentCount();
92        lp.countComponents();
93        lp.getComponent(1);
94        lp.getComponent(2);
95        Component[] cs = lp.getComponents();
96        lp.getLayout();
97        lp.setLayout(new FlowLayout());
98        lp.doLayout();
99        lp.layout();
100        lp.invalidate();
101        lp.validate();
102        lp.remove(0);
103        lp.remove(c2);
104        lp.removeAll();
105        lp.preferredSize();
106        lp.minimumSize();
107        lp.getComponentAt(1, 2);
108        lp.locate(1, 2);
109        lp.getComponentAt(new Point(1, 2));
110        lp.isFocusCycleRoot(new Container());
111        lp.transferFocusBackward();
112        lp.setName("goober");
113        lp.getName();
114        lp.getParent();
115        lp.getGraphicsConfiguration();
116        lp.getTreeLock();
117        lp.getToolkit();
118        lp.isValid();
119        lp.isDisplayable();
120        lp.isVisible();
121        lp.isShowing();
122        lp.isEnabled();
123        lp.enable(false);
124        lp.enable(true);
125        lp.enableInputMethods(false);
126        lp.enableInputMethods(true);
127        lp.show();
128        lp.show(false);
129        lp.show(true);
130        lp.hide();
131        lp.getForeground();
132        lp.isForegroundSet();
133        lp.getBackground();
134        lp.isBackgroundSet();
135        lp.getFont();
136        lp.isFontSet();
137        Container c = new Container();
138        c.add(lp);
139        lp.getLocale();
140        for (Locale locale : Locale.getAvailableLocales())
141            lp.setLocale(locale);
142
143        lp.getColorModel();
144        lp.getLocation();
145
146        boolean exceptions = false;
147        try {
148            lp.getLocationOnScreen();
149        } catch (IllegalComponentStateException e) {
150            exceptions = true;
151        }
152        if (!exceptions)
153            throw new RuntimeException("IllegalComponentStateException did not occur when expected");
154
155        lp.location();
156        lp.setLocation(1, 2);
157        lp.move(1, 2);
158        lp.setLocation(new Point(1, 2));
159        lp.getSize();
160        lp.size();
161        lp.setSize(1, 32);
162        lp.resize(1, 32);
163        lp.setSize(new Dimension(1, 32));
164        lp.resize(new Dimension(1, 32));
165        lp.getBounds();
166        lp.bounds();
167        lp.setBounds(10, 10, 10, 10);
168        lp.setBounds(new Rectangle(10, 10, 10, 10));
169        lp.isLightweight();
170        lp.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
171        lp.getCursor();
172        lp.isCursorSet();
173        lp.inside(1, 2);
174        lp.contains(new Point(1, 2));
175        lp.isFocusable();
176        lp.setFocusable(true);
177        lp.setFocusable(false);
178        lp.transferFocus();
179        lp.getFocusCycleRootAncestor();
180        lp.nextFocus();
181        lp.transferFocusUpCycle();
182        lp.hasFocus();
183        lp.isFocusOwner();
184        lp.toString();
185        lp.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
186        lp.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
187        lp.setComponentOrientation(ComponentOrientation.UNKNOWN);
188        lp.getComponentOrientation();
189    }
190}
191