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