1 /* 2 * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import javax.swing.*; 25 import java.awt.*; 26 import java.util.Locale; 27 28 /* 29 * @test 30 * @summary Check that JEditorPane constructors and methods do not throw unexpected 31 * exceptions in headless mode 32 * @run main/othervm -Djava.awt.headless=true HeadlessJEditorPane 33 */ 34 35 public class HeadlessJEditorPane { 36 public static void main(String args[]) { 37 JEditorPane b; 38 b = new JEditorPane("text/plain", "The Text"); 39 b = new JEditorPane("unknown/unknown", "The Text"); 40 b = new JEditorPane(); 41 b.getAccessibleContext(); 42 b.isFocusTraversable(); 43 b.setEnabled(false); 44 b.setEnabled(true); 45 b.requestFocus(); 46 b.requestFocusInWindow(); 47 b.getPreferredSize(); 48 b.getMaximumSize(); 49 b.getMinimumSize(); 50 b.contains(1, 2); 51 Component c1 = b.add(new Component(){}); 52 Component c2 = b.add(new Component(){}); 53 Component c3 = b.add(new Component(){}); 54 Insets ins = b.getInsets(); 55 b.getAlignmentY(); 56 b.getAlignmentX(); 57 b.getGraphics(); 58 b.setVisible(false); 59 b.setVisible(true); 60 b.setForeground(Color.red); 61 b.setBackground(Color.red); 62 for (String font : Toolkit.getDefaultToolkit().getFontList()) { 63 for (int j = 8; j < 17; j++) { 64 Font f1 = new Font(font, Font.PLAIN, j); 65 Font f2 = new Font(font, Font.BOLD, j); 66 Font f3 = new Font(font, Font.ITALIC, j); 67 Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j); 68 69 b.setFont(f1); 70 b.setFont(f2); 71 b.setFont(f3); 72 b.setFont(f4); 73 74 b.getFontMetrics(f1); 75 b.getFontMetrics(f2); 76 b.getFontMetrics(f3); 77 b.getFontMetrics(f4); 78 } 79 } 80 b.enable(); 81 b.disable(); 82 b.reshape(10, 10, 10, 10); 83 b.getBounds(new Rectangle(1, 1, 1, 1)); 84 b.getSize(new Dimension(1, 2)); 85 b.getLocation(new Point(1, 2)); 86 b.getX(); 87 b.getY(); 88 b.getWidth(); 89 b.getHeight(); 90 b.isOpaque(); 91 b.isValidateRoot(); 92 b.isOptimizedDrawingEnabled(); 93 b.isDoubleBuffered(); 94 b.getComponentCount(); 95 b.countComponents(); 96 b.getComponent(1); 97 b.getComponent(2); 98 Component[] cs = b.getComponents(); 99 b.getLayout(); 100 b.setLayout(new FlowLayout()); 101 b.doLayout(); 102 b.layout(); 103 b.invalidate(); 104 b.validate(); 105 b.remove(0); 106 b.remove(c2); 107 b.removeAll(); 108 b.preferredSize(); 109 b.minimumSize(); 110 b.getComponentAt(1, 2); 111 b.locate(1, 2); 112 b.getComponentAt(new Point(1, 2)); 113 b.isFocusCycleRoot(new Container()); 114 b.transferFocusBackward(); 115 b.setName("goober"); 116 b.getName(); 117 b.getParent(); 118 b.getPeer(); 119 b.getGraphicsConfiguration(); 120 b.getTreeLock(); 121 b.getToolkit(); 122 b.isValid(); 123 b.isDisplayable(); 124 b.isVisible(); 125 b.isShowing(); 126 b.isEnabled(); 127 b.enable(false); 128 b.enable(true); 129 b.enableInputMethods(false); 130 b.enableInputMethods(true); 131 b.show(); 132 b.show(false); 133 b.show(true); 134 b.hide(); 135 b.getForeground(); 136 b.isForegroundSet(); 137 b.getBackground(); 138 b.isBackgroundSet(); 139 b.getFont(); 140 b.isFontSet(); 141 Container c = new Container(); 142 c.add(b); 143 b.getLocale(); 144 for (Locale locale : Locale.getAvailableLocales()) 145 b.setLocale(locale); 146 147 b.getColorModel(); 148 b.getLocation(); 149 150 boolean exceptions = false; 151 try { 152 b.getLocationOnScreen(); 153 } catch (IllegalComponentStateException e) { 154 exceptions = true; 155 } 156 if (!exceptions) 157 throw new RuntimeException("IllegalComponentStateException did not occur when expected"); 158 159 b.location(); 160 b.setLocation(1, 2); 161 b.move(1, 2); 162 b.setLocation(new Point(1, 2)); 163 b.getSize(); 164 b.size(); 165 b.setSize(1, 32); 166 b.resize(1, 32); 167 b.setSize(new Dimension(1, 32)); 168 b.resize(new Dimension(1, 32)); 169 b.getBounds(); 170 b.bounds(); 171 b.setBounds(10, 10, 10, 10); 172 b.setBounds(new Rectangle(10, 10, 10, 10)); 173 b.isLightweight(); 174 b.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); 175 b.getCursor(); 176 b.isCursorSet(); 177 b.inside(1, 2); 178 b.contains(new Point(1, 2)); 179 b.isFocusable(); 180 b.setFocusable(true); 181 b.setFocusable(false); 182 b.transferFocus(); 183 b.getFocusCycleRootAncestor(); 184 b.nextFocus(); 185 b.transferFocusUpCycle(); 186 b.hasFocus(); 187 b.isFocusOwner(); 188 b.toString(); 189 b.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); 190 b.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 191 b.setComponentOrientation(ComponentOrientation.UNKNOWN); 192 b.getComponentOrientation(); 193 } 194 }