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