Path: blob/master/test/jdk/javax/swing/Headless/HeadlessJInternalFrame.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 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.getGraphicsConfiguration();138intf.getTreeLock();139intf.getToolkit();140intf.isValid();141intf.isDisplayable();142intf.isVisible();143intf.isShowing();144intf.isEnabled();145intf.enable(false);146intf.enable(true);147intf.enableInputMethods(false);148intf.enableInputMethods(true);149intf.show();150intf.show(false);151intf.show(true);152intf.hide();153intf.getForeground();154intf.isForegroundSet();155intf.getBackground();156intf.isBackgroundSet();157intf.getFont();158intf.isFontSet();159Container c = new Container();160c.add(intf);161intf.getLocale();162for (Locale locale : Locale.getAvailableLocales())163intf.setLocale(locale);164165intf.getColorModel();166intf.getLocation();167168boolean exceptions = false;169try {170intf.getLocationOnScreen();171} catch (IllegalComponentStateException e) {172exceptions = true;173}174if (!exceptions)175throw new RuntimeException("IllegalComponentStateException did not occur when expected");176177intf.location();178intf.setLocation(1, 2);179intf.move(1, 2);180intf.setLocation(new Point(1, 2));181intf.getSize();182intf.size();183intf.setSize(1, 32);184intf.resize(1, 32);185intf.setSize(new Dimension(1, 32));186intf.resize(new Dimension(1, 32));187intf.getBounds();188intf.bounds();189intf.setBounds(10, 10, 10, 10);190intf.setBounds(new Rectangle(10, 10, 10, 10));191intf.isLightweight();192intf.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));193intf.getCursor();194intf.isCursorSet();195intf.inside(1, 2);196intf.contains(new Point(1, 2));197intf.isFocusable();198intf.setFocusable(true);199intf.setFocusable(false);200intf.transferFocus();201intf.getFocusCycleRootAncestor();202intf.nextFocus();203intf.transferFocusUpCycle();204intf.hasFocus();205intf.isFocusOwner();206intf.toString();207intf.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);208intf.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);209intf.setComponentOrientation(ComponentOrientation.UNKNOWN);210intf.getComponentOrientation();211}212}213214215