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