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