Path: blob/master/test/jdk/javax/swing/Headless/HeadlessCellRendererPane.java
41149 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 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.getGraphicsConfiguration();94crp.getTreeLock();95crp.getToolkit();96crp.isValid();97crp.isDisplayable();98crp.isVisible();99crp.isShowing();100crp.isEnabled();101crp.setEnabled(false);102crp.setEnabled(true);103crp.enable();104crp.enable(false);105crp.enable(true);106crp.disable();107crp.isDoubleBuffered();108crp.enableInputMethods(false);109crp.enableInputMethods(true);110crp.setVisible(false);111crp.setVisible(true);112crp.show();113crp.show(false);114crp.show(true);115crp.hide();116crp.getForeground();117crp.setForeground(Color.red);118crp.isForegroundSet();119crp.getBackground();120crp.setBackground(Color.red);121crp.isBackgroundSet();122crp.getFont();123crp.isFontSet();124125boolean exceptions = false;126try {127Container c = new Container();128c.add(crp);129crp.getLocale();130} catch (IllegalComponentStateException e) {131exceptions = true;132}133if (!exceptions)134throw new RuntimeException("IllegalComponentStateException did not occur when expected");135136for (Locale locale : Locale.getAvailableLocales())137crp.setLocale(locale);138139crp.getColorModel();140crp.getLocation();141142exceptions = false;143try {144crp.getLocationOnScreen();145} catch (IllegalComponentStateException e) {146exceptions = true;147}148if (!exceptions)149throw new RuntimeException("IllegalComponentStateException did not occur when expected");150151crp.location();152crp.setLocation(1, 2);153crp.move(1, 2);154crp.setLocation(new Point(1, 2));155crp.getSize();156crp.size();157crp.setSize(1, 32);158crp.resize(1, 32);159crp.setSize(new Dimension(1, 32));160crp.resize(new Dimension(1, 32));161crp.getBounds();162crp.bounds();163crp.setBounds(10, 10, 10, 10);164crp.reshape(10, 10, 10, 10);165crp.setBounds(new Rectangle(10, 10, 10, 10));166crp.getX();167crp.getY();168crp.getWidth();169crp.getHeight();170crp.getBounds(new Rectangle(1, 1, 1, 1));171crp.getSize(new Dimension(1, 2));172crp.getLocation(new Point(1, 2));173crp.isOpaque();174crp.isLightweight();175crp.getGraphics();176crp.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));177crp.getCursor();178crp.isCursorSet();179crp.contains(1, 2);180crp.inside(1, 2);181crp.contains(new Point(1, 2));182crp.isFocusTraversable();183crp.isFocusable();184crp.setFocusable(true);185crp.setFocusable(false);186crp.requestFocus();187crp.requestFocusInWindow();188crp.transferFocus();189crp.getFocusCycleRootAncestor();190crp.nextFocus();191crp.transferFocusUpCycle();192crp.hasFocus();193crp.isFocusOwner();194crp.toString();195crp.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);196crp.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);197crp.setComponentOrientation(ComponentOrientation.UNKNOWN);198crp.getComponentOrientation();199}200}201202203