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