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