Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Component/Headless/HeadlessContainer.java
47311 views
/*1* Copyright (c) 2007, 2014, 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.getPeer();90lw.getGraphicsConfiguration();91lw.getTreeLock();92lw.getToolkit();93lw.isValid();94lw.isDisplayable();95lw.isVisible();96lw.isShowing();97lw.isEnabled();98lw.setEnabled(false);99lw.setEnabled(true);100lw.enable();101lw.enable(false);102lw.enable(true);103lw.disable();104lw.isDoubleBuffered();105lw.enableInputMethods(false);106lw.enableInputMethods(true);107lw.setVisible(false);108lw.setVisible(true);109lw.show();110lw.show(false);111lw.show(true);112lw.hide();113lw.getForeground();114lw.setForeground(Color.red);115lw.isForegroundSet();116lw.getBackground();117lw.setBackground(Color.red);118lw.isBackgroundSet();119lw.getFont();120lw.isFontSet();121122boolean exceptions = false;123try {124Container c = new Container();125lw = new java.awt.Container();126c.add(lw);127lw.getLocale();128} catch (IllegalComponentStateException e) {129exceptions = true;130}131if (!exceptions)132throw new RuntimeException("IllegalComponentStateException did not occur when expected");133134for (Locale locale : Locale.getAvailableLocales())135lw.setLocale(locale);136137lw.getColorModel();138lw.getLocation();139140exceptions = false;141try {142lw.getLocationOnScreen();143} catch (IllegalComponentStateException e) {144exceptions = true;145}146if (!exceptions)147throw new RuntimeException("IllegalComponentStateException did not occur when expected");148149lw.location();150lw.setLocation(1, 2);151lw.move(1, 2);152lw.setLocation(new Point(1, 2));153lw.getSize();154lw.size();155lw.setSize(1, 32);156lw.resize(1, 32);157lw.setSize(new Dimension(1, 32));158lw.resize(new Dimension(1, 32));159lw.getBounds();160lw.bounds();161lw.setBounds(10, 10, 10, 10);162lw.reshape(10, 10, 10, 10);163lw.setBounds(new Rectangle(10, 10, 10, 10));164lw.getX();165lw.getY();166lw.getWidth();167lw.getHeight();168lw.getBounds(new Rectangle(1, 1, 1, 1));169lw.getSize(new Dimension(1, 2));170lw.getLocation(new Point(1, 2));171lw.isOpaque();172lw.isLightweight();173lw.getGraphics();174175for (String font : Toolkit.getDefaultToolkit().getFontList()) {176for (int j = 8; j < 17; j++) {177Font f1 = new Font(font, Font.PLAIN, j);178Font f2 = new Font(font, Font.BOLD, j);179Font f3 = new Font(font, Font.ITALIC, j);180Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j);181182lw.getFontMetrics(f1);183lw.getFontMetrics(f2);184lw.getFontMetrics(f3);185lw.getFontMetrics(f4);186}187}188189Cursor c = new Cursor(Cursor.CROSSHAIR_CURSOR);190lw.setCursor(c);191lw.getCursor();192lw.isCursorSet();193lw.contains(1, 2);194lw.inside(1, 2);195lw.contains(new Point(1, 2));196lw.isFocusTraversable();197lw.isFocusable();198lw.setFocusable(true);199lw.setFocusable(false);200lw.requestFocus();201lw.requestFocusInWindow();202lw.transferFocus();203lw.getFocusCycleRootAncestor();204lw.nextFocus();205lw.transferFocusUpCycle();206lw.hasFocus();207lw.isFocusOwner();208lw.toString();209lw.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);210lw.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);211lw.setComponentOrientation(ComponentOrientation.UNKNOWN);212lw.getComponentOrientation();213lw.getAccessibleContext();214}215}216217218