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