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