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