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