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