Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/Headless/HeadlessJInternalFrame.java
38841 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 javax.swing.plaf.basic.BasicInternalFrameTitlePane;25import javax.swing.plaf.basic.BasicInternalFrameUI;26import java.awt.*;27import java.beans.PropertyChangeEvent;28import java.beans.PropertyChangeListener;29import java.util.Locale;3031/*32* @test33* @summary Check that JInternalFrame constructor and methods do not throw unexpected34* exceptions in headless mode35* @run main/othervm -Djava.awt.headless=true HeadlessJInternalFrame36*/3738public class HeadlessJInternalFrame {39public static void main(String args[]) {40JInternalFrame intf = new JInternalFrame("TEST");41intf.setUI(new BasicInternalFrameUI(intf) {42protected JComponent createNorthPane(JInternalFrame w) {43titlePane = new BasicInternalFrameTitlePane(w) {44protected PropertyChangeListener createPropertyChangeListener() {45return new BasicInternalFrameTitlePane.PropertyChangeHandler() {46int countUI = 0;4748public void propertyChange(PropertyChangeEvent evt) {49if (evt.getPropertyName().equals("UI"))50countUI++;51else if (countUI > 1)52throw new RuntimeException("Test failed. Listener not removed!");53}54};55}56};57return titlePane;58}59});60intf.setUI(null);61intf.getAccessibleContext();62intf.isFocusTraversable();63intf.setEnabled(false);64intf.setEnabled(true);65intf.requestFocus();66intf.requestFocusInWindow();67intf.getPreferredSize();68intf.getMaximumSize();69intf.getMinimumSize();70intf.contains(1, 2);71Component c1 = intf.add(new Component(){});72Component c2 = intf.add(new Component(){});73Component c3 = intf.add(new Component(){});74Insets ins = intf.getInsets();75intf.getAlignmentY();76intf.getAlignmentX();77intf.getGraphics();78intf.setVisible(false);79intf.setVisible(true);80intf.setForeground(Color.red);81intf.setBackground(Color.red);82for (String font : Toolkit.getDefaultToolkit().getFontList()) {83for (int j = 8; j < 17; j++) {84Font f1 = new Font(font, Font.PLAIN, j);85Font f2 = new Font(font, Font.BOLD, j);86Font f3 = new Font(font, Font.ITALIC, j);87Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j);8889intf.setFont(f1);90intf.setFont(f2);91intf.setFont(f3);92intf.setFont(f4);9394intf.getFontMetrics(f1);95intf.getFontMetrics(f2);96intf.getFontMetrics(f3);97intf.getFontMetrics(f4);98}99}100intf.enable();101intf.disable();102intf.reshape(10, 10, 10, 10);103intf.getBounds(new Rectangle(1, 1, 1, 1));104intf.getSize(new Dimension(1, 2));105intf.getLocation(new Point(1, 2));106intf.getX();107intf.getY();108intf.getWidth();109intf.getHeight();110intf.isOpaque();111intf.isValidateRoot();112intf.isOptimizedDrawingEnabled();113intf.isDoubleBuffered();114intf.getComponentCount();115intf.countComponents();116intf.getComponent(0);117Component[] cs = intf.getComponents();118intf.getLayout();119intf.setLayout(new FlowLayout());120intf.doLayout();121intf.layout();122intf.invalidate();123intf.validate();124intf.remove(0);125intf.remove(c2);126intf.removeAll();127intf.preferredSize();128intf.minimumSize();129intf.getComponentAt(1, 2);130intf.locate(1, 2);131intf.getComponentAt(new Point(1, 2));132intf.isFocusCycleRoot(new Container());133intf.transferFocusBackward();134intf.setName("goober");135intf.getName();136intf.getParent();137intf.getPeer();138intf.getGraphicsConfiguration();139intf.getTreeLock();140intf.getToolkit();141intf.isValid();142intf.isDisplayable();143intf.isVisible();144intf.isShowing();145intf.isEnabled();146intf.enable(false);147intf.enable(true);148intf.enableInputMethods(false);149intf.enableInputMethods(true);150intf.show();151intf.show(false);152intf.show(true);153intf.hide();154intf.getForeground();155intf.isForegroundSet();156intf.getBackground();157intf.isBackgroundSet();158intf.getFont();159intf.isFontSet();160Container c = new Container();161c.add(intf);162intf.getLocale();163for (Locale locale : Locale.getAvailableLocales())164intf.setLocale(locale);165166intf.getColorModel();167intf.getLocation();168169boolean exceptions = false;170try {171intf.getLocationOnScreen();172} catch (IllegalComponentStateException e) {173exceptions = true;174}175if (!exceptions)176throw new RuntimeException("IllegalComponentStateException did not occur when expected");177178intf.location();179intf.setLocation(1, 2);180intf.move(1, 2);181intf.setLocation(new Point(1, 2));182intf.getSize();183intf.size();184intf.setSize(1, 32);185intf.resize(1, 32);186intf.setSize(new Dimension(1, 32));187intf.resize(new Dimension(1, 32));188intf.getBounds();189intf.bounds();190intf.setBounds(10, 10, 10, 10);191intf.setBounds(new Rectangle(10, 10, 10, 10));192intf.isLightweight();193intf.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));194intf.getCursor();195intf.isCursorSet();196intf.inside(1, 2);197intf.contains(new Point(1, 2));198intf.isFocusable();199intf.setFocusable(true);200intf.setFocusable(false);201intf.transferFocus();202intf.getFocusCycleRootAncestor();203intf.nextFocus();204intf.transferFocusUpCycle();205intf.hasFocus();206intf.isFocusOwner();207intf.toString();208intf.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);209intf.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);210intf.setComponentOrientation(ComponentOrientation.UNKNOWN);211intf.getComponentOrientation();212}213}214215216