Path: blob/master/test/jdk/java/awt/Component/Headless/HeadlessPanel.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.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.getGraphicsConfiguration();79p.getTreeLock();80p.getToolkit();81p.isValid();82p.isDisplayable();83p.isVisible();84p.isShowing();85p.isEnabled();86p.setEnabled(false);87p.setEnabled(true);88p.enable();89p.enable(false);90p.enable(true);91p.disable();92p.isDoubleBuffered();93p.enableInputMethods(false);94p.enableInputMethods(true);95p.setVisible(false);96p.setVisible(true);97p.show();98p.show(false);99p.show(true);100p.hide();101p.getForeground();102p.setForeground(Color.red);103p.isForegroundSet();104p.getBackground();105p.setBackground(Color.red);106p.isBackgroundSet();107p.getFont();108p.isFontSet();109p.getColorModel();110p.getLocation();111p.location();112p.setLocation(1, 2);113p.move(1, 2);114p.setLocation(new Point(1, 2));115p.getSize();116p.size();117p.setSize(1, 32);118p.resize(1, 32);119p.setSize(new Dimension(1, 32));120p.resize(new Dimension(1, 32));121p.getBounds();122p.bounds();123p.setBounds(10, 10, 10, 10);124p.reshape(10, 10, 10, 10);125p.setBounds(new Rectangle(10, 10, 10, 10));126p.getX();127p.getY();128p.getWidth();129p.getHeight();130p.getBounds(new Rectangle(1, 1, 1, 1));131p.getSize(new Dimension(1, 2));132p.getLocation(new Point(1, 2));133p.isOpaque();134p.isLightweight();135p.getGraphics();136137138for (String font : Toolkit.getDefaultToolkit().getFontList()) {139for (int j = 8; j < 17; j++) {140Font f1 = new Font(font, Font.PLAIN, j);141Font f2 = new Font(font, Font.BOLD, j);142Font f3 = new Font(font, Font.ITALIC, j);143Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j);144145p.setFont(f1);146p.setFont(f2);147p.setFont(f3);148p.setFont(f4);149}150}151152boolean exceptions = false;153try {154Container c = new Container();155p = new Panel();156c.add(p);157p.getLocale();158} catch (IllegalComponentStateException e) {159exceptions = true;160}161if (!exceptions)162throw new RuntimeException("IllegalComponentStateException did not occur when expected");163164for (Locale locale : Locale.getAvailableLocales())165p.setLocale(locale);166167exceptions = false;168try {169p.getLocationOnScreen();170} catch (IllegalComponentStateException e) {171exceptions = true;172}173if (!exceptions)174throw new RuntimeException("IllegalComponentStateException did not occur when expected");175176for (String font : Toolkit.getDefaultToolkit().getFontList()) {177for (int j = 8; j178< 17; j++) {179Font f1 = new Font(font, Font.PLAIN, j);180Font f2 = new Font(font, Font.BOLD, j);181Font f3 = new Font(font, Font.ITALIC, j);182Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j);183184p.getFontMetrics(f1);185p.getFontMetrics(f2);186p.getFontMetrics(f3);187p.getFontMetrics(f4);188}189}190191Cursor c = new Cursor(Cursor.CROSSHAIR_CURSOR);192p.setCursor(c);193p.getCursor();194p.isCursorSet();195p.contains(1, 2);196p.inside(1, 2);197p.contains(new Point(1, 2));198p.isFocusTraversable();199p.isFocusable();200p.setFocusable(true);201p.setFocusable(false);202p.requestFocus();203p.requestFocusInWindow();204p.transferFocus();205p.getFocusCycleRootAncestor();206p.nextFocus();207p.transferFocusUpCycle();208p.hasFocus();209p.isFocusOwner();210p.toString();211p.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);212p.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);213p.setComponentOrientation(ComponentOrientation.UNKNOWN);214p.getComponentOrientation();215}216}217218219