Path: blob/master/test/jdk/java/awt/Component/Headless/HeadlessContainer.java
41153 views
/*1* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.*;24import java.util.*;2526/*27* @test28* @summary Check that Container methods do not throw unexpected exceptions29* in headless mode30* @run main/othervm -Djava.awt.headless=true HeadlessContainer31*/3233public class HeadlessContainer {34public static void main(String args[]) {35Container lw = new java.awt.Container();36Component c1 = lw.add(new Component(){});37Component c2 = lw.add(new Component(){});38Component c3 = lw.add(new Component(){});3940lw.getComponentCount();41lw.countComponents();42lw.getComponent(1);43lw.getComponent(2);44Component[] cs = lw.getComponents();45Insets ins = lw.getInsets();46ins = lw.insets();47lw.remove(1);48lw.remove((java.awt.Component) c2);49lw.removeAll();5051lw.add(c1);52lw.add(c2);53lw.add(c3);54lw.getLayout();55lw.setLayout(new FlowLayout());56lw.doLayout();57lw.layout();58lw.invalidate();59lw.validate();60for (String font : Toolkit.getDefaultToolkit().getFontList()) {61for (int i = 8; i < 17; i++) {62Font f1 = new Font(font, Font.PLAIN, i);63Font f2 = new Font(font, Font.BOLD, i);64Font f3 = new Font(font, Font.ITALIC, i);65Font f4 = new Font(font, Font.BOLD | Font.ITALIC, i);6667lw.setFont(f1);68lw.setFont(f2);69lw.setFont(f3);70lw.setFont(f4);71}72}73lw.getPreferredSize();74lw.preferredSize();75lw.getMinimumSize();76lw.minimumSize();77lw.getMaximumSize();78lw.getAlignmentX();79lw.getAlignmentY();80lw.getComponentAt(1, 2);81lw.locate(1, 2);82lw.getComponentAt(new Point(1, 2));83lw.isFocusCycleRoot(new Container());84lw.transferFocusBackward();85lw.getName();86lw.setName("goober");87lw.getName();88lw.getParent();89lw.getGraphicsConfiguration();90lw.getTreeLock();91lw.getToolkit();92lw.isValid();93lw.isDisplayable();94lw.isVisible();95lw.isShowing();96lw.isEnabled();97lw.setEnabled(false);98lw.setEnabled(true);99lw.enable();100lw.enable(false);101lw.enable(true);102lw.disable();103lw.isDoubleBuffered();104lw.enableInputMethods(false);105lw.enableInputMethods(true);106lw.setVisible(false);107lw.setVisible(true);108lw.show();109lw.show(false);110lw.show(true);111lw.hide();112lw.getForeground();113lw.setForeground(Color.red);114lw.isForegroundSet();115lw.getBackground();116lw.setBackground(Color.red);117lw.isBackgroundSet();118lw.getFont();119lw.isFontSet();120121boolean exceptions = false;122try {123Container c = new Container();124lw = new java.awt.Container();125c.add(lw);126lw.getLocale();127} catch (IllegalComponentStateException e) {128exceptions = true;129}130if (!exceptions)131throw new RuntimeException("IllegalComponentStateException did not occur when expected");132133for (Locale locale : Locale.getAvailableLocales())134lw.setLocale(locale);135136lw.getColorModel();137lw.getLocation();138139exceptions = false;140try {141lw.getLocationOnScreen();142} catch (IllegalComponentStateException e) {143exceptions = true;144}145if (!exceptions)146throw new RuntimeException("IllegalComponentStateException did not occur when expected");147148lw.location();149lw.setLocation(1, 2);150lw.move(1, 2);151lw.setLocation(new Point(1, 2));152lw.getSize();153lw.size();154lw.setSize(1, 32);155lw.resize(1, 32);156lw.setSize(new Dimension(1, 32));157lw.resize(new Dimension(1, 32));158lw.getBounds();159lw.bounds();160lw.setBounds(10, 10, 10, 10);161lw.reshape(10, 10, 10, 10);162lw.setBounds(new Rectangle(10, 10, 10, 10));163lw.getX();164lw.getY();165lw.getWidth();166lw.getHeight();167lw.getBounds(new Rectangle(1, 1, 1, 1));168lw.getSize(new Dimension(1, 2));169lw.getLocation(new Point(1, 2));170lw.isOpaque();171lw.isLightweight();172lw.getGraphics();173174for (String font : Toolkit.getDefaultToolkit().getFontList()) {175for (int j = 8; j < 17; j++) {176Font f1 = new Font(font, Font.PLAIN, j);177Font f2 = new Font(font, Font.BOLD, j);178Font f3 = new Font(font, Font.ITALIC, j);179Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j);180181lw.getFontMetrics(f1);182lw.getFontMetrics(f2);183lw.getFontMetrics(f3);184lw.getFontMetrics(f4);185}186}187188Cursor c = new Cursor(Cursor.CROSSHAIR_CURSOR);189lw.setCursor(c);190lw.getCursor();191lw.isCursorSet();192lw.contains(1, 2);193lw.inside(1, 2);194lw.contains(new Point(1, 2));195lw.isFocusTraversable();196lw.isFocusable();197lw.setFocusable(true);198lw.setFocusable(false);199lw.requestFocus();200lw.requestFocusInWindow();201lw.transferFocus();202lw.getFocusCycleRootAncestor();203lw.nextFocus();204lw.transferFocusUpCycle();205lw.hasFocus();206lw.isFocusOwner();207lw.toString();208lw.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);209lw.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);210lw.setComponentOrientation(ComponentOrientation.UNKNOWN);211lw.getComponentOrientation();212lw.getAccessibleContext();213}214}215216217