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