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