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